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