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