Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Parameters for execution on a 68000 series machine. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1989, 1990, 1992, 1993, 1994, 1995, 1996, 1998, |
3 | 1999, 2000 Free Software Foundation, Inc. | |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c | 21 | |
f88e2c52 AC |
22 | #include "regcache.h" |
23 | ||
103a1597 | 24 | #define GDB_MULTI_ARCH GDB_MULTI_ARCH_PARTIAL |
152d9db6 | 25 | |
c906108c SS |
26 | /* Generic 68000 stuff, to be included by other tm-*.h files. */ |
27 | ||
103a1597 GS |
28 | /* struct frame_info; */ |
29 | ||
30 | /* D0_REGNM and A0_REGNUM must be defined here because they are | |
31 | used by the monitor. */ | |
32 | ||
33 | #define D0_REGNUM 0 | |
34 | #define A0_REGNUM 8 | |
6300c360 GS |
35 | |
36 | /* Sequence of bytes for breakpoint instruction. | |
37 | This is a TRAP instruction. The last 4 bits (0xf below) is the | |
38 | vector. Systems which don't use 0xf should define BPT_VECTOR | |
39 | themselves before including this file. */ | |
40 | ||
103a1597 | 41 | #if !GDB_MULTI_ARCH |
6300c360 GS |
42 | #if !defined (BPT_VECTOR) |
43 | #define BPT_VECTOR 0xf | |
44 | #endif | |
45 | ||
46 | #if !defined (BREAKPOINT) | |
47 | #define BREAKPOINT {0x4e, (0x40 | BPT_VECTOR)} | |
48 | #endif | |
49 | ||
50 | /* We default to vector 1 for the "remote" target, but allow targets | |
51 | to override. */ | |
52 | #if !defined (REMOTE_BPT_VECTOR) | |
53 | #define REMOTE_BPT_VECTOR 1 | |
54 | #endif | |
103a1597 | 55 | #endif |
6300c360 | 56 | |
103a1597 | 57 | #if !GDB_MULTI_ARCH |
6300c360 GS |
58 | #if !defined (REMOTE_BREAKPOINT) |
59 | #define REMOTE_BREAKPOINT {0x4e, (0x40 | REMOTE_BPT_VECTOR)} | |
60 | #endif | |
103a1597 | 61 | #endif |
6300c360 | 62 | |
103a1597 | 63 | #if !GDB_MULTI_ARCH |
6300c360 GS |
64 | #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4) |
65 | #define REGISTER_BYTES_NOFP (16*4 + 8) | |
66 | ||
67 | ||
68 | #define NUM_FREGS (NUM_REGS-24) | |
69 | ||
103a1597 | 70 | |
6300c360 GS |
71 | /* This was determined by experimentation on hp300 BSD 4.3. Perhaps |
72 | it corresponds to some offset in /usr/include/sys/user.h or | |
73 | something like that. Using some system include file would | |
74 | have the advantage of probably being more robust in the face | |
75 | of OS upgrades, but the disadvantage of being wrong for | |
76 | cross-debugging. */ | |
77 | ||
78 | #define SIG_PC_FP_OFFSET 530 | |
79 | ||
80 | /* Offset from SP to first arg on stack at first instruction of a function */ | |
81 | ||
82 | #define SP_ARG0 (1 * 4) | |
83 | ||
84 | #define TARGET_M68K | |
103a1597 | 85 | #endif |
6300c360 | 86 | |
5d3ed2e3 | 87 | #if !GDB_MULTI_ARCH |
16f769f3 AC |
88 | #define TARGET_LONG_DOUBLE_FORMAT &floatformat_m68881_ext |
89 | ||
90 | #define TARGET_LONG_DOUBLE_BIT 96 | |
91 | ||
c906108c SS |
92 | /* Offset from address of function to start of its code. |
93 | Zero on most machines. */ | |
94 | ||
95 | #define FUNCTION_START_OFFSET 0 | |
96 | ||
97 | /* Advance PC across any function entry prologue instructions | |
98 | to reach some "real" code. */ | |
99 | ||
100 | #if !defined(SKIP_PROLOGUE) | |
b83266a0 | 101 | #define SKIP_PROLOGUE(ip) (m68k_skip_prologue (ip)) |
c906108c | 102 | #endif |
5d3ed2e3 | 103 | #endif |
a14ed312 | 104 | extern CORE_ADDR m68k_skip_prologue (CORE_ADDR ip); |
c906108c | 105 | |
5d3ed2e3 | 106 | |
c906108c SS |
107 | /* Immediately after a function call, return the saved pc. |
108 | Can't always go through the frames for this because on some machines | |
109 | the new frame is not set up until the new function executes | |
110 | some instructions. */ | |
111 | ||
5d3ed2e3 | 112 | #if !GDB_MULTI_ARCH |
a14ed312 | 113 | extern CORE_ADDR m68k_saved_pc_after_call (struct frame_info *); |
c906108c SS |
114 | |
115 | #define SAVED_PC_AFTER_CALL(frame) \ | |
116 | m68k_saved_pc_after_call(frame) | |
5d3ed2e3 | 117 | #endif |
c906108c SS |
118 | |
119 | /* Stack grows downward. */ | |
120 | ||
5d3ed2e3 | 121 | #if !GDB_MULTI_ARCH |
c906108c SS |
122 | #define INNER_THAN(lhs,rhs) ((lhs) < (rhs)) |
123 | ||
124 | /* Stack must be kept short aligned when doing function calls. */ | |
125 | ||
126 | #define STACK_ALIGN(ADDR) (((ADDR) + 1) & ~1) | |
5d3ed2e3 | 127 | #endif |
c906108c | 128 | |
c906108c SS |
129 | /* If your kernel resets the pc after the trap happens you may need to |
130 | define this before including this file. */ | |
131 | ||
942dc0e9 | 132 | #if !GDB_MULTI_ARCH |
c906108c SS |
133 | #if !defined (DECR_PC_AFTER_BREAK) |
134 | #define DECR_PC_AFTER_BREAK 2 | |
135 | #endif | |
942dc0e9 | 136 | #endif |
c906108c | 137 | |
6300c360 GS |
138 | #if !GDB_MULTI_ARCH |
139 | #ifndef NUM_REGS | |
140 | #define NUM_REGS 29 | |
141 | #endif | |
142 | #endif | |
143 | ||
c906108c SS |
144 | /* Say how long (ordinary) registers are. This is a piece of bogosity |
145 | used in push_word and a few other places; REGISTER_RAW_SIZE is the | |
146 | real way to know how big a register is. */ | |
147 | ||
5d3ed2e3 | 148 | #if !GDB_MULTI_ARCH |
c906108c | 149 | #define REGISTER_SIZE 4 |
5d3ed2e3 | 150 | #endif |
c906108c | 151 | |
942dc0e9 | 152 | #if !GDB_MULTI_ARCH |
c906108c SS |
153 | #ifndef REGISTER_BYTES_OK |
154 | #define REGISTER_BYTES_OK(b) \ | |
155 | ((b) == REGISTER_BYTES_FP \ | |
156 | || (b) == REGISTER_BYTES_NOFP) | |
157 | #endif | |
158 | ||
159 | #ifndef REGISTER_BYTES | |
160 | #define REGISTER_BYTES (16*4 + 8 + 8*12 + 3*4) | |
161 | #endif | |
103a1597 | 162 | #endif /* multi-arch */ |
c906108c SS |
163 | |
164 | /* Index within `registers' of the first byte of the space for | |
165 | register N. */ | |
166 | ||
5d3ed2e3 | 167 | #if !GDB_MULTI_ARCH |
c906108c SS |
168 | #define REGISTER_BYTE(N) \ |
169 | ((N) >= FPC_REGNUM ? (((N) - FPC_REGNUM) * 4) + 168 \ | |
170 | : (N) >= FP0_REGNUM ? (((N) - FP0_REGNUM) * 12) + 72 \ | |
171 | : (N) * 4) | |
5d3ed2e3 | 172 | #endif |
c906108c SS |
173 | |
174 | /* Number of bytes of storage in the actual machine representation | |
175 | for register N. On the 68000, all regs are 4 bytes | |
176 | except the floating point regs which are 12 bytes. */ | |
177 | /* Note that the unsigned cast here forces the result of the | |
178 | subtraction to very high positive values if N < FP0_REGNUM */ | |
5d3ed2e3 | 179 | #if !GDB_MULTI_ARCH |
c906108c SS |
180 | #define REGISTER_RAW_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 12 : 4) |
181 | ||
182 | /* Number of bytes of storage in the program's representation | |
183 | for register N. On the 68000, all regs are 4 bytes | |
16f769f3 | 184 | except the floating point regs which are 12-byte long doubles. */ |
c906108c | 185 | |
16f769f3 | 186 | #define REGISTER_VIRTUAL_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 12 : 4) |
c906108c SS |
187 | |
188 | /* Largest value REGISTER_RAW_SIZE can have. */ | |
189 | ||
190 | #define MAX_REGISTER_RAW_SIZE 12 | |
191 | ||
192 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ | |
193 | ||
16f769f3 | 194 | #define MAX_REGISTER_VIRTUAL_SIZE 12 |
103a1597 | 195 | #endif /* multi-arch */ |
942dc0e9 | 196 | |
c906108c | 197 | /* Return the GDB type object for the "standard" data type of data |
16f769f3 | 198 | in register N. This should be int for D0-D7, long double for FP0-FP7, |
c906108c SS |
199 | and void pointer for all others (A0-A7, PC, SR, FPCONTROL etc). |
200 | Note, for registers which contain addresses return pointer to void, | |
201 | not pointer to char, because we don't want to attempt to print | |
202 | the string after printing the address. */ | |
5d3ed2e3 | 203 | #if !GDB_MULTI_ARCH |
c906108c SS |
204 | #define REGISTER_VIRTUAL_TYPE(N) \ |
205 | ((unsigned) (N) >= FPC_REGNUM ? lookup_pointer_type (builtin_type_void) : \ | |
16f769f3 | 206 | (unsigned) (N) >= FP0_REGNUM ? builtin_type_long_double : \ |
c906108c SS |
207 | (unsigned) (N) >= A0_REGNUM ? lookup_pointer_type (builtin_type_void) : \ |
208 | builtin_type_int) | |
5d3ed2e3 | 209 | #endif |
c906108c SS |
210 | /* Initializer for an array of names of registers. |
211 | Entries beyond the first NUM_REGS are ignored. */ | |
212 | ||
5d3ed2e3 | 213 | #if !GDB_MULTI_ARCH |
c906108c SS |
214 | #define REGISTER_NAMES \ |
215 | {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", \ | |
216 | "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", \ | |
217 | "ps", "pc", \ | |
218 | "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", \ | |
219 | "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" } | |
5d3ed2e3 | 220 | #endif |
c906108c SS |
221 | |
222 | /* Register numbers of various important registers. | |
223 | Note that some of these values are "real" register numbers, | |
224 | and correspond to the general registers of the machine, | |
225 | and some are "phony" register numbers which are too large | |
226 | to be actual register numbers as far as the user is concerned | |
227 | but do serve to get the desired values when passed to read_register. */ | |
228 | ||
103a1597 | 229 | #if !GDB_MULTI_ARCH |
6300c360 | 230 | |
c906108c SS |
231 | #define A1_REGNUM 9 |
232 | #define FP_REGNUM 14 /* Contains address of executing stack frame */ | |
233 | #define SP_REGNUM 15 /* Contains address of top of stack */ | |
234 | #define PS_REGNUM 16 /* Contains processor status */ | |
235 | #define PC_REGNUM 17 /* Contains program counter */ | |
236 | #define FP0_REGNUM 18 /* Floating point register 0 */ | |
237 | #define FPC_REGNUM 26 /* 68881 control register */ | |
238 | #define FPS_REGNUM 27 /* 68881 status register */ | |
239 | #define FPI_REGNUM 28 /* 68881 iaddr register */ | |
103a1597 | 240 | #endif |
5d3ed2e3 | 241 | |
c906108c SS |
242 | /* Store the address of the place in which to copy the structure the |
243 | subroutine will return. This is called from call_function. */ | |
942dc0e9 | 244 | #if !GDB_MULTI_ARCH |
c906108c SS |
245 | #define STORE_STRUCT_RETURN(ADDR, SP) \ |
246 | { write_register (A1_REGNUM, (ADDR)); } | |
247 | ||
248 | /* Extract from an array REGBUF containing the (raw) register state | |
249 | a function return value of type TYPE, and copy that, in virtual format, | |
250 | into VALBUF. This is assuming that floating point values are returned | |
251 | as doubles in d0/d1. */ | |
252 | ||
26e9b323 AC |
253 | #if !defined (DEPRECATED_EXTRACT_RETURN_VALUE) |
254 | #define DEPRECATED_EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ | |
c906108c SS |
255 | memcpy ((VALBUF), \ |
256 | (char *)(REGBUF) + \ | |
257 | (TYPE_LENGTH(TYPE) >= 4 ? 0 : 4 - TYPE_LENGTH(TYPE)), \ | |
258 | TYPE_LENGTH(TYPE)) | |
259 | #endif | |
103a1597 | 260 | #endif /* multi-arch */ |
c906108c SS |
261 | |
262 | /* Write into appropriate registers a function return value | |
263 | of type TYPE, given in virtual format. Assumes floats are passed | |
264 | in d0/d1. */ | |
265 | ||
942dc0e9 | 266 | #if !GDB_MULTI_ARCH |
c906108c SS |
267 | #if !defined (STORE_RETURN_VALUE) |
268 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ | |
269 | write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) | |
270 | #endif | |
271 | ||
272 | /* Extract from an array REGBUF containing the (raw) register state | |
273 | the address in which a function should return its structure value, | |
274 | as a CORE_ADDR (or an expression that can be used as one). */ | |
275 | ||
26e9b323 | 276 | #define DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(CORE_ADDR *)(REGBUF)) |
103a1597 | 277 | #endif /* multi-arch */ |
c906108c SS |
278 | \f |
279 | /* Describe the pointer in each stack frame to the previous stack frame | |
280 | (its caller). */ | |
281 | ||
282 | /* FRAME_CHAIN takes a frame's nominal address and produces the frame's | |
283 | chain-pointer. | |
284 | In the case of the 68000, the frame's nominal address | |
285 | is the address of a 4-byte word containing the calling frame's address. */ | |
286 | ||
287 | /* If we are chaining from sigtramp, then manufacture a sigtramp frame | |
288 | (which isn't really on the stack. I'm not sure this is right for anything | |
289 | but BSD4.3 on an hp300. */ | |
942dc0e9 | 290 | #if !GDB_MULTI_ARCH |
c906108c SS |
291 | #define FRAME_CHAIN(thisframe) \ |
292 | (thisframe->signal_handler_caller \ | |
293 | ? thisframe->frame \ | |
294 | : (!inside_entry_file ((thisframe)->pc) \ | |
295 | ? read_memory_integer ((thisframe)->frame, 4) \ | |
296 | : 0)) | |
942dc0e9 | 297 | #endif |
c906108c SS |
298 | |
299 | /* Define other aspects of the stack frame. */ | |
300 | ||
301 | /* A macro that tells us whether the function invocation represented | |
302 | by FI does not have a frame on the stack associated with it. If it | |
303 | does not, FRAMELESS is set to 1, else 0. */ | |
942dc0e9 | 304 | #if !GDB_MULTI_ARCH |
392a587b JM |
305 | #define FRAMELESS_FUNCTION_INVOCATION(FI) \ |
306 | (((FI)->signal_handler_caller) ? 0 : frameless_look_for_prologue(FI)) | |
942dc0e9 | 307 | #endif |
c906108c | 308 | |
c906108c | 309 | |
c906108c | 310 | |
942dc0e9 | 311 | #if !GDB_MULTI_ARCH |
c906108c SS |
312 | #define FRAME_SAVED_PC(FRAME) \ |
313 | (((FRAME)->signal_handler_caller \ | |
314 | ? ((FRAME)->next \ | |
315 | ? read_memory_integer ((FRAME)->next->frame + SIG_PC_FP_OFFSET, 4) \ | |
316 | : read_memory_integer (read_register (SP_REGNUM) \ | |
317 | + SIG_PC_FP_OFFSET - 8, 4) \ | |
318 | ) \ | |
319 | : read_memory_integer ((FRAME)->frame + 4, 4)) \ | |
320 | ) | |
942dc0e9 | 321 | #endif |
c906108c | 322 | |
6300c360 | 323 | #if !GDB_MULTI_ARCH |
c906108c SS |
324 | #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame) |
325 | ||
326 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) | |
6300c360 | 327 | #endif |
c906108c SS |
328 | |
329 | /* Set VAL to the number of args passed to frame described by FI. | |
330 | Can set VAL to -1, meaning no way to tell. */ | |
331 | ||
332 | /* We can't tell how many args there are | |
333 | now that the C compiler delays popping them. */ | |
6300c360 | 334 | #if !GDB_MULTI_ARCH |
c906108c | 335 | #if !defined (FRAME_NUM_ARGS) |
392a587b | 336 | #define FRAME_NUM_ARGS(fi) (-1) |
c906108c SS |
337 | #endif |
338 | ||
6300c360 | 339 | |
c906108c SS |
340 | /* Return number of bytes at start of arglist that are not really args. */ |
341 | ||
342 | #define FRAME_ARGS_SKIP 8 | |
6300c360 | 343 | #endif |
78f6d055 AC |
344 | |
345 | /* Put here the code to store, into a struct frame_saved_regs, | |
346 | the addresses of the saved registers of frame described by FRAME_INFO. | |
347 | This includes special registers such as pc and fp saved in special | |
348 | ways in the stack frame. sp is even more special: | |
349 | the address we return for it IS the sp for the next frame. */ | |
350 | ||
351 | #if !GDB_MULTI_ARCH | |
352 | #if !defined (FRAME_INIT_SAVED_REGS) | |
353 | #define FRAME_INIT_SAVED_REGS(fi) m68k_frame_init_saved_regs ((fi)) | |
354 | void m68k_frame_init_saved_regs (struct frame_info *frame_info); | |
355 | #endif /* no FRAME_INIT_SAVED_REGS. */ | |
356 | #endif | |
c906108c | 357 | \f |
c5aa993b | 358 | |
c906108c SS |
359 | /* Things needed for making the inferior call functions. */ |
360 | ||
361 | /* The CALL_DUMMY macro is the sequence of instructions, as disassembled | |
362 | by gdb itself: | |
363 | ||
364 | These instructions exist only so that m68k_find_saved_regs can parse | |
365 | them as a "prologue"; they are never executed. | |
366 | ||
c5aa993b JM |
367 | fmovemx fp0-fp7,sp@- 0xf227 0xe0ff |
368 | moveml d0-a5,sp@- 0x48e7 0xfffc | |
369 | clrw sp@- 0x4267 | |
370 | movew ccr,sp@- 0x42e7 | |
c906108c SS |
371 | |
372 | The arguments are pushed at this point by GDB; no code is needed in | |
373 | the dummy for this. The CALL_DUMMY_START_OFFSET gives the position | |
374 | of the following jsr instruction. That is where we start | |
375 | executing. | |
376 | ||
c5aa993b JM |
377 | jsr @#0x32323232 0x4eb9 0x3232 0x3232 |
378 | addal #0x69696969,sp 0xdffc 0x6969 0x6969 | |
379 | trap #<your BPT_VECTOR number here> 0x4e4? | |
380 | nop 0x4e71 | |
c906108c SS |
381 | |
382 | Note this is CALL_DUMMY_LENGTH bytes (28 for the above example). | |
383 | ||
384 | The dummy frame always saves the floating-point registers, whether they | |
385 | actually exist on this target or not. */ | |
386 | ||
387 | /* FIXME: Wrong to hardwire this as BPT_VECTOR when sometimes it | |
388 | should be REMOTE_BPT_VECTOR. Best way to fix it would be to define | |
389 | CALL_DUMMY_BREAKPOINT_OFFSET. */ | |
78f6d055 | 390 | #if !GDB_MULTI_ARCH |
c906108c | 391 | #define CALL_DUMMY {0xf227e0ff, 0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, (0x4e404e71 | (BPT_VECTOR << 16))} |
c5aa993b JM |
392 | #define CALL_DUMMY_LENGTH 28 /* Size of CALL_DUMMY */ |
393 | #define CALL_DUMMY_START_OFFSET 12 /* Offset to jsr instruction */ | |
c906108c SS |
394 | #define CALL_DUMMY_BREAKPOINT_OFFSET (CALL_DUMMY_START_OFFSET + 12) |
395 | ||
396 | /* Insert the specified number of args and function address | |
397 | into a call sequence of the above form stored at DUMMYNAME. | |
398 | We use the BFD routines to store a big-endian value of known size. */ | |
399 | ||
400 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
401 | { bfd_putb32 (fun, (unsigned char *) dummyname + CALL_DUMMY_START_OFFSET + 2); \ | |
402 | bfd_putb32 (nargs*4, (unsigned char *) dummyname + CALL_DUMMY_START_OFFSET + 8); } | |
403 | ||
404 | /* Push an empty stack frame, to record the current PC, etc. */ | |
405 | ||
406 | #define PUSH_DUMMY_FRAME { m68k_push_dummy_frame (); } | |
407 | ||
a14ed312 | 408 | extern void m68k_push_dummy_frame (void); |
c906108c | 409 | |
a14ed312 | 410 | extern void m68k_pop_frame (void); |
c906108c SS |
411 | |
412 | /* Discard from the stack the innermost frame, restoring all registers. */ | |
413 | ||
414 | #define POP_FRAME { m68k_pop_frame (); } | |
c906108c | 415 | |
f4281f55 AC |
416 | |
417 | /* Figure out where the longjmp will land. Slurp the args out of the stack. | |
418 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
419 | we extract the pc (JB_PC) that we will land at. The pc is copied into ADDR. | |
420 | This routine returns true on success */ | |
421 | ||
422 | extern int m68k_get_longjmp_target (CORE_ADDR *); | |
6300c360 | 423 | #endif |