1 /* Target-dependent code for the Motorola 68000 series.
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000,
4 2001, 2002, 2003, 2004, 2005 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. */
24 #include "dwarf2-frame.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
28 #include "floatformat.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 unsigned char *
69 m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
71 static unsigned char 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"
126 regnum >= sizeof (register_names) / sizeof (register_names[0]))
127 internal_error (__FILE__, __LINE__,
128 "m68k_register_name: illegal register number %d", regnum);
130 return register_names[regnum];
133 /* Return nonzero if a value of type TYPE stored in register REGNUM
134 needs any special handling. */
137 m68k_convert_register_p (int regnum, struct type *type)
139 return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7);
142 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
143 return its contents in TO. */
146 m68k_register_to_value (struct frame_info *frame, int regnum,
147 struct type *type, void *to)
149 char from[M68K_MAX_REGISTER_SIZE];
151 /* We only support floating-point values. */
152 if (TYPE_CODE (type) != TYPE_CODE_FLT)
154 warning ("Cannot convert floating-point register value "
155 "to non-floating-point type.");
159 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
160 the extended floating-point format used by the FPU. */
161 get_frame_register (frame, regnum, from);
162 convert_typed_floating (from, builtin_type_m68881_ext, to, type);
165 /* Write the contents FROM of a value of type TYPE into register
166 REGNUM in frame FRAME. */
169 m68k_value_to_register (struct frame_info *frame, int regnum,
170 struct type *type, const void *from)
172 char to[M68K_MAX_REGISTER_SIZE];
174 /* We only support floating-point values. */
175 if (TYPE_CODE (type) != TYPE_CODE_FLT)
177 warning ("Cannot convert non-floating-point type "
178 "to floating-point register value.");
182 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
183 to the extended floating-point format used by the FPU. */
184 convert_typed_floating (from, type, to, builtin_type_m68881_ext);
185 put_frame_register (frame, regnum, to);
189 /* There is a fair number of calling conventions that are in somewhat
190 wide use. The 68000/08/10 don't support an FPU, not even as a
191 coprocessor. All function return values are stored in %d0/%d1.
192 Structures are returned in a static buffer, a pointer to which is
193 returned in %d0. This means that functions returning a structure
194 are not re-entrant. To avoid this problem some systems use a
195 convention where the caller passes a pointer to a buffer in %a1
196 where the return values is to be stored. This convention is the
197 default, and is implemented in the function m68k_return_value.
199 The 68020/030/040/060 do support an FPU, either as a coprocessor
200 (68881/2) or built-in (68040/68060). That's why System V release 4
201 (SVR4) instroduces a new calling convention specified by the SVR4
202 psABI. Integer values are returned in %d0/%d1, pointer return
203 values in %a0 and floating values in %fp0. When calling functions
204 returning a structure the caller should pass a pointer to a buffer
205 for the return value in %a0. This convention is implemented in the
206 function m68k_svr4_return_value, and by appropriately setting the
207 struct_value_regnum member of `struct gdbarch_tdep'.
209 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
210 for passing the structure return value buffer.
212 GCC can also generate code where small structures are returned in
213 %d0/%d1 instead of in memory by using -freg-struct-return. This is
214 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
215 embedded systems. This convention is implemented by setting the
216 struct_return member of `struct gdbarch_tdep' to reg_struct_return. */
218 /* Read a function return value of TYPE from REGCACHE, and copy that
222 m68k_extract_return_value (struct type *type, struct regcache *regcache,
225 int len = TYPE_LENGTH (type);
226 char buf[M68K_MAX_REGISTER_SIZE];
230 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
231 memcpy (valbuf, buf + (4 - len), len);
235 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
236 memcpy (valbuf, buf + (8 - len), len - 4);
237 regcache_raw_read (regcache, M68K_D1_REGNUM,
238 (char *) valbuf + (len - 4));
241 internal_error (__FILE__, __LINE__,
242 "Cannot extract return value of %d bytes long.", len);
246 m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
249 int len = TYPE_LENGTH (type);
250 char buf[M68K_MAX_REGISTER_SIZE];
252 if (TYPE_CODE (type) == TYPE_CODE_FLT)
254 regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
255 convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type);
257 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
258 regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
260 m68k_extract_return_value (type, regcache, valbuf);
263 /* Write a function return value of TYPE from VALBUF into REGCACHE. */
266 m68k_store_return_value (struct type *type, struct regcache *regcache,
269 int len = TYPE_LENGTH (type);
272 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf);
275 regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len,
277 regcache_raw_write (regcache, M68K_D1_REGNUM,
278 (char *) valbuf + (len - 4));
281 internal_error (__FILE__, __LINE__,
282 "Cannot store return value of %d bytes long.", len);
286 m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
289 int len = TYPE_LENGTH (type);
291 if (TYPE_CODE (type) == TYPE_CODE_FLT)
293 char buf[M68K_MAX_REGISTER_SIZE];
294 convert_typed_floating (valbuf, type, buf, builtin_type_m68881_ext);
295 regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
297 else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4)
299 regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
300 regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf);
303 m68k_store_return_value (type, regcache, valbuf);
306 /* Return non-zero if TYPE, which is assumed to be a structure or
307 union type, should be returned in registers for architecture
311 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
313 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
314 enum type_code code = TYPE_CODE (type);
315 int len = TYPE_LENGTH (type);
317 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION);
319 if (tdep->struct_return == pcc_struct_return)
322 return (len == 1 || len == 2 || len == 4 || len == 8);
325 /* Determine, for architecture GDBARCH, how a return value of TYPE
326 should be returned. If it is supposed to be returned in registers,
327 and READBUF is non-zero, read the appropriate value from REGCACHE,
328 and copy it into READBUF. If WRITEBUF is non-zero, write the value
329 from WRITEBUF into REGCACHE. */
331 static enum return_value_convention
332 m68k_return_value (struct gdbarch *gdbarch, struct type *type,
333 struct regcache *regcache, void *readbuf,
334 const void *writebuf)
336 enum type_code code = TYPE_CODE (type);
338 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
339 && !m68k_reg_struct_return_p (gdbarch, type))
340 return RETURN_VALUE_STRUCT_CONVENTION;
342 /* GCC returns a `long double' in memory. */
343 if (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12)
344 return RETURN_VALUE_STRUCT_CONVENTION;
347 m68k_extract_return_value (type, regcache, readbuf);
349 m68k_store_return_value (type, regcache, writebuf);
351 return RETURN_VALUE_REGISTER_CONVENTION;
354 static enum return_value_convention
355 m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *type,
356 struct regcache *regcache, void *readbuf,
357 const void *writebuf)
359 enum type_code code = TYPE_CODE (type);
361 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
362 && !m68k_reg_struct_return_p (gdbarch, type))
364 /* The System V ABI says that:
366 "A function returning a structure or union also sets %a0 to
367 the value it finds in %a0. Thus when the caller receives
368 control again, the address of the returned object resides in
371 So the ABI guarantees that we can always find the return
372 value just after the function has returned. */
378 regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr);
379 read_memory (addr, readbuf, TYPE_LENGTH (type));
382 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
385 /* This special case is for structures consisting of a single
386 `float' or `double' member. These structures are returned in
387 %fp0. For these structures, we call ourselves recursively,
388 changing TYPE into the type of the first member of the structure.
389 Since that should work for all structures that have only one
390 member, we don't bother to check the member's type here. */
391 if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
393 type = check_typedef (TYPE_FIELD_TYPE (type, 0));
394 return m68k_svr4_return_value (gdbarch, type, regcache,
399 m68k_svr4_extract_return_value (type, regcache, readbuf);
401 m68k_svr4_store_return_value (type, regcache, writebuf);
403 return RETURN_VALUE_REGISTER_CONVENTION;
408 m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
409 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
410 struct value **args, CORE_ADDR sp, int struct_return,
411 CORE_ADDR struct_addr)
413 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
417 /* Push arguments in reverse order. */
418 for (i = nargs - 1; i >= 0; i--)
420 struct type *value_type = value_enclosing_type (args[i]);
421 int len = TYPE_LENGTH (value_type);
422 int container_len = (len + 3) & ~3;
425 /* Non-scalars bigger than 4 bytes are left aligned, others are
427 if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
428 || TYPE_CODE (value_type) == TYPE_CODE_UNION
429 || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
433 offset = container_len - len;
435 write_memory (sp + offset, value_contents_all (args[i]), len);
438 /* Store struct value address. */
441 store_unsigned_integer (buf, 4, struct_addr);
442 regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
445 /* Store return address. */
447 store_unsigned_integer (buf, 4, bp_addr);
448 write_memory (sp, buf, 4);
450 /* Finally, update the stack pointer... */
451 store_unsigned_integer (buf, 4, sp);
452 regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);
454 /* ...and fake a frame pointer. */
455 regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);
457 /* DWARF2/GCC uses the stack address *before* the function call as a
462 struct m68k_frame_cache
469 /* Saved registers. */
470 CORE_ADDR saved_regs[M68K_NUM_REGS];
473 /* Stack space reserved for local variables. */
477 /* Allocate and initialize a frame cache. */
479 static struct m68k_frame_cache *
480 m68k_alloc_frame_cache (void)
482 struct m68k_frame_cache *cache;
485 cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
489 cache->sp_offset = -4;
492 /* Saved registers. We initialize these to -1 since zero is a valid
493 offset (that's where %fp is supposed to be stored). */
494 for (i = 0; i < M68K_NUM_REGS; i++)
495 cache->saved_regs[i] = -1;
497 /* Frameless until proven otherwise. */
503 /* Check whether PC points at a code that sets up a new stack frame.
504 If so, it updates CACHE and returns the address of the first
505 instruction after the sequence that sets removes the "hidden"
506 argument from the stack or CURRENT_PC, whichever is smaller.
507 Otherwise, return PC. */
510 m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc,
511 struct m68k_frame_cache *cache)
515 if (pc >= current_pc)
518 op = read_memory_unsigned_integer (pc, 2);
520 if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
522 cache->saved_regs[M68K_FP_REGNUM] = 0;
523 cache->sp_offset += 4;
524 if (op == P_LINKW_FP)
526 /* link.w %fp, #-N */
527 /* link.w %fp, #0; adda.l #-N, %sp */
528 cache->locals = -read_memory_integer (pc + 2, 2);
530 if (pc + 4 < current_pc && cache->locals == 0)
532 op = read_memory_unsigned_integer (pc + 4, 2);
533 if (op == P_ADDAL_SP)
535 cache->locals = read_memory_integer (pc + 6, 4);
542 else if (op == P_LINKL_FP)
544 /* link.l %fp, #-N */
545 cache->locals = -read_memory_integer (pc + 2, 4);
550 /* pea (%fp); movea.l %sp, %fp */
553 if (pc + 2 < current_pc)
555 op = read_memory_unsigned_integer (pc + 2, 2);
557 if (op == P_MOVEAL_SP_FP)
559 /* move.l %sp, %fp */
567 else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
569 /* subq.[wl] #N,%sp */
570 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
571 cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
572 if (pc + 2 < current_pc)
574 op = read_memory_unsigned_integer (pc + 2, 2);
575 if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
577 cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
583 else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
586 /* lea (-N,%sp),%sp */
587 cache->locals = -read_memory_integer (pc + 2, 2);
590 else if (op == P_ADDAL_SP)
593 cache->locals = -read_memory_integer (pc + 2, 4);
600 /* Check whether PC points at code that saves registers on the stack.
601 If so, it updates CACHE and returns the address of the first
602 instruction after the register saves or CURRENT_PC, whichever is
603 smaller. Otherwise, return PC. */
606 m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
607 struct m68k_frame_cache *cache)
609 if (cache->locals >= 0)
615 offset = -4 - cache->locals;
616 while (pc < current_pc)
618 op = read_memory_unsigned_integer (pc, 2);
619 if (op == P_FMOVEMX_SP)
621 /* fmovem.x REGS,-(%sp) */
622 op = read_memory_unsigned_integer (pc + 2, 2);
623 if ((op & 0xff00) == 0xe000)
626 for (i = 0; i < 16; i++, mask >>= 1)
630 cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
639 else if ((op & 0170677) == P_MOVEL_SP)
641 /* move.l %R,-(%sp) */
642 regno = ((op & 07000) >> 9) | ((op & 0100) >> 3);
643 cache->saved_regs[regno] = offset;
647 else if (op == P_MOVEML_SP)
649 /* movem.l REGS,-(%sp) */
650 mask = read_memory_unsigned_integer (pc + 2, 2);
651 for (i = 0; i < 16; i++, mask >>= 1)
655 cache->saved_regs[15 - i] = offset;
670 /* Do a full analysis of the prologue at PC and update CACHE
671 accordingly. Bail out early if CURRENT_PC is reached. Return the
672 address where the analysis stopped.
674 We handle all cases that can be generated by gcc.
676 For allocating a stack frame:
680 pea (%fp); move.l %sp,%fp
681 link.w %a6,#0; add.l #-N,%sp
684 subq.w #8,%sp; subq.w #N-8,%sp
689 For saving registers:
693 move.l R1,-(%sp); move.l R2,-(%sp)
696 For setting up the PIC register:
703 m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
704 struct m68k_frame_cache *cache)
708 pc = m68k_analyze_frame_setup (pc, current_pc, cache);
709 pc = m68k_analyze_register_saves (pc, current_pc, cache);
710 if (pc >= current_pc)
713 /* Check for GOT setup. */
714 op = read_memory_unsigned_integer (pc, 4);
715 if (op == P_LEA_PC_A5)
717 /* lea (%pc,N),%a5 */
724 /* Return PC of first real instruction. */
727 m68k_skip_prologue (CORE_ADDR start_pc)
729 struct m68k_frame_cache cache;
734 pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache);
735 if (cache.locals < 0)
741 m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
745 frame_unwind_register (next_frame, PC_REGNUM, buf);
746 return extract_typed_address (buf, builtin_type_void_func_ptr);
751 static struct m68k_frame_cache *
752 m68k_frame_cache (struct frame_info *next_frame, void **this_cache)
754 struct m68k_frame_cache *cache;
761 cache = m68k_alloc_frame_cache ();
764 /* In principle, for normal frames, %fp holds the frame pointer,
765 which holds the base address for the current stack frame.
766 However, for functions that don't need it, the frame pointer is
767 optional. For these "frameless" functions the frame pointer is
768 actually the frame pointer of the calling frame. Signal
769 trampolines are just a special case of a "frameless" function.
770 They (usually) share their frame pointer with the frame that was
771 in progress when the signal occurred. */
773 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
774 cache->base = extract_unsigned_integer (buf, 4);
775 if (cache->base == 0)
778 /* For normal frames, %pc is stored at 4(%fp). */
779 cache->saved_regs[M68K_PC_REGNUM] = 4;
781 cache->pc = frame_func_unwind (next_frame);
783 m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache);
785 if (cache->locals < 0)
787 /* We didn't find a valid frame, which means that CACHE->base
788 currently holds the frame pointer for our calling frame. If
789 we're at the start of a function, or somewhere half-way its
790 prologue, the function's frame probably hasn't been fully
791 setup yet. Try to reconstruct the base address for the stack
792 frame by looking at the stack pointer. For truly "frameless"
793 functions this might work too. */
795 frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
796 cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset;
799 /* Now that we have the base address for the stack frame we can
800 calculate the value of %sp in the calling frame. */
801 cache->saved_sp = cache->base + 8;
803 /* Adjust all the saved registers such that they contain addresses
804 instead of offsets. */
805 for (i = 0; i < M68K_NUM_REGS; i++)
806 if (cache->saved_regs[i] != -1)
807 cache->saved_regs[i] += cache->base;
813 m68k_frame_this_id (struct frame_info *next_frame, void **this_cache,
814 struct frame_id *this_id)
816 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
818 /* This marks the outermost frame. */
819 if (cache->base == 0)
822 /* See the end of m68k_push_dummy_call. */
823 *this_id = frame_id_build (cache->base + 8, cache->pc);
827 m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache,
828 int regnum, int *optimizedp,
829 enum lval_type *lvalp, CORE_ADDR *addrp,
830 int *realnump, void *valuep)
832 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
834 gdb_assert (regnum >= 0);
836 if (regnum == M68K_SP_REGNUM && cache->saved_sp)
844 /* Store the value. */
845 store_unsigned_integer (valuep, 4, cache->saved_sp);
850 if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
853 *lvalp = lval_memory;
854 *addrp = cache->saved_regs[regnum];
858 /* Read the value in from memory. */
859 read_memory (*addrp, valuep,
860 register_size (current_gdbarch, regnum));
866 *lvalp = lval_register;
870 frame_unwind_register (next_frame, (*realnump), valuep);
873 static const struct frame_unwind m68k_frame_unwind =
877 m68k_frame_prev_register
880 static const struct frame_unwind *
881 m68k_frame_sniffer (struct frame_info *next_frame)
883 return &m68k_frame_unwind;
887 m68k_frame_base_address (struct frame_info *next_frame, void **this_cache)
889 struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache);
894 static const struct frame_base m68k_frame_base =
897 m68k_frame_base_address,
898 m68k_frame_base_address,
899 m68k_frame_base_address
902 static struct frame_id
903 m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
908 frame_unwind_register (next_frame, M68K_FP_REGNUM, buf);
909 fp = extract_unsigned_integer (buf, 4);
911 /* See the end of m68k_push_dummy_call. */
912 return frame_id_build (fp + 8, frame_pc_unwind (next_frame));
915 #ifdef USE_PROC_FS /* Target dependent support for /proc */
917 #include <sys/procfs.h>
919 /* Prototypes for supply_gregset etc. */
922 /* The /proc interface divides the target machine's register set up into
923 two different sets, the general register set (gregset) and the floating
924 point register set (fpregset). For each set, there is an ioctl to get
925 the current register set and another ioctl to set the current values.
927 The actual structure passed through the ioctl interface is, of course,
928 naturally machine dependent, and is different for each set of registers.
929 For the m68k for example, the general register set is typically defined
932 typedef int gregset_t[18];
938 and the floating point set by:
940 typedef struct fpregset {
944 int f_fpregs[8][3]; (8 regs, 96 bits each)
947 These routines provide the packing and unpacking of gregset_t and
948 fpregset_t formatted data.
952 /* Atari SVR4 has R_SR but not R_PS */
954 #if !defined (R_PS) && defined (R_SR)
958 /* Given a pointer to a general register set in /proc format (gregset_t *),
959 unpack the register contents and supply them as gdb's idea of the current
963 supply_gregset (gregset_t *gregsetp)
966 greg_t *regp = (greg_t *) gregsetp;
968 for (regi = 0; regi < R_PC; regi++)
970 regcache_raw_supply (current_regcache, regi, (char *) (regp + regi));
972 regcache_raw_supply (current_regcache, PS_REGNUM, (char *) (regp + R_PS));
973 regcache_raw_supply (current_regcache, PC_REGNUM, (char *) (regp + R_PC));
977 fill_gregset (gregset_t *gregsetp, int regno)
980 greg_t *regp = (greg_t *) gregsetp;
982 for (regi = 0; regi < R_PC; regi++)
984 if (regno == -1 || regno == regi)
985 regcache_raw_collect (current_regcache, regi, regp + regi);
987 if (regno == -1 || regno == PS_REGNUM)
988 regcache_raw_collect (current_regcache, PS_REGNUM, regp + R_PS);
989 if (regno == -1 || regno == PC_REGNUM)
990 regcache_raw_collect (current_regcache, PC_REGNUM, regp + R_PC);
993 #if defined (FP0_REGNUM)
995 /* Given a pointer to a floating point register set in /proc format
996 (fpregset_t *), unpack the register contents and supply them as gdb's
997 idea of the current floating point register values. */
1000 supply_fpregset (fpregset_t *fpregsetp)
1005 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
1007 from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
1008 regcache_raw_supply (current_regcache, regi, from);
1010 regcache_raw_supply (current_regcache, M68K_FPC_REGNUM,
1011 (char *) &(fpregsetp->f_pcr));
1012 regcache_raw_supply (current_regcache, M68K_FPS_REGNUM,
1013 (char *) &(fpregsetp->f_psr));
1014 regcache_raw_supply (current_regcache, M68K_FPI_REGNUM,
1015 (char *) &(fpregsetp->f_fpiaddr));
1018 /* Given a pointer to a floating point register set in /proc format
1019 (fpregset_t *), update the register specified by REGNO from gdb's idea
1020 of the current floating point register set. If REGNO is -1, update
1024 fill_fpregset (fpregset_t *fpregsetp, int regno)
1028 for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++)
1030 if (regno == -1 || regno == regi)
1031 regcache_raw_collect (current_regcache, regi,
1032 &fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
1034 if (regno == -1 || regno == M68K_FPC_REGNUM)
1035 regcache_raw_collect (current_regcache, M68K_FPC_REGNUM,
1037 if (regno == -1 || regno == M68K_FPS_REGNUM)
1038 regcache_raw_collect (current_regcache, M68K_FPS_REGNUM,
1040 if (regno == -1 || regno == M68K_FPI_REGNUM)
1041 regcache_raw_collect (current_regcache, M68K_FPI_REGNUM,
1042 &fpregsetp->f_fpiaddr);
1045 #endif /* defined (FP0_REGNUM) */
1047 #endif /* USE_PROC_FS */
1049 /* Figure out where the longjmp will land. Slurp the args out of the stack.
1050 We expect the first arg to be a pointer to the jmp_buf structure from which
1051 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
1052 This routine returns true on success. */
1055 m68k_get_longjmp_target (CORE_ADDR *pc)
1058 CORE_ADDR sp, jb_addr;
1059 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1061 if (tdep->jb_pc < 0)
1063 internal_error (__FILE__, __LINE__,
1064 "m68k_get_longjmp_target: not implemented");
1068 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
1069 sp = read_register (SP_REGNUM);
1071 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
1072 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
1075 jb_addr = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1077 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
1078 TARGET_PTR_BIT / TARGET_CHAR_BIT))
1081 *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1086 /* System V Release 4 (SVR4). */
1089 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1091 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1093 /* SVR4 uses a different calling convention. */
1094 set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
1096 /* SVR4 uses %a0 instead of %a1. */
1097 tdep->struct_value_regnum = M68K_A0_REGNUM;
1101 /* Function: m68k_gdbarch_init
1102 Initializer function for the m68k gdbarch vector.
1103 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1105 static struct gdbarch *
1106 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1108 struct gdbarch_tdep *tdep = NULL;
1109 struct gdbarch *gdbarch;
1111 /* find a candidate among the list of pre-declared architectures. */
1112 arches = gdbarch_list_lookup_by_info (arches, &info);
1114 return (arches->gdbarch);
1116 tdep = xmalloc (sizeof (struct gdbarch_tdep));
1117 gdbarch = gdbarch_alloc (&info, tdep);
1119 set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
1120 set_gdbarch_long_double_bit (gdbarch, 96);
1122 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
1123 set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
1125 /* Stack grows down. */
1126 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1128 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1129 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1131 set_gdbarch_frame_args_skip (gdbarch, 8);
1133 set_gdbarch_register_type (gdbarch, m68k_register_type);
1134 set_gdbarch_register_name (gdbarch, m68k_register_name);
1135 set_gdbarch_num_regs (gdbarch, 29);
1136 set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
1137 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
1138 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1139 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1140 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
1141 set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
1142 set_gdbarch_register_to_value (gdbarch, m68k_register_to_value);
1143 set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
1145 set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
1146 set_gdbarch_return_value (gdbarch, m68k_return_value);
1149 set_gdbarch_print_insn (gdbarch, print_insn_m68k);
1151 #if defined JB_PC && defined JB_ELEMENT_SIZE
1152 tdep->jb_pc = JB_PC;
1153 tdep->jb_elt_size = JB_ELEMENT_SIZE;
1157 tdep->struct_value_regnum = M68K_A1_REGNUM;
1158 tdep->struct_return = reg_struct_return;
1160 /* Frame unwinder. */
1161 set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id);
1162 set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
1164 /* Hook in the DWARF CFI frame unwinder. */
1165 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
1167 frame_base_set_default (gdbarch, &m68k_frame_base);
1169 /* Hook in ABI-specific overrides, if they have been registered. */
1170 gdbarch_init_osabi (info, gdbarch);
1172 /* Now we have tuned the configuration, set a few final things,
1173 based on what the OS ABI has told us. */
1175 if (tdep->jb_pc >= 0)
1176 set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
1178 frame_unwind_append_sniffer (gdbarch, m68k_frame_sniffer);
1185 m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1187 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
1193 extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */
1196 _initialize_m68k_tdep (void)
1198 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);