Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Definitions to target GDB to a merlin under utek 2.1 |
fbcb5095 | 2 | Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc. |
dd3b648e RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
99a7de40 | 6 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 7 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
dd3b648e | 10 | |
99a7de40 | 11 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e RP |
19 | |
20 | #define TARGET_BYTE_ORDER LITTLE_ENDIAN | |
21 | ||
22 | /* I don't know if this will work for cross-debugging, even if you do get | |
23 | a copy of the right include file. */ | |
24 | #include <machine/reg.h> | |
25 | ||
26 | /* Define this if the C compiler puts an underscore at the front | |
27 | of external names before giving them to the linker. */ | |
28 | ||
29 | #define NAMES_HAVE_UNDERSCORE | |
30 | ||
dd3b648e RP |
31 | /* Offset from address of function to start of its code. |
32 | Zero on most machines. */ | |
33 | ||
34 | #define FUNCTION_START_OFFSET 0 | |
35 | ||
36 | /* Advance PC across any function entry prologue instructions | |
37 | to reach some "real" code. */ | |
38 | ||
39 | #define SKIP_PROLOGUE(pc) \ | |
40 | { register int op = read_memory_integer (pc, 1); \ | |
41 | if (op == 0x82) \ | |
42 | { op = read_memory_integer (pc+2,1); \ | |
43 | if ((op & 0x80) == 0) pc += 3; \ | |
44 | else if ((op & 0xc0) == 0x80) pc += 4; \ | |
45 | else pc += 6; \ | |
46 | }} | |
47 | ||
48 | /* Immediately after a function call, return the saved pc. | |
49 | Can't always go through the frames for this because on some machines | |
50 | the new frame is not set up until the new function executes | |
51 | some instructions. */ | |
52 | ||
53 | #define SAVED_PC_AFTER_CALL(frame) \ | |
54 | read_memory_integer (read_register (SP_REGNUM), 4) | |
55 | ||
56 | /* Address of end of stack space. */ | |
57 | ||
58 | #define STACK_END_ADDR (0x800000) | |
59 | ||
60 | /* Stack grows downward. */ | |
61 | ||
62 | #define INNER_THAN < | |
63 | ||
64 | /* Sequence of bytes for breakpoint instruction. */ | |
65 | ||
66 | #define BREAKPOINT {0xf2} | |
67 | ||
68 | /* Amount PC must be decremented by after a breakpoint. | |
69 | This is often the number of bytes in BREAKPOINT | |
70 | but not always. */ | |
71 | ||
72 | #define DECR_PC_AFTER_BREAK 0 | |
73 | ||
74 | /* Nonzero if instruction at PC is a return instruction. */ | |
75 | ||
76 | #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0x12) | |
77 | ||
78 | /* Return 1 if P points to an invalid floating point value. */ | |
79 | ||
80 | #define INVALID_FLOAT(p, len) 0 | |
81 | ||
82 | /* Define this to say that the "svc" insn is followed by | |
83 | codes in memory saying which kind of system call it is. */ | |
84 | ||
85 | #define NS32K_SVC_IMMED_OPERANDS | |
86 | ||
87 | /* Say how long (ordinary) registers are. */ | |
88 | ||
89 | #define REGISTER_TYPE long | |
90 | ||
91 | /* Number of machine registers */ | |
92 | ||
93 | #define NUM_REGS 25 | |
94 | ||
95 | #define NUM_GENERAL_REGS 8 | |
96 | ||
97 | /* Initializer for an array of names of registers. | |
98 | There should be NUM_REGS strings in this initializer. */ | |
99 | ||
100 | #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \ | |
101 | "pc", "sp", "fp", "ps", \ | |
102 | "fsr", \ | |
103 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \ | |
104 | "l0", "l1", "l2", "l3", "l4", \ | |
105 | } | |
106 | ||
107 | /* Register numbers of various important registers. | |
108 | Note that some of these values are "real" register numbers, | |
109 | and correspond to the general registers of the machine, | |
110 | and some are "phony" register numbers which are too large | |
111 | to be actual register numbers as far as the user is concerned | |
112 | but do serve to get the desired values when passed to read_register. */ | |
113 | ||
114 | #define AP_REGNUM FP_REGNUM | |
115 | #define FP_REGNUM 10 /* Contains address of executing stack frame */ | |
116 | #define SP_REGNUM 9 /* Contains address of top of stack */ | |
117 | #define PC_REGNUM 8 /* Contains program counter */ | |
118 | #define PS_REGNUM 11 /* Contains processor status */ | |
119 | #define FPS_REGNUM 12 /* Floating point status register */ | |
120 | #define FP0_REGNUM 13 /* Floating point register 0 */ | |
121 | #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */ | |
122 | ||
123 | /* Total amount of space needed to store our copies of the machine's | |
124 | register state, the array `registers'. */ | |
125 | #define REGISTER_BYTES ((NUM_REGS - 4) * sizeof (int) + 4 * sizeof (double)) | |
126 | ||
127 | /* Index within `registers' of the first byte of the space for | |
128 | register N. */ | |
129 | ||
130 | #define REGISTER_BYTE(N) ((N) >= LP0_REGNUM ? \ | |
131 | LP0_REGNUM * 4 + ((N) - LP0_REGNUM) * 8 : (N) * 4) | |
132 | ||
133 | /* Number of bytes of storage in the actual machine representation | |
134 | for register N. On the 32000, all regs are 4 bytes | |
135 | except for the doubled floating registers. */ | |
136 | ||
137 | #define REGISTER_RAW_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4) | |
138 | ||
139 | /* Number of bytes of storage in the program's representation | |
140 | for register N. On the 32000, all regs are 4 bytes | |
141 | except for the doubled floating registers. */ | |
142 | ||
143 | #define REGISTER_VIRTUAL_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4) | |
144 | ||
145 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
146 | ||
147 | #define MAX_REGISTER_RAW_SIZE 8 | |
148 | ||
149 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
150 | ||
151 | #define MAX_REGISTER_VIRTUAL_SIZE 8 | |
152 | ||
153 | /* Nonzero if register N requires conversion | |
154 | from raw format to virtual format. */ | |
155 | ||
156 | #define REGISTER_CONVERTIBLE(N) 0 | |
157 | ||
158 | /* Convert data from raw format for register REGNUM | |
159 | to virtual format for register REGNUM. */ | |
160 | ||
161 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \ | |
162 | bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM)); | |
163 | ||
164 | /* Convert data from virtual format for register REGNUM | |
165 | to raw format for register REGNUM. */ | |
166 | ||
167 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \ | |
168 | bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM)); | |
169 | ||
170 | /* Return the GDB type object for the "standard" data type | |
171 | of data in register N. */ | |
172 | ||
173 | #define REGISTER_VIRTUAL_TYPE(N) \ | |
174 | ((N) >= FP0_REGNUM ? \ | |
175 | ((N) >= LP0_REGNUM ? \ | |
176 | builtin_type_double \ | |
177 | : builtin_type_float) \ | |
178 | : builtin_type_int) | |
179 | ||
180 | /* Store the address of the place in which to copy the structure the | |
181 | subroutine will return. This is called from call_function. | |
182 | ||
183 | On this machine this is a no-op, as gcc doesn't run on it yet. | |
184 | This calling convention is not used. */ | |
185 | ||
186 | #define STORE_STRUCT_RETURN(ADDR, SP) | |
187 | ||
188 | /* Extract from an array REGBUF containing the (raw) register state | |
189 | a function return value of type TYPE, and copy that, in virtual format, | |
190 | into VALBUF. */ | |
191 | ||
192 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
193 | bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE)) | |
194 | ||
195 | /* Write into appropriate registers a function return value | |
196 | of type TYPE, given in virtual format. */ | |
197 | ||
198 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
199 | write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) | |
200 | ||
201 | /* Extract from an array REGBUF containing the (raw) register state | |
202 | the address in which a function should return its structure value, | |
203 | as a CORE_ADDR (or an expression that can be used as one). */ | |
204 | ||
205 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) | |
206 | \f | |
207 | /* Describe the pointer in each stack frame to the previous stack frame | |
208 | (its caller). */ | |
209 | ||
210 | /* FRAME_CHAIN takes a frame's nominal address | |
211 | and produces the frame's chain-pointer. | |
212 | ||
dd3b648e | 213 | However, if FRAME_CHAIN_VALID returns zero, |
e140f1da | 214 | it means the given frame is the outermost one and has no caller. */ |
dd3b648e RP |
215 | |
216 | /* In the case of the Merlin, the frame's nominal address is the FP value, | |
217 | and at that address is saved previous FP value as a 4-byte word. */ | |
218 | ||
219 | #define FRAME_CHAIN(thisframe) \ | |
220 | (outside_startup_file ((thisframe)->pc) ? \ | |
221 | read_memory_integer ((thisframe)->frame, 4) :\ | |
222 | 0) | |
223 | ||
224 | #define FRAME_CHAIN_VALID(chain, thisframe) \ | |
225 | (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe)))) | |
226 | ||
dd3b648e RP |
227 | /* Define other aspects of the stack frame. */ |
228 | ||
229 | #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) | |
230 | ||
231 | /* compute base of arguments */ | |
232 | #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame) | |
233 | ||
234 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) | |
235 | ||
236 | /* Return number of args passed to a frame. | |
237 | Can return -1, meaning no way to tell. */ | |
238 | ||
239 | #define FRAME_NUM_ARGS(numargs, fi) \ | |
240 | { CORE_ADDR pc; \ | |
241 | int insn; \ | |
242 | int addr_mode; \ | |
243 | int width; \ | |
244 | \ | |
245 | pc = FRAME_SAVED_PC (fi); \ | |
246 | insn = read_memory_integer (pc,2); \ | |
247 | addr_mode = (insn >> 11) & 0x1f; \ | |
248 | insn = insn & 0x7ff; \ | |
249 | if ((insn & 0x7fc) == 0x57c \ | |
250 | && addr_mode == 0x14) /* immediate */ \ | |
251 | { if (insn == 0x57c) /* adjspb */ \ | |
252 | width = 1; \ | |
253 | else if (insn == 0x57d) /* adjspw */ \ | |
254 | width = 2; \ | |
255 | else if (insn == 0x57f) /* adjspd */ \ | |
256 | width = 4; \ | |
257 | numargs = read_memory_integer (pc+2,width); \ | |
258 | if (width > 1) \ | |
259 | flip_bytes (&numargs, width); \ | |
260 | numargs = - sign_extend (numargs, width*8) / 4; } \ | |
261 | else numargs = -1; \ | |
262 | } | |
263 | ||
264 | /* Return number of bytes at start of arglist that are not really args. */ | |
265 | ||
266 | #define FRAME_ARGS_SKIP 8 | |
267 | ||
268 | /* Put here the code to store, into a struct frame_saved_regs, | |
269 | the addresses of the saved registers of frame described by FRAME_INFO. | |
270 | This includes special registers such as pc and fp saved in special | |
271 | ways in the stack frame. sp is even more special: | |
272 | the address we return for it IS the sp for the next frame. */ | |
273 | ||
274 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ | |
275 | { int regmask,regnum; \ | |
276 | int localcount; \ | |
277 | CORE_ADDR enter_addr; \ | |
278 | CORE_ADDR next_addr; \ | |
279 | \ | |
280 | enter_addr = get_pc_function_start ((frame_info)->pc); \ | |
281 | regmask = read_memory_integer (enter_addr+1, 1); \ | |
282 | localcount = ns32k_localcount (enter_addr); \ | |
283 | next_addr = (frame_info)->frame + localcount; \ | |
284 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \ | |
285 | (frame_saved_regs).regs[regnum] \ | |
286 | = (regmask & 1) ? (next_addr -= 4) : 0; \ | |
287 | (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4; \ | |
288 | (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4; \ | |
289 | (frame_saved_regs).regs[FP_REGNUM] \ | |
290 | = read_memory_integer ((frame_info)->frame, 4); } | |
291 | ||
292 | \f | |
293 | /* Things needed for making the inferior call functions. */ | |
294 | ||
295 | /* Push an empty stack frame, to record the current PC, etc. */ | |
296 | ||
297 | #define PUSH_DUMMY_FRAME \ | |
298 | { register CORE_ADDR sp = read_register (SP_REGNUM); \ | |
299 | register int regnum; \ | |
300 | sp = push_word (sp, read_register (PC_REGNUM)); \ | |
301 | sp = push_word (sp, read_register (FP_REGNUM)); \ | |
302 | write_register (FP_REGNUM, sp); \ | |
303 | for (regnum = 0; regnum < 8; regnum++) \ | |
304 | sp = push_word (sp, read_register (regnum)); \ | |
305 | write_register (SP_REGNUM, sp); \ | |
306 | } | |
307 | ||
308 | /* Discard from the stack the innermost frame, restoring all registers. */ | |
309 | ||
310 | #define POP_FRAME \ | |
311 | { register FRAME frame = get_current_frame (); \ | |
312 | register CORE_ADDR fp; \ | |
313 | register int regnum; \ | |
314 | struct frame_saved_regs fsr; \ | |
315 | struct frame_info *fi; \ | |
316 | fi = get_frame_info (frame); \ | |
317 | fp = fi->frame; \ | |
318 | get_frame_saved_regs (fi, &fsr); \ | |
319 | for (regnum = 0; regnum < 8; regnum++) \ | |
320 | if (fsr.regs[regnum]) \ | |
321 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \ | |
322 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); \ | |
323 | write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \ | |
324 | write_register (SP_REGNUM, fp + 8); \ | |
325 | flush_cached_frames (); \ | |
326 | set_current_frame (create_new_frame (read_register (FP_REGNUM),\ | |
327 | read_pc ())); \ | |
328 | } | |
329 | ||
330 | /* This sequence of words is the instructions | |
331 | enter 0xff,0 82 ff 00 | |
332 | jsr @0x00010203 7f ae c0 01 02 03 | |
333 | adjspd 0x69696969 7f a5 01 02 03 04 | |
334 | bpt f2 | |
335 | Note this is 16 bytes. */ | |
336 | ||
337 | #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 } | |
338 | ||
339 | #define CALL_DUMMY_START_OFFSET 3 | |
340 | #define CALL_DUMMY_LENGTH 16 | |
341 | #define CALL_DUMMY_ADDR 5 | |
342 | #define CALL_DUMMY_NARGS 11 | |
343 | ||
344 | /* Insert the specified number of args and function address | |
345 | into a call sequence of the above form stored at DUMMYNAME. */ | |
346 | ||
347 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
348 | { int flipped = fun | 0xc0000000; \ | |
349 | flip_bytes (&flipped, 4); \ | |
350 | *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \ | |
351 | flipped = - nargs * 4; \ | |
352 | flip_bytes (&flipped, 4); \ | |
353 | *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \ | |
354 | } |