1 /* Definitions to target GDB to a merlin under utek 2.1
2 Copyright 1986, 1987, 1989, 1991, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #define TARGET_BYTE_ORDER LITTLE_ENDIAN
22 /* Offset from address of function to start of its code.
23 Zero on most machines. */
25 #define FUNCTION_START_OFFSET 0
27 /* Advance PC across any function entry prologue instructions
28 to reach some "real" code. */
30 #define SKIP_PROLOGUE(pc) \
31 { register int op = read_memory_integer (pc, 1); \
33 { op = read_memory_integer (pc+2,1); \
34 if ((op & 0x80) == 0) pc += 3; \
35 else if ((op & 0xc0) == 0x80) pc += 4; \
39 /* Immediately after a function call, return the saved pc.
40 Can't always go through the frames for this because on some machines
41 the new frame is not set up until the new function executes
44 #define SAVED_PC_AFTER_CALL(frame) \
45 read_memory_integer (read_register (SP_REGNUM), 4)
47 /* Address of end of stack space. */
49 #define STACK_END_ADDR (0x800000)
51 /* Stack grows downward. */
55 /* Sequence of bytes for breakpoint instruction. */
57 #define BREAKPOINT {0xf2}
59 /* Amount PC must be decremented by after a breakpoint.
60 This is often the number of bytes in BREAKPOINT
63 #define DECR_PC_AFTER_BREAK 0
65 /* Nonzero if instruction at PC is a return instruction. */
67 #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0x12)
69 /* Return 1 if P points to an invalid floating point value. */
71 #define INVALID_FLOAT(p, len) 0
73 /* Define this to say that the "svc" insn is followed by
74 codes in memory saying which kind of system call it is. */
76 #define NS32K_SVC_IMMED_OPERANDS
78 /* Say how long (ordinary) registers are. */
80 #define REGISTER_TYPE long
82 /* Number of machine registers */
86 #define NUM_GENERAL_REGS 8
88 /* Initializer for an array of names of registers.
89 There should be NUM_REGS strings in this initializer. */
91 #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
92 "pc", "sp", "fp", "ps", \
94 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
95 "l0", "l1", "l2", "l3", "l4", \
98 /* Register numbers of various important registers.
99 Note that some of these values are "real" register numbers,
100 and correspond to the general registers of the machine,
101 and some are "phony" register numbers which are too large
102 to be actual register numbers as far as the user is concerned
103 but do serve to get the desired values when passed to read_register. */
105 #define AP_REGNUM FP_REGNUM
106 #define FP_REGNUM 10 /* Contains address of executing stack frame */
107 #define SP_REGNUM 9 /* Contains address of top of stack */
108 #define PC_REGNUM 8 /* Contains program counter */
109 #define PS_REGNUM 11 /* Contains processor status */
110 #define FPS_REGNUM 12 /* Floating point status register */
111 #define FP0_REGNUM 13 /* Floating point register 0 */
112 #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */
114 /* Total amount of space needed to store our copies of the machine's
115 register state, the array `registers'. */
116 #define REGISTER_BYTES ((NUM_REGS - 4) * sizeof (int) + 4 * sizeof (double))
118 /* Index within `registers' of the first byte of the space for
121 #define REGISTER_BYTE(N) ((N) >= LP0_REGNUM ? \
122 LP0_REGNUM * 4 + ((N) - LP0_REGNUM) * 8 : (N) * 4)
124 /* Number of bytes of storage in the actual machine representation
125 for register N. On the 32000, all regs are 4 bytes
126 except for the doubled floating registers. */
128 #define REGISTER_RAW_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
130 /* Number of bytes of storage in the program's representation
131 for register N. On the 32000, all regs are 4 bytes
132 except for the doubled floating registers. */
134 #define REGISTER_VIRTUAL_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4)
136 /* Largest value REGISTER_RAW_SIZE can have. */
138 #define MAX_REGISTER_RAW_SIZE 8
140 /* Largest value REGISTER_VIRTUAL_SIZE can have. */
142 #define MAX_REGISTER_VIRTUAL_SIZE 8
144 /* Nonzero if register N requires conversion
145 from raw format to virtual format. */
147 #define REGISTER_CONVERTIBLE(N) 0
149 /* Convert data from raw format for register REGNUM
150 to virtual format for register REGNUM. */
152 #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
153 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
155 /* Convert data from virtual format for register REGNUM
156 to raw format for register REGNUM. */
158 #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
159 bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM));
161 /* Return the GDB type object for the "standard" data type
162 of data in register N. */
164 #define REGISTER_VIRTUAL_TYPE(N) \
165 ((N) >= FP0_REGNUM ? \
166 ((N) >= LP0_REGNUM ? \
167 builtin_type_double \
168 : builtin_type_float) \
171 /* Store the address of the place in which to copy the structure the
172 subroutine will return. This is called from call_function.
174 On this machine this is a no-op, as gcc doesn't run on it yet.
175 This calling convention is not used. */
177 #define STORE_STRUCT_RETURN(ADDR, SP)
179 /* Extract from an array REGBUF containing the (raw) register state
180 a function return value of type TYPE, and copy that, in virtual format,
183 #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
184 bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
186 /* Write into appropriate registers a function return value
187 of type TYPE, given in virtual format. */
189 #define STORE_RETURN_VALUE(TYPE,VALBUF) \
190 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
192 /* Extract from an array REGBUF containing the (raw) register state
193 the address in which a function should return its structure value,
194 as a CORE_ADDR (or an expression that can be used as one). */
196 #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
198 /* Describe the pointer in each stack frame to the previous stack frame
201 /* FRAME_CHAIN takes a frame's nominal address
202 and produces the frame's chain-pointer. */
204 /* In the case of the Merlin, the frame's nominal address is the FP value,
205 and at that address is saved previous FP value as a 4-byte word. */
207 #define FRAME_CHAIN(thisframe) \
208 (!inside_entry_file ((thisframe)->pc) ? \
209 read_memory_integer ((thisframe)->frame, 4) :\
212 /* Define other aspects of the stack frame. */
214 #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
216 /* compute base of arguments */
217 #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
219 #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
221 /* Return number of args passed to a frame.
222 Can return -1, meaning no way to tell. */
224 #define FRAME_NUM_ARGS(numargs, fi) \
230 pc = FRAME_SAVED_PC (fi); \
231 insn = read_memory_integer (pc,2); \
232 addr_mode = (insn >> 11) & 0x1f; \
233 insn = insn & 0x7ff; \
234 if ((insn & 0x7fc) == 0x57c \
235 && addr_mode == 0x14) /* immediate */ \
236 { if (insn == 0x57c) /* adjspb */ \
238 else if (insn == 0x57d) /* adjspw */ \
240 else if (insn == 0x57f) /* adjspd */ \
242 numargs = read_memory_integer (pc+2,width); \
244 flip_bytes (&numargs, width); \
245 numargs = - sign_extend (numargs, width*8) / 4; } \
249 /* Return number of bytes at start of arglist that are not really args. */
251 #define FRAME_ARGS_SKIP 8
253 /* Put here the code to store, into a struct frame_saved_regs,
254 the addresses of the saved registers of frame described by FRAME_INFO.
255 This includes special registers such as pc and fp saved in special
256 ways in the stack frame. sp is even more special:
257 the address we return for it IS the sp for the next frame. */
259 #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
260 { int regmask,regnum; \
262 CORE_ADDR enter_addr; \
263 CORE_ADDR next_addr; \
265 enter_addr = get_pc_function_start ((frame_info)->pc); \
266 regmask = read_memory_integer (enter_addr+1, 1); \
267 localcount = ns32k_localcount (enter_addr); \
268 next_addr = (frame_info)->frame + localcount; \
269 for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \
270 (frame_saved_regs).regs[regnum] \
271 = (regmask & 1) ? (next_addr -= 4) : 0; \
272 (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4; \
273 (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4; \
274 (frame_saved_regs).regs[FP_REGNUM] \
275 = read_memory_integer ((frame_info)->frame, 4); }
278 /* Things needed for making the inferior call functions. */
280 /* Push an empty stack frame, to record the current PC, etc. */
282 #define PUSH_DUMMY_FRAME \
283 { register CORE_ADDR sp = read_register (SP_REGNUM); \
284 register int regnum; \
285 sp = push_word (sp, read_register (PC_REGNUM)); \
286 sp = push_word (sp, read_register (FP_REGNUM)); \
287 write_register (FP_REGNUM, sp); \
288 for (regnum = 0; regnum < 8; regnum++) \
289 sp = push_word (sp, read_register (regnum)); \
290 write_register (SP_REGNUM, sp); \
293 /* Discard from the stack the innermost frame, restoring all registers. */
296 { register FRAME frame = get_current_frame (); \
297 register CORE_ADDR fp; \
298 register int regnum; \
299 struct frame_saved_regs fsr; \
300 struct frame_info *fi; \
301 fi = get_frame_info (frame); \
303 get_frame_saved_regs (fi, &fsr); \
304 for (regnum = 0; regnum < 8; regnum++) \
305 if (fsr.regs[regnum]) \
306 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
307 write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
308 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
309 write_register (SP_REGNUM, fp + 8); \
310 flush_cached_frames (); \
311 set_current_frame (create_new_frame (read_register (FP_REGNUM),\
315 /* This sequence of words is the instructions
316 enter 0xff,0 82 ff 00
317 jsr @0x00010203 7f ae c0 01 02 03
318 adjspd 0x69696969 7f a5 01 02 03 04
320 Note this is 16 bytes. */
322 #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 }
324 #define CALL_DUMMY_START_OFFSET 3
325 #define CALL_DUMMY_LENGTH 16
326 #define CALL_DUMMY_ADDR 5
327 #define CALL_DUMMY_NARGS 11
329 /* Insert the specified number of args and function address
330 into a call sequence of the above form stored at DUMMYNAME. */
332 #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \
333 { int flipped = fun | 0xc0000000; \
334 flip_bytes (&flipped, 4); \
335 *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \
336 flipped = - nargs * 4; \
337 flip_bytes (&flipped, 4); \
338 *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \