1 /* Target-dependent code for the Motorola 68000 series.
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 #include "dwarf2-frame.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
32 #include "gdb_string.h"
33 #include "gdb_assert.h"
36 #include "arch-utils.h"
40 #include "m68k-tdep.h"
43 #define P_LINKL_FP 0x480e
44 #define P_LINKW_FP 0x4e56
45 #define P_PEA_FP 0x4856
46 #define P_MOVEAL_SP_FP 0x2c4f
47 #define P_ADDAW_SP 0xdefc
48 #define P_ADDAL_SP 0xdffc
49 #define P_SUBQW_SP 0x514f
50 #define P_SUBQL_SP 0x518f
51 #define P_LEA_SP_SP 0x4fef
52 #define P_LEA_PC_A5 0x4bfb0170
53 #define P_FMOVEMX_SP 0xf227
54 #define P_MOVEL_SP 0x2f00
55 #define P_MOVEML_SP 0x48e7
57 /* Offset from SP to first arg on stack at first instruction of a function */
58 #define SP_ARG0 (1 * 4)
60 #if !defined (BPT_VECTOR)
61 #define BPT_VECTOR 0xf
64 static const gdb_byte
*
65 m68k_local_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
67 static gdb_byte break_insn
[] = {0x4e, (0x40 | BPT_VECTOR
)};
68 *lenptr
= sizeof (break_insn
);
72 /* Return the GDB type object for the "standard" data type of data in
73 register N. This should be int for D0-D7, SR, FPCONTROL and
74 FPSTATUS, long double for FP0-FP7, and void pointer for all others
75 (A0-A7, PC, FPIADDR). Note, for registers which contain
76 addresses return pointer to void, not pointer to char, because we
77 don't want to attempt to print the string after printing the
81 m68k_register_type (struct gdbarch
*gdbarch
, int regnum
)
83 if (regnum
>= FP0_REGNUM
&& regnum
<= FP0_REGNUM
+ 7)
84 return builtin_type_m68881_ext
;
86 if (regnum
== M68K_FPI_REGNUM
|| regnum
== PC_REGNUM
)
87 return builtin_type_void_func_ptr
;
89 if (regnum
== M68K_FPC_REGNUM
|| regnum
== M68K_FPS_REGNUM
90 || regnum
== PS_REGNUM
)
91 return builtin_type_int32
;
93 if (regnum
>= M68K_A0_REGNUM
&& regnum
<= M68K_A0_REGNUM
+ 7)
94 return builtin_type_void_data_ptr
;
96 return builtin_type_int32
;
99 /* Function: m68k_register_name
100 Returns the name of the standard m68k register regnum. */
103 m68k_register_name (int regnum
)
105 static char *register_names
[] = {
106 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
107 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
109 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
110 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
113 if (regnum
< 0 || regnum
>= ARRAY_SIZE (register_names
))
114 internal_error (__FILE__
, __LINE__
,
115 _("m68k_register_name: illegal register number %d"), regnum
);
117 return register_names
[regnum
];
120 /* Return nonzero if a value of type TYPE stored in register REGNUM
121 needs any special handling. */
124 m68k_convert_register_p (int regnum
, struct type
*type
)
126 return (regnum
>= M68K_FP0_REGNUM
&& regnum
<= M68K_FP0_REGNUM
+ 7);
129 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
130 return its contents in TO. */
133 m68k_register_to_value (struct frame_info
*frame
, int regnum
,
134 struct type
*type
, gdb_byte
*to
)
136 gdb_byte from
[M68K_MAX_REGISTER_SIZE
];
138 /* We only support floating-point values. */
139 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
141 warning (_("Cannot convert floating-point register value "
142 "to non-floating-point type."));
146 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
147 the extended floating-point format used by the FPU. */
148 get_frame_register (frame
, regnum
, from
);
149 convert_typed_floating (from
, builtin_type_m68881_ext
, to
, type
);
152 /* Write the contents FROM of a value of type TYPE into register
153 REGNUM in frame FRAME. */
156 m68k_value_to_register (struct frame_info
*frame
, int regnum
,
157 struct type
*type
, const gdb_byte
*from
)
159 gdb_byte to
[M68K_MAX_REGISTER_SIZE
];
161 /* We only support floating-point values. */
162 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
164 warning (_("Cannot convert non-floating-point type "
165 "to floating-point register value."));
169 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
170 to the extended floating-point format used by the FPU. */
171 convert_typed_floating (from
, type
, to
, builtin_type_m68881_ext
);
172 put_frame_register (frame
, regnum
, to
);
176 /* There is a fair number of calling conventions that are in somewhat
177 wide use. The 68000/08/10 don't support an FPU, not even as a
178 coprocessor. All function return values are stored in %d0/%d1.
179 Structures are returned in a static buffer, a pointer to which is
180 returned in %d0. This means that functions returning a structure
181 are not re-entrant. To avoid this problem some systems use a
182 convention where the caller passes a pointer to a buffer in %a1
183 where the return values is to be stored. This convention is the
184 default, and is implemented in the function m68k_return_value.
186 The 68020/030/040/060 do support an FPU, either as a coprocessor
187 (68881/2) or built-in (68040/68060). That's why System V release 4
188 (SVR4) instroduces a new calling convention specified by the SVR4
189 psABI. Integer values are returned in %d0/%d1, pointer return
190 values in %a0 and floating values in %fp0. When calling functions
191 returning a structure the caller should pass a pointer to a buffer
192 for the return value in %a0. This convention is implemented in the
193 function m68k_svr4_return_value, and by appropriately setting the
194 struct_value_regnum member of `struct gdbarch_tdep'.
196 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
197 for passing the structure return value buffer.
199 GCC can also generate code where small structures are returned in
200 %d0/%d1 instead of in memory by using -freg-struct-return. This is
201 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
202 embedded systems. This convention is implemented by setting the
203 struct_return member of `struct gdbarch_tdep' to reg_struct_return. */
205 /* Read a function return value of TYPE from REGCACHE, and copy that
209 m68k_extract_return_value (struct type
*type
, struct regcache
*regcache
,
212 int len
= TYPE_LENGTH (type
);
213 gdb_byte buf
[M68K_MAX_REGISTER_SIZE
];
217 regcache_raw_read (regcache
, M68K_D0_REGNUM
, buf
);
218 memcpy (valbuf
, buf
+ (4 - len
), len
);
222 regcache_raw_read (regcache
, M68K_D0_REGNUM
, buf
);
223 memcpy (valbuf
, buf
+ (8 - len
), len
- 4);
224 regcache_raw_read (regcache
, M68K_D1_REGNUM
, valbuf
+ (len
- 4));
227 internal_error (__FILE__
, __LINE__
,
228 _("Cannot extract return value of %d bytes long."), len
);
232 m68k_svr4_extract_return_value (struct type
*type
, struct regcache
*regcache
,
235 int len
= TYPE_LENGTH (type
);
236 gdb_byte buf
[M68K_MAX_REGISTER_SIZE
];
238 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
240 regcache_raw_read (regcache
, M68K_FP0_REGNUM
, buf
);
241 convert_typed_floating (buf
, builtin_type_m68881_ext
, valbuf
, type
);
243 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
&& len
== 4)
244 regcache_raw_read (regcache
, M68K_A0_REGNUM
, valbuf
);
246 m68k_extract_return_value (type
, regcache
, valbuf
);
249 /* Write a function return value of TYPE from VALBUF into REGCACHE. */
252 m68k_store_return_value (struct type
*type
, struct regcache
*regcache
,
253 const gdb_byte
*valbuf
)
255 int len
= TYPE_LENGTH (type
);
258 regcache_raw_write_part (regcache
, M68K_D0_REGNUM
, 4 - len
, len
, valbuf
);
261 regcache_raw_write_part (regcache
, M68K_D0_REGNUM
, 8 - len
,
263 regcache_raw_write (regcache
, M68K_D1_REGNUM
, valbuf
+ (len
- 4));
266 internal_error (__FILE__
, __LINE__
,
267 _("Cannot store return value of %d bytes long."), len
);
271 m68k_svr4_store_return_value (struct type
*type
, struct regcache
*regcache
,
272 const gdb_byte
*valbuf
)
274 int len
= TYPE_LENGTH (type
);
276 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
278 gdb_byte buf
[M68K_MAX_REGISTER_SIZE
];
279 convert_typed_floating (valbuf
, type
, buf
, builtin_type_m68881_ext
);
280 regcache_raw_write (regcache
, M68K_FP0_REGNUM
, buf
);
282 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
&& len
== 4)
284 regcache_raw_write (regcache
, M68K_A0_REGNUM
, valbuf
);
285 regcache_raw_write (regcache
, M68K_D0_REGNUM
, valbuf
);
288 m68k_store_return_value (type
, regcache
, valbuf
);
291 /* Return non-zero if TYPE, which is assumed to be a structure or
292 union type, should be returned in registers for architecture
296 m68k_reg_struct_return_p (struct gdbarch
*gdbarch
, struct type
*type
)
298 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
299 enum type_code code
= TYPE_CODE (type
);
300 int len
= TYPE_LENGTH (type
);
302 gdb_assert (code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
);
304 if (tdep
->struct_return
== pcc_struct_return
)
307 return (len
== 1 || len
== 2 || len
== 4 || len
== 8);
310 /* Determine, for architecture GDBARCH, how a return value of TYPE
311 should be returned. If it is supposed to be returned in registers,
312 and READBUF is non-zero, read the appropriate value from REGCACHE,
313 and copy it into READBUF. If WRITEBUF is non-zero, write the value
314 from WRITEBUF into REGCACHE. */
316 static enum return_value_convention
317 m68k_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
318 struct regcache
*regcache
, gdb_byte
*readbuf
,
319 const gdb_byte
*writebuf
)
321 enum type_code code
= TYPE_CODE (type
);
323 /* GCC returns a `long double' in memory too. */
324 if (((code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
325 && !m68k_reg_struct_return_p (gdbarch
, type
))
326 || (code
== TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 12))
328 /* The default on m68k is to return structures in static memory.
329 Consequently a function must return the address where we can
330 find the return value. */
336 regcache_raw_read_unsigned (regcache
, M68K_D0_REGNUM
, &addr
);
337 read_memory (addr
, readbuf
, TYPE_LENGTH (type
));
340 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
344 m68k_extract_return_value (type
, regcache
, readbuf
);
346 m68k_store_return_value (type
, regcache
, writebuf
);
348 return RETURN_VALUE_REGISTER_CONVENTION
;
351 static enum return_value_convention
352 m68k_svr4_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
353 struct regcache
*regcache
, gdb_byte
*readbuf
,
354 const gdb_byte
*writebuf
)
356 enum type_code code
= TYPE_CODE (type
);
358 if ((code
== TYPE_CODE_STRUCT
|| code
== TYPE_CODE_UNION
)
359 && !m68k_reg_struct_return_p (gdbarch
, type
))
361 /* The System V ABI says that:
363 "A function returning a structure or union also sets %a0 to
364 the value it finds in %a0. Thus when the caller receives
365 control again, the address of the returned object resides in
368 So the ABI guarantees that we can always find the return
369 value just after the function has returned. */
375 regcache_raw_read_unsigned (regcache
, M68K_A0_REGNUM
, &addr
);
376 read_memory (addr
, readbuf
, TYPE_LENGTH (type
));
379 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
382 /* This special case is for structures consisting of a single
383 `float' or `double' member. These structures are returned in
384 %fp0. For these structures, we call ourselves recursively,
385 changing TYPE into the type of the first member of the structure.
386 Since that should work for all structures that have only one
387 member, we don't bother to check the member's type here. */
388 if (code
== TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
390 type
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
391 return m68k_svr4_return_value (gdbarch
, type
, regcache
,
396 m68k_svr4_extract_return_value (type
, regcache
, readbuf
);
398 m68k_svr4_store_return_value (type
, regcache
, writebuf
);
400 return RETURN_VALUE_REGISTER_CONVENTION
;
404 /* Always align the frame to a 4-byte boundary. This is required on
405 coldfire and harmless on the rest. */
408 m68k_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
410 /* Align the stack to four bytes. */
415 m68k_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
416 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
417 struct value
**args
, CORE_ADDR sp
, int struct_return
,
418 CORE_ADDR struct_addr
)
420 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
424 /* Push arguments in reverse order. */
425 for (i
= nargs
- 1; i
>= 0; i
--)
427 struct type
*value_type
= value_enclosing_type (args
[i
]);
428 int len
= TYPE_LENGTH (value_type
);
429 int container_len
= (len
+ 3) & ~3;
432 /* Non-scalars bigger than 4 bytes are left aligned, others are
434 if ((TYPE_CODE (value_type
) == TYPE_CODE_STRUCT
435 || TYPE_CODE (value_type
) == TYPE_CODE_UNION
436 || TYPE_CODE (value_type
) == TYPE_CODE_ARRAY
)
440 offset
= container_len
- len
;
442 write_memory (sp
+ offset
, value_contents_all (args
[i
]), len
);
445 /* Store struct value address. */
448 store_unsigned_integer (buf
, 4, struct_addr
);
449 regcache_cooked_write (regcache
, tdep
->struct_value_regnum
, buf
);
452 /* Store return address. */
454 store_unsigned_integer (buf
, 4, bp_addr
);
455 write_memory (sp
, buf
, 4);
457 /* Finally, update the stack pointer... */
458 store_unsigned_integer (buf
, 4, sp
);
459 regcache_cooked_write (regcache
, M68K_SP_REGNUM
, buf
);
461 /* ...and fake a frame pointer. */
462 regcache_cooked_write (regcache
, M68K_FP_REGNUM
, buf
);
464 /* DWARF2/GCC uses the stack address *before* the function call as a
469 /* Convert a dwarf or dwarf2 regnumber to a GDB regnum. */
472 m68k_dwarf_reg_to_regnum (int num
)
476 return (num
- 0) + M68K_D0_REGNUM
;
479 return (num
- 8) + M68K_A0_REGNUM
;
482 return (num
- 16) + M68K_FP0_REGNUM
;
485 return M68K_PC_REGNUM
;
487 return gdbarch_num_regs (current_gdbarch
)
488 + gdbarch_num_pseudo_regs (current_gdbarch
);
492 struct m68k_frame_cache
499 /* Saved registers. */
500 CORE_ADDR saved_regs
[M68K_NUM_REGS
];
503 /* Stack space reserved for local variables. */
507 /* Allocate and initialize a frame cache. */
509 static struct m68k_frame_cache
*
510 m68k_alloc_frame_cache (void)
512 struct m68k_frame_cache
*cache
;
515 cache
= FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache
);
519 cache
->sp_offset
= -4;
522 /* Saved registers. We initialize these to -1 since zero is a valid
523 offset (that's where %fp is supposed to be stored). */
524 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
525 cache
->saved_regs
[i
] = -1;
527 /* Frameless until proven otherwise. */
533 /* Check whether PC points at a code that sets up a new stack frame.
534 If so, it updates CACHE and returns the address of the first
535 instruction after the sequence that sets removes the "hidden"
536 argument from the stack or CURRENT_PC, whichever is smaller.
537 Otherwise, return PC. */
540 m68k_analyze_frame_setup (CORE_ADDR pc
, CORE_ADDR current_pc
,
541 struct m68k_frame_cache
*cache
)
545 if (pc
>= current_pc
)
548 op
= read_memory_unsigned_integer (pc
, 2);
550 if (op
== P_LINKW_FP
|| op
== P_LINKL_FP
|| op
== P_PEA_FP
)
552 cache
->saved_regs
[M68K_FP_REGNUM
] = 0;
553 cache
->sp_offset
+= 4;
554 if (op
== P_LINKW_FP
)
556 /* link.w %fp, #-N */
557 /* link.w %fp, #0; adda.l #-N, %sp */
558 cache
->locals
= -read_memory_integer (pc
+ 2, 2);
560 if (pc
+ 4 < current_pc
&& cache
->locals
== 0)
562 op
= read_memory_unsigned_integer (pc
+ 4, 2);
563 if (op
== P_ADDAL_SP
)
565 cache
->locals
= read_memory_integer (pc
+ 6, 4);
572 else if (op
== P_LINKL_FP
)
574 /* link.l %fp, #-N */
575 cache
->locals
= -read_memory_integer (pc
+ 2, 4);
580 /* pea (%fp); movea.l %sp, %fp */
583 if (pc
+ 2 < current_pc
)
585 op
= read_memory_unsigned_integer (pc
+ 2, 2);
587 if (op
== P_MOVEAL_SP_FP
)
589 /* move.l %sp, %fp */
597 else if ((op
& 0170777) == P_SUBQW_SP
|| (op
& 0170777) == P_SUBQL_SP
)
599 /* subq.[wl] #N,%sp */
600 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
601 cache
->locals
= (op
& 07000) == 0 ? 8 : (op
& 07000) >> 9;
602 if (pc
+ 2 < current_pc
)
604 op
= read_memory_unsigned_integer (pc
+ 2, 2);
605 if ((op
& 0170777) == P_SUBQW_SP
|| (op
& 0170777) == P_SUBQL_SP
)
607 cache
->locals
+= (op
& 07000) == 0 ? 8 : (op
& 07000) >> 9;
613 else if (op
== P_ADDAW_SP
|| op
== P_LEA_SP_SP
)
616 /* lea (-N,%sp),%sp */
617 cache
->locals
= -read_memory_integer (pc
+ 2, 2);
620 else if (op
== P_ADDAL_SP
)
623 cache
->locals
= -read_memory_integer (pc
+ 2, 4);
630 /* Check whether PC points at code that saves registers on the stack.
631 If so, it updates CACHE and returns the address of the first
632 instruction after the register saves or CURRENT_PC, whichever is
633 smaller. Otherwise, return PC. */
636 m68k_analyze_register_saves (CORE_ADDR pc
, CORE_ADDR current_pc
,
637 struct m68k_frame_cache
*cache
)
639 if (cache
->locals
>= 0)
645 offset
= -4 - cache
->locals
;
646 while (pc
< current_pc
)
648 op
= read_memory_unsigned_integer (pc
, 2);
649 if (op
== P_FMOVEMX_SP
)
651 /* fmovem.x REGS,-(%sp) */
652 op
= read_memory_unsigned_integer (pc
+ 2, 2);
653 if ((op
& 0xff00) == 0xe000)
656 for (i
= 0; i
< 16; i
++, mask
>>= 1)
660 cache
->saved_regs
[i
+ M68K_FP0_REGNUM
] = offset
;
669 else if ((op
& 0177760) == P_MOVEL_SP
)
671 /* move.l %R,-(%sp) */
673 cache
->saved_regs
[regno
] = offset
;
677 else if (op
== P_MOVEML_SP
)
679 /* movem.l REGS,-(%sp) */
680 mask
= read_memory_unsigned_integer (pc
+ 2, 2);
681 for (i
= 0; i
< 16; i
++, mask
>>= 1)
685 cache
->saved_regs
[15 - i
] = offset
;
700 /* Do a full analysis of the prologue at PC and update CACHE
701 accordingly. Bail out early if CURRENT_PC is reached. Return the
702 address where the analysis stopped.
704 We handle all cases that can be generated by gcc.
706 For allocating a stack frame:
710 pea (%fp); move.l %sp,%fp
711 link.w %a6,#0; add.l #-N,%sp
714 subq.w #8,%sp; subq.w #N-8,%sp
719 For saving registers:
723 move.l R1,-(%sp); move.l R2,-(%sp)
726 For setting up the PIC register:
733 m68k_analyze_prologue (CORE_ADDR pc
, CORE_ADDR current_pc
,
734 struct m68k_frame_cache
*cache
)
738 pc
= m68k_analyze_frame_setup (pc
, current_pc
, cache
);
739 pc
= m68k_analyze_register_saves (pc
, current_pc
, cache
);
740 if (pc
>= current_pc
)
743 /* Check for GOT setup. */
744 op
= read_memory_unsigned_integer (pc
, 4);
745 if (op
== P_LEA_PC_A5
)
747 /* lea (%pc,N),%a5 */
754 /* Return PC of first real instruction. */
757 m68k_skip_prologue (CORE_ADDR start_pc
)
759 struct m68k_frame_cache cache
;
764 pc
= m68k_analyze_prologue (start_pc
, (CORE_ADDR
) -1, &cache
);
765 if (cache
.locals
< 0)
771 m68k_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
775 frame_unwind_register (next_frame
, PC_REGNUM
, buf
);
776 return extract_typed_address (buf
, builtin_type_void_func_ptr
);
781 static struct m68k_frame_cache
*
782 m68k_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
784 struct m68k_frame_cache
*cache
;
791 cache
= m68k_alloc_frame_cache ();
794 /* In principle, for normal frames, %fp holds the frame pointer,
795 which holds the base address for the current stack frame.
796 However, for functions that don't need it, the frame pointer is
797 optional. For these "frameless" functions the frame pointer is
798 actually the frame pointer of the calling frame. Signal
799 trampolines are just a special case of a "frameless" function.
800 They (usually) share their frame pointer with the frame that was
801 in progress when the signal occurred. */
803 frame_unwind_register (next_frame
, M68K_FP_REGNUM
, buf
);
804 cache
->base
= extract_unsigned_integer (buf
, 4);
805 if (cache
->base
== 0)
808 /* For normal frames, %pc is stored at 4(%fp). */
809 cache
->saved_regs
[M68K_PC_REGNUM
] = 4;
811 cache
->pc
= frame_func_unwind (next_frame
, NORMAL_FRAME
);
813 m68k_analyze_prologue (cache
->pc
, frame_pc_unwind (next_frame
), cache
);
815 if (cache
->locals
< 0)
817 /* We didn't find a valid frame, which means that CACHE->base
818 currently holds the frame pointer for our calling frame. If
819 we're at the start of a function, or somewhere half-way its
820 prologue, the function's frame probably hasn't been fully
821 setup yet. Try to reconstruct the base address for the stack
822 frame by looking at the stack pointer. For truly "frameless"
823 functions this might work too. */
825 frame_unwind_register (next_frame
, M68K_SP_REGNUM
, buf
);
826 cache
->base
= extract_unsigned_integer (buf
, 4) + cache
->sp_offset
;
829 /* Now that we have the base address for the stack frame we can
830 calculate the value of %sp in the calling frame. */
831 cache
->saved_sp
= cache
->base
+ 8;
833 /* Adjust all the saved registers such that they contain addresses
834 instead of offsets. */
835 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
836 if (cache
->saved_regs
[i
] != -1)
837 cache
->saved_regs
[i
] += cache
->base
;
843 m68k_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
844 struct frame_id
*this_id
)
846 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
848 /* This marks the outermost frame. */
849 if (cache
->base
== 0)
852 /* See the end of m68k_push_dummy_call. */
853 *this_id
= frame_id_build (cache
->base
+ 8, cache
->pc
);
857 m68k_frame_prev_register (struct frame_info
*next_frame
, void **this_cache
,
858 int regnum
, int *optimizedp
,
859 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
860 int *realnump
, gdb_byte
*valuep
)
862 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
864 gdb_assert (regnum
>= 0);
866 if (regnum
== M68K_SP_REGNUM
&& cache
->saved_sp
)
874 /* Store the value. */
875 store_unsigned_integer (valuep
, 4, cache
->saved_sp
);
880 if (regnum
< M68K_NUM_REGS
&& cache
->saved_regs
[regnum
] != -1)
883 *lvalp
= lval_memory
;
884 *addrp
= cache
->saved_regs
[regnum
];
888 /* Read the value in from memory. */
889 read_memory (*addrp
, valuep
,
890 register_size (current_gdbarch
, regnum
));
896 *lvalp
= lval_register
;
900 frame_unwind_register (next_frame
, (*realnump
), valuep
);
903 static const struct frame_unwind m68k_frame_unwind
=
907 m68k_frame_prev_register
910 static const struct frame_unwind
*
911 m68k_frame_sniffer (struct frame_info
*next_frame
)
913 return &m68k_frame_unwind
;
917 m68k_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
919 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
924 static const struct frame_base m68k_frame_base
=
927 m68k_frame_base_address
,
928 m68k_frame_base_address
,
929 m68k_frame_base_address
932 static struct frame_id
933 m68k_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
938 frame_unwind_register (next_frame
, M68K_FP_REGNUM
, buf
);
939 fp
= extract_unsigned_integer (buf
, 4);
941 /* See the end of m68k_push_dummy_call. */
942 return frame_id_build (fp
+ 8, frame_pc_unwind (next_frame
));
946 /* Figure out where the longjmp will land. Slurp the args out of the stack.
947 We expect the first arg to be a pointer to the jmp_buf structure from which
948 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
949 This routine returns true on success. */
952 m68k_get_longjmp_target (CORE_ADDR
*pc
)
955 CORE_ADDR sp
, jb_addr
;
956 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
960 internal_error (__FILE__
, __LINE__
,
961 _("m68k_get_longjmp_target: not implemented"));
965 buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
966 sp
= read_register (SP_REGNUM
);
968 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack */
969 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
972 jb_addr
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
974 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
975 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
978 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
983 /* System V Release 4 (SVR4). */
986 m68k_svr4_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
988 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
990 /* SVR4 uses a different calling convention. */
991 set_gdbarch_return_value (gdbarch
, m68k_svr4_return_value
);
993 /* SVR4 uses %a0 instead of %a1. */
994 tdep
->struct_value_regnum
= M68K_A0_REGNUM
;
998 /* Function: m68k_gdbarch_init
999 Initializer function for the m68k gdbarch vector.
1000 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1002 static struct gdbarch
*
1003 m68k_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1005 struct gdbarch_tdep
*tdep
= NULL
;
1006 struct gdbarch
*gdbarch
;
1008 /* find a candidate among the list of pre-declared architectures. */
1009 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1011 return (arches
->gdbarch
);
1013 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
1014 gdbarch
= gdbarch_alloc (&info
, tdep
);
1016 set_gdbarch_long_double_format (gdbarch
, floatformats_m68881_ext
);
1017 set_gdbarch_long_double_bit (gdbarch
, 96);
1019 set_gdbarch_skip_prologue (gdbarch
, m68k_skip_prologue
);
1020 set_gdbarch_breakpoint_from_pc (gdbarch
, m68k_local_breakpoint_from_pc
);
1022 /* Stack grows down. */
1023 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1024 set_gdbarch_frame_align (gdbarch
, m68k_frame_align
);
1026 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
1028 set_gdbarch_frame_args_skip (gdbarch
, 8);
1029 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, m68k_dwarf_reg_to_regnum
);
1030 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, m68k_dwarf_reg_to_regnum
);
1032 set_gdbarch_register_type (gdbarch
, m68k_register_type
);
1033 set_gdbarch_register_name (gdbarch
, m68k_register_name
);
1034 set_gdbarch_num_regs (gdbarch
, M68K_NUM_REGS
);
1035 set_gdbarch_sp_regnum (gdbarch
, M68K_SP_REGNUM
);
1036 set_gdbarch_pc_regnum (gdbarch
, M68K_PC_REGNUM
);
1037 set_gdbarch_ps_regnum (gdbarch
, M68K_PS_REGNUM
);
1038 set_gdbarch_fp0_regnum (gdbarch
, M68K_FP0_REGNUM
);
1039 set_gdbarch_convert_register_p (gdbarch
, m68k_convert_register_p
);
1040 set_gdbarch_register_to_value (gdbarch
, m68k_register_to_value
);
1041 set_gdbarch_value_to_register (gdbarch
, m68k_value_to_register
);
1043 set_gdbarch_push_dummy_call (gdbarch
, m68k_push_dummy_call
);
1044 set_gdbarch_return_value (gdbarch
, m68k_return_value
);
1047 set_gdbarch_print_insn (gdbarch
, print_insn_m68k
);
1049 #if defined JB_PC && defined JB_ELEMENT_SIZE
1050 tdep
->jb_pc
= JB_PC
;
1051 tdep
->jb_elt_size
= JB_ELEMENT_SIZE
;
1055 tdep
->struct_value_regnum
= M68K_A1_REGNUM
;
1056 tdep
->struct_return
= reg_struct_return
;
1058 /* Frame unwinder. */
1059 set_gdbarch_unwind_dummy_id (gdbarch
, m68k_unwind_dummy_id
);
1060 set_gdbarch_unwind_pc (gdbarch
, m68k_unwind_pc
);
1062 /* Hook in the DWARF CFI frame unwinder. */
1063 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
1065 frame_base_set_default (gdbarch
, &m68k_frame_base
);
1067 /* Hook in ABI-specific overrides, if they have been registered. */
1068 gdbarch_init_osabi (info
, gdbarch
);
1070 /* Now we have tuned the configuration, set a few final things,
1071 based on what the OS ABI has told us. */
1073 if (tdep
->jb_pc
>= 0)
1074 set_gdbarch_get_longjmp_target (gdbarch
, m68k_get_longjmp_target
);
1076 frame_unwind_append_sniffer (gdbarch
, m68k_frame_sniffer
);
1083 m68k_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1085 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1091 extern initialize_file_ftype _initialize_m68k_tdep
; /* -Wmissing-prototypes */
1094 _initialize_m68k_tdep (void)
1096 gdbarch_register (bfd_arch_m68k
, m68k_gdbarch_init
, m68k_dump_tdep
);