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