]>
Commit | Line | Data |
---|---|---|
5076de82 FF |
1 | /* Definitions to make GDB run on an encore under umax 4.2 |
2 | Copyright 1987, 1989, 1991, 1993 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
20 | #define TARGET_BYTE_ORDER LITTLE_ENDIAN | |
21 | ||
22 | /* Need to get function ends by adding this to epilogue address from .bf | |
23 | record, not using x_fsize field. */ | |
24 | #define FUNCTION_EPILOGUE_SIZE 4 | |
25 | ||
26 | /* Offset from address of function to start of its code. | |
27 | Zero on most machines. */ | |
28 | ||
29 | #define FUNCTION_START_OFFSET 0 | |
30 | ||
31 | /* Advance PC across any function entry prologue instructions | |
32 | to reach some "real" code. */ | |
33 | ||
34 | #define SKIP_PROLOGUE(pc) \ | |
35 | { register unsigned char op = read_memory_integer (pc, 1); \ | |
36 | if (op == 0x82) { op = read_memory_integer (pc+2,1); \ | |
37 | if ((op & 0x80) == 0) pc += 3; \ | |
38 | else if ((op & 0xc0) == 0x80) pc += 4; \ | |
39 | else pc += 6; \ | |
40 | } \ | |
41 | } | |
42 | ||
43 | /* Immediately after a function call, return the saved pc. | |
44 | Can't always go through the frames for this because on some machines | |
45 | the new frame is not set up until the new function executes | |
46 | some instructions. */ | |
47 | ||
48 | #define SAVED_PC_AFTER_CALL(frame) \ | |
49 | read_memory_integer (read_register (SP_REGNUM), 4) | |
50 | ||
51 | /* Address of end of stack space. */ | |
52 | ||
53 | #define STACK_END_ADDR (0xfffff000) | |
54 | ||
55 | /* Stack grows downward. */ | |
56 | ||
57 | #define INNER_THAN < | |
58 | ||
59 | /* Sequence of bytes for breakpoint instruction. */ | |
60 | ||
61 | #define BREAKPOINT {0xf2} | |
62 | ||
63 | /* Amount PC must be decremented by after a breakpoint. | |
64 | This is often the number of bytes in BREAKPOINT | |
65 | but not always. */ | |
66 | ||
67 | #define DECR_PC_AFTER_BREAK 0 | |
68 | ||
69 | /* Nonzero if instruction at PC is a return instruction. */ | |
70 | ||
71 | #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0x12) | |
72 | ||
73 | #ifndef NaN | |
74 | #include <nan.h> | |
75 | #endif NaN | |
76 | ||
77 | /* Return 1 if P points to an invalid floating point value. */ | |
78 | /* Surely wrong for cross-debugging. */ | |
79 | #define INVALID_FLOAT(p, s) \ | |
80 | ((s == sizeof (float))? \ | |
81 | NaF (*(float *) p) : \ | |
82 | NaD (*(double *) p)) | |
83 | ||
84 | /* Say how long (ordinary) registers are. */ | |
85 | ||
86 | #define REGISTER_TYPE long | |
87 | ||
88 | /* Number of machine registers */ | |
89 | ||
90 | #define NUM_REGS 25 | |
91 | ||
92 | #define NUM_GENERAL_REGS 8 | |
93 | ||
94 | /* Initializer for an array of names of registers. | |
95 | There should be NUM_REGS strings in this initializer. */ | |
96 | ||
97 | #define REGISTER_NAMES {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \ | |
98 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \ | |
99 | "sp", "fp", "pc", "ps", \ | |
100 | "fsr", \ | |
101 | "l0", "l1", "l2", "l3", "xx", \ | |
102 | } | |
103 | ||
104 | /* Register numbers of various important registers. | |
105 | Note that some of these values are "real" register numbers, | |
106 | and correspond to the general registers of the machine, | |
107 | and some are "phony" register numbers which are too large | |
108 | to be actual register numbers as far as the user is concerned | |
109 | but do serve to get the desired values when passed to read_register. */ | |
110 | ||
111 | #define R0_REGNUM 0 /* General register 0 */ | |
112 | #define FP0_REGNUM 8 /* Floating point register 0 */ | |
113 | #define SP_REGNUM 16 /* Contains address of top of stack */ | |
114 | #define AP_REGNUM FP_REGNUM | |
115 | #define FP_REGNUM 17 /* Contains address of executing stack frame */ | |
116 | #define PC_REGNUM 18 /* Contains program counter */ | |
117 | #define PS_REGNUM 19 /* Contains processor status */ | |
118 | #define FPS_REGNUM 20 /* Floating point status register */ | |
119 | #define LP0_REGNUM 21 /* Double register 0 (same as FP0) */ | |
120 | ||
121 | /* Total amount of space needed to store our copies of the machine's | |
122 | register state, the array `registers'. */ | |
123 | #define REGISTER_BYTES \ | |
124 | ((NUM_REGS - 4) * REGISTER_RAW_SIZE(R0_REGNUM) \ | |
125 | + 4 * REGISTER_RAW_SIZE(LP0_REGNUM)) | |
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) \ | |
ade40d31 | 162 | memcpy ((TO), (FROM), REGISTER_VIRTUAL_SIZE(REGNUM)); |
5076de82 FF |
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) \ | |
ade40d31 | 168 | memcpy ((TO), (FROM), REGISTER_VIRTUAL_SIZE(REGNUM)); |
5076de82 FF |
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 | builtin_type_int : \ | |
176 | ((N) < FP0_REGNUM + 8) ? \ | |
177 | builtin_type_float : \ | |
178 | ((N) < LP0_REGNUM) ? \ | |
179 | builtin_type_int : \ | |
180 | builtin_type_double) | |
181 | ||
182 | /* Store the address of the place in which to copy the structure the | |
183 | subroutine will return. This is called from call_function. | |
184 | ||
185 | On this machine this is a no-op, because gcc isn't used on it | |
186 | yet. So this calling convention is not used. */ | |
187 | ||
188 | #define STORE_STRUCT_RETURN(ADDR, SP) | |
189 | ||
190 | /* Extract from an array REGBUF containing the (raw) register state | |
191 | a function return value of type TYPE, and copy that, in virtual format, | |
192 | into VALBUF. */ | |
193 | ||
194 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
ade40d31 | 195 | memcpy (VALBUF, REGBUF+REGISTER_BYTE (TYPE_CODE (TYPE) == TYPE_CODE_FLT ? FP0_REGNUM : 0), TYPE_LENGTH (TYPE)) |
5076de82 FF |
196 | |
197 | /* Write into appropriate registers a function return value | |
198 | of type TYPE, given in virtual format. */ | |
199 | ||
200 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
201 | write_register_bytes (REGISTER_BYTE (TYPE_CODE (TYPE) == TYPE_CODE_FLT ? FP0_REGNUM : 0), VALBUF, TYPE_LENGTH (TYPE)) | |
202 | ||
203 | /* Extract from an array REGBUF containing the (raw) register state | |
204 | the address in which a function should return its structure value, | |
205 | as a CORE_ADDR (or an expression that can be used as one). */ | |
206 | ||
207 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) | |
208 | \f | |
209 | /* Describe the pointer in each stack frame to the previous stack frame | |
210 | (its caller). */ | |
211 | ||
212 | /* FRAME_CHAIN takes a frame's nominal address | |
213 | and produces the frame's chain-pointer. */ | |
214 | ||
215 | /* In the case of the ns32000 series, the frame's nominal address is the FP | |
216 | value, and at that address is saved previous FP value as a 4-byte word. */ | |
217 | ||
218 | #define FRAME_CHAIN(thisframe) \ | |
219 | (!inside_entry_file ((thisframe)->pc) ? \ | |
220 | read_memory_integer ((thisframe)->frame, 4) :\ | |
221 | 0) | |
222 | ||
223 | /* Define other aspects of the stack frame. */ | |
224 | ||
225 | #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) | |
226 | ||
227 | /* Compute base of arguments. */ | |
228 | ||
229 | #define FRAME_ARGS_ADDRESS(fi) \ | |
230 | ((ns32k_get_enter_addr ((fi)->pc) > 1) ? \ | |
231 | ((fi)->frame) : (read_register (SP_REGNUM) - 4)) | |
232 | ||
233 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) | |
234 | ||
235 | /* Get the address of the enter opcode for this function, if it is active. | |
236 | Returns positive address > 1 if pc is between enter/exit, | |
237 | 1 if pc before enter or after exit, 0 otherwise. */ | |
238 | ||
239 | extern CORE_ADDR ns32k_get_enter_addr (); | |
240 | ||
241 | /* Return number of args passed to a frame. | |
242 | Can return -1, meaning no way to tell. | |
243 | Encore's C compiler often reuses same area on stack for args, | |
244 | so this will often not work properly. If the arg names | |
245 | are known, it's likely most of them will be printed. */ | |
246 | ||
247 | #define FRAME_NUM_ARGS(numargs, fi) \ | |
248 | { CORE_ADDR pc; \ | |
249 | CORE_ADDR enter_addr; \ | |
250 | unsigned int insn; \ | |
251 | unsigned int addr_mode; \ | |
252 | int width; \ | |
253 | \ | |
254 | numargs = -1; \ | |
255 | enter_addr = ns32k_get_enter_addr ((fi)->pc); \ | |
256 | if (enter_addr > 0) \ | |
257 | { \ | |
258 | pc = (enter_addr == 1) ? \ | |
259 | SAVED_PC_AFTER_CALL (fi) : \ | |
260 | FRAME_SAVED_PC (fi); \ | |
261 | insn = read_memory_integer (pc,2); \ | |
262 | addr_mode = (insn >> 11) & 0x1f; \ | |
263 | insn = insn & 0x7ff; \ | |
264 | if ((insn & 0x7fc) == 0x57c && \ | |
265 | addr_mode == 0x14) /* immediate */ \ | |
266 | { \ | |
267 | if (insn == 0x57c) /* adjspb */ \ | |
268 | width = 1; \ | |
269 | else if (insn == 0x57d) /* adjspw */ \ | |
270 | width = 2; \ | |
271 | else if (insn == 0x57f) /* adjspd */ \ | |
272 | width = 4; \ | |
273 | numargs = read_memory_integer (pc+2,width); \ | |
274 | if (width > 1) \ | |
275 | flip_bytes (&numargs, width); \ | |
276 | numargs = - sign_extend (numargs, width*8) / 4;\ | |
277 | } \ | |
278 | } \ | |
279 | } | |
280 | ||
281 | /* Return number of bytes at start of arglist that are not really args. */ | |
282 | ||
283 | #define FRAME_ARGS_SKIP 8 | |
284 | ||
285 | /* Put here the code to store, into a struct frame_saved_regs, | |
286 | the addresses of the saved registers of frame described by FRAME_INFO. | |
287 | This includes special registers such as pc and fp saved in special | |
288 | ways in the stack frame. sp is even more special: | |
289 | the address we return for it IS the sp for the next frame. */ | |
290 | ||
291 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ | |
292 | { \ | |
293 | register int regmask, regnum; \ | |
294 | int localcount; \ | |
295 | register CORE_ADDR enter_addr; \ | |
296 | register CORE_ADDR next_addr; \ | |
297 | \ | |
4ed97c9a | 298 | memset (&(frame_saved_regs), '\0', sizeof (frame_saved_regs)); \ |
5076de82 FF |
299 | enter_addr = ns32k_get_enter_addr ((frame_info)->pc); \ |
300 | if (enter_addr > 1) \ | |
301 | { \ | |
302 | regmask = read_memory_integer (enter_addr+1, 1) & 0xff; \ | |
303 | localcount = ns32k_localcount (enter_addr); \ | |
304 | next_addr = (frame_info)->frame + localcount; \ | |
305 | for (regnum = 0; regnum < 8; regnum++, regmask >>= 1) \ | |
306 | (frame_saved_regs).regs[regnum] = (regmask & 1) ? \ | |
307 | (next_addr -= 4) : 0; \ | |
308 | (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 4;\ | |
309 | (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4;\ | |
310 | (frame_saved_regs).regs[FP_REGNUM] = \ | |
311 | (read_memory_integer ((frame_info)->frame, 4));\ | |
312 | } \ | |
313 | else if (enter_addr == 1) \ | |
314 | { \ | |
315 | CORE_ADDR sp = read_register (SP_REGNUM); \ | |
316 | (frame_saved_regs).regs[PC_REGNUM] = sp; \ | |
317 | (frame_saved_regs).regs[SP_REGNUM] = sp + 4; \ | |
318 | } \ | |
319 | } | |
320 | \f | |
321 | /* Things needed for making the inferior call functions. */ | |
322 | ||
323 | /* Push an empty stack frame, to record the current PC, etc. */ | |
324 | ||
325 | #define PUSH_DUMMY_FRAME \ | |
326 | { register CORE_ADDR sp = read_register (SP_REGNUM);\ | |
327 | register int regnum; \ | |
328 | sp = push_word (sp, read_register (PC_REGNUM)); \ | |
329 | sp = push_word (sp, read_register (FP_REGNUM)); \ | |
330 | write_register (FP_REGNUM, sp); \ | |
331 | for (regnum = 0; regnum < 8; regnum++) \ | |
332 | sp = push_word (sp, read_register (regnum)); \ | |
333 | write_register (SP_REGNUM, sp); \ | |
334 | } | |
335 | ||
336 | /* Discard from the stack the innermost frame, restoring all registers. */ | |
337 | ||
338 | #define POP_FRAME \ | |
339 | { register FRAME frame = get_current_frame (); \ | |
340 | register CORE_ADDR fp; \ | |
341 | register int regnum; \ | |
342 | struct frame_saved_regs fsr; \ | |
343 | struct frame_info *fi; \ | |
344 | fi = get_frame_info (frame); \ | |
345 | fp = fi->frame; \ | |
346 | get_frame_saved_regs (fi, &fsr); \ | |
347 | for (regnum = 0; regnum < 8; regnum++) \ | |
348 | if (fsr.regs[regnum]) \ | |
349 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \ | |
350 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); \ | |
351 | write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \ | |
352 | write_register (SP_REGNUM, fp + 8); \ | |
353 | flush_cached_frames (); \ | |
354 | set_current_frame (create_new_frame (read_register (FP_REGNUM),\ | |
355 | read_pc ())); } | |
356 | ||
357 | /* This sequence of words is the instructions | |
358 | enter 0xff,0 82 ff 00 | |
359 | jsr @0x00010203 7f ae c0 01 02 03 | |
360 | adjspd 0x69696969 7f a5 01 02 03 04 | |
361 | bpt f2 | |
362 | Note this is 16 bytes. */ | |
363 | ||
364 | #define CALL_DUMMY { 0x7f00ff82, 0x0201c0ae, 0x01a57f03, 0xf2040302 } | |
365 | ||
366 | #define CALL_DUMMY_START_OFFSET 3 | |
367 | #define CALL_DUMMY_LENGTH 16 | |
368 | #define CALL_DUMMY_ADDR 5 | |
369 | #define CALL_DUMMY_NARGS 11 | |
370 | ||
371 | /* Insert the specified number of args and function address | |
372 | into a call sequence of the above form stored at DUMMYNAME. */ | |
373 | ||
374 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
375 | { \ | |
376 | int flipped; \ | |
377 | flipped = fun | 0xc0000000; \ | |
378 | flip_bytes (&flipped, 4); \ | |
379 | *((int *) (((char *) dummyname)+CALL_DUMMY_ADDR)) = flipped; \ | |
380 | flipped = - nargs * 4; \ | |
381 | flip_bytes (&flipped, 4); \ | |
382 | *((int *) (((char *) dummyname)+CALL_DUMMY_NARGS)) = flipped; \ | |
383 | } |