Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target dependent code for the Motorola 68000 series. |
51603483 DJ |
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001, |
3 | 2002, 2003 | |
a1de33a8 | 4 | Free Software Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbcore.h" | |
27 | #include "value.h" | |
28 | #include "gdb_string.h" | |
7a292a7a | 29 | #include "inferior.h" |
4e052eda | 30 | #include "regcache.h" |
5d3ed2e3 | 31 | #include "arch-utils.h" |
55809acb | 32 | #include "osabi.h" |
32eeb91a AS |
33 | |
34 | #include "m68k-tdep.h" | |
c906108c | 35 | \f |
c5aa993b | 36 | |
89c3b6d3 PDM |
37 | #define P_LINKL_FP 0x480e |
38 | #define P_LINKW_FP 0x4e56 | |
39 | #define P_PEA_FP 0x4856 | |
40 | #define P_MOVL_SP_FP 0x2c4f | |
41 | #define P_MOVL 0x207c | |
42 | #define P_JSR 0x4eb9 | |
43 | #define P_BSR 0x61ff | |
44 | #define P_LEAL 0x43fb | |
45 | #define P_MOVML 0x48ef | |
46 | #define P_FMOVM 0xf237 | |
47 | #define P_TRAP 0x4e40 | |
48 | ||
103a1597 | 49 | |
103a1597 GS |
50 | #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4) |
51 | #define REGISTER_BYTES_NOFP (16*4 + 8) | |
52 | ||
53 | #define NUM_FREGS (NUM_REGS-24) | |
54 | ||
55 | /* Offset from SP to first arg on stack at first instruction of a function */ | |
56 | ||
57 | #define SP_ARG0 (1 * 4) | |
58 | ||
59 | /* This was determined by experimentation on hp300 BSD 4.3. Perhaps | |
60 | it corresponds to some offset in /usr/include/sys/user.h or | |
61 | something like that. Using some system include file would | |
62 | have the advantage of probably being more robust in the face | |
63 | of OS upgrades, but the disadvantage of being wrong for | |
64 | cross-debugging. */ | |
65 | ||
66 | #define SIG_PC_FP_OFFSET 530 | |
67 | ||
68 | #define TARGET_M68K | |
69 | ||
70 | ||
71 | #if !defined (BPT_VECTOR) | |
72 | #define BPT_VECTOR 0xf | |
73 | #endif | |
74 | ||
75 | #if !defined (REMOTE_BPT_VECTOR) | |
76 | #define REMOTE_BPT_VECTOR 1 | |
77 | #endif | |
78 | ||
79 | ||
7f8e7424 GS |
80 | void m68k_frame_init_saved_regs (struct frame_info *frame_info); |
81 | ||
103a1597 GS |
82 | |
83 | /* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc | |
84 | so m68k_remote_breakpoint_from_pc is currently not used. */ | |
85 | ||
86 | const static unsigned char * | |
87 | m68k_remote_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
88 | { | |
89 | static unsigned char break_insn[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR)}; | |
90 | *lenptr = sizeof (break_insn); | |
91 | return break_insn; | |
92 | } | |
93 | ||
94 | const static unsigned char * | |
95 | m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
96 | { | |
97 | static unsigned char break_insn[] = {0x4e, (0x40 | BPT_VECTOR)}; | |
98 | *lenptr = sizeof (break_insn); | |
99 | return break_insn; | |
100 | } | |
101 | ||
102 | ||
942dc0e9 | 103 | static int |
5ae5f592 | 104 | m68k_register_bytes_ok (long numbytes) |
942dc0e9 GS |
105 | { |
106 | return ((numbytes == REGISTER_BYTES_FP) | |
107 | || (numbytes == REGISTER_BYTES_NOFP)); | |
108 | } | |
109 | ||
5d3ed2e3 GS |
110 | /* Number of bytes of storage in the actual machine representation |
111 | for register regnum. On the 68000, all regs are 4 bytes | |
112 | except the floating point regs which are 12 bytes. */ | |
113 | /* Note that the unsigned cast here forces the result of the | |
114 | subtraction to very high positive values if regnum < FP0_REGNUM */ | |
115 | ||
116 | static int | |
117 | m68k_register_raw_size (int regnum) | |
118 | { | |
119 | return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4); | |
120 | } | |
121 | ||
122 | /* Number of bytes of storage in the program's representation | |
123 | for register regnum. On the 68000, all regs are 4 bytes | |
124 | except the floating point regs which are 12-byte long doubles. */ | |
125 | ||
126 | static int | |
127 | m68k_register_virtual_size (int regnum) | |
128 | { | |
129 | return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4); | |
130 | } | |
131 | ||
d85fe7f7 AS |
132 | /* Return the GDB type object for the "standard" data type of data in |
133 | register N. This should be int for D0-D7, SR, FPCONTROL and | |
134 | FPSTATUS, long double for FP0-FP7, and void pointer for all others | |
135 | (A0-A7, PC, FPIADDR). Note, for registers which contain | |
136 | addresses return pointer to void, not pointer to char, because we | |
137 | don't want to attempt to print the string after printing the | |
138 | address. */ | |
5d3ed2e3 GS |
139 | |
140 | static struct type * | |
141 | m68k_register_virtual_type (int regnum) | |
142 | { | |
03dac896 AS |
143 | if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7) |
144 | return builtin_type_m68881_ext; | |
145 | ||
32eeb91a | 146 | if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM) |
03dac896 AS |
147 | return builtin_type_void_func_ptr; |
148 | ||
32eeb91a AS |
149 | if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM |
150 | || regnum == PS_REGNUM) | |
03dac896 AS |
151 | return builtin_type_int32; |
152 | ||
32eeb91a | 153 | if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7) |
03dac896 AS |
154 | return builtin_type_void_data_ptr; |
155 | ||
156 | return builtin_type_int32; | |
5d3ed2e3 GS |
157 | } |
158 | ||
159 | /* Function: m68k_register_name | |
160 | Returns the name of the standard m68k register regnum. */ | |
161 | ||
162 | static const char * | |
163 | m68k_register_name (int regnum) | |
164 | { | |
165 | static char *register_names[] = { | |
166 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", | |
167 | "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", | |
168 | "ps", "pc", | |
169 | "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", | |
170 | "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" | |
171 | }; | |
172 | ||
173 | if (regnum < 0 || | |
174 | regnum >= sizeof (register_names) / sizeof (register_names[0])) | |
175 | internal_error (__FILE__, __LINE__, | |
176 | "m68k_register_name: illegal register number %d", regnum); | |
177 | else | |
178 | return register_names[regnum]; | |
179 | } | |
180 | ||
181 | /* Stack must be kept short aligned when doing function calls. */ | |
182 | ||
183 | static CORE_ADDR | |
184 | m68k_stack_align (CORE_ADDR addr) | |
185 | { | |
186 | return ((addr + 1) & ~1); | |
187 | } | |
188 | ||
189 | /* Index within `registers' of the first byte of the space for | |
190 | register regnum. */ | |
191 | ||
192 | static int | |
193 | m68k_register_byte (int regnum) | |
194 | { | |
32eeb91a AS |
195 | if (regnum >= M68K_FPC_REGNUM) |
196 | return (((regnum - M68K_FPC_REGNUM) * 4) + 168); | |
5d3ed2e3 GS |
197 | else if (regnum >= FP0_REGNUM) |
198 | return (((regnum - FP0_REGNUM) * 12) + 72); | |
199 | else | |
200 | return (regnum * 4); | |
201 | } | |
202 | ||
942dc0e9 GS |
203 | /* Store the address of the place in which to copy the structure the |
204 | subroutine will return. This is called from call_function. */ | |
205 | ||
206 | static void | |
207 | m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) | |
208 | { | |
32eeb91a | 209 | write_register (M68K_A1_REGNUM, addr); |
942dc0e9 GS |
210 | } |
211 | ||
212 | /* Extract from an array regbuf containing the (raw) register state | |
213 | a function return value of type type, and copy that, in virtual format, | |
214 | into valbuf. This is assuming that floating point values are returned | |
215 | as doubles in d0/d1. */ | |
216 | ||
217 | static void | |
218 | m68k_deprecated_extract_return_value (struct type *type, char *regbuf, | |
219 | char *valbuf) | |
220 | { | |
221 | int offset = 0; | |
222 | int typeLength = TYPE_LENGTH (type); | |
223 | ||
224 | if (typeLength < 4) | |
225 | offset = 4 - typeLength; | |
226 | ||
227 | memcpy (valbuf, regbuf + offset, typeLength); | |
228 | } | |
229 | ||
230 | static CORE_ADDR | |
231 | m68k_deprecated_extract_struct_value_address (char *regbuf) | |
232 | { | |
233 | return (*(CORE_ADDR *) (regbuf)); | |
234 | } | |
235 | ||
236 | /* Write into appropriate registers a function return value | |
237 | of type TYPE, given in virtual format. Assumes floats are passed | |
238 | in d0/d1. */ | |
239 | ||
240 | static void | |
241 | m68k_store_return_value (struct type *type, char *valbuf) | |
242 | { | |
73937e03 | 243 | deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type)); |
942dc0e9 GS |
244 | } |
245 | ||
246 | /* Describe the pointer in each stack frame to the previous stack frame | |
247 | (its caller). */ | |
248 | ||
618ce49f AC |
249 | /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and produces |
250 | the frame's chain-pointer. In the case of the 68000, the frame's | |
251 | nominal address is the address of a 4-byte word containing the | |
252 | calling frame's address. */ | |
942dc0e9 GS |
253 | |
254 | /* If we are chaining from sigtramp, then manufacture a sigtramp frame | |
255 | (which isn't really on the stack. I'm not sure this is right for anything | |
256 | but BSD4.3 on an hp300. */ | |
257 | ||
258 | static CORE_ADDR | |
259 | m68k_frame_chain (struct frame_info *thisframe) | |
260 | { | |
32eeb91a | 261 | if (get_frame_type (thisframe) == SIGTRAMP_FRAME) |
1e2330ba | 262 | return get_frame_base (thisframe); |
50abf9e5 | 263 | else if (!inside_entry_file (get_frame_pc (thisframe))) |
1e2330ba | 264 | return read_memory_unsigned_integer (get_frame_base (thisframe), 4); |
942dc0e9 GS |
265 | else |
266 | return 0; | |
267 | } | |
268 | ||
269 | /* A function that tells us whether the function invocation represented | |
270 | by fi does not have a frame on the stack associated with it. If it | |
271 | does not, FRAMELESS is set to 1, else 0. */ | |
272 | ||
273 | static int | |
274 | m68k_frameless_function_invocation (struct frame_info *fi) | |
275 | { | |
32eeb91a | 276 | if (get_frame_type (fi) == SIGTRAMP_FRAME) |
942dc0e9 GS |
277 | return 0; |
278 | else | |
279 | return frameless_look_for_prologue (fi); | |
280 | } | |
281 | ||
282 | static CORE_ADDR | |
283 | m68k_frame_saved_pc (struct frame_info *frame) | |
284 | { | |
32eeb91a | 285 | if (get_frame_type (frame) == SIGTRAMP_FRAME) |
942dc0e9 | 286 | { |
11c02a10 AC |
287 | if (get_next_frame (frame)) |
288 | return read_memory_unsigned_integer (get_frame_base (get_next_frame (frame)) | |
b5fc49aa | 289 | + SIG_PC_FP_OFFSET, 4); |
942dc0e9 | 290 | else |
b5fc49aa AS |
291 | return read_memory_unsigned_integer (read_register (SP_REGNUM) |
292 | + SIG_PC_FP_OFFSET - 8, 4); | |
942dc0e9 GS |
293 | } |
294 | else | |
1e2330ba | 295 | return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4); |
942dc0e9 GS |
296 | } |
297 | ||
298 | ||
b83266a0 SS |
299 | /* The only reason this is here is the tm-altos.h reference below. It |
300 | was moved back here from tm-m68k.h. FIXME? */ | |
301 | ||
302 | extern CORE_ADDR | |
fba45db2 | 303 | altos_skip_prologue (CORE_ADDR pc) |
b83266a0 | 304 | { |
b5fc49aa | 305 | register int op = read_memory_unsigned_integer (pc, 2); |
89c3b6d3 | 306 | if (op == P_LINKW_FP) |
c5aa993b | 307 | pc += 4; /* Skip link #word */ |
89c3b6d3 | 308 | else if (op == P_LINKL_FP) |
c5aa993b | 309 | pc += 6; /* Skip link #long */ |
b83266a0 | 310 | /* Not sure why branches are here. */ |
514e603d | 311 | /* From tm-altos.h */ |
b83266a0 | 312 | else if (op == 0060000) |
c5aa993b | 313 | pc += 4; /* Skip bra #word */ |
b83266a0 | 314 | else if (op == 00600377) |
c5aa993b | 315 | pc += 6; /* skip bra #long */ |
b83266a0 | 316 | else if ((op & 0177400) == 0060000) |
c5aa993b | 317 | pc += 2; /* skip bra #char */ |
b83266a0 SS |
318 | return pc; |
319 | } | |
320 | ||
89c3b6d3 | 321 | int |
fba45db2 | 322 | delta68_in_sigtramp (CORE_ADDR pc, char *name) |
89c3b6d3 | 323 | { |
1bd54964 AC |
324 | if (name != NULL) |
325 | return strcmp (name, "_sigcode") == 0; | |
326 | else | |
327 | return 0; | |
89c3b6d3 PDM |
328 | } |
329 | ||
330 | CORE_ADDR | |
fba45db2 | 331 | delta68_frame_args_address (struct frame_info *frame_info) |
89c3b6d3 PDM |
332 | { |
333 | /* we assume here that the only frameless functions are the system calls | |
334 | or other functions who do not put anything on the stack. */ | |
32eeb91a | 335 | if (get_frame_type (frame_info) == SIGTRAMP_FRAME) |
1e2330ba | 336 | return get_frame_base (frame_info) + 12; |
89c3b6d3 PDM |
337 | else if (frameless_look_for_prologue (frame_info)) |
338 | { | |
b5d78d39 | 339 | /* Check for an interrupted system call */ |
11c02a10 AC |
340 | if (get_next_frame (frame_info) && (get_frame_type (get_next_frame (frame_info)) == SIGTRAMP_FRAME)) |
341 | return get_frame_base (get_next_frame (frame_info)) + 16; | |
b5d78d39 | 342 | else |
1e2330ba | 343 | return get_frame_base (frame_info) + 4; |
89c3b6d3 PDM |
344 | } |
345 | else | |
1e2330ba | 346 | return get_frame_base (frame_info); |
89c3b6d3 PDM |
347 | } |
348 | ||
349 | CORE_ADDR | |
fba45db2 | 350 | delta68_frame_saved_pc (struct frame_info *frame_info) |
89c3b6d3 | 351 | { |
b5fc49aa AS |
352 | return read_memory_unsigned_integer (delta68_frame_args_address (frame_info) |
353 | + 4, 4); | |
89c3b6d3 PDM |
354 | } |
355 | ||
392a587b JM |
356 | /* Return number of args passed to a frame. |
357 | Can return -1, meaning no way to tell. */ | |
358 | ||
359 | int | |
fba45db2 | 360 | isi_frame_num_args (struct frame_info *fi) |
392a587b JM |
361 | { |
362 | int val; | |
8bedc050 | 363 | CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi); |
b5fc49aa | 364 | int insn = read_memory_unsigned_integer (pc, 2); |
392a587b | 365 | val = 0; |
c5aa993b | 366 | if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ |
392a587b | 367 | val = read_memory_integer (pc + 2, 2); |
c5aa993b JM |
368 | else if ((insn & 0170777) == 0050217 /* addql #N, sp */ |
369 | || (insn & 0170777) == 0050117) /* addqw */ | |
392a587b JM |
370 | { |
371 | val = (insn >> 9) & 7; | |
372 | if (val == 0) | |
373 | val = 8; | |
374 | } | |
c5aa993b | 375 | else if (insn == 0157774) /* addal #WW, sp */ |
392a587b JM |
376 | val = read_memory_integer (pc + 2, 4); |
377 | val >>= 2; | |
378 | return val; | |
379 | } | |
380 | ||
381 | int | |
fba45db2 | 382 | delta68_frame_num_args (struct frame_info *fi) |
392a587b JM |
383 | { |
384 | int val; | |
8bedc050 | 385 | CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi); |
b5fc49aa | 386 | int insn = read_memory_unsigned_integer (pc, 2); |
392a587b | 387 | val = 0; |
c5aa993b | 388 | if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ |
392a587b | 389 | val = read_memory_integer (pc + 2, 2); |
c5aa993b JM |
390 | else if ((insn & 0170777) == 0050217 /* addql #N, sp */ |
391 | || (insn & 0170777) == 0050117) /* addqw */ | |
392a587b JM |
392 | { |
393 | val = (insn >> 9) & 7; | |
394 | if (val == 0) | |
395 | val = 8; | |
396 | } | |
c5aa993b | 397 | else if (insn == 0157774) /* addal #WW, sp */ |
392a587b JM |
398 | val = read_memory_integer (pc + 2, 4); |
399 | val >>= 2; | |
400 | return val; | |
401 | } | |
402 | ||
403 | int | |
fba45db2 | 404 | news_frame_num_args (struct frame_info *fi) |
392a587b JM |
405 | { |
406 | int val; | |
8bedc050 | 407 | CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi); |
b5fc49aa | 408 | int insn = read_memory_unsigned_integer (pc, 2); |
392a587b | 409 | val = 0; |
c5aa993b | 410 | if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ |
392a587b | 411 | val = read_memory_integer (pc + 2, 2); |
c5aa993b JM |
412 | else if ((insn & 0170777) == 0050217 /* addql #N, sp */ |
413 | || (insn & 0170777) == 0050117) /* addqw */ | |
392a587b JM |
414 | { |
415 | val = (insn >> 9) & 7; | |
416 | if (val == 0) | |
417 | val = 8; | |
418 | } | |
c5aa993b | 419 | else if (insn == 0157774) /* addal #WW, sp */ |
392a587b JM |
420 | val = read_memory_integer (pc + 2, 4); |
421 | val >>= 2; | |
422 | return val; | |
423 | } | |
b83266a0 | 424 | |
7f8e7424 GS |
425 | /* Insert the specified number of args and function address |
426 | into a call sequence of the above form stored at DUMMYNAME. | |
427 | We use the BFD routines to store a big-endian value of known size. */ | |
428 | ||
429 | void | |
a2c6a6d5 GS |
430 | m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, |
431 | struct value **args, struct type *type, int gcc_p) | |
7f8e7424 | 432 | { |
b1e29e33 | 433 | bfd_putb32 (fun, (unsigned char *) dummy + DEPRECATED_CALL_DUMMY_START_OFFSET + 2); |
a2c6a6d5 | 434 | bfd_putb32 (nargs * 4, |
b1e29e33 | 435 | (unsigned char *) dummy + DEPRECATED_CALL_DUMMY_START_OFFSET + 8); |
7f8e7424 GS |
436 | } |
437 | ||
438 | ||
c906108c SS |
439 | /* Push an empty stack frame, to record the current PC, etc. */ |
440 | ||
441 | void | |
fba45db2 | 442 | m68k_push_dummy_frame (void) |
c906108c SS |
443 | { |
444 | register CORE_ADDR sp = read_register (SP_REGNUM); | |
445 | register int regnum; | |
446 | char raw_buffer[12]; | |
447 | ||
448 | sp = push_word (sp, read_register (PC_REGNUM)); | |
0ba6dca9 AC |
449 | sp = push_word (sp, read_register (DEPRECATED_FP_REGNUM)); |
450 | write_register (DEPRECATED_FP_REGNUM, sp); | |
c906108c SS |
451 | |
452 | /* Always save the floating-point registers, whether they exist on | |
453 | this target or not. */ | |
454 | for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) | |
455 | { | |
73937e03 | 456 | deprecated_read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12); |
c906108c SS |
457 | sp = push_bytes (sp, raw_buffer, 12); |
458 | } | |
459 | ||
0ba6dca9 | 460 | for (regnum = DEPRECATED_FP_REGNUM - 1; regnum >= 0; regnum--) |
c906108c SS |
461 | { |
462 | sp = push_word (sp, read_register (regnum)); | |
463 | } | |
464 | sp = push_word (sp, read_register (PS_REGNUM)); | |
465 | write_register (SP_REGNUM, sp); | |
466 | } | |
467 | ||
468 | /* Discard from the stack the innermost frame, | |
469 | restoring all saved registers. */ | |
470 | ||
471 | void | |
fba45db2 | 472 | m68k_pop_frame (void) |
c906108c SS |
473 | { |
474 | register struct frame_info *frame = get_current_frame (); | |
475 | register CORE_ADDR fp; | |
476 | register int regnum; | |
c906108c SS |
477 | char raw_buffer[12]; |
478 | ||
c193f6ac | 479 | fp = get_frame_base (frame); |
7f8e7424 | 480 | m68k_frame_init_saved_regs (frame); |
c5aa993b | 481 | for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) |
c906108c | 482 | { |
b2fb4676 | 483 | if (get_frame_saved_regs (frame)[regnum]) |
c906108c | 484 | { |
b2fb4676 | 485 | read_memory (get_frame_saved_regs (frame)[regnum], raw_buffer, 12); |
73937e03 AC |
486 | deprecated_write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, |
487 | 12); | |
c906108c SS |
488 | } |
489 | } | |
0ba6dca9 | 490 | for (regnum = DEPRECATED_FP_REGNUM - 1; regnum >= 0; regnum--) |
c906108c | 491 | { |
b2fb4676 | 492 | if (get_frame_saved_regs (frame)[regnum]) |
c906108c | 493 | { |
a2c6a6d5 | 494 | write_register (regnum, |
b2fb4676 | 495 | read_memory_integer (get_frame_saved_regs (frame)[regnum], 4)); |
c906108c SS |
496 | } |
497 | } | |
b2fb4676 | 498 | if (get_frame_saved_regs (frame)[PS_REGNUM]) |
c906108c | 499 | { |
b5d78d39 | 500 | write_register (PS_REGNUM, |
b2fb4676 | 501 | read_memory_integer (get_frame_saved_regs (frame)[PS_REGNUM], 4)); |
c906108c | 502 | } |
0ba6dca9 | 503 | write_register (DEPRECATED_FP_REGNUM, read_memory_integer (fp, 4)); |
c906108c SS |
504 | write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); |
505 | write_register (SP_REGNUM, fp + 8); | |
506 | flush_cached_frames (); | |
507 | } | |
c906108c | 508 | \f |
c5aa993b | 509 | |
c906108c SS |
510 | /* Given an ip value corresponding to the start of a function, |
511 | return the ip of the first instruction after the function | |
512 | prologue. This is the generic m68k support. Machines which | |
513 | require something different can override the SKIP_PROLOGUE | |
514 | macro to point elsewhere. | |
515 | ||
516 | Some instructions which typically may appear in a function | |
517 | prologue include: | |
518 | ||
519 | A link instruction, word form: | |
520 | ||
c5aa993b | 521 | link.w %a6,&0 4e56 XXXX |
c906108c SS |
522 | |
523 | A link instruction, long form: | |
524 | ||
c5aa993b | 525 | link.l %fp,&F%1 480e XXXX XXXX |
c906108c SS |
526 | |
527 | A movm instruction to preserve integer regs: | |
528 | ||
c5aa993b | 529 | movm.l &M%1,(4,%sp) 48ef XXXX XXXX |
c906108c SS |
530 | |
531 | A fmovm instruction to preserve float regs: | |
532 | ||
c5aa993b | 533 | fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX |
c906108c SS |
534 | |
535 | Some profiling setup code (FIXME, not recognized yet): | |
536 | ||
c5aa993b JM |
537 | lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX |
538 | bsr _mcount 61ff XXXX XXXX | |
c906108c | 539 | |
c5aa993b | 540 | */ |
c906108c | 541 | |
c906108c | 542 | CORE_ADDR |
fba45db2 | 543 | m68k_skip_prologue (CORE_ADDR ip) |
c906108c SS |
544 | { |
545 | register CORE_ADDR limit; | |
546 | struct symtab_and_line sal; | |
547 | register int op; | |
548 | ||
549 | /* Find out if there is a known limit for the extent of the prologue. | |
550 | If so, ensure we don't go past it. If not, assume "infinity". */ | |
551 | ||
552 | sal = find_pc_line (ip, 0); | |
b5d78d39 | 553 | limit = (sal.end) ? sal.end : (CORE_ADDR) ~0; |
c906108c SS |
554 | |
555 | while (ip < limit) | |
556 | { | |
b5fc49aa | 557 | op = read_memory_unsigned_integer (ip, 2); |
c5aa993b | 558 | |
89c3b6d3 PDM |
559 | if (op == P_LINKW_FP) |
560 | ip += 4; /* Skip link.w */ | |
561 | else if (op == P_PEA_FP) | |
c5aa993b | 562 | ip += 2; /* Skip pea %fp */ |
89c3b6d3 | 563 | else if (op == P_MOVL_SP_FP) |
c5aa993b | 564 | ip += 2; /* Skip move.l %sp, %fp */ |
89c3b6d3 PDM |
565 | else if (op == P_LINKL_FP) |
566 | ip += 6; /* Skip link.l */ | |
567 | else if (op == P_MOVML) | |
568 | ip += 6; /* Skip movm.l */ | |
c906108c | 569 | else if (op == P_FMOVM) |
89c3b6d3 | 570 | ip += 10; /* Skip fmovm */ |
c906108c | 571 | else |
b5d78d39 | 572 | break; /* Found unknown code, bail out. */ |
c906108c SS |
573 | } |
574 | return (ip); | |
575 | } | |
576 | ||
7f8e7424 GS |
577 | /* Store the addresses of the saved registers of the frame described by |
578 | FRAME_INFO in its saved_regs field. | |
579 | This includes special registers such as pc and fp saved in special | |
580 | ways in the stack frame. sp is even more special: | |
581 | the address we return for it IS the sp for the next frame. */ | |
582 | ||
c906108c | 583 | void |
7f8e7424 | 584 | m68k_frame_init_saved_regs (struct frame_info *frame_info) |
c906108c | 585 | { |
c5aa993b JM |
586 | register int regnum; |
587 | register int regmask; | |
588 | register CORE_ADDR next_addr; | |
c906108c SS |
589 | register CORE_ADDR pc; |
590 | ||
591 | /* First possible address for a pc in a call dummy for this frame. */ | |
592 | CORE_ADDR possible_call_dummy_start = | |
0ba6dca9 | 593 | get_frame_base (frame_info) - 28 - DEPRECATED_FP_REGNUM * 4 - 4 - 8 * 12; |
c906108c SS |
594 | |
595 | int nextinsn; | |
7f8e7424 | 596 | |
b2fb4676 | 597 | if (get_frame_saved_regs (frame_info)) |
7f8e7424 GS |
598 | return; |
599 | ||
600 | frame_saved_regs_zalloc (frame_info); | |
601 | ||
b2fb4676 | 602 | memset (get_frame_saved_regs (frame_info), 0, SIZEOF_FRAME_SAVED_REGS); |
7f8e7424 | 603 | |
50abf9e5 | 604 | if (get_frame_pc (frame_info) >= possible_call_dummy_start |
1e2330ba | 605 | && get_frame_pc (frame_info) <= get_frame_base (frame_info)) |
c906108c SS |
606 | { |
607 | ||
608 | /* It is a call dummy. We could just stop now, since we know | |
c5aa993b JM |
609 | what the call dummy saves and where. But this code proceeds |
610 | to parse the "prologue" which is part of the call dummy. | |
611 | This is needlessly complex and confusing. FIXME. */ | |
c906108c | 612 | |
1e2330ba | 613 | next_addr = get_frame_base (frame_info); |
c906108c SS |
614 | pc = possible_call_dummy_start; |
615 | } | |
c5aa993b | 616 | else |
c906108c | 617 | { |
be41e9f4 | 618 | pc = get_frame_func (frame_info); |
c906108c | 619 | |
b5fc49aa | 620 | nextinsn = read_memory_unsigned_integer (pc, 2); |
89c3b6d3 | 621 | if (P_PEA_FP == nextinsn |
b5fc49aa | 622 | && P_MOVL_SP_FP == read_memory_unsigned_integer (pc + 2, 2)) |
c906108c | 623 | { |
89c3b6d3 | 624 | /* pea %fp |
c5aa993b | 625 | move.l %sp, %fp */ |
1e2330ba | 626 | next_addr = get_frame_base (frame_info); |
89c3b6d3 | 627 | pc += 4; |
c906108c | 628 | } |
89c3b6d3 | 629 | else if (P_LINKL_FP == nextinsn) |
c906108c SS |
630 | /* link.l %fp */ |
631 | /* Find the address above the saved | |
632 | regs using the amount of storage from the link instruction. */ | |
89c3b6d3 | 633 | { |
1e2330ba | 634 | next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 4); |
89c3b6d3 PDM |
635 | pc += 6; |
636 | } | |
637 | else if (P_LINKW_FP == nextinsn) | |
c906108c SS |
638 | /* link.w %fp */ |
639 | /* Find the address above the saved | |
640 | regs using the amount of storage from the link instruction. */ | |
89c3b6d3 | 641 | { |
1e2330ba | 642 | next_addr = get_frame_base (frame_info) + read_memory_integer (pc + 2, 2); |
89c3b6d3 PDM |
643 | pc += 4; |
644 | } | |
c5aa993b JM |
645 | else |
646 | goto lose; | |
647 | ||
648 | /* If have an addal #-n, sp next, adjust next_addr. */ | |
b5fc49aa | 649 | if (read_memory_unsigned_integer (pc, 2) == 0157774) |
c5aa993b JM |
650 | next_addr += read_memory_integer (pc += 2, 4), pc += 4; |
651 | } | |
c5aa993b | 652 | |
b5d78d39 | 653 | for (;;) |
c5aa993b | 654 | { |
b5fc49aa AS |
655 | nextinsn = read_memory_unsigned_integer (pc, 2); |
656 | regmask = read_memory_unsigned_integer (pc + 2, 2); | |
89c3b6d3 PDM |
657 | /* fmovemx to -(sp) */ |
658 | if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000) | |
c906108c | 659 | { |
89c3b6d3 PDM |
660 | /* Regmask's low bit is for register fp7, the first pushed */ |
661 | for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1) | |
662 | if (regmask & 1) | |
b2fb4676 | 663 | get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 12); |
89c3b6d3 PDM |
664 | pc += 4; |
665 | } | |
666 | /* fmovemx to (fp + displacement) */ | |
667 | else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000) | |
668 | { | |
669 | register CORE_ADDR addr; | |
670 | ||
1e2330ba | 671 | addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2); |
89c3b6d3 PDM |
672 | /* Regmask's low bit is for register fp7, the first pushed */ |
673 | for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1) | |
674 | if (regmask & 1) | |
675 | { | |
b2fb4676 | 676 | get_frame_saved_regs (frame_info)[regnum] = addr; |
89c3b6d3 PDM |
677 | addr += 12; |
678 | } | |
679 | pc += 6; | |
680 | } | |
681 | /* moveml to (sp) */ | |
682 | else if (0044327 == nextinsn) | |
683 | { | |
684 | /* Regmask's low bit is for register 0, the first written */ | |
685 | for (regnum = 0; regnum < 16; regnum++, regmask >>= 1) | |
686 | if (regmask & 1) | |
687 | { | |
b2fb4676 | 688 | get_frame_saved_regs (frame_info)[regnum] = next_addr; |
89c3b6d3 PDM |
689 | next_addr += 4; |
690 | } | |
691 | pc += 4; | |
692 | } | |
693 | /* moveml to (fp + displacement) */ | |
694 | else if (0044356 == nextinsn) | |
695 | { | |
696 | register CORE_ADDR addr; | |
697 | ||
1e2330ba | 698 | addr = get_frame_base (frame_info) + read_memory_integer (pc + 4, 2); |
89c3b6d3 PDM |
699 | /* Regmask's low bit is for register 0, the first written */ |
700 | for (regnum = 0; regnum < 16; regnum++, regmask >>= 1) | |
701 | if (regmask & 1) | |
702 | { | |
b2fb4676 | 703 | get_frame_saved_regs (frame_info)[regnum] = addr; |
89c3b6d3 PDM |
704 | addr += 4; |
705 | } | |
706 | pc += 6; | |
707 | } | |
708 | /* moveml to -(sp) */ | |
709 | else if (0044347 == nextinsn) | |
710 | { | |
711 | /* Regmask's low bit is for register 15, the first pushed */ | |
712 | for (regnum = 16; --regnum >= 0; regmask >>= 1) | |
713 | if (regmask & 1) | |
b2fb4676 | 714 | get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4); |
89c3b6d3 PDM |
715 | pc += 4; |
716 | } | |
717 | /* movl r,-(sp) */ | |
718 | else if (0x2f00 == (0xfff0 & nextinsn)) | |
719 | { | |
720 | regnum = 0xf & nextinsn; | |
b2fb4676 | 721 | get_frame_saved_regs (frame_info)[regnum] = (next_addr -= 4); |
89c3b6d3 | 722 | pc += 2; |
c906108c | 723 | } |
89c3b6d3 PDM |
724 | /* fmovemx to index of sp */ |
725 | else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000) | |
726 | { | |
727 | /* Regmask's low bit is for register fp0, the first written */ | |
728 | for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1) | |
729 | if (regmask & 1) | |
730 | { | |
b2fb4676 | 731 | get_frame_saved_regs (frame_info)[regnum] = next_addr; |
89c3b6d3 PDM |
732 | next_addr += 12; |
733 | } | |
734 | pc += 10; | |
735 | } | |
736 | /* clrw -(sp); movw ccr,-(sp) */ | |
737 | else if (0x4267 == nextinsn && 0x42e7 == regmask) | |
738 | { | |
b2fb4676 | 739 | get_frame_saved_regs (frame_info)[PS_REGNUM] = (next_addr -= 4); |
89c3b6d3 PDM |
740 | pc += 4; |
741 | } | |
742 | else | |
743 | break; | |
c906108c | 744 | } |
c5aa993b | 745 | lose:; |
1e2330ba | 746 | get_frame_saved_regs (frame_info)[SP_REGNUM] = get_frame_base (frame_info) + 8; |
0ba6dca9 | 747 | get_frame_saved_regs (frame_info)[DEPRECATED_FP_REGNUM] = get_frame_base (frame_info); |
1e2330ba | 748 | get_frame_saved_regs (frame_info)[PC_REGNUM] = get_frame_base (frame_info) + 4; |
c906108c SS |
749 | #ifdef SIG_SP_FP_OFFSET |
750 | /* Adjust saved SP_REGNUM for fake _sigtramp frames. */ | |
5a203e44 | 751 | if ((get_frame_type (frame_info) == SIGTRAMP_FRAME) && frame_info->next) |
7f8e7424 GS |
752 | frame_info->saved_regs[SP_REGNUM] = |
753 | frame_info->next->frame + SIG_SP_FP_OFFSET; | |
c906108c SS |
754 | #endif |
755 | } | |
756 | ||
757 | ||
c5aa993b | 758 | #ifdef USE_PROC_FS /* Target dependent support for /proc */ |
c906108c SS |
759 | |
760 | #include <sys/procfs.h> | |
761 | ||
c60c0f5f MS |
762 | /* Prototypes for supply_gregset etc. */ |
763 | #include "gregset.h" | |
764 | ||
c906108c | 765 | /* The /proc interface divides the target machine's register set up into |
c5aa993b JM |
766 | two different sets, the general register set (gregset) and the floating |
767 | point register set (fpregset). For each set, there is an ioctl to get | |
768 | the current register set and another ioctl to set the current values. | |
c906108c | 769 | |
c5aa993b JM |
770 | The actual structure passed through the ioctl interface is, of course, |
771 | naturally machine dependent, and is different for each set of registers. | |
772 | For the m68k for example, the general register set is typically defined | |
773 | by: | |
c906108c | 774 | |
c5aa993b | 775 | typedef int gregset_t[18]; |
c906108c | 776 | |
c5aa993b JM |
777 | #define R_D0 0 |
778 | ... | |
779 | #define R_PS 17 | |
c906108c | 780 | |
c5aa993b | 781 | and the floating point set by: |
c906108c | 782 | |
c5aa993b JM |
783 | typedef struct fpregset { |
784 | int f_pcr; | |
785 | int f_psr; | |
786 | int f_fpiaddr; | |
787 | int f_fpregs[8][3]; (8 regs, 96 bits each) | |
788 | } fpregset_t; | |
c906108c | 789 | |
c5aa993b JM |
790 | These routines provide the packing and unpacking of gregset_t and |
791 | fpregset_t formatted data. | |
c906108c SS |
792 | |
793 | */ | |
794 | ||
795 | /* Atari SVR4 has R_SR but not R_PS */ | |
796 | ||
797 | #if !defined (R_PS) && defined (R_SR) | |
798 | #define R_PS R_SR | |
799 | #endif | |
800 | ||
801 | /* Given a pointer to a general register set in /proc format (gregset_t *), | |
c5aa993b JM |
802 | unpack the register contents and supply them as gdb's idea of the current |
803 | register values. */ | |
c906108c SS |
804 | |
805 | void | |
fba45db2 | 806 | supply_gregset (gregset_t *gregsetp) |
c906108c SS |
807 | { |
808 | register int regi; | |
809 | register greg_t *regp = (greg_t *) gregsetp; | |
810 | ||
c5aa993b | 811 | for (regi = 0; regi < R_PC; regi++) |
c906108c SS |
812 | { |
813 | supply_register (regi, (char *) (regp + regi)); | |
814 | } | |
815 | supply_register (PS_REGNUM, (char *) (regp + R_PS)); | |
816 | supply_register (PC_REGNUM, (char *) (regp + R_PC)); | |
817 | } | |
818 | ||
819 | void | |
fba45db2 | 820 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
821 | { |
822 | register int regi; | |
823 | register greg_t *regp = (greg_t *) gregsetp; | |
c906108c | 824 | |
c5aa993b | 825 | for (regi = 0; regi < R_PC; regi++) |
c906108c SS |
826 | { |
827 | if ((regno == -1) || (regno == regi)) | |
828 | { | |
524d7c18 | 829 | *(regp + regi) = *(int *) &deprecated_registers[REGISTER_BYTE (regi)]; |
c906108c SS |
830 | } |
831 | } | |
832 | if ((regno == -1) || (regno == PS_REGNUM)) | |
833 | { | |
524d7c18 | 834 | *(regp + R_PS) = *(int *) &deprecated_registers[REGISTER_BYTE (PS_REGNUM)]; |
c906108c SS |
835 | } |
836 | if ((regno == -1) || (regno == PC_REGNUM)) | |
837 | { | |
524d7c18 | 838 | *(regp + R_PC) = *(int *) &deprecated_registers[REGISTER_BYTE (PC_REGNUM)]; |
c906108c SS |
839 | } |
840 | } | |
841 | ||
842 | #if defined (FP0_REGNUM) | |
843 | ||
844 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
845 | (fpregset_t *), unpack the register contents and supply them as gdb's |
846 | idea of the current floating point register values. */ | |
c906108c | 847 | |
c5aa993b | 848 | void |
fba45db2 | 849 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c SS |
850 | { |
851 | register int regi; | |
852 | char *from; | |
c5aa993b | 853 | |
32eeb91a | 854 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c | 855 | { |
c5aa993b | 856 | from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); |
c906108c SS |
857 | supply_register (regi, from); |
858 | } | |
32eeb91a AS |
859 | supply_register (M68K_FPC_REGNUM, (char *) &(fpregsetp->f_pcr)); |
860 | supply_register (M68K_FPS_REGNUM, (char *) &(fpregsetp->f_psr)); | |
861 | supply_register (M68K_FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr)); | |
c906108c SS |
862 | } |
863 | ||
864 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
865 | (fpregset_t *), update the register specified by REGNO from gdb's idea |
866 | of the current floating point register set. If REGNO is -1, update | |
867 | them all. */ | |
c906108c SS |
868 | |
869 | void | |
fba45db2 | 870 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
871 | { |
872 | int regi; | |
873 | char *to; | |
874 | char *from; | |
c906108c | 875 | |
32eeb91a | 876 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c SS |
877 | { |
878 | if ((regno == -1) || (regno == regi)) | |
879 | { | |
524d7c18 | 880 | from = (char *) &deprecated_registers[REGISTER_BYTE (regi)]; |
c5aa993b | 881 | to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); |
c906108c SS |
882 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
883 | } | |
884 | } | |
32eeb91a | 885 | if ((regno == -1) || (regno == M68K_FPC_REGNUM)) |
c906108c | 886 | { |
32eeb91a | 887 | fpregsetp->f_pcr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPC_REGNUM)]; |
c906108c | 888 | } |
32eeb91a | 889 | if ((regno == -1) || (regno == M68K_FPS_REGNUM)) |
c906108c | 890 | { |
32eeb91a | 891 | fpregsetp->f_psr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPS_REGNUM)]; |
c906108c | 892 | } |
32eeb91a | 893 | if ((regno == -1) || (regno == M68K_FPI_REGNUM)) |
c906108c | 894 | { |
32eeb91a | 895 | fpregsetp->f_fpiaddr = *(int *) &deprecated_registers[REGISTER_BYTE (M68K_FPI_REGNUM)]; |
c906108c SS |
896 | } |
897 | } | |
898 | ||
c5aa993b | 899 | #endif /* defined (FP0_REGNUM) */ |
c906108c | 900 | |
c5aa993b | 901 | #endif /* USE_PROC_FS */ |
c906108c | 902 | |
c906108c SS |
903 | /* Figure out where the longjmp will land. Slurp the args out of the stack. |
904 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
905 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
906 | This routine returns true on success. */ | |
907 | ||
2765b798 AC |
908 | /* NOTE: cagney/2000-11-08: For this function to be fully multi-arched |
909 | the macro's JB_PC and JB_ELEMENT_SIZE would need to be moved into | |
910 | the ``struct gdbarch_tdep'' object and then set on a target ISA/ABI | |
911 | dependant basis. */ | |
912 | ||
c906108c | 913 | int |
f4281f55 | 914 | m68k_get_longjmp_target (CORE_ADDR *pc) |
c906108c | 915 | { |
2765b798 | 916 | #if defined (JB_PC) && defined (JB_ELEMENT_SIZE) |
35fc8285 | 917 | char *buf; |
c906108c SS |
918 | CORE_ADDR sp, jb_addr; |
919 | ||
35fc8285 | 920 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c5aa993b | 921 | sp = read_register (SP_REGNUM); |
c906108c | 922 | |
b5d78d39 GS |
923 | if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */ |
924 | buf, TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
c906108c SS |
925 | return 0; |
926 | ||
927 | jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
928 | ||
929 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, | |
930 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
931 | return 0; | |
932 | ||
933 | *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
934 | ||
935 | return 1; | |
2765b798 | 936 | #else |
8e65ff28 AC |
937 | internal_error (__FILE__, __LINE__, |
938 | "m68k_get_longjmp_target: not implemented"); | |
2765b798 AC |
939 | return 0; |
940 | #endif | |
c906108c | 941 | } |
c906108c SS |
942 | |
943 | /* Immediately after a function call, return the saved pc before the frame | |
944 | is setup. For sun3's, we check for the common case of being inside of a | |
945 | system call, and if so, we know that Sun pushes the call # on the stack | |
946 | prior to doing the trap. */ | |
947 | ||
948 | CORE_ADDR | |
fba45db2 | 949 | m68k_saved_pc_after_call (struct frame_info *frame) |
c906108c SS |
950 | { |
951 | #ifdef SYSCALL_TRAP | |
952 | int op; | |
953 | ||
b5fc49aa | 954 | op = read_memory_unsigned_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2); |
c906108c SS |
955 | |
956 | if (op == SYSCALL_TRAP) | |
b5fc49aa | 957 | return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4); |
c906108c SS |
958 | else |
959 | #endif /* SYSCALL_TRAP */ | |
b5fc49aa | 960 | return read_memory_unsigned_integer (read_register (SP_REGNUM), 4); |
c906108c SS |
961 | } |
962 | ||
152d9db6 GS |
963 | /* Function: m68k_gdbarch_init |
964 | Initializer function for the m68k gdbarch vector. | |
965 | Called by gdbarch. Sets up the gdbarch vector(s) for this target. */ | |
966 | ||
967 | static struct gdbarch * | |
968 | m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
969 | { | |
a2c6a6d5 GS |
970 | static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7, |
971 | 0x4eb93232, 0x3232dffc, 0x69696969, | |
972 | (0x4e404e71 | (BPT_VECTOR << 16)) | |
973 | }; | |
152d9db6 GS |
974 | struct gdbarch_tdep *tdep = NULL; |
975 | struct gdbarch *gdbarch; | |
976 | ||
977 | /* find a candidate among the list of pre-declared architectures. */ | |
978 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
979 | if (arches != NULL) | |
980 | return (arches->gdbarch); | |
981 | ||
982 | #if 0 | |
983 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep)); | |
984 | #endif | |
6300c360 | 985 | |
152d9db6 GS |
986 | gdbarch = gdbarch_alloc (&info, 0); |
987 | ||
a5afb99f AC |
988 | /* NOTE: cagney/2002-12-06: This can be deleted when this arch is |
989 | ready to unwind the PC first (see frame.c:get_prev_frame()). */ | |
990 | set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default); | |
991 | ||
5d3ed2e3 GS |
992 | set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext); |
993 | set_gdbarch_long_double_bit (gdbarch, 96); | |
994 | ||
995 | set_gdbarch_function_start_offset (gdbarch, 0); | |
996 | ||
997 | set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue); | |
6913c89a | 998 | set_gdbarch_deprecated_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call); |
103a1597 | 999 | set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc); |
5d3ed2e3 GS |
1000 | |
1001 | /* Stack grows down. */ | |
1002 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1003 | set_gdbarch_stack_align (gdbarch, m68k_stack_align); | |
f933a9c5 | 1004 | set_gdbarch_deprecated_extra_stack_alignment_needed (gdbarch, 1); |
6300c360 GS |
1005 | |
1006 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); | |
942dc0e9 GS |
1007 | set_gdbarch_decr_pc_after_break (gdbarch, 2); |
1008 | ||
4183d812 | 1009 | set_gdbarch_deprecated_store_struct_return (gdbarch, m68k_store_struct_return); |
942dc0e9 GS |
1010 | set_gdbarch_deprecated_extract_return_value (gdbarch, |
1011 | m68k_deprecated_extract_return_value); | |
ebba8386 | 1012 | set_gdbarch_deprecated_store_return_value (gdbarch, m68k_store_return_value); |
942dc0e9 | 1013 | |
618ce49f | 1014 | set_gdbarch_deprecated_frame_chain (gdbarch, m68k_frame_chain); |
8bedc050 | 1015 | set_gdbarch_deprecated_frame_saved_pc (gdbarch, m68k_frame_saved_pc); |
f30ee0bc | 1016 | set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs); |
942dc0e9 GS |
1017 | set_gdbarch_frameless_function_invocation (gdbarch, |
1018 | m68k_frameless_function_invocation); | |
6300c360 GS |
1019 | /* OK to default this value to 'unknown'. */ |
1020 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1021 | set_gdbarch_frame_args_skip (gdbarch, 8); | |
942dc0e9 | 1022 | |
5d3ed2e3 GS |
1023 | set_gdbarch_register_raw_size (gdbarch, m68k_register_raw_size); |
1024 | set_gdbarch_register_virtual_size (gdbarch, m68k_register_virtual_size); | |
a0ed5532 AC |
1025 | set_gdbarch_deprecated_max_register_raw_size (gdbarch, 12); |
1026 | set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 12); | |
5d3ed2e3 GS |
1027 | set_gdbarch_register_virtual_type (gdbarch, m68k_register_virtual_type); |
1028 | set_gdbarch_register_name (gdbarch, m68k_register_name); | |
b1e29e33 | 1029 | set_gdbarch_deprecated_register_size (gdbarch, 4); |
5d3ed2e3 | 1030 | set_gdbarch_register_byte (gdbarch, m68k_register_byte); |
942dc0e9 GS |
1031 | set_gdbarch_num_regs (gdbarch, 29); |
1032 | set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok); | |
b8b527c5 | 1033 | set_gdbarch_deprecated_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4)); |
32eeb91a | 1034 | set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM); |
0ba6dca9 | 1035 | set_gdbarch_deprecated_fp_regnum (gdbarch, M68K_FP_REGNUM); |
32eeb91a AS |
1036 | set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM); |
1037 | set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM); | |
1038 | set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM); | |
a2c6a6d5 | 1039 | |
07555a72 | 1040 | set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0); |
7f8e7424 | 1041 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); |
b1e29e33 | 1042 | set_gdbarch_deprecated_call_dummy_breakpoint_offset (gdbarch, 24); |
ae45cd16 | 1043 | set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_on_stack); |
b1e29e33 AC |
1044 | set_gdbarch_deprecated_call_dummy_length (gdbarch, 28); |
1045 | set_gdbarch_deprecated_call_dummy_start_offset (gdbarch, 12); | |
a2c6a6d5 | 1046 | |
b1e29e33 AC |
1047 | set_gdbarch_deprecated_call_dummy_words (gdbarch, call_dummy_words); |
1048 | set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words)); | |
1049 | set_gdbarch_deprecated_fix_call_dummy (gdbarch, m68k_fix_call_dummy); | |
f3824013 | 1050 | set_gdbarch_deprecated_push_dummy_frame (gdbarch, m68k_push_dummy_frame); |
749b82f6 | 1051 | set_gdbarch_deprecated_pop_frame (gdbarch, m68k_pop_frame); |
a2c6a6d5 | 1052 | |
6c0e89ed AC |
1053 | /* Should be using push_dummy_call. */ |
1054 | set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp); | |
1055 | ||
55809acb AS |
1056 | /* Hook in ABI-specific overrides, if they have been registered. */ |
1057 | gdbarch_init_osabi (info, gdbarch); | |
1058 | ||
152d9db6 GS |
1059 | return gdbarch; |
1060 | } | |
1061 | ||
1062 | ||
1063 | static void | |
1064 | m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
1065 | { | |
1066 | ||
1067 | } | |
2acceee2 | 1068 | |
c906108c | 1069 | void |
fba45db2 | 1070 | _initialize_m68k_tdep (void) |
c906108c | 1071 | { |
152d9db6 | 1072 | gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep); |
d7a27068 | 1073 | deprecated_tm_print_insn = print_insn_m68k; |
c906108c | 1074 | } |