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
58 #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
59 #define REGISTER_BYTES_NOFP (16*4 + 8)
61 /* Offset from SP to first arg on stack at first instruction of a function */
62 #define SP_ARG0 (1 * 4)
64 #if !defined (BPT_VECTOR)
65 #define BPT_VECTOR 0xf
68 static const gdb_byte *
69 m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
71 static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
72 *lenptr = sizeof (break_insn);
78 m68k_register_bytes_ok (long numbytes)
80 return ((numbytes == REGISTER_BYTES_FP)
81 || (numbytes == REGISTER_BYTES_NOFP));
84 /* Return the GDB type object for the "standard" data type of data in
85 register N. This should be int for D0-D7, SR, FPCONTROL and
86 FPSTATUS, long double for FP0-FP7, and void pointer for all others
87 (A0-A7, PC, FPIADDR). Note, for registers which contain
88 addresses return pointer to void, not pointer to char, because we
89 don't want to attempt to print the string after printing the
93 m68k_register_type (struct gdbarch *gdbarch, int regnum)
95 if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7)
96 return builtin_type_m68881_ext;
98 if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM)
99 return builtin_type_void_func_ptr;
101 if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM
102 || regnum == PS_REGNUM)
103 return builtin_type_int32;
105 if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
106 return builtin_type_void_data_ptr;
108 return builtin_type_int32;
111 /* Function: m68k_register_name
112 Returns the name of the standard m68k register regnum. */
115 m68k_register_name (int regnum)
117 static char *register_names[] = {
118 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
119 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
121 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
122 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
125 if (regnum < 0 || regnum >= ARRAY_SIZE (register_names))
126 internal_error (__FILE__, __LINE__,
127 _("m68k_register_name: illegal register number %d"), regnum);
129 return register_names[regnum];
132 /* Return nonzero if a value of type TYPE stored in register REGNUM
133 needs any special handling. */
136 m68k_convert_register_p (int regnum, struct type *type)
138 return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7);
141 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
142 return its contents in TO. */
145 m68k_register_to_value (struct frame_info *frame, int regnum,
146 struct type *type, gdb_byte *to)
148 gdb_byte from[M68K_MAX_REGISTER_SIZE];
150 /* We only support floating-point values. */
151 if (TYPE_CODE (type) != TYPE_CODE_FLT)
153 warning (_("Cannot convert floating-point register value "
154 "to non-floating-point type."));
158 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
159 the extended floating-point format used by the FPU. */
160 get_frame_register (frame, regnum, from);
161 convert_typed_floating (from, builtin_type_m68881_ext, to, type);
164 /* Write the contents FROM of a value of type TYPE into register
165 REGNUM in frame FRAME. */
168 m68k_value_to_register (struct frame_info *frame, int regnum,
169 struct type *type, const gdb_byte *from)
171 gdb_byte to[M68K_MAX_REGISTER_SIZE];
173 /* We only support floating-point values. */
174 if (TYPE_CODE (type) != TYPE_CODE_FLT)
176 warning (_("Cannot convert non-floating-point type "
177 "to floating-point register value."));
181 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
182 to the extended floating-point format used by the FPU. */
183 convert_typed_floating (from, type, to, builtin_type_m68881_ext);
184 put_frame_register (frame, regnum, to);
188 /* There is a fair number of calling conventions that are in somewhat
189 wide use. The 68000/08/10 don't support an FPU, not even as a
190 coprocessor. All function return values are stored in %d0/%d1.
191 Structures are returned in a static buffer, a pointer to which is
192 returned in %d0. This means that functions returning a structure
193 are not re-entrant. To avoid this problem some systems use a
194 convention where the caller passes a pointer to a buffer in %a1
195 where the return values is to be stored. This convention is the
196 default, and is implemented in the function m68k_return_value.
198 The 68020/030/040/060 do support an FPU, either as a coprocessor
199 (68881/2) or built-in (68040/68060). That's why System V release 4
200 (SVR4) instroduces a new calling convention specified by the SVR4
201 psABI. Integer values are returned in %d0/%d1, pointer return
202 values in %a0 and floating values in %fp0. When calling functions
203 returning a structure the caller should pass a pointer to a buffer
204 for the return value in %a0. This convention is implemented in the
205 function m68k_svr4_return_value, and by appropriately setting the
206 struct_value_regnum member of `struct gdbarch_tdep'.
208 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
209 for passing the structure return value buffer.
211 GCC can also generate code where small structures are returned in
212 %d0/%d1 instead of in memory by using -freg-struct-return. This is
213 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
214 embedded systems. This convention is implemented by setting the
215 struct_return member of `struct gdbarch_tdep' to reg_struct_return. */
217 /* Read a function return value of TYPE from REGCACHE, and copy that
221 m68k_extract_return_value (struct type *type, struct regcache *regcache,
224 int len = TYPE_LENGTH (type);
225 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
229 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
230 memcpy (valbuf, buf + (4 - len), len);
234 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
235 memcpy (valbuf, buf + (8 - len), len - 4);
236 regcache_raw_read (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
239 internal_error (__FILE__, __LINE__,
240 _("Cannot extract return value of %d bytes long."), len);
244 m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
247 int len = TYPE_LENGTH (type);
248 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
250 if (TYPE_CODE (type) == TYPE_CODE_FLT)
252 regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
253 convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type);
255 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
256 regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
258 m68k_extract_return_value (type, regcache, valbuf);
261 /* Write a function return value of TYPE from VALBUF into REGCACHE. */
264 m68k_store_return_value (struct type *type, struct regcache *regcache,
265 const gdb_byte *valbuf)
267 int len = TYPE_LENGTH (type);
270 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
273 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len,
275 regcache_raw_write (regcache, M68K_D1_REGNUM, valbuf + (len - 4));
278 internal_error (__FILE__, __LINE__,
279 _("Cannot store return value of %d bytes long."), len);
283 m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
284 const gdb_byte *valbuf)
286 int len = TYPE_LENGTH (type);
288 if (TYPE_CODE (type) == TYPE_CODE_FLT)
290 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
291 convert_typed_floating (valbuf, type, buf, builtin_type_m68881_ext);
292 regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
294 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
296 regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
297 regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf);
300 m68k_store_return_value (type, regcache, valbuf);
303 /* Return non-zero if TYPE, which is assumed to be a structure or
304 union type, should be returned in registers for architecture
308 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
310 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
311 enum type_code code = TYPE_CODE (type);
312 int len = TYPE_LENGTH (type);
314 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
316 if (tdep->struct_return == pcc_struct_return)
319 return (len == 1 || len == 2 || len == 4 || len == 8);
322 /* Determine, for architecture GDBARCH, how a return value of TYPE
323 should be returned. If it is supposed to be returned in registers,
324 and READBUF is non-zero, read the appropriate value from REGCACHE,
325 and copy it into READBUF. If WRITEBUF is non-zero, write the value
326 from WRITEBUF into REGCACHE. */
328 static enum return_value_convention
329 m68k_return_value (struct gdbarch *gdbarch, struct type *type,
330 struct regcache *regcache, gdb_byte *readbuf,
331 const gdb_byte *writebuf)
333 enum type_code code = TYPE_CODE (type);
335 /* GCC returns a `long double' in memory too. */
336 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
337 && !m68k_reg_struct_return_p (gdbarch, type))
338 || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
340 /* The default on m68k is to return structures in static memory.
341 Consequently a function must return the address where we can
342 find the return value. */
348 regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
349 read_memory (addr, readbuf, TYPE_LENGTH (type));
352 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
356 m68k_extract_return_value (type, regcache, readbuf);
358 m68k_store_return_value (type, regcache, writebuf);
360 return RETURN_VALUE_REGISTER_CONVENTION;
363 static enum return_value_convention
364 m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *type,
365 struct regcache *regcache, gdb_byte *readbuf,
366 const gdb_byte *writebuf)
368 enum type_code code = TYPE_CODE (type);
370 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
371 && !m68k_reg_struct_return_p (gdbarch, type))
373 /* The System V ABI says that:
375 "A function returning a structure or union also sets %a0 to
376 the value it finds in %a0. Thus when the caller receives
377 control again, the address of the returned object resides in
380 So the ABI guarantees that we can always find the return
381 value just after the function has returned. */
387 regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
388 read_memory (addr, readbuf, TYPE_LENGTH (type));
391 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
394 /* This special case is for structures consisting of a single
395 `float' or `double' member. These structures are returned in
396 %fp0. For these structures, we call ourselves recursively,
397 changing TYPE into the type of the first member of the structure.
398 Since that should work for all structures that have only one
399 member, we don't bother to check the member's type here. */
400 if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
402 type = check_typedef (TYPE_FIELD_TYPE (type, 0));
403 return m68k_svr4_return_value (gdbarch, type, regcache,
408 m68k_svr4_extract_return_value (type, regcache, readbuf);
410 m68k_svr4_store_return_value (type, regcache, writebuf);
412 return RETURN_VALUE_REGISTER_CONVENTION;
416 /* Always align the frame to a 4-byte boundary. This is required on
417 coldfire and harmless on the rest. */
420 m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
422 /* Align the stack to four bytes. */
427 m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
428 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
429 struct value **args, CORE_ADDR sp, int struct_return,
430 CORE_ADDR struct_addr)
432 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
436 /* Push arguments in reverse order. */
437 for (i = nargs - 1; i >= 0; i--)
439 struct type *value_type = value_enclosing_type (args[i]);
440 int len = TYPE_LENGTH (value_type);
441 int container_len = (len + 3) & ~3;
444 /* Non-scalars bigger than 4 bytes are left aligned, others are
446 if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
447 || TYPE_CODE (value_type) == TYPE_CODE_UNION
448 || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
452 offset = container_len - len;
454 write_memory (sp + offset, value_contents_all (args[i]), len);
457 /* Store struct value address. */
460 store_unsigned_integer (buf, 4, struct_addr);
461 regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
464 /* Store return address. */
466 store_unsigned_integer (buf, 4, bp_addr);
467 write_memory (sp, buf, 4);
469 /* Finally, update the stack pointer... */
470 store_unsigned_integer (buf, 4, sp);
471 regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);
473 /* ...and fake a frame pointer. */
474 regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);
476 /* DWARF2/GCC uses the stack address *before* the function call as a
481 /* Convert a dwarf or dwarf2 regnumber to a GDB regnum. */
484 m68k_dwarf_reg_to_regnum (int num)
488 return (num - 0) + M68K_D0_REGNUM;
491 return (num - 8) + M68K_A0_REGNUM;
494 return (num - 16) + M68K_FP0_REGNUM;
497 return M68K_PC_REGNUM;
499 return NUM_REGS + NUM_PSEUDO_REGS;
503 struct m68k_frame_cache
510 /* Saved registers. */
511 CORE_ADDR saved_regs[M68K_NUM_REGS];
514 /* Stack space reserved for local variables. */
518 /* Allocate and initialize a frame cache. */
520 static struct m68k_frame_cache *
521 m68k_alloc_frame_cache (void)
523 struct m68k_frame_cache *cache;
526 cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
530 cache->sp_offset = -4;
533 /* Saved registers. We initialize these to -1 since zero is a valid
534 offset (that's where %fp is supposed to be stored). */
535 for (i = 0; i < M68K_NUM_REGS; i++)
536 cache->saved_regs[i] = -1;
538 /* Frameless until proven otherwise. */
544 /* Check whether PC points at a code that sets up a new stack frame.
545 If so, it updates CACHE and returns the address of the first
546 instruction after the sequence that sets removes the "hidden"
547 argument from the stack or CURRENT_PC, whichever is smaller.
548 Otherwise, return PC. */
551 m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc,
552 struct m68k_frame_cache *cache)
556 if (pc >= current_pc)
559 op = read_memory_unsigned_integer (pc, 2);
561 if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
563 cache->saved_regs[M68K_FP_REGNUM] = 0;
564 cache->sp_offset += 4;
565 if (op == P_LINKW_FP)
567 /* link.w %fp, #-N */
568 /* link.w %fp, #0; adda.l #-N, %sp */
569 cache->locals = -read_memory_integer (pc + 2, 2);
571 if (pc + 4 < current_pc && cache->locals == 0)
573 op = read_memory_unsigned_integer (pc + 4, 2);
574 if (op == P_ADDAL_SP)
576 cache->locals = read_memory_integer (pc + 6, 4);
583 else if (op == P_LINKL_FP)
585 /* link.l %fp, #-N */
586 cache->locals = -read_memory_integer (pc + 2, 4);
591 /* pea (%fp); movea.l %sp, %fp */
594 if (pc + 2 < current_pc)
596 op = read_memory_unsigned_integer (pc + 2, 2);
598 if (op == P_MOVEAL_SP_FP)
600 /* move.l %sp, %fp */
608 else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
610 /* subq.[wl] #N,%sp */
611 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
612 cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
613 if (pc + 2 < current_pc)
615 op = read_memory_unsigned_integer (pc + 2, 2);
616 if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
618 cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
624 else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
627 /* lea (-N,%sp),%sp */
628 cache->locals = -read_memory_integer (pc + 2, 2);
631 else if (op == P_ADDAL_SP)
634 cache->locals = -read_memory_integer (pc + 2, 4);
641 /* Check whether PC points at code that saves registers on the stack.
642 If so, it updates CACHE and returns the address of the first
643 instruction after the register saves or CURRENT_PC, whichever is
644 smaller. Otherwise, return PC. */
647 m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
648 struct m68k_frame_cache *cache)
650 if (cache->locals >= 0)
656 offset = -4 - cache->locals;
657 while (pc < current_pc)
659 op = read_memory_unsigned_integer (pc, 2);
660 if (op == P_FMOVEMX_SP)
662 /* fmovem.x REGS,-(%sp) */
663 op = read_memory_unsigned_integer (pc + 2, 2);
664 if ((op & 0xff00) == 0xe000)
667 for (i = 0; i < 16; i++, mask >>= 1)
671 cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
680 else if ((op & 0177760) == P_MOVEL_SP)
682 /* move.l %R,-(%sp) */
684 cache->saved_regs[regno] = offset;
688 else if (op == P_MOVEML_SP)
690 /* movem.l REGS,-(%sp) */
691 mask = read_memory_unsigned_integer (pc + 2, 2);
692 for (i = 0; i < 16; i++, mask >>= 1)
696 cache->saved_regs[15 - i] = offset;
711 /* Do a full analysis of the prologue at PC and update CACHE
712 accordingly. Bail out early if CURRENT_PC is reached. Return the
713 address where the analysis stopped.
715 We handle all cases that can be generated by gcc.
717 For allocating a stack frame:
721 pea (%fp); move.l %sp,%fp
722 link.w %a6,#0; add.l #-N,%sp
725 subq.w #8,%sp; subq.w #N-8,%sp
730 For saving registers:
734 move.l R1,-(%sp); move.l R2,-(%sp)
737 For setting up the PIC register:
744 m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
745 struct m68k_frame_cache *cache)
749 pc = m68k_analyze_frame_setup (pc, current_pc, cache);
750 pc = m68k_analyze_register_saves (pc, current_pc, cache);
751 if (pc >= current_pc)
754 /* Check for GOT setup. */
755 op = read_memory_unsigned_integer (pc, 4);
756 if (op == P_LEA_PC_A5)
758 /* lea (%pc,N),%a5 */
765 /* Return PC of first real instruction. */
768 m68k_skip_prologue (CORE_ADDR start_pc)
770 struct m68k_frame_cache cache;
775 pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache);
776 if (cache.locals < 0)
782 m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
786 frame_unwind_register (next_frame, PC_REGNUM, buf);
787 return extract_typed_address (buf, builtin_type_void_func_ptr);
792 static struct m68k_frame_cache *
793 m68k_frame_cache (struct frame_info *next_frame, void **this_cache)
795 struct m68k_frame_cache *cache;
802 cache = m68k_alloc_frame_cache ();
805 /* In principle, for normal frames, %fp holds the frame pointer,
806 which holds the base address for the current stack frame.
807 However, for functions that don't need it, the frame pointer is
808 optional. For these "frameless" functions the frame pointer is
809 actually the frame pointer of the calling frame. Signal
810 trampolines are just a special case of a "frameless" function.
811 They (usually) share their frame pointer with the frame that was
812 in progress when the signal occurred. */
814 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
815 cache->base = extract_unsigned_integer (buf, 4);
816 if (cache->base == 0)
819 /* For normal frames, %pc is stored at 4(%fp). */
820 cache->saved_regs[M68K_PC_REGNUM] = 4;
822 cache->pc = frame_func_unwind (next_frame);
824 m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache);
826 if (cache->locals < 0)
828 /* We didn't find a valid frame, which means that CACHE->base
829 currently holds the frame pointer for our calling frame. If
830 we're at the start of a function, or somewhere half-way its
831 prologue, the function's frame probably hasn't been fully
832 setup yet. Try to reconstruct the base address for the stack
833 frame by looking at the stack pointer. For truly "frameless"
834 functions this might work too. */
836 frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
837 cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset;
840 /* Now that we have the base address for the stack frame we can
841 calculate the value of %sp in the calling frame. */
842 cache->saved_sp = cache->base + 8;
844 /* Adjust all the saved registers such that they contain addresses
845 instead of offsets. */
846 for (i = 0; i < M68K_NUM_REGS; i++)
847 if (cache->saved_regs[i] != -1)
848 cache->saved_regs[i] += cache->base;
854 m68k_frame_this_id (struct frame_info *next_frame, void **this_cache,
855 struct frame_id *this_id)
857 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
859 /* This marks the outermost frame. */
860 if (cache->base == 0)
863 /* See the end of m68k_push_dummy_call. */
864 *this_id = frame_id_build (cache->base + 8, cache->pc);
868 m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache,
869 int regnum, int *optimizedp,
870 enum lval_type *lvalp, CORE_ADDR *addrp,
871 int *realnump, gdb_byte *valuep)
873 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
875 gdb_assert (regnum >= 0);
877 if (regnum == M68K_SP_REGNUM && cache->saved_sp)
885 /* Store the value. */
886 store_unsigned_integer (valuep, 4, cache->saved_sp);
891 if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
894 *lvalp = lval_memory;
895 *addrp = cache->saved_regs[regnum];
899 /* Read the value in from memory. */
900 read_memory (*addrp, valuep,
901 register_size (current_gdbarch, regnum));
907 *lvalp = lval_register;
911 frame_unwind_register (next_frame, (*realnump), valuep);
914 static const struct frame_unwind m68k_frame_unwind =
918 m68k_frame_prev_register
921 static const struct frame_unwind *
922 m68k_frame_sniffer (struct frame_info *next_frame)
924 return &m68k_frame_unwind;
928 m68k_frame_base_address (struct frame_info *next_frame, void **this_cache)
930 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
935 static const struct frame_base m68k_frame_base =
938 m68k_frame_base_address,
939 m68k_frame_base_address,
940 m68k_frame_base_address
943 static struct frame_id
944 m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
949 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
950 fp = extract_unsigned_integer (buf, 4);
952 /* See the end of m68k_push_dummy_call. */
953 return frame_id_build (fp + 8, frame_pc_unwind (next_frame));
956 #ifdef USE_PROC_FS /* Target dependent support for /proc */
958 #include <sys/procfs.h>
960 /* Prototypes for supply_gregset etc. */
963 /* The /proc interface divides the target machine's register set up into
964 two different sets, the general register set (gregset) and the floating
965 point register set (fpregset). For each set, there is an ioctl to get
966 the current register set and another ioctl to set the current values.
968 The actual structure passed through the ioctl interface is, of course,
969 naturally machine dependent, and is different for each set of registers.
970 For the m68k for example, the general register set is typically defined
973 typedef int gregset_t[18];
979 and the floating point set by:
981 typedef struct fpregset {
985 int f_fpregs[8][3]; (8 regs, 96 bits each)
988 These routines provide the packing and unpacking of gregset_t and
989 fpregset_t formatted data.
993 /* Atari SVR4 has R_SR but not R_PS */
995 #if !defined (R_PS) && defined (R_SR)
999 /* Given a pointer to a general register set in /proc format (gregset_t *),
1000 unpack the register contents and supply them as gdb's idea of the current
1004 supply_gregset (gregset_t *gregsetp)
1007 greg_t *regp = (greg_t *) gregsetp;
1009 for (regi = 0; regi < R_PC; regi++)
1011 regcache_raw_supply (current_regcache, regi, (char *) (regp + regi));
1013 regcache_raw_supply (current_regcache, PS_REGNUM, (char *) (regp + R_PS));
1014 regcache_raw_supply (current_regcache, PC_REGNUM, (char *) (regp + R_PC));
1018 fill_gregset (gregset_t *gregsetp, int regno)
1021 greg_t *regp = (greg_t *) gregsetp;
1023 for (regi = 0; regi < R_PC; regi++)
1025 if (regno == -1 || regno == regi)
1026 regcache_raw_collect (current_regcache, regi, regp + regi);
1028 if (regno == -1 || regno == PS_REGNUM)
1029 regcache_raw_collect (current_regcache, PS_REGNUM, regp + R_PS);
1030 if (regno == -1 || regno == PC_REGNUM)
1031 regcache_raw_collect (current_regcache, PC_REGNUM, regp + R_PC);
1034 #if defined (FP0_REGNUM)
1036 /* Given a pointer to a floating point register set in /proc format
1037 (fpregset_t *), unpack the register contents and supply them as gdb's
1038 idea of the current floating point register values. */
1041 supply_fpregset (fpregset_t *fpregsetp)
1046 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
1048 from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
1049 regcache_raw_supply (current_regcache, regi, from);
1051 regcache_raw_supply (current_regcache, M68K_FPC_REGNUM,
1052 (char *) &(fpregsetp->f_pcr));
1053 regcache_raw_supply (current_regcache, M68K_FPS_REGNUM,
1054 (char *) &(fpregsetp->f_psr));
1055 regcache_raw_supply (current_regcache, M68K_FPI_REGNUM,
1056 (char *) &(fpregsetp->f_fpiaddr));
1059 /* Given a pointer to a floating point register set in /proc format
1060 (fpregset_t *), update the register specified by REGNO from gdb's idea
1061 of the current floating point register set. If REGNO is -1, update
1065 fill_fpregset (fpregset_t *fpregsetp, int regno)
1069 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
1071 if (regno == -1 || regno == regi)
1072 regcache_raw_collect (current_regcache, regi,
1073 &fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
1075 if (regno == -1 || regno == M68K_FPC_REGNUM)
1076 regcache_raw_collect (current_regcache, M68K_FPC_REGNUM,
1078 if (regno == -1 || regno == M68K_FPS_REGNUM)
1079 regcache_raw_collect (current_regcache, M68K_FPS_REGNUM,
1081 if (regno == -1 || regno == M68K_FPI_REGNUM)
1082 regcache_raw_collect (current_regcache, M68K_FPI_REGNUM,
1083 &fpregsetp->f_fpiaddr);
1086 #endif /* defined (FP0_REGNUM) */
1088 #endif /* USE_PROC_FS */
1090 /* Figure out where the longjmp will land. Slurp the args out of the stack.
1091 We expect the first arg to be a pointer to the jmp_buf structure from which
1092 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
1093 This routine returns true on success. */
1096 m68k_get_longjmp_target (CORE_ADDR *pc)
1099 CORE_ADDR sp, jb_addr;
1100 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1102 if (tdep->jb_pc < 0)
1104 internal_error (__FILE__, __LINE__,
1105 _("m68k_get_longjmp_target: not implemented"));
1109 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
1110 sp = read_register (SP_REGNUM);
1112 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
1113 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
1116 jb_addr = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1118 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
1119 TARGET_PTR_BIT / TARGET_CHAR_BIT))
1122 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1127 /* System V Release 4 (SVR4). */
1130 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1132 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1134 /* SVR4 uses a different calling convention. */
1135 set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
1137 /* SVR4 uses %a0 instead of %a1. */
1138 tdep->struct_value_regnum = M68K_A0_REGNUM;
1142 /* Function: m68k_gdbarch_init
1143 Initializer function for the m68k gdbarch vector.
1144 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1146 static struct gdbarch *
1147 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1149 struct gdbarch_tdep *tdep = NULL;
1150 struct gdbarch *gdbarch;
1152 /* find a candidate among the list of pre-declared architectures. */
1153 arches = gdbarch_list_lookup_by_info (arches, &info);
1155 return (arches->gdbarch);
1157 tdep = xmalloc (sizeof (struct gdbarch_tdep));
1158 gdbarch = gdbarch_alloc (&info, tdep);
1160 set_gdbarch_long_double_format (gdbarch, floatformats_m68881_ext);
1161 set_gdbarch_long_double_bit (gdbarch, 96);
1163 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
1164 set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
1166 /* Stack grows down. */
1167 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1168 set_gdbarch_frame_align (gdbarch, m68k_frame_align);
1170 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1171 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1173 set_gdbarch_frame_args_skip (gdbarch, 8);
1174 set_gdbarch_dwarf_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
1175 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
1177 set_gdbarch_register_type (gdbarch, m68k_register_type);
1178 set_gdbarch_register_name (gdbarch, m68k_register_name);
1179 set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
1180 set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
1181 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
1182 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1183 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1184 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
1185 set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
1186 set_gdbarch_register_to_value (gdbarch, m68k_register_to_value);
1187 set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
1189 set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
1190 set_gdbarch_return_value (gdbarch, m68k_return_value);
1193 set_gdbarch_print_insn (gdbarch, print_insn_m68k);
1195 #if defined JB_PC && defined JB_ELEMENT_SIZE
1196 tdep->jb_pc = JB_PC;
1197 tdep->jb_elt_size = JB_ELEMENT_SIZE;
1201 tdep->struct_value_regnum = M68K_A1_REGNUM;
1202 tdep->struct_return = reg_struct_return;
1204 /* Frame unwinder. */
1205 set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id);
1206 set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
1208 /* Hook in the DWARF CFI frame unwinder. */
1209 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
1211 frame_base_set_default (gdbarch, &m68k_frame_base);
1213 /* Hook in ABI-specific overrides, if they have been registered. */
1214 gdbarch_init_osabi (info, gdbarch);
1216 /* Now we have tuned the configuration, set a few final things,
1217 based on what the OS ABI has told us. */
1219 if (tdep->jb_pc >= 0)
1220 set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
1222 frame_unwind_append_sniffer (gdbarch, m68k_frame_sniffer);
1229 m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1231 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1237 extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */
1240 _initialize_m68k_tdep (void)
1242 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);