]>
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" | |
8de307e0 AS |
25 | #include "frame-base.h" |
26 | #include "frame-unwind.h" | |
c906108c SS |
27 | #include "symtab.h" |
28 | #include "gdbcore.h" | |
29 | #include "value.h" | |
30 | #include "gdb_string.h" | |
8de307e0 | 31 | #include "gdb_assert.h" |
7a292a7a | 32 | #include "inferior.h" |
4e052eda | 33 | #include "regcache.h" |
5d3ed2e3 | 34 | #include "arch-utils.h" |
55809acb | 35 | #include "osabi.h" |
a89aa300 | 36 | #include "dis-asm.h" |
32eeb91a AS |
37 | |
38 | #include "m68k-tdep.h" | |
c906108c | 39 | \f |
c5aa993b | 40 | |
89c3b6d3 PDM |
41 | #define P_LINKL_FP 0x480e |
42 | #define P_LINKW_FP 0x4e56 | |
43 | #define P_PEA_FP 0x4856 | |
8de307e0 AS |
44 | #define P_MOVEAL_SP_FP 0x2c4f |
45 | #define P_ADDAW_SP 0xdefc | |
46 | #define P_ADDAL_SP 0xdffc | |
47 | #define P_SUBQW_SP 0x514f | |
48 | #define P_SUBQL_SP 0x518f | |
49 | #define P_LEA_SP_SP 0x4fef | |
50 | #define P_LEA_PC_A5 0x4bfb0170 | |
51 | #define P_FMOVEMX_SP 0xf227 | |
52 | #define P_MOVEL_SP 0x2f00 | |
53 | #define P_MOVEML_SP 0x48e7 | |
89c3b6d3 | 54 | |
103a1597 | 55 | |
103a1597 GS |
56 | #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4) |
57 | #define REGISTER_BYTES_NOFP (16*4 + 8) | |
58 | ||
103a1597 | 59 | /* Offset from SP to first arg on stack at first instruction of a function */ |
103a1597 GS |
60 | #define SP_ARG0 (1 * 4) |
61 | ||
103a1597 GS |
62 | #if !defined (BPT_VECTOR) |
63 | #define BPT_VECTOR 0xf | |
64 | #endif | |
65 | ||
66 | #if !defined (REMOTE_BPT_VECTOR) | |
67 | #define REMOTE_BPT_VECTOR 1 | |
68 | #endif | |
69 | ||
70 | ||
103a1597 GS |
71 | /* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc |
72 | so m68k_remote_breakpoint_from_pc is currently not used. */ | |
73 | ||
eb2e12d7 | 74 | static const unsigned char * |
103a1597 GS |
75 | m68k_remote_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
76 | { | |
77 | static unsigned char break_insn[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR)}; | |
78 | *lenptr = sizeof (break_insn); | |
79 | return break_insn; | |
80 | } | |
81 | ||
eb2e12d7 | 82 | static const unsigned char * |
103a1597 GS |
83 | m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
84 | { | |
85 | static unsigned char break_insn[] = {0x4e, (0x40 | BPT_VECTOR)}; | |
86 | *lenptr = sizeof (break_insn); | |
87 | return break_insn; | |
88 | } | |
89 | ||
90 | ||
942dc0e9 | 91 | static int |
5ae5f592 | 92 | m68k_register_bytes_ok (long numbytes) |
942dc0e9 GS |
93 | { |
94 | return ((numbytes == REGISTER_BYTES_FP) | |
95 | || (numbytes == REGISTER_BYTES_NOFP)); | |
96 | } | |
97 | ||
d85fe7f7 AS |
98 | /* Return the GDB type object for the "standard" data type of data in |
99 | register N. This should be int for D0-D7, SR, FPCONTROL and | |
100 | FPSTATUS, long double for FP0-FP7, and void pointer for all others | |
101 | (A0-A7, PC, FPIADDR). Note, for registers which contain | |
102 | addresses return pointer to void, not pointer to char, because we | |
103 | don't want to attempt to print the string after printing the | |
104 | address. */ | |
5d3ed2e3 GS |
105 | |
106 | static struct type * | |
8de307e0 | 107 | m68k_register_type (struct gdbarch *gdbarch, int regnum) |
5d3ed2e3 | 108 | { |
03dac896 AS |
109 | if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7) |
110 | return builtin_type_m68881_ext; | |
111 | ||
32eeb91a | 112 | if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM) |
03dac896 AS |
113 | return builtin_type_void_func_ptr; |
114 | ||
32eeb91a AS |
115 | if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM |
116 | || regnum == PS_REGNUM) | |
03dac896 AS |
117 | return builtin_type_int32; |
118 | ||
32eeb91a | 119 | if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7) |
03dac896 AS |
120 | return builtin_type_void_data_ptr; |
121 | ||
122 | return builtin_type_int32; | |
5d3ed2e3 GS |
123 | } |
124 | ||
125 | /* Function: m68k_register_name | |
126 | Returns the name of the standard m68k register regnum. */ | |
127 | ||
128 | static const char * | |
129 | m68k_register_name (int regnum) | |
130 | { | |
131 | static char *register_names[] = { | |
132 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", | |
133 | "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", | |
134 | "ps", "pc", | |
135 | "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", | |
136 | "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" | |
137 | }; | |
138 | ||
139 | if (regnum < 0 || | |
140 | regnum >= sizeof (register_names) / sizeof (register_names[0])) | |
141 | internal_error (__FILE__, __LINE__, | |
142 | "m68k_register_name: illegal register number %d", regnum); | |
143 | else | |
144 | return register_names[regnum]; | |
145 | } | |
146 | ||
5d3ed2e3 GS |
147 | /* Index within `registers' of the first byte of the space for |
148 | register regnum. */ | |
149 | ||
150 | static int | |
151 | m68k_register_byte (int regnum) | |
152 | { | |
32eeb91a AS |
153 | if (regnum >= M68K_FPC_REGNUM) |
154 | return (((regnum - M68K_FPC_REGNUM) * 4) + 168); | |
5d3ed2e3 GS |
155 | else if (regnum >= FP0_REGNUM) |
156 | return (((regnum - FP0_REGNUM) * 12) + 72); | |
157 | else | |
158 | return (regnum * 4); | |
159 | } | |
8de307e0 AS |
160 | \f |
161 | /* Extract from an array REGBUF containing the (raw) register state, a | |
162 | function return value of TYPE, and copy that, in virtual format, | |
163 | into VALBUF. */ | |
942dc0e9 GS |
164 | |
165 | static void | |
8de307e0 AS |
166 | m68k_extract_return_value (struct type *type, struct regcache *regcache, |
167 | void *valbuf) | |
942dc0e9 | 168 | { |
8de307e0 AS |
169 | int len = TYPE_LENGTH (type); |
170 | char buf[M68K_MAX_REGISTER_SIZE]; | |
942dc0e9 | 171 | |
8de307e0 AS |
172 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
173 | && TYPE_NFIELDS (type) == 1) | |
174 | { | |
175 | m68k_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf); | |
176 | return; | |
177 | } | |
942dc0e9 | 178 | |
8de307e0 AS |
179 | if (len <= 4) |
180 | { | |
181 | regcache_raw_read (regcache, M68K_D0_REGNUM, buf); | |
182 | memcpy (valbuf, buf + (4 - len), len); | |
183 | } | |
184 | else if (len <= 8) | |
185 | { | |
186 | regcache_raw_read (regcache, M68K_D0_REGNUM, buf); | |
187 | memcpy (valbuf, buf + (8 - len), len - 4); | |
188 | regcache_raw_read (regcache, M68K_D1_REGNUM, | |
189 | (char *) valbuf + (len - 4)); | |
190 | } | |
191 | else | |
192 | internal_error (__FILE__, __LINE__, | |
193 | "Cannot extract return value of %d bytes long.", len); | |
942dc0e9 GS |
194 | } |
195 | ||
8de307e0 AS |
196 | /* Write into the appropriate registers a function return value stored |
197 | in VALBUF of type TYPE, given in virtual format. */ | |
942dc0e9 GS |
198 | |
199 | static void | |
8de307e0 AS |
200 | m68k_store_return_value (struct type *type, struct regcache *regcache, |
201 | const void *valbuf) | |
942dc0e9 | 202 | { |
8de307e0 | 203 | int len = TYPE_LENGTH (type); |
942dc0e9 | 204 | |
8de307e0 AS |
205 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
206 | && TYPE_NFIELDS (type) == 1) | |
207 | { | |
208 | m68k_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf); | |
209 | return; | |
210 | } | |
942dc0e9 | 211 | |
8de307e0 AS |
212 | if (len <= 4) |
213 | regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf); | |
214 | else if (len <= 8) | |
215 | { | |
216 | regcache_raw_write_part (regcache, M68K_D1_REGNUM, 8 - len, | |
217 | len - 4, valbuf); | |
218 | regcache_raw_write (regcache, M68K_D0_REGNUM, | |
219 | (char *) valbuf + (len - 4)); | |
220 | } | |
221 | else | |
222 | internal_error (__FILE__, __LINE__, | |
223 | "Cannot store return value of %d bytes long.", len); | |
224 | } | |
942dc0e9 | 225 | |
8de307e0 AS |
226 | /* Extract from REGCACHE, which contains the (raw) register state, the |
227 | address in which a function should return its structure value, as a | |
228 | CORE_ADDR. */ | |
942dc0e9 GS |
229 | |
230 | static CORE_ADDR | |
8de307e0 | 231 | m68k_extract_struct_value_address (struct regcache *regcache) |
942dc0e9 | 232 | { |
8de307e0 AS |
233 | char buf[4]; |
234 | ||
235 | regcache_cooked_read (regcache, M68K_D0_REGNUM, buf); | |
236 | return extract_unsigned_integer (buf, 4); | |
942dc0e9 GS |
237 | } |
238 | ||
c481dac7 AS |
239 | static int |
240 | m68k_use_struct_convention (int gcc_p, struct type *type) | |
241 | { | |
242 | enum struct_return struct_return; | |
243 | ||
244 | struct_return = gdbarch_tdep (current_gdbarch)->struct_return; | |
245 | return generic_use_struct_convention (struct_return == reg_struct_return, | |
246 | type); | |
247 | } | |
248 | ||
942dc0e9 GS |
249 | /* A function that tells us whether the function invocation represented |
250 | by fi does not have a frame on the stack associated with it. If it | |
251 | does not, FRAMELESS is set to 1, else 0. */ | |
252 | ||
253 | static int | |
254 | m68k_frameless_function_invocation (struct frame_info *fi) | |
255 | { | |
32eeb91a | 256 | if (get_frame_type (fi) == SIGTRAMP_FRAME) |
942dc0e9 GS |
257 | return 0; |
258 | else | |
259 | return frameless_look_for_prologue (fi); | |
260 | } | |
261 | ||
89c3b6d3 | 262 | int |
fba45db2 | 263 | delta68_in_sigtramp (CORE_ADDR pc, char *name) |
89c3b6d3 | 264 | { |
1bd54964 AC |
265 | if (name != NULL) |
266 | return strcmp (name, "_sigcode") == 0; | |
267 | else | |
268 | return 0; | |
89c3b6d3 PDM |
269 | } |
270 | ||
271 | CORE_ADDR | |
fba45db2 | 272 | delta68_frame_args_address (struct frame_info *frame_info) |
89c3b6d3 PDM |
273 | { |
274 | /* we assume here that the only frameless functions are the system calls | |
275 | or other functions who do not put anything on the stack. */ | |
32eeb91a | 276 | if (get_frame_type (frame_info) == SIGTRAMP_FRAME) |
1e2330ba | 277 | return get_frame_base (frame_info) + 12; |
89c3b6d3 PDM |
278 | else if (frameless_look_for_prologue (frame_info)) |
279 | { | |
b5d78d39 | 280 | /* Check for an interrupted system call */ |
11c02a10 AC |
281 | if (get_next_frame (frame_info) && (get_frame_type (get_next_frame (frame_info)) == SIGTRAMP_FRAME)) |
282 | return get_frame_base (get_next_frame (frame_info)) + 16; | |
b5d78d39 | 283 | else |
1e2330ba | 284 | return get_frame_base (frame_info) + 4; |
89c3b6d3 PDM |
285 | } |
286 | else | |
1e2330ba | 287 | return get_frame_base (frame_info); |
89c3b6d3 PDM |
288 | } |
289 | ||
290 | CORE_ADDR | |
fba45db2 | 291 | delta68_frame_saved_pc (struct frame_info *frame_info) |
89c3b6d3 | 292 | { |
b5fc49aa AS |
293 | return read_memory_unsigned_integer (delta68_frame_args_address (frame_info) |
294 | + 4, 4); | |
89c3b6d3 PDM |
295 | } |
296 | ||
392a587b | 297 | int |
fba45db2 | 298 | delta68_frame_num_args (struct frame_info *fi) |
392a587b JM |
299 | { |
300 | int val; | |
8bedc050 | 301 | CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi); |
b5fc49aa | 302 | int insn = read_memory_unsigned_integer (pc, 2); |
392a587b | 303 | val = 0; |
c5aa993b | 304 | if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ |
392a587b | 305 | val = read_memory_integer (pc + 2, 2); |
c5aa993b JM |
306 | else if ((insn & 0170777) == 0050217 /* addql #N, sp */ |
307 | || (insn & 0170777) == 0050117) /* addqw */ | |
392a587b JM |
308 | { |
309 | val = (insn >> 9) & 7; | |
310 | if (val == 0) | |
311 | val = 8; | |
312 | } | |
c5aa993b | 313 | else if (insn == 0157774) /* addal #WW, sp */ |
392a587b JM |
314 | val = read_memory_integer (pc + 2, 4); |
315 | val >>= 2; | |
316 | return val; | |
317 | } | |
318 | ||
8de307e0 AS |
319 | static CORE_ADDR |
320 | m68k_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, | |
321 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, | |
322 | struct value **args, CORE_ADDR sp, int struct_return, | |
323 | CORE_ADDR struct_addr) | |
7f8e7424 | 324 | { |
8de307e0 AS |
325 | char buf[4]; |
326 | int i; | |
327 | ||
328 | /* Push arguments in reverse order. */ | |
329 | for (i = nargs - 1; i >= 0; i--) | |
330 | { | |
c481dac7 AS |
331 | struct type *value_type = VALUE_ENCLOSING_TYPE (args[i]); |
332 | int len = TYPE_LENGTH (value_type); | |
8de307e0 | 333 | int container_len = (len + 3) & ~3; |
c481dac7 AS |
334 | int offset; |
335 | ||
336 | /* Non-scalars bigger than 4 bytes are left aligned, others are | |
337 | right aligned. */ | |
338 | if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT | |
339 | || TYPE_CODE (value_type) == TYPE_CODE_UNION | |
340 | || TYPE_CODE (value_type) == TYPE_CODE_ARRAY) | |
341 | && len > 4) | |
342 | offset = 0; | |
343 | else | |
344 | offset = container_len - len; | |
8de307e0 AS |
345 | sp -= container_len; |
346 | write_memory (sp + offset, VALUE_CONTENTS_ALL (args[i]), len); | |
347 | } | |
348 | ||
c481dac7 | 349 | /* Store struct value address. */ |
8de307e0 AS |
350 | if (struct_return) |
351 | { | |
8de307e0 | 352 | store_unsigned_integer (buf, 4, struct_addr); |
c481dac7 | 353 | regcache_cooked_write (regcache, M68K_A1_REGNUM, buf); |
8de307e0 AS |
354 | } |
355 | ||
356 | /* Store return address. */ | |
357 | sp -= 4; | |
358 | store_unsigned_integer (buf, 4, bp_addr); | |
359 | write_memory (sp, buf, 4); | |
360 | ||
361 | /* Finally, update the stack pointer... */ | |
362 | store_unsigned_integer (buf, 4, sp); | |
363 | regcache_cooked_write (regcache, M68K_SP_REGNUM, buf); | |
364 | ||
365 | /* ...and fake a frame pointer. */ | |
366 | regcache_cooked_write (regcache, M68K_FP_REGNUM, buf); | |
367 | ||
368 | /* DWARF2/GCC uses the stack address *before* the function call as a | |
369 | frame's CFA. */ | |
370 | return sp + 8; | |
7f8e7424 | 371 | } |
8de307e0 AS |
372 | \f |
373 | struct m68k_frame_cache | |
374 | { | |
375 | /* Base address. */ | |
376 | CORE_ADDR base; | |
377 | CORE_ADDR sp_offset; | |
378 | CORE_ADDR pc; | |
7f8e7424 | 379 | |
8de307e0 AS |
380 | /* Saved registers. */ |
381 | CORE_ADDR saved_regs[M68K_NUM_REGS]; | |
382 | CORE_ADDR saved_sp; | |
7f8e7424 | 383 | |
8de307e0 AS |
384 | /* Stack space reserved for local variables. */ |
385 | long locals; | |
386 | }; | |
c906108c | 387 | |
8de307e0 AS |
388 | /* Allocate and initialize a frame cache. */ |
389 | ||
390 | static struct m68k_frame_cache * | |
391 | m68k_alloc_frame_cache (void) | |
c906108c | 392 | { |
8de307e0 AS |
393 | struct m68k_frame_cache *cache; |
394 | int i; | |
c906108c | 395 | |
8de307e0 | 396 | cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache); |
c906108c | 397 | |
8de307e0 AS |
398 | /* Base address. */ |
399 | cache->base = 0; | |
400 | cache->sp_offset = -4; | |
401 | cache->pc = 0; | |
c906108c | 402 | |
8de307e0 AS |
403 | /* Saved registers. We initialize these to -1 since zero is a valid |
404 | offset (that's where %fp is supposed to be stored). */ | |
405 | for (i = 0; i < M68K_NUM_REGS; i++) | |
406 | cache->saved_regs[i] = -1; | |
407 | ||
408 | /* Frameless until proven otherwise. */ | |
409 | cache->locals = -1; | |
410 | ||
411 | return cache; | |
c906108c SS |
412 | } |
413 | ||
8de307e0 AS |
414 | /* Check whether PC points at a code that sets up a new stack frame. |
415 | If so, it updates CACHE and returns the address of the first | |
416 | instruction after the sequence that sets removes the "hidden" | |
417 | argument from the stack or CURRENT_PC, whichever is smaller. | |
418 | Otherwise, return PC. */ | |
c906108c | 419 | |
8de307e0 AS |
420 | static CORE_ADDR |
421 | m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc, | |
422 | struct m68k_frame_cache *cache) | |
c906108c | 423 | { |
8de307e0 AS |
424 | int op; |
425 | ||
426 | if (pc >= current_pc) | |
427 | return current_pc; | |
c906108c | 428 | |
8de307e0 AS |
429 | op = read_memory_unsigned_integer (pc, 2); |
430 | ||
431 | if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP) | |
c906108c | 432 | { |
8de307e0 AS |
433 | cache->saved_regs[M68K_FP_REGNUM] = 0; |
434 | cache->sp_offset += 4; | |
435 | if (op == P_LINKW_FP) | |
436 | { | |
437 | /* link.w %fp, #-N */ | |
438 | /* link.w %fp, #0; adda.l #-N, %sp */ | |
439 | cache->locals = -read_memory_integer (pc + 2, 2); | |
440 | ||
441 | if (pc + 4 < current_pc && cache->locals == 0) | |
442 | { | |
443 | op = read_memory_unsigned_integer (pc + 4, 2); | |
444 | if (op == P_ADDAL_SP) | |
445 | { | |
446 | cache->locals = read_memory_integer (pc + 6, 4); | |
447 | return pc + 10; | |
448 | } | |
449 | } | |
450 | ||
451 | return pc + 4; | |
452 | } | |
453 | else if (op == P_LINKL_FP) | |
c906108c | 454 | { |
8de307e0 AS |
455 | /* link.l %fp, #-N */ |
456 | cache->locals = -read_memory_integer (pc + 2, 4); | |
457 | return pc + 6; | |
458 | } | |
459 | else | |
460 | { | |
461 | /* pea (%fp); movea.l %sp, %fp */ | |
462 | cache->locals = 0; | |
463 | ||
464 | if (pc + 2 < current_pc) | |
465 | { | |
466 | op = read_memory_unsigned_integer (pc + 2, 2); | |
467 | ||
468 | if (op == P_MOVEAL_SP_FP) | |
469 | { | |
470 | /* move.l %sp, %fp */ | |
471 | return pc + 4; | |
472 | } | |
473 | } | |
474 | ||
475 | return pc + 2; | |
c906108c SS |
476 | } |
477 | } | |
8de307e0 | 478 | else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP) |
c906108c | 479 | { |
8de307e0 AS |
480 | /* subq.[wl] #N,%sp */ |
481 | /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */ | |
482 | cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9; | |
483 | if (pc + 2 < current_pc) | |
c906108c | 484 | { |
8de307e0 AS |
485 | op = read_memory_unsigned_integer (pc + 2, 2); |
486 | if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP) | |
487 | { | |
488 | cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9; | |
489 | return pc + 4; | |
490 | } | |
c906108c | 491 | } |
8de307e0 AS |
492 | return pc + 2; |
493 | } | |
494 | else if (op == P_ADDAW_SP || op == P_LEA_SP_SP) | |
495 | { | |
496 | /* adda.w #-N,%sp */ | |
497 | /* lea (-N,%sp),%sp */ | |
498 | cache->locals = -read_memory_integer (pc + 2, 2); | |
499 | return pc + 4; | |
c906108c | 500 | } |
8de307e0 | 501 | else if (op == P_ADDAL_SP) |
c906108c | 502 | { |
8de307e0 AS |
503 | /* adda.l #-N,%sp */ |
504 | cache->locals = -read_memory_integer (pc + 2, 4); | |
505 | return pc + 6; | |
c906108c | 506 | } |
8de307e0 AS |
507 | |
508 | return pc; | |
c906108c | 509 | } |
c5aa993b | 510 | |
8de307e0 AS |
511 | /* Check whether PC points at code that saves registers on the stack. |
512 | If so, it updates CACHE and returns the address of the first | |
513 | instruction after the register saves or CURRENT_PC, whichever is | |
514 | smaller. Otherwise, return PC. */ | |
c906108c | 515 | |
8de307e0 AS |
516 | static CORE_ADDR |
517 | m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc, | |
518 | struct m68k_frame_cache *cache) | |
519 | { | |
520 | if (cache->locals >= 0) | |
521 | { | |
522 | CORE_ADDR offset; | |
523 | int op; | |
524 | int i, mask, regno; | |
c906108c | 525 | |
8de307e0 AS |
526 | offset = -4 - cache->locals; |
527 | while (pc < current_pc) | |
528 | { | |
529 | op = read_memory_unsigned_integer (pc, 2); | |
530 | if (op == P_FMOVEMX_SP) | |
531 | { | |
532 | /* fmovem.x REGS,-(%sp) */ | |
533 | op = read_memory_unsigned_integer (pc + 2, 2); | |
534 | if ((op & 0xff00) == 0xe000) | |
535 | { | |
536 | mask = op & 0xff; | |
537 | for (i = 0; i < 16; i++, mask >>= 1) | |
538 | { | |
539 | if (mask & 1) | |
540 | { | |
541 | cache->saved_regs[i + M68K_FP0_REGNUM] = offset; | |
542 | offset -= 12; | |
543 | } | |
544 | } | |
545 | pc += 4; | |
546 | } | |
547 | else | |
548 | break; | |
549 | } | |
550 | else if ((op & 0170677) == P_MOVEL_SP) | |
551 | { | |
552 | /* move.l %R,-(%sp) */ | |
553 | regno = ((op & 07000) >> 9) | ((op & 0100) >> 3); | |
554 | cache->saved_regs[regno] = offset; | |
555 | offset -= 4; | |
556 | pc += 2; | |
557 | } | |
558 | else if (op == P_MOVEML_SP) | |
559 | { | |
560 | /* movem.l REGS,-(%sp) */ | |
561 | mask = read_memory_unsigned_integer (pc + 2, 2); | |
562 | for (i = 0; i < 16; i++, mask >>= 1) | |
563 | { | |
564 | if (mask & 1) | |
565 | { | |
566 | cache->saved_regs[15 - i] = offset; | |
567 | offset -= 4; | |
568 | } | |
569 | } | |
570 | pc += 4; | |
571 | } | |
572 | else | |
573 | break; | |
574 | } | |
575 | } | |
576 | ||
577 | return pc; | |
578 | } | |
c906108c | 579 | |
c906108c | 580 | |
8de307e0 AS |
581 | /* Do a full analysis of the prologue at PC and update CACHE |
582 | accordingly. Bail out early if CURRENT_PC is reached. Return the | |
583 | address where the analysis stopped. | |
c906108c | 584 | |
8de307e0 | 585 | We handle all cases that can be generated by gcc. |
c906108c | 586 | |
8de307e0 | 587 | For allocating a stack frame: |
c906108c | 588 | |
8de307e0 AS |
589 | link.w %a6,#-N |
590 | link.l %a6,#-N | |
591 | pea (%fp); move.l %sp,%fp | |
592 | link.w %a6,#0; add.l #-N,%sp | |
593 | subq.l #N,%sp | |
594 | subq.w #N,%sp | |
595 | subq.w #8,%sp; subq.w #N-8,%sp | |
596 | add.w #-N,%sp | |
597 | lea (-N,%sp),%sp | |
598 | add.l #-N,%sp | |
c906108c | 599 | |
8de307e0 | 600 | For saving registers: |
c906108c | 601 | |
8de307e0 AS |
602 | fmovem.x REGS,-(%sp) |
603 | move.l R1,-(%sp) | |
604 | move.l R1,-(%sp); move.l R2,-(%sp) | |
605 | movem.l REGS,-(%sp) | |
c906108c | 606 | |
8de307e0 | 607 | For setting up the PIC register: |
c906108c | 608 | |
8de307e0 | 609 | lea (%pc,N),%a5 |
c906108c | 610 | |
8de307e0 | 611 | */ |
c906108c | 612 | |
eb2e12d7 | 613 | static CORE_ADDR |
8de307e0 AS |
614 | m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc, |
615 | struct m68k_frame_cache *cache) | |
c906108c | 616 | { |
8de307e0 | 617 | unsigned int op; |
c906108c | 618 | |
8de307e0 AS |
619 | pc = m68k_analyze_frame_setup (pc, current_pc, cache); |
620 | pc = m68k_analyze_register_saves (pc, current_pc, cache); | |
621 | if (pc >= current_pc) | |
622 | return current_pc; | |
c906108c | 623 | |
8de307e0 AS |
624 | /* Check for GOT setup. */ |
625 | op = read_memory_unsigned_integer (pc, 4); | |
626 | if (op == P_LEA_PC_A5) | |
c906108c | 627 | { |
8de307e0 AS |
628 | /* lea (%pc,N),%a5 */ |
629 | return pc + 6; | |
c906108c | 630 | } |
8de307e0 AS |
631 | |
632 | return pc; | |
c906108c SS |
633 | } |
634 | ||
8de307e0 | 635 | /* Return PC of first real instruction. */ |
7f8e7424 | 636 | |
8de307e0 AS |
637 | static CORE_ADDR |
638 | m68k_skip_prologue (CORE_ADDR start_pc) | |
c906108c | 639 | { |
8de307e0 AS |
640 | struct m68k_frame_cache cache; |
641 | CORE_ADDR pc; | |
642 | int op; | |
c906108c | 643 | |
8de307e0 AS |
644 | cache.locals = -1; |
645 | pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache); | |
646 | if (cache.locals < 0) | |
647 | return start_pc; | |
648 | return pc; | |
649 | } | |
c906108c | 650 | |
8de307e0 AS |
651 | static CORE_ADDR |
652 | m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
653 | { | |
654 | char buf[8]; | |
7f8e7424 | 655 | |
8de307e0 AS |
656 | frame_unwind_register (next_frame, PC_REGNUM, buf); |
657 | return extract_typed_address (buf, builtin_type_void_func_ptr); | |
658 | } | |
659 | \f | |
660 | /* Normal frames. */ | |
7f8e7424 | 661 | |
8de307e0 AS |
662 | static struct m68k_frame_cache * |
663 | m68k_frame_cache (struct frame_info *next_frame, void **this_cache) | |
664 | { | |
665 | struct m68k_frame_cache *cache; | |
666 | char buf[4]; | |
667 | int i; | |
668 | ||
669 | if (*this_cache) | |
670 | return *this_cache; | |
671 | ||
672 | cache = m68k_alloc_frame_cache (); | |
673 | *this_cache = cache; | |
674 | ||
675 | /* In principle, for normal frames, %fp holds the frame pointer, | |
676 | which holds the base address for the current stack frame. | |
677 | However, for functions that don't need it, the frame pointer is | |
678 | optional. For these "frameless" functions the frame pointer is | |
679 | actually the frame pointer of the calling frame. Signal | |
680 | trampolines are just a special case of a "frameless" function. | |
681 | They (usually) share their frame pointer with the frame that was | |
682 | in progress when the signal occurred. */ | |
683 | ||
684 | frame_unwind_register (next_frame, M68K_FP_REGNUM, buf); | |
685 | cache->base = extract_unsigned_integer (buf, 4); | |
686 | if (cache->base == 0) | |
687 | return cache; | |
688 | ||
689 | /* For normal frames, %pc is stored at 4(%fp). */ | |
690 | cache->saved_regs[M68K_PC_REGNUM] = 4; | |
691 | ||
692 | cache->pc = frame_func_unwind (next_frame); | |
693 | if (cache->pc != 0) | |
694 | m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache); | |
695 | ||
696 | if (cache->locals < 0) | |
697 | { | |
698 | /* We didn't find a valid frame, which means that CACHE->base | |
699 | currently holds the frame pointer for our calling frame. If | |
700 | we're at the start of a function, or somewhere half-way its | |
701 | prologue, the function's frame probably hasn't been fully | |
702 | setup yet. Try to reconstruct the base address for the stack | |
703 | frame by looking at the stack pointer. For truly "frameless" | |
704 | functions this might work too. */ | |
705 | ||
706 | frame_unwind_register (next_frame, M68K_SP_REGNUM, buf); | |
707 | cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset; | |
708 | } | |
7f8e7424 | 709 | |
8de307e0 AS |
710 | /* Now that we have the base address for the stack frame we can |
711 | calculate the value of %sp in the calling frame. */ | |
712 | cache->saved_sp = cache->base + 8; | |
7f8e7424 | 713 | |
8de307e0 AS |
714 | /* Adjust all the saved registers such that they contain addresses |
715 | instead of offsets. */ | |
716 | for (i = 0; i < M68K_NUM_REGS; i++) | |
717 | if (cache->saved_regs[i] != -1) | |
718 | cache->saved_regs[i] += cache->base; | |
c906108c | 719 | |
8de307e0 AS |
720 | return cache; |
721 | } | |
c906108c | 722 | |
8de307e0 AS |
723 | static void |
724 | m68k_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
725 | struct frame_id *this_id) | |
726 | { | |
727 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
c906108c | 728 | |
8de307e0 AS |
729 | /* This marks the outermost frame. */ |
730 | if (cache->base == 0) | |
731 | return; | |
c5aa993b | 732 | |
8de307e0 AS |
733 | /* See the end of m68k_push_dummy_call. */ |
734 | *this_id = frame_id_build (cache->base + 8, cache->pc); | |
735 | } | |
c5aa993b | 736 | |
8de307e0 AS |
737 | static void |
738 | m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache, | |
739 | int regnum, int *optimizedp, | |
740 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
741 | int *realnump, void *valuep) | |
742 | { | |
743 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
744 | ||
745 | gdb_assert (regnum >= 0); | |
746 | ||
747 | if (regnum == M68K_SP_REGNUM && cache->saved_sp) | |
c5aa993b | 748 | { |
8de307e0 AS |
749 | *optimizedp = 0; |
750 | *lvalp = not_lval; | |
751 | *addrp = 0; | |
752 | *realnump = -1; | |
753 | if (valuep) | |
c906108c | 754 | { |
8de307e0 AS |
755 | /* Store the value. */ |
756 | store_unsigned_integer (valuep, 4, cache->saved_sp); | |
89c3b6d3 | 757 | } |
8de307e0 AS |
758 | return; |
759 | } | |
760 | ||
761 | if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1) | |
762 | { | |
763 | *optimizedp = 0; | |
764 | *lvalp = lval_memory; | |
765 | *addrp = cache->saved_regs[regnum]; | |
766 | *realnump = -1; | |
767 | if (valuep) | |
89c3b6d3 | 768 | { |
8de307e0 AS |
769 | /* Read the value in from memory. */ |
770 | read_memory (*addrp, valuep, | |
771 | register_size (current_gdbarch, regnum)); | |
89c3b6d3 | 772 | } |
8de307e0 | 773 | return; |
c906108c | 774 | } |
8de307e0 AS |
775 | |
776 | frame_register_unwind (next_frame, regnum, | |
777 | optimizedp, lvalp, addrp, realnump, valuep); | |
778 | } | |
779 | ||
780 | static const struct frame_unwind m68k_frame_unwind = | |
781 | { | |
782 | NORMAL_FRAME, | |
783 | m68k_frame_this_id, | |
784 | m68k_frame_prev_register | |
785 | }; | |
786 | ||
787 | static const struct frame_unwind * | |
336d1bba | 788 | m68k_frame_sniffer (struct frame_info *next_frame) |
8de307e0 AS |
789 | { |
790 | return &m68k_frame_unwind; | |
791 | } | |
792 | \f | |
793 | /* Signal trampolines. */ | |
794 | ||
795 | static struct m68k_frame_cache * | |
796 | m68k_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache) | |
797 | { | |
798 | struct m68k_frame_cache *cache; | |
799 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
800 | struct m68k_sigtramp_info info; | |
801 | char buf[4]; | |
802 | int i; | |
803 | ||
804 | if (*this_cache) | |
805 | return *this_cache; | |
806 | ||
807 | cache = m68k_alloc_frame_cache (); | |
808 | ||
809 | frame_unwind_register (next_frame, M68K_SP_REGNUM, buf); | |
810 | cache->base = extract_unsigned_integer (buf, 4) - 4; | |
811 | ||
812 | info = tdep->get_sigtramp_info (next_frame); | |
813 | ||
814 | for (i = 0; i < M68K_NUM_REGS; i++) | |
815 | if (info.sc_reg_offset[i] != -1) | |
816 | cache->saved_regs[i] = info.sigcontext_addr + info.sc_reg_offset[i]; | |
817 | ||
818 | *this_cache = cache; | |
819 | return cache; | |
820 | } | |
821 | ||
822 | static void | |
823 | m68k_sigtramp_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
824 | struct frame_id *this_id) | |
825 | { | |
826 | struct m68k_frame_cache *cache = | |
827 | m68k_sigtramp_frame_cache (next_frame, this_cache); | |
828 | ||
829 | /* See the end of m68k_push_dummy_call. */ | |
830 | *this_id = frame_id_build (cache->base + 8, frame_pc_unwind (next_frame)); | |
831 | } | |
832 | ||
833 | static void | |
834 | m68k_sigtramp_frame_prev_register (struct frame_info *next_frame, | |
835 | void **this_cache, | |
836 | int regnum, int *optimizedp, | |
837 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
838 | int *realnump, void *valuep) | |
839 | { | |
840 | /* Make sure we've initialized the cache. */ | |
841 | m68k_sigtramp_frame_cache (next_frame, this_cache); | |
842 | ||
843 | m68k_frame_prev_register (next_frame, this_cache, regnum, | |
844 | optimizedp, lvalp, addrp, realnump, valuep); | |
845 | } | |
846 | ||
847 | static const struct frame_unwind m68k_sigtramp_frame_unwind = | |
848 | { | |
849 | SIGTRAMP_FRAME, | |
850 | m68k_sigtramp_frame_this_id, | |
851 | m68k_sigtramp_frame_prev_register | |
852 | }; | |
853 | ||
854 | static const struct frame_unwind * | |
336d1bba | 855 | m68k_sigtramp_frame_sniffer (struct frame_info *next_frame) |
8de307e0 | 856 | { |
336d1bba | 857 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
8de307e0 AS |
858 | char *name; |
859 | ||
860 | /* We shouldn't even bother to try if the OSABI didn't register | |
861 | a get_sigtramp_info handler. */ | |
862 | if (!gdbarch_tdep (current_gdbarch)->get_sigtramp_info) | |
863 | return NULL; | |
864 | ||
865 | find_pc_partial_function (pc, &name, NULL, NULL); | |
866 | if (PC_IN_SIGTRAMP (pc, name)) | |
867 | return &m68k_sigtramp_frame_unwind; | |
868 | ||
869 | return NULL; | |
c906108c | 870 | } |
8de307e0 AS |
871 | \f |
872 | static CORE_ADDR | |
873 | m68k_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
874 | { | |
875 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
876 | ||
877 | return cache->base; | |
878 | } | |
879 | ||
880 | static const struct frame_base m68k_frame_base = | |
881 | { | |
882 | &m68k_frame_unwind, | |
883 | m68k_frame_base_address, | |
884 | m68k_frame_base_address, | |
885 | m68k_frame_base_address | |
886 | }; | |
887 | ||
888 | static struct frame_id | |
889 | m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
890 | { | |
891 | char buf[4]; | |
892 | CORE_ADDR fp; | |
c906108c | 893 | |
8de307e0 AS |
894 | frame_unwind_register (next_frame, M68K_FP_REGNUM, buf); |
895 | fp = extract_unsigned_integer (buf, 4); | |
c906108c | 896 | |
8de307e0 AS |
897 | /* See the end of m68k_push_dummy_call. */ |
898 | return frame_id_build (fp + 8, frame_pc_unwind (next_frame)); | |
899 | } | |
900 | \f | |
c5aa993b | 901 | #ifdef USE_PROC_FS /* Target dependent support for /proc */ |
c906108c SS |
902 | |
903 | #include <sys/procfs.h> | |
904 | ||
c60c0f5f MS |
905 | /* Prototypes for supply_gregset etc. */ |
906 | #include "gregset.h" | |
907 | ||
c906108c | 908 | /* The /proc interface divides the target machine's register set up into |
c5aa993b JM |
909 | two different sets, the general register set (gregset) and the floating |
910 | point register set (fpregset). For each set, there is an ioctl to get | |
911 | the current register set and another ioctl to set the current values. | |
c906108c | 912 | |
c5aa993b JM |
913 | The actual structure passed through the ioctl interface is, of course, |
914 | naturally machine dependent, and is different for each set of registers. | |
915 | For the m68k for example, the general register set is typically defined | |
916 | by: | |
c906108c | 917 | |
c5aa993b | 918 | typedef int gregset_t[18]; |
c906108c | 919 | |
c5aa993b JM |
920 | #define R_D0 0 |
921 | ... | |
922 | #define R_PS 17 | |
c906108c | 923 | |
c5aa993b | 924 | and the floating point set by: |
c906108c | 925 | |
c5aa993b JM |
926 | typedef struct fpregset { |
927 | int f_pcr; | |
928 | int f_psr; | |
929 | int f_fpiaddr; | |
930 | int f_fpregs[8][3]; (8 regs, 96 bits each) | |
931 | } fpregset_t; | |
c906108c | 932 | |
c5aa993b JM |
933 | These routines provide the packing and unpacking of gregset_t and |
934 | fpregset_t formatted data. | |
c906108c SS |
935 | |
936 | */ | |
937 | ||
938 | /* Atari SVR4 has R_SR but not R_PS */ | |
939 | ||
940 | #if !defined (R_PS) && defined (R_SR) | |
941 | #define R_PS R_SR | |
942 | #endif | |
943 | ||
944 | /* Given a pointer to a general register set in /proc format (gregset_t *), | |
c5aa993b JM |
945 | unpack the register contents and supply them as gdb's idea of the current |
946 | register values. */ | |
c906108c SS |
947 | |
948 | void | |
fba45db2 | 949 | supply_gregset (gregset_t *gregsetp) |
c906108c | 950 | { |
52f0bd74 AC |
951 | int regi; |
952 | greg_t *regp = (greg_t *) gregsetp; | |
c906108c | 953 | |
c5aa993b | 954 | for (regi = 0; regi < R_PC; regi++) |
c906108c SS |
955 | { |
956 | supply_register (regi, (char *) (regp + regi)); | |
957 | } | |
958 | supply_register (PS_REGNUM, (char *) (regp + R_PS)); | |
959 | supply_register (PC_REGNUM, (char *) (regp + R_PC)); | |
960 | } | |
961 | ||
962 | void | |
fba45db2 | 963 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c | 964 | { |
52f0bd74 AC |
965 | int regi; |
966 | greg_t *regp = (greg_t *) gregsetp; | |
c906108c | 967 | |
c5aa993b | 968 | for (regi = 0; regi < R_PC; regi++) |
c906108c | 969 | { |
8de307e0 AS |
970 | if (regno == -1 || regno == regi) |
971 | regcache_collect (regi, regp + regi); | |
c906108c | 972 | } |
8de307e0 AS |
973 | if (regno == -1 || regno == PS_REGNUM) |
974 | regcache_collect (PS_REGNUM, regp + R_PS); | |
975 | if (regno == -1 || regno == PC_REGNUM) | |
976 | regcache_collect (PC_REGNUM, regp + R_PC); | |
c906108c SS |
977 | } |
978 | ||
979 | #if defined (FP0_REGNUM) | |
980 | ||
981 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
982 | (fpregset_t *), unpack the register contents and supply them as gdb's |
983 | idea of the current floating point register values. */ | |
c906108c | 984 | |
c5aa993b | 985 | void |
fba45db2 | 986 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c | 987 | { |
52f0bd74 | 988 | int regi; |
c906108c | 989 | char *from; |
c5aa993b | 990 | |
32eeb91a | 991 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c | 992 | { |
c5aa993b | 993 | from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); |
c906108c SS |
994 | supply_register (regi, from); |
995 | } | |
32eeb91a AS |
996 | supply_register (M68K_FPC_REGNUM, (char *) &(fpregsetp->f_pcr)); |
997 | supply_register (M68K_FPS_REGNUM, (char *) &(fpregsetp->f_psr)); | |
998 | supply_register (M68K_FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr)); | |
c906108c SS |
999 | } |
1000 | ||
1001 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
1002 | (fpregset_t *), update the register specified by REGNO from gdb's idea |
1003 | of the current floating point register set. If REGNO is -1, update | |
1004 | them all. */ | |
c906108c SS |
1005 | |
1006 | void | |
fba45db2 | 1007 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
1008 | { |
1009 | int regi; | |
c906108c | 1010 | |
32eeb91a | 1011 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c | 1012 | { |
8de307e0 AS |
1013 | if (regno == -1 || regno == regi) |
1014 | regcache_collect (regi, &fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); | |
c906108c | 1015 | } |
8de307e0 AS |
1016 | if (regno == -1 || regno == M68K_FPC_REGNUM) |
1017 | regcache_collect (M68K_FPC_REGNUM, &fpregsetp->f_pcr); | |
1018 | if (regno == -1 || regno == M68K_FPS_REGNUM) | |
1019 | regcache_collect (M68K_FPS_REGNUM, &fpregsetp->f_psr); | |
1020 | if (regno == -1 || regno == M68K_FPI_REGNUM) | |
1021 | regcache_collect (M68K_FPI_REGNUM, &fpregsetp->f_fpiaddr); | |
c906108c SS |
1022 | } |
1023 | ||
c5aa993b | 1024 | #endif /* defined (FP0_REGNUM) */ |
c906108c | 1025 | |
c5aa993b | 1026 | #endif /* USE_PROC_FS */ |
c906108c | 1027 | |
c906108c SS |
1028 | /* Figure out where the longjmp will land. Slurp the args out of the stack. |
1029 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
1030 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
1031 | This routine returns true on success. */ | |
1032 | ||
1033 | int | |
f4281f55 | 1034 | m68k_get_longjmp_target (CORE_ADDR *pc) |
c906108c | 1035 | { |
35fc8285 | 1036 | char *buf; |
c906108c | 1037 | CORE_ADDR sp, jb_addr; |
eb2e12d7 AS |
1038 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
1039 | ||
1040 | if (tdep->jb_pc < 0) | |
1041 | { | |
1042 | internal_error (__FILE__, __LINE__, | |
1043 | "m68k_get_longjmp_target: not implemented"); | |
1044 | return 0; | |
1045 | } | |
c906108c | 1046 | |
35fc8285 | 1047 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c5aa993b | 1048 | sp = read_register (SP_REGNUM); |
c906108c | 1049 | |
b5d78d39 GS |
1050 | if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */ |
1051 | buf, TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
c906108c SS |
1052 | return 0; |
1053 | ||
7c0b4a20 | 1054 | jb_addr = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c | 1055 | |
eb2e12d7 | 1056 | if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf, |
c906108c SS |
1057 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) |
1058 | return 0; | |
1059 | ||
7c0b4a20 | 1060 | *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
1061 | return 1; |
1062 | } | |
c906108c | 1063 | |
8de307e0 | 1064 | #ifdef SYSCALL_TRAP |
c906108c SS |
1065 | /* Immediately after a function call, return the saved pc before the frame |
1066 | is setup. For sun3's, we check for the common case of being inside of a | |
1067 | system call, and if so, we know that Sun pushes the call # on the stack | |
1068 | prior to doing the trap. */ | |
1069 | ||
eb2e12d7 | 1070 | static CORE_ADDR |
fba45db2 | 1071 | m68k_saved_pc_after_call (struct frame_info *frame) |
c906108c | 1072 | { |
c906108c SS |
1073 | int op; |
1074 | ||
b5fc49aa | 1075 | op = read_memory_unsigned_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2); |
c906108c SS |
1076 | |
1077 | if (op == SYSCALL_TRAP) | |
b5fc49aa | 1078 | return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4); |
c906108c | 1079 | else |
b5fc49aa | 1080 | return read_memory_unsigned_integer (read_register (SP_REGNUM), 4); |
c906108c | 1081 | } |
8de307e0 | 1082 | #endif /* SYSCALL_TRAP */ |
c906108c | 1083 | |
152d9db6 GS |
1084 | /* Function: m68k_gdbarch_init |
1085 | Initializer function for the m68k gdbarch vector. | |
1086 | Called by gdbarch. Sets up the gdbarch vector(s) for this target. */ | |
1087 | ||
1088 | static struct gdbarch * | |
1089 | m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1090 | { | |
1091 | struct gdbarch_tdep *tdep = NULL; | |
1092 | struct gdbarch *gdbarch; | |
1093 | ||
1094 | /* find a candidate among the list of pre-declared architectures. */ | |
1095 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1096 | if (arches != NULL) | |
1097 | return (arches->gdbarch); | |
1098 | ||
eb2e12d7 AS |
1099 | tdep = xmalloc (sizeof (struct gdbarch_tdep)); |
1100 | gdbarch = gdbarch_alloc (&info, tdep); | |
152d9db6 | 1101 | |
5d3ed2e3 GS |
1102 | set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext); |
1103 | set_gdbarch_long_double_bit (gdbarch, 96); | |
1104 | ||
1105 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1106 | ||
1107 | set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue); | |
8de307e0 | 1108 | #ifdef SYSCALL_TRAP |
6913c89a | 1109 | set_gdbarch_deprecated_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call); |
8de307e0 | 1110 | #endif |
103a1597 | 1111 | set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc); |
5d3ed2e3 GS |
1112 | |
1113 | /* Stack grows down. */ | |
1114 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
78bf922a | 1115 | set_gdbarch_parm_boundary (gdbarch, 32); |
6300c360 GS |
1116 | |
1117 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); | |
942dc0e9 GS |
1118 | set_gdbarch_decr_pc_after_break (gdbarch, 2); |
1119 | ||
8de307e0 AS |
1120 | set_gdbarch_extract_return_value (gdbarch, m68k_extract_return_value); |
1121 | set_gdbarch_store_return_value (gdbarch, m68k_store_return_value); | |
1122 | set_gdbarch_extract_struct_value_address (gdbarch, | |
1123 | m68k_extract_struct_value_address); | |
c481dac7 | 1124 | set_gdbarch_use_struct_convention (gdbarch, m68k_use_struct_convention); |
942dc0e9 | 1125 | |
942dc0e9 GS |
1126 | set_gdbarch_frameless_function_invocation (gdbarch, |
1127 | m68k_frameless_function_invocation); | |
6300c360 | 1128 | set_gdbarch_frame_args_skip (gdbarch, 8); |
942dc0e9 | 1129 | |
8de307e0 | 1130 | set_gdbarch_register_type (gdbarch, m68k_register_type); |
5d3ed2e3 | 1131 | set_gdbarch_register_name (gdbarch, m68k_register_name); |
942dc0e9 GS |
1132 | set_gdbarch_num_regs (gdbarch, 29); |
1133 | set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok); | |
32eeb91a | 1134 | set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM); |
32eeb91a AS |
1135 | set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM); |
1136 | set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM); | |
1137 | set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM); | |
a2c6a6d5 | 1138 | |
8de307e0 | 1139 | set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call); |
6c0e89ed | 1140 | |
650fcc91 AS |
1141 | /* Disassembler. */ |
1142 | set_gdbarch_print_insn (gdbarch, print_insn_m68k); | |
1143 | ||
eb2e12d7 AS |
1144 | #if defined JB_PC && defined JB_ELEMENT_SIZE |
1145 | tdep->jb_pc = JB_PC; | |
1146 | tdep->jb_elt_size = JB_ELEMENT_SIZE; | |
1147 | #else | |
1148 | tdep->jb_pc = -1; | |
1149 | #endif | |
8de307e0 | 1150 | tdep->get_sigtramp_info = NULL; |
c481dac7 | 1151 | tdep->struct_return = pcc_struct_return; |
8de307e0 AS |
1152 | |
1153 | /* Frame unwinder. */ | |
1154 | set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id); | |
1155 | set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc); | |
1156 | frame_base_set_default (gdbarch, &m68k_frame_base); | |
eb2e12d7 | 1157 | |
55809acb AS |
1158 | /* Hook in ABI-specific overrides, if they have been registered. */ |
1159 | gdbarch_init_osabi (info, gdbarch); | |
1160 | ||
eb2e12d7 AS |
1161 | /* Now we have tuned the configuration, set a few final things, |
1162 | based on what the OS ABI has told us. */ | |
1163 | ||
1164 | if (tdep->jb_pc >= 0) | |
1165 | set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target); | |
1166 | ||
336d1bba AC |
1167 | frame_unwind_append_sniffer (gdbarch, m68k_sigtramp_frame_sniffer); |
1168 | frame_unwind_append_sniffer (gdbarch, m68k_frame_sniffer); | |
8de307e0 | 1169 | |
152d9db6 GS |
1170 | return gdbarch; |
1171 | } | |
1172 | ||
1173 | ||
1174 | static void | |
1175 | m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
1176 | { | |
eb2e12d7 | 1177 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
152d9db6 | 1178 | |
eb2e12d7 AS |
1179 | if (tdep == NULL) |
1180 | return; | |
152d9db6 | 1181 | } |
2acceee2 | 1182 | |
a78f21af AC |
1183 | extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */ |
1184 | ||
c906108c | 1185 | void |
fba45db2 | 1186 | _initialize_m68k_tdep (void) |
c906108c | 1187 | { |
152d9db6 | 1188 | gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep); |
c906108c | 1189 | } |