1 /* Target dependent code for the Motorola 68000 series.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
4 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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "frame-base.h"
26 #include "frame-unwind.h"
30 #include "gdb_string.h"
31 #include "gdb_assert.h"
34 #include "arch-utils.h"
37 #include "m68k-tdep.h"
40 #define P_LINKL_FP 0x480e
41 #define P_LINKW_FP 0x4e56
42 #define P_PEA_FP 0x4856
43 #define P_MOVEAL_SP_FP 0x2c4f
44 #define P_ADDAW_SP 0xdefc
45 #define P_ADDAL_SP 0xdffc
46 #define P_SUBQW_SP 0x514f
47 #define P_SUBQL_SP 0x518f
48 #define P_LEA_SP_SP 0x4fef
49 #define P_LEA_PC_A5 0x4bfb0170
50 #define P_FMOVEMX_SP 0xf227
51 #define P_MOVEL_SP 0x2f00
52 #define P_MOVEML_SP 0x48e7
55 #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
56 #define REGISTER_BYTES_NOFP (16*4 + 8)
58 /* Offset from SP to first arg on stack at first instruction of a function */
59 #define SP_ARG0 (1 * 4)
61 #if !defined (BPT_VECTOR)
62 #define BPT_VECTOR 0xf
65 #if !defined (REMOTE_BPT_VECTOR)
66 #define REMOTE_BPT_VECTOR 1
70 /* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
71 so m68k_remote_breakpoint_from_pc is currently not used. */
73 static const unsigned char *
74 m68k_remote_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
76 static unsigned char break_insn
[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR
)};
77 *lenptr
= sizeof (break_insn
);
81 static const unsigned char *
82 m68k_local_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
84 static unsigned char break_insn
[] = {0x4e, (0x40 | BPT_VECTOR
)};
85 *lenptr
= sizeof (break_insn
);
91 m68k_register_bytes_ok (long numbytes
)
93 return ((numbytes
== REGISTER_BYTES_FP
)
94 || (numbytes
== REGISTER_BYTES_NOFP
));
97 /* Return the GDB type object for the "standard" data type of data in
98 register N. This should be int for D0-D7, SR, FPCONTROL and
99 FPSTATUS, long double for FP0-FP7, and void pointer for all others
100 (A0-A7, PC, FPIADDR). Note, for registers which contain
101 addresses return pointer to void, not pointer to char, because we
102 don't want to attempt to print the string after printing the
106 m68k_register_type (struct gdbarch
*gdbarch
, int regnum
)
108 if (regnum
>= FP0_REGNUM
&& regnum
<= FP0_REGNUM
+ 7)
109 return builtin_type_m68881_ext
;
111 if (regnum
== M68K_FPI_REGNUM
|| regnum
== PC_REGNUM
)
112 return builtin_type_void_func_ptr
;
114 if (regnum
== M68K_FPC_REGNUM
|| regnum
== M68K_FPS_REGNUM
115 || regnum
== PS_REGNUM
)
116 return builtin_type_int32
;
118 if (regnum
>= M68K_A0_REGNUM
&& regnum
<= M68K_A0_REGNUM
+ 7)
119 return builtin_type_void_data_ptr
;
121 return builtin_type_int32
;
124 /* Function: m68k_register_name
125 Returns the name of the standard m68k register regnum. */
128 m68k_register_name (int regnum
)
130 static char *register_names
[] = {
131 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
132 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
134 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
135 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
139 regnum
>= sizeof (register_names
) / sizeof (register_names
[0]))
140 internal_error (__FILE__
, __LINE__
,
141 "m68k_register_name: illegal register number %d", regnum
);
143 return register_names
[regnum
];
146 /* Index within `registers' of the first byte of the space for
150 m68k_register_byte (int regnum
)
152 if (regnum
>= M68K_FPC_REGNUM
)
153 return (((regnum
- M68K_FPC_REGNUM
) * 4) + 168);
154 else if (regnum
>= FP0_REGNUM
)
155 return (((regnum
- FP0_REGNUM
) * 12) + 72);
160 /* Extract from an array REGBUF containing the (raw) register state, a
161 function return value of TYPE, and copy that, in virtual format,
165 m68k_extract_return_value (struct type
*type
, struct regcache
*regcache
,
168 int len
= TYPE_LENGTH (type
);
169 char buf
[M68K_MAX_REGISTER_SIZE
];
171 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
172 && TYPE_NFIELDS (type
) == 1)
174 m68k_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regcache
, valbuf
);
180 regcache_raw_read (regcache
, M68K_D0_REGNUM
, buf
);
181 memcpy (valbuf
, buf
+ (4 - len
), len
);
185 regcache_raw_read (regcache
, M68K_D0_REGNUM
, buf
);
186 memcpy (valbuf
, buf
+ (8 - len
), len
- 4);
187 regcache_raw_read (regcache
, M68K_D1_REGNUM
,
188 (char *) valbuf
+ (len
- 4));
191 internal_error (__FILE__
, __LINE__
,
192 "Cannot extract return value of %d bytes long.", len
);
195 /* Write into the appropriate registers a function return value stored
196 in VALBUF of type TYPE, given in virtual format. */
199 m68k_store_return_value (struct type
*type
, struct regcache
*regcache
,
202 int len
= TYPE_LENGTH (type
);
204 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
205 && TYPE_NFIELDS (type
) == 1)
207 m68k_store_return_value (TYPE_FIELD_TYPE (type
, 0), regcache
, valbuf
);
212 regcache_raw_write_part (regcache
, M68K_D0_REGNUM
, 4 - len
, len
, valbuf
);
215 regcache_raw_write_part (regcache
, M68K_D1_REGNUM
, 8 - len
,
217 regcache_raw_write (regcache
, M68K_D0_REGNUM
,
218 (char *) valbuf
+ (len
- 4));
221 internal_error (__FILE__
, __LINE__
,
222 "Cannot store return value of %d bytes long.", len
);
225 /* Extract from REGCACHE, which contains the (raw) register state, the
226 address in which a function should return its structure value, as a
230 m68k_extract_struct_value_address (struct regcache
*regcache
)
234 regcache_cooked_read (regcache
, M68K_D0_REGNUM
, buf
);
235 return extract_unsigned_integer (buf
, 4);
239 m68k_use_struct_convention (int gcc_p
, struct type
*type
)
241 enum struct_return struct_return
;
243 struct_return
= gdbarch_tdep (current_gdbarch
)->struct_return
;
244 return generic_use_struct_convention (struct_return
== reg_struct_return
,
248 /* A function that tells us whether the function invocation represented
249 by fi does not have a frame on the stack associated with it. If it
250 does not, FRAMELESS is set to 1, else 0. */
253 m68k_frameless_function_invocation (struct frame_info
*fi
)
255 if (get_frame_type (fi
) == SIGTRAMP_FRAME
)
258 return frameless_look_for_prologue (fi
);
262 delta68_in_sigtramp (CORE_ADDR pc
, char *name
)
265 return strcmp (name
, "_sigcode") == 0;
271 delta68_frame_args_address (struct frame_info
*frame_info
)
273 /* we assume here that the only frameless functions are the system calls
274 or other functions who do not put anything on the stack. */
275 if (get_frame_type (frame_info
) == SIGTRAMP_FRAME
)
276 return get_frame_base (frame_info
) + 12;
277 else if (frameless_look_for_prologue (frame_info
))
279 /* Check for an interrupted system call */
280 if (get_next_frame (frame_info
) && (get_frame_type (get_next_frame (frame_info
)) == SIGTRAMP_FRAME
))
281 return get_frame_base (get_next_frame (frame_info
)) + 16;
283 return get_frame_base (frame_info
) + 4;
286 return get_frame_base (frame_info
);
290 delta68_frame_saved_pc (struct frame_info
*frame_info
)
292 return read_memory_unsigned_integer (delta68_frame_args_address (frame_info
)
297 delta68_frame_num_args (struct frame_info
*fi
)
300 CORE_ADDR pc
= DEPRECATED_FRAME_SAVED_PC (fi
);
301 int insn
= read_memory_unsigned_integer (pc
, 2);
303 if (insn
== 0047757 || insn
== 0157374) /* lea W(sp),sp or addaw #W,sp */
304 val
= read_memory_integer (pc
+ 2, 2);
305 else if ((insn
& 0170777) == 0050217 /* addql #N, sp */
306 || (insn
& 0170777) == 0050117) /* addqw */
308 val
= (insn
>> 9) & 7;
312 else if (insn
== 0157774) /* addal #WW, sp */
313 val
= read_memory_integer (pc
+ 2, 4);
319 m68k_push_dummy_call (struct gdbarch
*gdbarch
, CORE_ADDR func_addr
,
320 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
321 struct value
**args
, CORE_ADDR sp
, int struct_return
,
322 CORE_ADDR struct_addr
)
327 /* Push arguments in reverse order. */
328 for (i
= nargs
- 1; i
>= 0; i
--)
330 struct type
*value_type
= VALUE_ENCLOSING_TYPE (args
[i
]);
331 int len
= TYPE_LENGTH (value_type
);
332 int container_len
= (len
+ 3) & ~3;
335 /* Non-scalars bigger than 4 bytes are left aligned, others are
337 if ((TYPE_CODE (value_type
) == TYPE_CODE_STRUCT
338 || TYPE_CODE (value_type
) == TYPE_CODE_UNION
339 || TYPE_CODE (value_type
) == TYPE_CODE_ARRAY
)
343 offset
= container_len
- len
;
345 write_memory (sp
+ offset
, VALUE_CONTENTS_ALL (args
[i
]), len
);
348 /* Store struct value address. */
351 store_unsigned_integer (buf
, 4, struct_addr
);
352 regcache_cooked_write (regcache
, M68K_A1_REGNUM
, buf
);
355 /* Store return address. */
357 store_unsigned_integer (buf
, 4, bp_addr
);
358 write_memory (sp
, buf
, 4);
360 /* Finally, update the stack pointer... */
361 store_unsigned_integer (buf
, 4, sp
);
362 regcache_cooked_write (regcache
, M68K_SP_REGNUM
, buf
);
364 /* ...and fake a frame pointer. */
365 regcache_cooked_write (regcache
, M68K_FP_REGNUM
, buf
);
367 /* DWARF2/GCC uses the stack address *before* the function call as a
372 struct m68k_frame_cache
379 /* Saved registers. */
380 CORE_ADDR saved_regs
[M68K_NUM_REGS
];
383 /* Stack space reserved for local variables. */
387 /* Allocate and initialize a frame cache. */
389 static struct m68k_frame_cache
*
390 m68k_alloc_frame_cache (void)
392 struct m68k_frame_cache
*cache
;
395 cache
= FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache
);
399 cache
->sp_offset
= -4;
402 /* Saved registers. We initialize these to -1 since zero is a valid
403 offset (that's where %fp is supposed to be stored). */
404 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
405 cache
->saved_regs
[i
] = -1;
407 /* Frameless until proven otherwise. */
413 /* Check whether PC points at a code that sets up a new stack frame.
414 If so, it updates CACHE and returns the address of the first
415 instruction after the sequence that sets removes the "hidden"
416 argument from the stack or CURRENT_PC, whichever is smaller.
417 Otherwise, return PC. */
420 m68k_analyze_frame_setup (CORE_ADDR pc
, CORE_ADDR current_pc
,
421 struct m68k_frame_cache
*cache
)
425 if (pc
>= current_pc
)
428 op
= read_memory_unsigned_integer (pc
, 2);
430 if (op
== P_LINKW_FP
|| op
== P_LINKL_FP
|| op
== P_PEA_FP
)
432 cache
->saved_regs
[M68K_FP_REGNUM
] = 0;
433 cache
->sp_offset
+= 4;
434 if (op
== P_LINKW_FP
)
436 /* link.w %fp, #-N */
437 /* link.w %fp, #0; adda.l #-N, %sp */
438 cache
->locals
= -read_memory_integer (pc
+ 2, 2);
440 if (pc
+ 4 < current_pc
&& cache
->locals
== 0)
442 op
= read_memory_unsigned_integer (pc
+ 4, 2);
443 if (op
== P_ADDAL_SP
)
445 cache
->locals
= read_memory_integer (pc
+ 6, 4);
452 else if (op
== P_LINKL_FP
)
454 /* link.l %fp, #-N */
455 cache
->locals
= -read_memory_integer (pc
+ 2, 4);
460 /* pea (%fp); movea.l %sp, %fp */
463 if (pc
+ 2 < current_pc
)
465 op
= read_memory_unsigned_integer (pc
+ 2, 2);
467 if (op
== P_MOVEAL_SP_FP
)
469 /* move.l %sp, %fp */
477 else if ((op
& 0170777) == P_SUBQW_SP
|| (op
& 0170777) == P_SUBQL_SP
)
479 /* subq.[wl] #N,%sp */
480 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
481 cache
->locals
= (op
& 07000) == 0 ? 8 : (op
& 07000) >> 9;
482 if (pc
+ 2 < current_pc
)
484 op
= read_memory_unsigned_integer (pc
+ 2, 2);
485 if ((op
& 0170777) == P_SUBQW_SP
|| (op
& 0170777) == P_SUBQL_SP
)
487 cache
->locals
+= (op
& 07000) == 0 ? 8 : (op
& 07000) >> 9;
493 else if (op
== P_ADDAW_SP
|| op
== P_LEA_SP_SP
)
496 /* lea (-N,%sp),%sp */
497 cache
->locals
= -read_memory_integer (pc
+ 2, 2);
500 else if (op
== P_ADDAL_SP
)
503 cache
->locals
= -read_memory_integer (pc
+ 2, 4);
510 /* Check whether PC points at code that saves registers on the stack.
511 If so, it updates CACHE and returns the address of the first
512 instruction after the register saves or CURRENT_PC, whichever is
513 smaller. Otherwise, return PC. */
516 m68k_analyze_register_saves (CORE_ADDR pc
, CORE_ADDR current_pc
,
517 struct m68k_frame_cache
*cache
)
519 if (cache
->locals
>= 0)
525 offset
= -4 - cache
->locals
;
526 while (pc
< current_pc
)
528 op
= read_memory_unsigned_integer (pc
, 2);
529 if (op
== P_FMOVEMX_SP
)
531 /* fmovem.x REGS,-(%sp) */
532 op
= read_memory_unsigned_integer (pc
+ 2, 2);
533 if ((op
& 0xff00) == 0xe000)
536 for (i
= 0; i
< 16; i
++, mask
>>= 1)
540 cache
->saved_regs
[i
+ M68K_FP0_REGNUM
] = offset
;
549 else if ((op
& 0170677) == P_MOVEL_SP
)
551 /* move.l %R,-(%sp) */
552 regno
= ((op
& 07000) >> 9) | ((op
& 0100) >> 3);
553 cache
->saved_regs
[regno
] = offset
;
557 else if (op
== P_MOVEML_SP
)
559 /* movem.l REGS,-(%sp) */
560 mask
= read_memory_unsigned_integer (pc
+ 2, 2);
561 for (i
= 0; i
< 16; i
++, mask
>>= 1)
565 cache
->saved_regs
[15 - i
] = offset
;
580 /* Do a full analysis of the prologue at PC and update CACHE
581 accordingly. Bail out early if CURRENT_PC is reached. Return the
582 address where the analysis stopped.
584 We handle all cases that can be generated by gcc.
586 For allocating a stack frame:
590 pea (%fp); move.l %sp,%fp
591 link.w %a6,#0; add.l #-N,%sp
594 subq.w #8,%sp; subq.w #N-8,%sp
599 For saving registers:
603 move.l R1,-(%sp); move.l R2,-(%sp)
606 For setting up the PIC register:
613 m68k_analyze_prologue (CORE_ADDR pc
, CORE_ADDR current_pc
,
614 struct m68k_frame_cache
*cache
)
618 pc
= m68k_analyze_frame_setup (pc
, current_pc
, cache
);
619 pc
= m68k_analyze_register_saves (pc
, current_pc
, cache
);
620 if (pc
>= current_pc
)
623 /* Check for GOT setup. */
624 op
= read_memory_unsigned_integer (pc
, 4);
625 if (op
== P_LEA_PC_A5
)
627 /* lea (%pc,N),%a5 */
634 /* Return PC of first real instruction. */
637 m68k_skip_prologue (CORE_ADDR start_pc
)
639 struct m68k_frame_cache cache
;
644 pc
= m68k_analyze_prologue (start_pc
, (CORE_ADDR
) -1, &cache
);
645 if (cache
.locals
< 0)
651 m68k_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
655 frame_unwind_register (next_frame
, PC_REGNUM
, buf
);
656 return extract_typed_address (buf
, builtin_type_void_func_ptr
);
661 static struct m68k_frame_cache
*
662 m68k_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
664 struct m68k_frame_cache
*cache
;
671 cache
= m68k_alloc_frame_cache ();
674 /* In principle, for normal frames, %fp holds the frame pointer,
675 which holds the base address for the current stack frame.
676 However, for functions that don't need it, the frame pointer is
677 optional. For these "frameless" functions the frame pointer is
678 actually the frame pointer of the calling frame. Signal
679 trampolines are just a special case of a "frameless" function.
680 They (usually) share their frame pointer with the frame that was
681 in progress when the signal occurred. */
683 frame_unwind_register (next_frame
, M68K_FP_REGNUM
, buf
);
684 cache
->base
= extract_unsigned_integer (buf
, 4);
685 if (cache
->base
== 0)
688 /* For normal frames, %pc is stored at 4(%fp). */
689 cache
->saved_regs
[M68K_PC_REGNUM
] = 4;
691 cache
->pc
= frame_func_unwind (next_frame
);
693 m68k_analyze_prologue (cache
->pc
, frame_pc_unwind (next_frame
), cache
);
695 if (cache
->locals
< 0)
697 /* We didn't find a valid frame, which means that CACHE->base
698 currently holds the frame pointer for our calling frame. If
699 we're at the start of a function, or somewhere half-way its
700 prologue, the function's frame probably hasn't been fully
701 setup yet. Try to reconstruct the base address for the stack
702 frame by looking at the stack pointer. For truly "frameless"
703 functions this might work too. */
705 frame_unwind_register (next_frame
, M68K_SP_REGNUM
, buf
);
706 cache
->base
= extract_unsigned_integer (buf
, 4) + cache
->sp_offset
;
709 /* Now that we have the base address for the stack frame we can
710 calculate the value of %sp in the calling frame. */
711 cache
->saved_sp
= cache
->base
+ 8;
713 /* Adjust all the saved registers such that they contain addresses
714 instead of offsets. */
715 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
716 if (cache
->saved_regs
[i
] != -1)
717 cache
->saved_regs
[i
] += cache
->base
;
723 m68k_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
724 struct frame_id
*this_id
)
726 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
728 /* This marks the outermost frame. */
729 if (cache
->base
== 0)
732 /* See the end of m68k_push_dummy_call. */
733 *this_id
= frame_id_build (cache
->base
+ 8, cache
->pc
);
737 m68k_frame_prev_register (struct frame_info
*next_frame
, void **this_cache
,
738 int regnum
, int *optimizedp
,
739 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
740 int *realnump
, void *valuep
)
742 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
744 gdb_assert (regnum
>= 0);
746 if (regnum
== M68K_SP_REGNUM
&& cache
->saved_sp
)
754 /* Store the value. */
755 store_unsigned_integer (valuep
, 4, cache
->saved_sp
);
760 if (regnum
< M68K_NUM_REGS
&& cache
->saved_regs
[regnum
] != -1)
763 *lvalp
= lval_memory
;
764 *addrp
= cache
->saved_regs
[regnum
];
768 /* Read the value in from memory. */
769 read_memory (*addrp
, valuep
,
770 register_size (current_gdbarch
, regnum
));
775 frame_register_unwind (next_frame
, regnum
,
776 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
779 static const struct frame_unwind m68k_frame_unwind
=
783 m68k_frame_prev_register
786 static const struct frame_unwind
*
787 m68k_frame_sniffer (struct frame_info
*next_frame
)
789 return &m68k_frame_unwind
;
792 /* Signal trampolines. */
794 static struct m68k_frame_cache
*
795 m68k_sigtramp_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
797 struct m68k_frame_cache
*cache
;
798 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
799 struct m68k_sigtramp_info info
;
806 cache
= m68k_alloc_frame_cache ();
808 frame_unwind_register (next_frame
, M68K_SP_REGNUM
, buf
);
809 cache
->base
= extract_unsigned_integer (buf
, 4) - 4;
811 info
= tdep
->get_sigtramp_info (next_frame
);
813 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
814 if (info
.sc_reg_offset
[i
] != -1)
815 cache
->saved_regs
[i
] = info
.sigcontext_addr
+ info
.sc_reg_offset
[i
];
822 m68k_sigtramp_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
823 struct frame_id
*this_id
)
825 struct m68k_frame_cache
*cache
=
826 m68k_sigtramp_frame_cache (next_frame
, this_cache
);
828 /* See the end of m68k_push_dummy_call. */
829 *this_id
= frame_id_build (cache
->base
+ 8, frame_pc_unwind (next_frame
));
833 m68k_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
835 int regnum
, int *optimizedp
,
836 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
837 int *realnump
, void *valuep
)
839 /* Make sure we've initialized the cache. */
840 m68k_sigtramp_frame_cache (next_frame
, this_cache
);
842 m68k_frame_prev_register (next_frame
, this_cache
, regnum
,
843 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
846 static const struct frame_unwind m68k_sigtramp_frame_unwind
=
849 m68k_sigtramp_frame_this_id
,
850 m68k_sigtramp_frame_prev_register
853 static const struct frame_unwind
*
854 m68k_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
856 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
859 /* We shouldn't even bother to try if the OSABI didn't register
860 a get_sigtramp_info handler. */
861 if (!gdbarch_tdep (current_gdbarch
)->get_sigtramp_info
)
864 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
865 if (PC_IN_SIGTRAMP (pc
, name
))
866 return &m68k_sigtramp_frame_unwind
;
872 m68k_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
874 struct m68k_frame_cache
*cache
= m68k_frame_cache (next_frame
, this_cache
);
879 static const struct frame_base m68k_frame_base
=
882 m68k_frame_base_address
,
883 m68k_frame_base_address
,
884 m68k_frame_base_address
887 static struct frame_id
888 m68k_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
893 frame_unwind_register (next_frame
, M68K_FP_REGNUM
, buf
);
894 fp
= extract_unsigned_integer (buf
, 4);
896 /* See the end of m68k_push_dummy_call. */
897 return frame_id_build (fp
+ 8, frame_pc_unwind (next_frame
));
900 #ifdef USE_PROC_FS /* Target dependent support for /proc */
902 #include <sys/procfs.h>
904 /* Prototypes for supply_gregset etc. */
907 /* The /proc interface divides the target machine's register set up into
908 two different sets, the general register set (gregset) and the floating
909 point register set (fpregset). For each set, there is an ioctl to get
910 the current register set and another ioctl to set the current values.
912 The actual structure passed through the ioctl interface is, of course,
913 naturally machine dependent, and is different for each set of registers.
914 For the m68k for example, the general register set is typically defined
917 typedef int gregset_t[18];
923 and the floating point set by:
925 typedef struct fpregset {
929 int f_fpregs[8][3]; (8 regs, 96 bits each)
932 These routines provide the packing and unpacking of gregset_t and
933 fpregset_t formatted data.
937 /* Atari SVR4 has R_SR but not R_PS */
939 #if !defined (R_PS) && defined (R_SR)
943 /* Given a pointer to a general register set in /proc format (gregset_t *),
944 unpack the register contents and supply them as gdb's idea of the current
948 supply_gregset (gregset_t
*gregsetp
)
951 register greg_t
*regp
= (greg_t
*) gregsetp
;
953 for (regi
= 0; regi
< R_PC
; regi
++)
955 supply_register (regi
, (char *) (regp
+ regi
));
957 supply_register (PS_REGNUM
, (char *) (regp
+ R_PS
));
958 supply_register (PC_REGNUM
, (char *) (regp
+ R_PC
));
962 fill_gregset (gregset_t
*gregsetp
, int regno
)
965 register greg_t
*regp
= (greg_t
*) gregsetp
;
967 for (regi
= 0; regi
< R_PC
; regi
++)
969 if (regno
== -1 || regno
== regi
)
970 regcache_collect (regi
, regp
+ regi
);
972 if (regno
== -1 || regno
== PS_REGNUM
)
973 regcache_collect (PS_REGNUM
, regp
+ R_PS
);
974 if (regno
== -1 || regno
== PC_REGNUM
)
975 regcache_collect (PC_REGNUM
, regp
+ R_PC
);
978 #if defined (FP0_REGNUM)
980 /* Given a pointer to a floating point register set in /proc format
981 (fpregset_t *), unpack the register contents and supply them as gdb's
982 idea of the current floating point register values. */
985 supply_fpregset (fpregset_t
*fpregsetp
)
990 for (regi
= FP0_REGNUM
; regi
< M68K_FPC_REGNUM
; regi
++)
992 from
= (char *) &(fpregsetp
->f_fpregs
[regi
- FP0_REGNUM
][0]);
993 supply_register (regi
, from
);
995 supply_register (M68K_FPC_REGNUM
, (char *) &(fpregsetp
->f_pcr
));
996 supply_register (M68K_FPS_REGNUM
, (char *) &(fpregsetp
->f_psr
));
997 supply_register (M68K_FPI_REGNUM
, (char *) &(fpregsetp
->f_fpiaddr
));
1000 /* Given a pointer to a floating point register set in /proc format
1001 (fpregset_t *), update the register specified by REGNO from gdb's idea
1002 of the current floating point register set. If REGNO is -1, update
1006 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
1010 for (regi
= FP0_REGNUM
; regi
< M68K_FPC_REGNUM
; regi
++)
1012 if (regno
== -1 || regno
== regi
)
1013 regcache_collect (regi
, &fpregsetp
->f_fpregs
[regi
- FP0_REGNUM
][0]);
1015 if (regno
== -1 || regno
== M68K_FPC_REGNUM
)
1016 regcache_collect (M68K_FPC_REGNUM
, &fpregsetp
->f_pcr
);
1017 if (regno
== -1 || regno
== M68K_FPS_REGNUM
)
1018 regcache_collect (M68K_FPS_REGNUM
, &fpregsetp
->f_psr
);
1019 if (regno
== -1 || regno
== M68K_FPI_REGNUM
)
1020 regcache_collect (M68K_FPI_REGNUM
, &fpregsetp
->f_fpiaddr
);
1023 #endif /* defined (FP0_REGNUM) */
1025 #endif /* USE_PROC_FS */
1027 /* Figure out where the longjmp will land. Slurp the args out of the stack.
1028 We expect the first arg to be a pointer to the jmp_buf structure from which
1029 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
1030 This routine returns true on success. */
1033 m68k_get_longjmp_target (CORE_ADDR
*pc
)
1036 CORE_ADDR sp
, jb_addr
;
1037 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1039 if (tdep
->jb_pc
< 0)
1041 internal_error (__FILE__
, __LINE__
,
1042 "m68k_get_longjmp_target: not implemented");
1046 buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
1047 sp
= read_register (SP_REGNUM
);
1049 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack */
1050 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
1053 jb_addr
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
1055 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
1056 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
1059 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
1064 /* Immediately after a function call, return the saved pc before the frame
1065 is setup. For sun3's, we check for the common case of being inside of a
1066 system call, and if so, we know that Sun pushes the call # on the stack
1067 prior to doing the trap. */
1070 m68k_saved_pc_after_call (struct frame_info
*frame
)
1074 op
= read_memory_unsigned_integer (frame
->pc
- SYSCALL_TRAP_OFFSET
, 2);
1076 if (op
== SYSCALL_TRAP
)
1077 return read_memory_unsigned_integer (read_register (SP_REGNUM
) + 4, 4);
1079 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
1081 #endif /* SYSCALL_TRAP */
1083 /* Function: m68k_gdbarch_init
1084 Initializer function for the m68k gdbarch vector.
1085 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1087 static struct gdbarch
*
1088 m68k_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1090 struct gdbarch_tdep
*tdep
= NULL
;
1091 struct gdbarch
*gdbarch
;
1093 /* find a candidate among the list of pre-declared architectures. */
1094 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1096 return (arches
->gdbarch
);
1098 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
1099 gdbarch
= gdbarch_alloc (&info
, tdep
);
1101 set_gdbarch_long_double_format (gdbarch
, &floatformat_m68881_ext
);
1102 set_gdbarch_long_double_bit (gdbarch
, 96);
1104 set_gdbarch_function_start_offset (gdbarch
, 0);
1106 set_gdbarch_skip_prologue (gdbarch
, m68k_skip_prologue
);
1108 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, m68k_saved_pc_after_call
);
1110 set_gdbarch_breakpoint_from_pc (gdbarch
, m68k_local_breakpoint_from_pc
);
1112 /* Stack grows down. */
1113 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1114 set_gdbarch_parm_boundary (gdbarch
, 32);
1116 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
1117 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
1119 set_gdbarch_extract_return_value (gdbarch
, m68k_extract_return_value
);
1120 set_gdbarch_store_return_value (gdbarch
, m68k_store_return_value
);
1121 set_gdbarch_extract_struct_value_address (gdbarch
,
1122 m68k_extract_struct_value_address
);
1123 set_gdbarch_use_struct_convention (gdbarch
, m68k_use_struct_convention
);
1125 set_gdbarch_frameless_function_invocation (gdbarch
,
1126 m68k_frameless_function_invocation
);
1127 set_gdbarch_frame_args_skip (gdbarch
, 8);
1129 set_gdbarch_register_type (gdbarch
, m68k_register_type
);
1130 set_gdbarch_register_name (gdbarch
, m68k_register_name
);
1131 set_gdbarch_num_regs (gdbarch
, 29);
1132 set_gdbarch_register_bytes_ok (gdbarch
, m68k_register_bytes_ok
);
1133 set_gdbarch_sp_regnum (gdbarch
, M68K_SP_REGNUM
);
1134 set_gdbarch_pc_regnum (gdbarch
, M68K_PC_REGNUM
);
1135 set_gdbarch_ps_regnum (gdbarch
, M68K_PS_REGNUM
);
1136 set_gdbarch_fp0_regnum (gdbarch
, M68K_FP0_REGNUM
);
1138 set_gdbarch_push_dummy_call (gdbarch
, m68k_push_dummy_call
);
1141 set_gdbarch_print_insn (gdbarch
, print_insn_m68k
);
1143 #if defined JB_PC && defined JB_ELEMENT_SIZE
1144 tdep
->jb_pc
= JB_PC
;
1145 tdep
->jb_elt_size
= JB_ELEMENT_SIZE
;
1149 tdep
->get_sigtramp_info
= NULL
;
1150 tdep
->struct_return
= pcc_struct_return
;
1152 /* Frame unwinder. */
1153 set_gdbarch_unwind_dummy_id (gdbarch
, m68k_unwind_dummy_id
);
1154 set_gdbarch_unwind_pc (gdbarch
, m68k_unwind_pc
);
1155 frame_base_set_default (gdbarch
, &m68k_frame_base
);
1157 /* Hook in ABI-specific overrides, if they have been registered. */
1158 gdbarch_init_osabi (info
, gdbarch
);
1160 /* Now we have tuned the configuration, set a few final things,
1161 based on what the OS ABI has told us. */
1163 if (tdep
->jb_pc
>= 0)
1164 set_gdbarch_get_longjmp_target (gdbarch
, m68k_get_longjmp_target
);
1166 frame_unwind_append_sniffer (gdbarch
, m68k_sigtramp_frame_sniffer
);
1167 frame_unwind_append_sniffer (gdbarch
, m68k_frame_sniffer
);
1174 m68k_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
1176 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1182 extern initialize_file_ftype _initialize_m68k_tdep
; /* -Wmissing-prototypes */
1185 _initialize_m68k_tdep (void)
1187 gdbarch_register (bfd_arch_m68k
, m68k_gdbarch_init
, m68k_dump_tdep
);