]>
Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Definitions to make GDB run on an encore under umax 4.2 |
fbcb5095 | 2 | Copyright (C) 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 | /* Define this if the C compiler puts an underscore at the front | |
23 | of external names before giving them to the linker. */ | |
24 | ||
25 | #define NAMES_HAVE_UNDERSCORE | |
26 | ||
dd3b648e RP |
27 | /* Need to get function ends by adding this to epilogue address from .bf |
28 | record, not using x_fsize field. */ | |
29 | #define FUNCTION_EPILOGUE_SIZE 4 | |
30 | ||
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 unsigned char op = read_memory_integer (pc, 1); \ | |
41 | if (op == 0x82) { op = read_memory_integer (pc+2,1); \ | |
42 | if ((op & 0x80) == 0) pc += 3; \ | |
43 | else if ((op & 0xc0) == 0x80) pc += 4; \ | |
44 | else pc += 6; \ | |
45 | } \ | |
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 (0xfffff000) | |
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 | #ifndef NaN | |
79 | #include <nan.h> | |
80 | #endif NaN | |
81 | ||
82 | /* Return 1 if P points to an invalid floating point value. */ | |
83 | /* Surely wrong for cross-debugging. */ | |
84 | #define INVALID_FLOAT(p, s) \ | |
85 | ((s == sizeof (float))? \ | |
86 | NaF (*(float *) p) : \ | |
87 | NaD (*(double *) p)) | |
88 | ||
89 | /* Say how long (ordinary) registers are. */ | |
90 | ||
91 | #define REGISTER_TYPE long | |
92 | ||
93 | /* Number of machine registers */ | |
94 | ||
95 | #define NUM_REGS 25 | |
96 | ||
97 | #define NUM_GENERAL_REGS 8 | |
98 | ||
99 | /* Initializer for an array of names of registers. | |
100 | There should be NUM_REGS strings in this initializer. */ | |
101 | ||
102 | #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \ | |
103 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \ | |
104 | "sp", "fp", "pc", "ps", \ | |
105 | "fsr", \ | |
106 | "l0", "l1", "l2", "l3", "xx", \ | |
107 | } | |
108 | ||
109 | /* Register numbers of various important registers. | |
110 | Note that some of these values are "real" register numbers, | |
111 | and correspond to the general registers of the machine, | |
112 | and some are "phony" register numbers which are too large | |
113 | to be actual register numbers as far as the user is concerned | |
114 | but do serve to get the desired values when passed to read_register. */ | |
115 | ||
116 | #define FP0_REGNUM 8 /* Floating point register 0 */ | |
117 | #define SP_REGNUM 16 /* Contains address of top of stack */ | |
118 | #define AP_REGNUM FP_REGNUM | |
119 | #define FP_REGNUM 17 /* Contains address of executing stack frame */ | |
120 | #define PC_REGNUM 18 /* Contains program counter */ | |
121 | #define PS_REGNUM 19 /* Contains processor status */ | |
122 | #define FPS_REGNUM 20 /* Floating point status register */ | |
123 | #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */ | |
124 | ||
125 | /* Total amount of space needed to store our copies of the machine's | |
126 | register state, the array `registers'. */ | |
127 | #define REGISTER_BYTES ((NUM_REGS - 4) * sizeof (int) + 4 * sizeof (double)) | |
128 | ||
129 | /* Index within `registers' of the first byte of the space for | |
130 | register N. */ | |
131 | ||
132 | #define REGISTER_BYTE(N) ((N) >= LP0_REGNUM ? \ | |
133 | LP0_REGNUM * 4 + ((N) - LP0_REGNUM) * 8 : (N) * 4) | |
134 | ||
135 | /* Number of bytes of storage in the actual machine representation | |
136 | for register N. On the 32000, all regs are 4 bytes | |
137 | except for the doubled floating registers. */ | |
138 | ||
139 | #define REGISTER_RAW_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4) | |
140 | ||
141 | /* Number of bytes of storage in the program's representation | |
142 | for register N. On the 32000, all regs are 4 bytes | |
143 | except for the doubled floating registers. */ | |
144 | ||
145 | #define REGISTER_VIRTUAL_SIZE(N) ((N) >= LP0_REGNUM ? 8 : 4) | |
146 | ||
147 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
148 | ||
149 | #define MAX_REGISTER_RAW_SIZE 8 | |
150 | ||
151 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
152 | ||
153 | #define MAX_REGISTER_VIRTUAL_SIZE 8 | |
154 | ||
155 | /* Nonzero if register N requires conversion | |
156 | from raw format to virtual format. */ | |
157 | ||
158 | #define REGISTER_CONVERTIBLE(N) 0 | |
159 | ||
160 | /* Convert data from raw format for register REGNUM | |
161 | to virtual format for register REGNUM. */ | |
162 | ||
163 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \ | |
164 | bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM)); | |
165 | ||
166 | /* Convert data from virtual format for register REGNUM | |
167 | to raw format for register REGNUM. */ | |
168 | ||
169 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \ | |
170 | bcopy ((FROM), (TO), REGISTER_VIRTUAL_SIZE(REGNUM)); | |
171 | ||
172 | /* Return the GDB type object for the "standard" data type | |
173 | of data in register N. */ | |
174 | ||
175 | #define REGISTER_VIRTUAL_TYPE(N) \ | |
176 | (((N) < FP0_REGNUM) ? \ | |
177 | builtin_type_int : \ | |
178 | ((N) < FP0_REGNUM + 8) ? \ | |
179 | builtin_type_float : \ | |
180 | ((N) < LP0_REGNUM) ? \ | |
181 | builtin_type_int : \ | |
182 | builtin_type_double) | |
183 | ||
184 | /* Store the address of the place in which to copy the structure the | |
185 | subroutine will return. This is called from call_function. | |
186 | ||
187 | On this machine this is a no-op, because gcc isn't used on it | |
188 | yet. So this calling convention is not used. */ | |
189 | ||
190 | #define STORE_STRUCT_RETURN(ADDR, SP) | |
191 | ||
192 | /* Extract from an array REGBUF containing the (raw) register state | |
193 | a function return value of type TYPE, and copy that, in virtual format, | |
194 | into VALBUF. */ | |
195 | ||
196 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
197 | bcopy (REGBUF+REGISTER_BYTE (TYPE_CODE (TYPE) == TYPE_CODE_FLT ? FP0_REGNUM : 0), VALBUF, TYPE_LENGTH (TYPE)) | |
198 | ||
199 | /* Write into appropriate registers a function return value | |
200 | of type TYPE, given in virtual format. */ | |
201 | ||
202 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
203 | write_register_bytes (REGISTER_BYTE (TYPE_CODE (TYPE) == TYPE_CODE_FLT ? FP0_REGNUM : 0), VALBUF, TYPE_LENGTH (TYPE)) | |
204 | ||
205 | /* Extract from an array REGBUF containing the (raw) register state | |
206 | the address in which a function should return its structure value, | |
207 | as a CORE_ADDR (or an expression that can be used as one). */ | |
208 | ||
209 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) | |
210 | \f | |
211 | /* Describe the pointer in each stack frame to the previous stack frame | |
212 | (its caller). */ | |
213 | ||
214 | /* FRAME_CHAIN takes a frame's nominal address | |
215 | and produces the frame's chain-pointer. | |
216 | ||
217 | FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address | |
218 | and produces the nominal address of the caller frame. | |
219 | ||
220 | However, if FRAME_CHAIN_VALID returns zero, | |
221 | it means the given frame is the outermost one and has no caller. | |
222 | In that case, FRAME_CHAIN_COMBINE is not used. */ | |
223 | ||
224 | /* In the case of the ns32000 series, the frame's nominal address is the FP | |
225 | value, and at that address is saved previous FP value as a 4-byte word. */ | |
226 | ||
227 | #define FRAME_CHAIN(thisframe) \ | |
228 | (outside_startup_file ((thisframe)->pc) ? \ | |
229 | read_memory_integer ((thisframe)->frame, 4) :\ | |
230 | 0) | |
231 | ||
232 | #define FRAME_CHAIN_VALID(chain, thisframe) \ | |
233 | (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe)))) | |
234 | ||
235 | #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) | |
236 | ||
237 | /* Define other aspects of the stack frame. */ | |
238 | ||
239 | #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) | |
240 | ||
241 | /* Compute base of arguments. */ | |
242 | ||
243 | #define FRAME_ARGS_ADDRESS(fi) \ | |
244 | ((ns32k_get_enter_addr ((fi)->pc) > 1) ? \ | |
245 | ((fi)->frame) : (read_register (SP_REGNUM) - 4)) | |
246 | ||
247 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) | |
248 | ||
249 | /* Get the address of the enter opcode for this function, if it is active. | |
250 | Returns positive address > 1 if pc is between enter/exit, | |
251 | 1 if pc before enter or after exit, 0 otherwise. */ | |
252 | ||
253 | #ifndef CORE_ADDR | |
254 | #include "defs.h" /* Make sure CORE_ADDR is defined. */ | |
255 | #endif | |
256 | ||
257 | extern CORE_ADDR ns32k_get_enter_addr (); | |
258 | ||
259 | /* Return number of args passed to a frame. | |
260 | Can return -1, meaning no way to tell. | |
261 | Encore's C compiler often reuses same area on stack for args, | |
262 | so this will often not work properly. If the arg names | |
263 | are known, it's likely most of them will be printed. */ | |
264 | ||
265 | #define FRAME_NUM_ARGS(numargs, fi) \ | |
266 | { CORE_ADDR pc; \ | |
267 | CORE_ADDR enter_addr; \ | |
268 | unsigned int insn; \ | |
269 | unsigned int addr_mode; \ | |
270 | int width; \ | |
271 | \ | |
272 | numargs = -1; \ | |
273 | enter_addr = ns32k_get_enter_addr ((fi)->pc); \ | |
274 | if (enter_addr > 0) \ | |
275 | { \ | |
276 | pc = (enter_addr == 1) ? \ | |
277 | SAVED_PC_AFTER_CALL (fi) : \ | |
278 | FRAME_SAVED_PC (fi); \ | |
279 | insn = read_memory_integer (pc,2); \ | |
280 | addr_mode = (insn >> 11) & 0x1f; \ | |
281 | insn = insn & 0x7ff; \ | |
282 | if ((insn & 0x7fc) == 0x57c && \ | |
283 | addr_mode == 0x14) /* immediate */ \ | |
284 | { \ | |
285 | if (insn == 0x57c) /* adjspb */ \ | |
286 | width = 1; \ | |
287 | else if (insn == 0x57d) /* adjspw */ \ | |
288 | width = 2; \ | |
289 | else if (insn == 0x57f) /* adjspd */ \ | |
290 | width = 4; \ | |
291 | numargs = read_memory_integer (pc+2,width); \ | |
292 | if (width > 1) \ | |
293 | flip_bytes (&numargs, width); \ | |
294 | numargs = - sign_extend (numargs, width*8) / 4;\ | |
295 | } \ | |
296 | } \ | |
297 | } | |
298 | ||
299 | /* Return number of bytes at start of arglist that are not really args. */ | |
300 | ||
301 | #define FRAME_ARGS_SKIP 8 | |
302 | ||
303 | /* Put here the code to store, into a struct frame_saved_regs, | |
304 | the addresses of the saved registers of frame described by FRAME_INFO. | |
305 | This includes special registers such as pc and fp saved in special | |
306 | ways in the stack frame. sp is even more special: | |
307 | the address we return for it IS the sp for the next frame. */ | |
308 | ||
309 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ | |
310 | { \ | |
311 | register int regmask, regnum; \ | |
312 | int localcount; \ | |
313 | register CORE_ADDR enter_addr; \ | |
314 | register CORE_ADDR next_addr; \ | |
315 | \ | |
316 | bzero (&(frame_saved_regs), sizeof (frame_saved_regs)); \ | |
317 | enter_addr = ns32k_get_enter_addr ((frame_info)->pc); \ | |
318 | if (enter_addr > 1) \ | |
319 | { \ | |
320 | regmask = read_memory_integer (enter_addr+1, 1) & 0xff; \ | |
321 | localcount = ns32k_localcount (enter_addr); \ | |
322 | next_addr = (frame_info)->frame + localcount; \ | |
323 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \ | |
324 | (frame_saved_regs).regs[regnum] = (regmask & 1) ? \ | |
325 | (next_addr -= 4) : 0; \ | |
326 | (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4;\ | |
327 | (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4;\ | |
328 | (frame_saved_regs).regs[FP_REGNUM] = \ | |
329 | (read_memory_integer ((frame_info)->frame, 4));\ | |
330 | } \ | |
331 | else if (enter_addr == 1) \ | |
332 | { \ | |
333 | CORE_ADDR sp = read_register (SP_REGNUM); \ | |
334 | (frame_saved_regs).regs[PC_REGNUM] = sp; \ | |
335 | (frame_saved_regs).regs[SP_REGNUM] = sp + 4; \ | |
336 | } \ | |
337 | } | |
338 | \f | |
339 | /* Things needed for making the inferior call functions. */ | |
340 | ||
341 | /* Push an empty stack frame, to record the current PC, etc. */ | |
342 | ||
343 | #define PUSH_DUMMY_FRAME \ | |
344 | { register CORE_ADDR sp = read_register (SP_REGNUM);\ | |
345 | register int regnum; \ | |
346 | sp = push_word (sp, read_register (PC_REGNUM)); \ | |
347 | sp = push_word (sp, read_register (FP_REGNUM)); \ | |
348 | write_register (FP_REGNUM, sp); \ | |
349 | for (regnum = 0; regnum < 8; regnum++) \ | |
350 | sp = push_word (sp, read_register (regnum)); \ | |
351 | write_register (SP_REGNUM, sp); \ | |
352 | } | |
353 | ||
354 | /* Discard from the stack the innermost frame, restoring all registers. */ | |
355 | ||
356 | #define POP_FRAME \ | |
357 | { register FRAME frame = get_current_frame (); \ | |
358 | register CORE_ADDR fp; \ | |
359 | register int regnum; \ | |
360 | struct frame_saved_regs fsr; \ | |
361 | struct frame_info *fi; \ | |
362 | fi = get_frame_info (frame); \ | |
363 | fp = fi->frame; \ | |
364 | get_frame_saved_regs (fi, &fsr); \ | |
365 | for (regnum = 0; regnum < 8; regnum++) \ | |
366 | if (fsr.regs[regnum]) \ | |
367 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \ | |
368 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); \ | |
369 | write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \ | |
370 | write_register (SP_REGNUM, fp + 8); \ | |
371 | flush_cached_frames (); \ | |
372 | set_current_frame (create_new_frame (read_register (FP_REGNUM),\ | |
373 | read_pc ())); } | |
374 | ||
375 | /* This sequence of words is the instructions | |
376 | enter 0xff,0 82 ff 00 | |
377 | jsr @0x00010203 7f ae c0 01 02 03 | |
378 | adjspd 0x69696969 7f a5 01 02 03 04 | |
379 | bpt f2 | |
380 | Note this is 16 bytes. */ | |
381 | ||
382 | #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 } | |
383 | ||
384 | #define CALL_DUMMY_START_OFFSET 3 | |
385 | #define CALL_DUMMY_LENGTH 16 | |
386 | #define CALL_DUMMY_ADDR 5 | |
387 | #define CALL_DUMMY_NARGS 11 | |
388 | ||
389 | /* Insert the specified number of args and function address | |
390 | into a call sequence of the above form stored at DUMMYNAME. */ | |
391 | ||
392 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
393 | { \ | |
394 | int flipped; \ | |
395 | flipped = fun | 0xc0000000; \ | |
396 | flip_bytes (&flipped, 4); \ | |
397 | *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \ | |
398 | flipped = - nargs * 4; \ | |
399 | flip_bytes (&flipped, 4); \ | |
400 | *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \ | |
401 | } |