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. */
28 #include "gdb_string.h"
31 #include "arch-utils.h"
34 #include "m68k-tdep.h"
37 #define P_LINKL_FP 0x480e
38 #define P_LINKW_FP 0x4e56
39 #define P_PEA_FP 0x4856
40 #define P_MOVL_SP_FP 0x2c4f
45 #define P_MOVML 0x48ef
46 #define P_FMOVM 0xf237
50 #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
51 #define REGISTER_BYTES_NOFP (16*4 + 8)
53 #define NUM_FREGS (NUM_REGS-24)
55 /* Offset from SP to first arg on stack at first instruction of a function */
57 #define SP_ARG0 (1 * 4)
59 /* This was determined by experimentation on hp300 BSD 4.3. Perhaps
60 it corresponds to some offset in /usr/include/sys/user.h or
61 something like that. Using some system include file would
62 have the advantage of probably being more robust in the face
63 of OS upgrades, but the disadvantage of being wrong for
66 #define SIG_PC_FP_OFFSET 530
71 #if !defined (BPT_VECTOR)
72 #define BPT_VECTOR 0xf
75 #if !defined (REMOTE_BPT_VECTOR)
76 #define REMOTE_BPT_VECTOR 1
80 static void m68k_frame_init_saved_regs (struct frame_info
*frame_info
);
83 /* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
84 so m68k_remote_breakpoint_from_pc is currently not used. */
86 static const unsigned char *
87 m68k_remote_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
89 static unsigned char break_insn
[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR
)};
90 *lenptr
= sizeof (break_insn
);
94 static const unsigned char *
95 m68k_local_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
97 static unsigned char break_insn
[] = {0x4e, (0x40 | BPT_VECTOR
)};
98 *lenptr
= sizeof (break_insn
);
104 m68k_register_bytes_ok (long numbytes
)
106 return ((numbytes
== REGISTER_BYTES_FP
)
107 || (numbytes
== REGISTER_BYTES_NOFP
));
110 /* Number of bytes of storage in the actual machine representation
111 for register regnum. On the 68000, all regs are 4 bytes
112 except the floating point regs which are 12 bytes. */
115 m68k_register_raw_size (int regnum
)
117 return (regnum
>= FP0_REGNUM
&& regnum
< FP0_REGNUM
+ 8 ? 12 : 4);
120 /* Number of bytes of storage in the program's representation
121 for register regnum. On the 68000, all regs are 4 bytes
122 except the floating point regs which are 12-byte long doubles. */
125 m68k_register_virtual_size (int regnum
)
127 return (regnum
>= FP0_REGNUM
&& regnum
< FP0_REGNUM
+ 8 ? 12 : 4);
130 /* Return the GDB type object for the "standard" data type of data in
131 register N. This should be int for D0-D7, SR, FPCONTROL and
132 FPSTATUS, long double for FP0-FP7, and void pointer for all others
133 (A0-A7, PC, FPIADDR). Note, for registers which contain
134 addresses return pointer to void, not pointer to char, because we
135 don't want to attempt to print the string after printing the
139 m68k_register_virtual_type (int regnum
)
141 if (regnum
>= FP0_REGNUM
&& regnum
<= FP0_REGNUM
+ 7)
142 return builtin_type_m68881_ext
;
144 if (regnum
== M68K_FPI_REGNUM
|| regnum
== PC_REGNUM
)
145 return builtin_type_void_func_ptr
;
147 if (regnum
== M68K_FPC_REGNUM
|| regnum
== M68K_FPS_REGNUM
148 || regnum
== PS_REGNUM
)
149 return builtin_type_int32
;
151 if (regnum
>= M68K_A0_REGNUM
&& regnum
<= M68K_A0_REGNUM
+ 7)
152 return builtin_type_void_data_ptr
;
154 return builtin_type_int32
;
157 /* Function: m68k_register_name
158 Returns the name of the standard m68k register regnum. */
161 m68k_register_name (int regnum
)
163 static char *register_names
[] = {
164 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
165 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
167 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
168 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
172 regnum
>= sizeof (register_names
) / sizeof (register_names
[0]))
173 internal_error (__FILE__
, __LINE__
,
174 "m68k_register_name: illegal register number %d", regnum
);
176 return register_names
[regnum
];
179 /* Index within `registers' of the first byte of the space for
183 m68k_register_byte (int regnum
)
185 if (regnum
>= M68K_FPC_REGNUM
)
186 return (((regnum
- M68K_FPC_REGNUM
) * 4) + 168);
187 else if (regnum
>= FP0_REGNUM
)
188 return (((regnum
- FP0_REGNUM
) * 12) + 72);
193 /* Store the address of the place in which to copy the structure the
194 subroutine will return. This is called from call_function. */
197 m68k_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
199 write_register (M68K_A1_REGNUM
, addr
);
202 /* Extract from an array regbuf containing the (raw) register state
203 a function return value of type type, and copy that, in virtual format,
204 into valbuf. This is assuming that floating point values are returned
205 as doubles in d0/d1. */
208 m68k_deprecated_extract_return_value (struct type
*type
, char *regbuf
,
212 int typeLength
= TYPE_LENGTH (type
);
215 offset
= 4 - typeLength
;
217 memcpy (valbuf
, regbuf
+ offset
, typeLength
);
221 m68k_deprecated_extract_struct_value_address (char *regbuf
)
223 return (*(CORE_ADDR
*) (regbuf
));
226 /* Write into appropriate registers a function return value
227 of type TYPE, given in virtual format. Assumes floats are passed
231 m68k_store_return_value (struct type
*type
, char *valbuf
)
233 deprecated_write_register_bytes (0, valbuf
, TYPE_LENGTH (type
));
236 /* Describe the pointer in each stack frame to the previous stack frame
239 /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and produces
240 the frame's chain-pointer. In the case of the 68000, the frame's
241 nominal address is the address of a 4-byte word containing the
242 calling frame's address. */
244 /* If we are chaining from sigtramp, then manufacture a sigtramp frame
245 (which isn't really on the stack. I'm not sure this is right for anything
246 but BSD4.3 on an hp300. */
249 m68k_frame_chain (struct frame_info
*thisframe
)
251 if (get_frame_type (thisframe
) == SIGTRAMP_FRAME
)
252 return get_frame_base (thisframe
);
253 else if (!inside_entry_file (get_frame_pc (thisframe
)))
254 return read_memory_unsigned_integer (get_frame_base (thisframe
), 4);
259 /* A function that tells us whether the function invocation represented
260 by fi does not have a frame on the stack associated with it. If it
261 does not, FRAMELESS is set to 1, else 0. */
264 m68k_frameless_function_invocation (struct frame_info
*fi
)
266 if (get_frame_type (fi
) == SIGTRAMP_FRAME
)
269 return frameless_look_for_prologue (fi
);
273 m68k_frame_saved_pc (struct frame_info
*frame
)
275 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
277 if (get_next_frame (frame
))
278 return read_memory_unsigned_integer (get_frame_base (get_next_frame (frame
))
279 + SIG_PC_FP_OFFSET
, 4);
281 return read_memory_unsigned_integer (read_register (SP_REGNUM
)
282 + SIG_PC_FP_OFFSET
- 8, 4);
285 return read_memory_unsigned_integer (get_frame_base (frame
) + 4, 4);
290 delta68_in_sigtramp (CORE_ADDR pc
, char *name
)
293 return strcmp (name
, "_sigcode") == 0;
299 delta68_frame_args_address (struct frame_info
*frame_info
)
301 /* we assume here that the only frameless functions are the system calls
302 or other functions who do not put anything on the stack. */
303 if (get_frame_type (frame_info
) == SIGTRAMP_FRAME
)
304 return get_frame_base (frame_info
) + 12;
305 else if (frameless_look_for_prologue (frame_info
))
307 /* Check for an interrupted system call */
308 if (get_next_frame (frame_info
) && (get_frame_type (get_next_frame (frame_info
)) == SIGTRAMP_FRAME
))
309 return get_frame_base (get_next_frame (frame_info
)) + 16;
311 return get_frame_base (frame_info
) + 4;
314 return get_frame_base (frame_info
);
318 delta68_frame_saved_pc (struct frame_info
*frame_info
)
320 return read_memory_unsigned_integer (delta68_frame_args_address (frame_info
)
325 delta68_frame_num_args (struct frame_info
*fi
)
328 CORE_ADDR pc
= DEPRECATED_FRAME_SAVED_PC (fi
);
329 int insn
= read_memory_unsigned_integer (pc
, 2);
331 if (insn
== 0047757 || insn
== 0157374) /* lea W(sp),sp or addaw #W,sp */
332 val
= read_memory_integer (pc
+ 2, 2);
333 else if ((insn
& 0170777) == 0050217 /* addql #N, sp */
334 || (insn
& 0170777) == 0050117) /* addqw */
336 val
= (insn
>> 9) & 7;
340 else if (insn
== 0157774) /* addal #WW, sp */
341 val
= read_memory_integer (pc
+ 2, 4);
346 /* Insert the specified number of args and function address
347 into a call sequence of the above form stored at DUMMYNAME.
348 We use the BFD routines to store a big-endian value of known size. */
351 m68k_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
352 struct value
**args
, struct type
*type
, int gcc_p
)
354 bfd_putb32 (fun
, (unsigned char *) dummy
+ DEPRECATED_CALL_DUMMY_START_OFFSET
+ 2);
355 bfd_putb32 (nargs
* 4,
356 (unsigned char *) dummy
+ DEPRECATED_CALL_DUMMY_START_OFFSET
+ 8);
360 /* Push an empty stack frame, to record the current PC, etc. */
363 m68k_push_dummy_frame (void)
365 register CORE_ADDR sp
= read_register (SP_REGNUM
);
369 sp
= push_word (sp
, read_register (PC_REGNUM
));
370 sp
= push_word (sp
, read_register (DEPRECATED_FP_REGNUM
));
371 write_register (DEPRECATED_FP_REGNUM
, sp
);
373 /* Always save the floating-point registers, whether they exist on
374 this target or not. */
375 for (regnum
= FP0_REGNUM
+ 7; regnum
>= FP0_REGNUM
; regnum
--)
377 deprecated_read_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, 12);
378 sp
= push_bytes (sp
, raw_buffer
, 12);
381 for (regnum
= DEPRECATED_FP_REGNUM
- 1; regnum
>= 0; regnum
--)
383 sp
= push_word (sp
, read_register (regnum
));
385 sp
= push_word (sp
, read_register (PS_REGNUM
));
386 write_register (SP_REGNUM
, sp
);
389 /* Discard from the stack the innermost frame,
390 restoring all saved registers. */
393 m68k_pop_frame (void)
395 register struct frame_info
*frame
= get_current_frame ();
396 register CORE_ADDR fp
;
400 fp
= get_frame_base (frame
);
401 m68k_frame_init_saved_regs (frame
);
402 for (regnum
= FP0_REGNUM
+ 7; regnum
>= FP0_REGNUM
; regnum
--)
404 if (get_frame_saved_regs (frame
)[regnum
])
406 read_memory (get_frame_saved_regs (frame
)[regnum
], raw_buffer
, 12);
407 deprecated_write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
,
411 for (regnum
= DEPRECATED_FP_REGNUM
- 1; regnum
>= 0; regnum
--)
413 if (get_frame_saved_regs (frame
)[regnum
])
415 write_register (regnum
,
416 read_memory_integer (get_frame_saved_regs (frame
)[regnum
], 4));
419 if (get_frame_saved_regs (frame
)[PS_REGNUM
])
421 write_register (PS_REGNUM
,
422 read_memory_integer (get_frame_saved_regs (frame
)[PS_REGNUM
], 4));
424 write_register (DEPRECATED_FP_REGNUM
, read_memory_integer (fp
, 4));
425 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
426 write_register (SP_REGNUM
, fp
+ 8);
427 flush_cached_frames ();
431 /* Given an ip value corresponding to the start of a function,
432 return the ip of the first instruction after the function
433 prologue. This is the generic m68k support. Machines which
434 require something different can override the SKIP_PROLOGUE
435 macro to point elsewhere.
437 Some instructions which typically may appear in a function
440 A link instruction, word form:
442 link.w %a6,&0 4e56 XXXX
444 A link instruction, long form:
446 link.l %fp,&F%1 480e XXXX XXXX
448 A movm instruction to preserve integer regs:
450 movm.l &M%1,(4,%sp) 48ef XXXX XXXX
452 A fmovm instruction to preserve float regs:
454 fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
456 Some profiling setup code (FIXME, not recognized yet):
458 lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
459 bsr _mcount 61ff XXXX XXXX
464 m68k_skip_prologue (CORE_ADDR ip
)
466 register CORE_ADDR limit
;
467 struct symtab_and_line sal
;
470 /* Find out if there is a known limit for the extent of the prologue.
471 If so, ensure we don't go past it. If not, assume "infinity". */
473 sal
= find_pc_line (ip
, 0);
474 limit
= (sal
.end
) ? sal
.end
: (CORE_ADDR
) ~0;
478 op
= read_memory_unsigned_integer (ip
, 2);
480 if (op
== P_LINKW_FP
)
481 ip
+= 4; /* Skip link.w */
482 else if (op
== P_PEA_FP
)
483 ip
+= 2; /* Skip pea %fp */
484 else if (op
== P_MOVL_SP_FP
)
485 ip
+= 2; /* Skip move.l %sp, %fp */
486 else if (op
== P_LINKL_FP
)
487 ip
+= 6; /* Skip link.l */
488 else if (op
== P_MOVML
)
489 ip
+= 6; /* Skip movm.l */
490 else if (op
== P_FMOVM
)
491 ip
+= 10; /* Skip fmovm */
493 break; /* Found unknown code, bail out. */
498 /* Store the addresses of the saved registers of the frame described by
499 FRAME_INFO in its saved_regs field.
500 This includes special registers such as pc and fp saved in special
501 ways in the stack frame. sp is even more special:
502 the address we return for it IS the sp for the next frame. */
505 m68k_frame_init_saved_regs (struct frame_info
*frame_info
)
508 register int regmask
;
509 register CORE_ADDR next_addr
;
510 register CORE_ADDR pc
;
512 /* First possible address for a pc in a call dummy for this frame. */
513 CORE_ADDR possible_call_dummy_start
=
514 get_frame_base (frame_info
) - 28 - DEPRECATED_FP_REGNUM
* 4 - 4 - 8 * 12;
518 if (get_frame_saved_regs (frame_info
))
521 frame_saved_regs_zalloc (frame_info
);
523 memset (get_frame_saved_regs (frame_info
), 0, SIZEOF_FRAME_SAVED_REGS
);
525 if (get_frame_pc (frame_info
) >= possible_call_dummy_start
526 && get_frame_pc (frame_info
) <= get_frame_base (frame_info
))
529 /* It is a call dummy. We could just stop now, since we know
530 what the call dummy saves and where. But this code proceeds
531 to parse the "prologue" which is part of the call dummy.
532 This is needlessly complex and confusing. FIXME. */
534 next_addr
= get_frame_base (frame_info
);
535 pc
= possible_call_dummy_start
;
539 pc
= get_frame_func (frame_info
);
541 nextinsn
= read_memory_unsigned_integer (pc
, 2);
542 if (P_PEA_FP
== nextinsn
543 && P_MOVL_SP_FP
== read_memory_unsigned_integer (pc
+ 2, 2))
547 next_addr
= get_frame_base (frame_info
);
550 else if (P_LINKL_FP
== nextinsn
)
552 /* Find the address above the saved
553 regs using the amount of storage from the link instruction. */
555 next_addr
= get_frame_base (frame_info
) + read_memory_integer (pc
+ 2, 4);
558 else if (P_LINKW_FP
== nextinsn
)
560 /* Find the address above the saved
561 regs using the amount of storage from the link instruction. */
563 next_addr
= get_frame_base (frame_info
) + read_memory_integer (pc
+ 2, 2);
569 /* If have an addal #-n, sp next, adjust next_addr. */
570 if (read_memory_unsigned_integer (pc
, 2) == 0157774)
571 next_addr
+= read_memory_integer (pc
+= 2, 4), pc
+= 4;
576 nextinsn
= read_memory_unsigned_integer (pc
, 2);
577 regmask
= read_memory_unsigned_integer (pc
+ 2, 2);
578 /* fmovemx to -(sp) */
579 if (0xf227 == nextinsn
&& (regmask
& 0xff00) == 0xe000)
581 /* Regmask's low bit is for register fp7, the first pushed */
582 for (regnum
= FP0_REGNUM
+ 8; --regnum
>= FP0_REGNUM
; regmask
>>= 1)
584 get_frame_saved_regs (frame_info
)[regnum
] = (next_addr
-= 12);
587 /* fmovemx to (fp + displacement) */
588 else if (0171056 == nextinsn
&& (regmask
& 0xff00) == 0xf000)
590 register CORE_ADDR addr
;
592 addr
= get_frame_base (frame_info
) + read_memory_integer (pc
+ 4, 2);
593 /* Regmask's low bit is for register fp7, the first pushed */
594 for (regnum
= FP0_REGNUM
+ 8; --regnum
>= FP0_REGNUM
; regmask
>>= 1)
597 get_frame_saved_regs (frame_info
)[regnum
] = addr
;
603 else if (0044327 == nextinsn
)
605 /* Regmask's low bit is for register 0, the first written */
606 for (regnum
= 0; regnum
< 16; regnum
++, regmask
>>= 1)
609 get_frame_saved_regs (frame_info
)[regnum
] = next_addr
;
614 /* moveml to (fp + displacement) */
615 else if (0044356 == nextinsn
)
617 register CORE_ADDR addr
;
619 addr
= get_frame_base (frame_info
) + read_memory_integer (pc
+ 4, 2);
620 /* Regmask's low bit is for register 0, the first written */
621 for (regnum
= 0; regnum
< 16; regnum
++, regmask
>>= 1)
624 get_frame_saved_regs (frame_info
)[regnum
] = addr
;
629 /* moveml to -(sp) */
630 else if (0044347 == nextinsn
)
632 /* Regmask's low bit is for register 15, the first pushed */
633 for (regnum
= 16; --regnum
>= 0; regmask
>>= 1)
635 get_frame_saved_regs (frame_info
)[regnum
] = (next_addr
-= 4);
639 else if (0x2f00 == (0xfff0 & nextinsn
))
641 regnum
= 0xf & nextinsn
;
642 get_frame_saved_regs (frame_info
)[regnum
] = (next_addr
-= 4);
645 /* fmovemx to index of sp */
646 else if (0xf236 == nextinsn
&& (regmask
& 0xff00) == 0xf000)
648 /* Regmask's low bit is for register fp0, the first written */
649 for (regnum
= FP0_REGNUM
+ 8; --regnum
>= FP0_REGNUM
; regmask
>>= 1)
652 get_frame_saved_regs (frame_info
)[regnum
] = next_addr
;
657 /* clrw -(sp); movw ccr,-(sp) */
658 else if (0x4267 == nextinsn
&& 0x42e7 == regmask
)
660 get_frame_saved_regs (frame_info
)[PS_REGNUM
] = (next_addr
-= 4);
667 get_frame_saved_regs (frame_info
)[SP_REGNUM
] = get_frame_base (frame_info
) + 8;
668 get_frame_saved_regs (frame_info
)[DEPRECATED_FP_REGNUM
] = get_frame_base (frame_info
);
669 get_frame_saved_regs (frame_info
)[PC_REGNUM
] = get_frame_base (frame_info
) + 4;
670 #ifdef SIG_SP_FP_OFFSET
671 /* Adjust saved SP_REGNUM for fake _sigtramp frames. */
672 if ((get_frame_type (frame_info
) == SIGTRAMP_FRAME
) && frame_info
->next
)
673 frame_info
->saved_regs
[SP_REGNUM
] =
674 frame_info
->next
->frame
+ SIG_SP_FP_OFFSET
;
679 #ifdef USE_PROC_FS /* Target dependent support for /proc */
681 #include <sys/procfs.h>
683 /* Prototypes for supply_gregset etc. */
686 /* The /proc interface divides the target machine's register set up into
687 two different sets, the general register set (gregset) and the floating
688 point register set (fpregset). For each set, there is an ioctl to get
689 the current register set and another ioctl to set the current values.
691 The actual structure passed through the ioctl interface is, of course,
692 naturally machine dependent, and is different for each set of registers.
693 For the m68k for example, the general register set is typically defined
696 typedef int gregset_t[18];
702 and the floating point set by:
704 typedef struct fpregset {
708 int f_fpregs[8][3]; (8 regs, 96 bits each)
711 These routines provide the packing and unpacking of gregset_t and
712 fpregset_t formatted data.
716 /* Atari SVR4 has R_SR but not R_PS */
718 #if !defined (R_PS) && defined (R_SR)
722 /* Given a pointer to a general register set in /proc format (gregset_t *),
723 unpack the register contents and supply them as gdb's idea of the current
727 supply_gregset (gregset_t
*gregsetp
)
730 register greg_t
*regp
= (greg_t
*) gregsetp
;
732 for (regi
= 0; regi
< R_PC
; regi
++)
734 supply_register (regi
, (char *) (regp
+ regi
));
736 supply_register (PS_REGNUM
, (char *) (regp
+ R_PS
));
737 supply_register (PC_REGNUM
, (char *) (regp
+ R_PC
));
741 fill_gregset (gregset_t
*gregsetp
, int regno
)
744 register greg_t
*regp
= (greg_t
*) gregsetp
;
746 for (regi
= 0; regi
< R_PC
; regi
++)
748 if ((regno
== -1) || (regno
== regi
))
750 *(regp
+ regi
) = *(int *) &deprecated_registers
[REGISTER_BYTE (regi
)];
753 if ((regno
== -1) || (regno
== PS_REGNUM
))
755 *(regp
+ R_PS
) = *(int *) &deprecated_registers
[REGISTER_BYTE (PS_REGNUM
)];
757 if ((regno
== -1) || (regno
== PC_REGNUM
))
759 *(regp
+ R_PC
) = *(int *) &deprecated_registers
[REGISTER_BYTE (PC_REGNUM
)];
763 #if defined (FP0_REGNUM)
765 /* Given a pointer to a floating point register set in /proc format
766 (fpregset_t *), unpack the register contents and supply them as gdb's
767 idea of the current floating point register values. */
770 supply_fpregset (fpregset_t
*fpregsetp
)
775 for (regi
= FP0_REGNUM
; regi
< M68K_FPC_REGNUM
; regi
++)
777 from
= (char *) &(fpregsetp
->f_fpregs
[regi
- FP0_REGNUM
][0]);
778 supply_register (regi
, from
);
780 supply_register (M68K_FPC_REGNUM
, (char *) &(fpregsetp
->f_pcr
));
781 supply_register (M68K_FPS_REGNUM
, (char *) &(fpregsetp
->f_psr
));
782 supply_register (M68K_FPI_REGNUM
, (char *) &(fpregsetp
->f_fpiaddr
));
785 /* Given a pointer to a floating point register set in /proc format
786 (fpregset_t *), update the register specified by REGNO from gdb's idea
787 of the current floating point register set. If REGNO is -1, update
791 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
797 for (regi
= FP0_REGNUM
; regi
< M68K_FPC_REGNUM
; regi
++)
799 if ((regno
== -1) || (regno
== regi
))
801 from
= (char *) &deprecated_registers
[REGISTER_BYTE (regi
)];
802 to
= (char *) &(fpregsetp
->f_fpregs
[regi
- FP0_REGNUM
][0]);
803 memcpy (to
, from
, REGISTER_RAW_SIZE (regi
));
806 if ((regno
== -1) || (regno
== M68K_FPC_REGNUM
))
808 fpregsetp
->f_pcr
= *(int *) &deprecated_registers
[REGISTER_BYTE (M68K_FPC_REGNUM
)];
810 if ((regno
== -1) || (regno
== M68K_FPS_REGNUM
))
812 fpregsetp
->f_psr
= *(int *) &deprecated_registers
[REGISTER_BYTE (M68K_FPS_REGNUM
)];
814 if ((regno
== -1) || (regno
== M68K_FPI_REGNUM
))
816 fpregsetp
->f_fpiaddr
= *(int *) &deprecated_registers
[REGISTER_BYTE (M68K_FPI_REGNUM
)];
820 #endif /* defined (FP0_REGNUM) */
822 #endif /* USE_PROC_FS */
824 /* Figure out where the longjmp will land. Slurp the args out of the stack.
825 We expect the first arg to be a pointer to the jmp_buf structure from which
826 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
827 This routine returns true on success. */
830 m68k_get_longjmp_target (CORE_ADDR
*pc
)
833 CORE_ADDR sp
, jb_addr
;
834 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
838 internal_error (__FILE__
, __LINE__
,
839 "m68k_get_longjmp_target: not implemented");
843 buf
= alloca (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
844 sp
= read_register (SP_REGNUM
);
846 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack */
847 buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
850 jb_addr
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
852 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
853 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
856 *pc
= extract_unsigned_integer (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
860 /* Immediately after a function call, return the saved pc before the frame
861 is setup. For sun3's, we check for the common case of being inside of a
862 system call, and if so, we know that Sun pushes the call # on the stack
863 prior to doing the trap. */
866 m68k_saved_pc_after_call (struct frame_info
*frame
)
871 op
= read_memory_unsigned_integer (frame
->pc
- SYSCALL_TRAP_OFFSET
, 2);
873 if (op
== SYSCALL_TRAP
)
874 return read_memory_unsigned_integer (read_register (SP_REGNUM
) + 4, 4);
876 #endif /* SYSCALL_TRAP */
877 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
880 /* Function: m68k_gdbarch_init
881 Initializer function for the m68k gdbarch vector.
882 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
884 static struct gdbarch
*
885 m68k_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
887 static LONGEST call_dummy_words
[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
888 0x4eb93232, 0x3232dffc, 0x69696969,
889 (0x4e404e71 | (BPT_VECTOR
<< 16))
891 struct gdbarch_tdep
*tdep
= NULL
;
892 struct gdbarch
*gdbarch
;
894 /* find a candidate among the list of pre-declared architectures. */
895 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
897 return (arches
->gdbarch
);
899 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
900 gdbarch
= gdbarch_alloc (&info
, tdep
);
902 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
903 ready to unwind the PC first (see frame.c:get_prev_frame()). */
904 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
906 set_gdbarch_long_double_format (gdbarch
, &floatformat_m68881_ext
);
907 set_gdbarch_long_double_bit (gdbarch
, 96);
909 set_gdbarch_function_start_offset (gdbarch
, 0);
911 set_gdbarch_skip_prologue (gdbarch
, m68k_skip_prologue
);
912 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, m68k_saved_pc_after_call
);
913 set_gdbarch_breakpoint_from_pc (gdbarch
, m68k_local_breakpoint_from_pc
);
915 /* Stack grows down. */
916 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
917 set_gdbarch_parm_boundary (gdbarch
, 32);
919 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
920 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
922 set_gdbarch_deprecated_store_struct_return (gdbarch
, m68k_store_struct_return
);
923 set_gdbarch_deprecated_extract_return_value (gdbarch
,
924 m68k_deprecated_extract_return_value
);
925 set_gdbarch_deprecated_store_return_value (gdbarch
, m68k_store_return_value
);
927 set_gdbarch_deprecated_frame_chain (gdbarch
, m68k_frame_chain
);
928 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, m68k_frame_saved_pc
);
929 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, m68k_frame_init_saved_regs
);
930 set_gdbarch_frameless_function_invocation (gdbarch
,
931 m68k_frameless_function_invocation
);
932 /* OK to default this value to 'unknown'. */
933 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
934 set_gdbarch_frame_args_skip (gdbarch
, 8);
936 set_gdbarch_register_raw_size (gdbarch
, m68k_register_raw_size
);
937 set_gdbarch_register_virtual_size (gdbarch
, m68k_register_virtual_size
);
938 set_gdbarch_deprecated_max_register_raw_size (gdbarch
, 12);
939 set_gdbarch_deprecated_max_register_virtual_size (gdbarch
, 12);
940 set_gdbarch_register_virtual_type (gdbarch
, m68k_register_virtual_type
);
941 set_gdbarch_register_name (gdbarch
, m68k_register_name
);
942 set_gdbarch_deprecated_register_size (gdbarch
, 4);
943 set_gdbarch_register_byte (gdbarch
, m68k_register_byte
);
944 set_gdbarch_num_regs (gdbarch
, 29);
945 set_gdbarch_register_bytes_ok (gdbarch
, m68k_register_bytes_ok
);
946 set_gdbarch_deprecated_register_bytes (gdbarch
, (16 * 4 + 8 + 8 * 12 + 3 * 4));
947 set_gdbarch_sp_regnum (gdbarch
, M68K_SP_REGNUM
);
948 set_gdbarch_deprecated_fp_regnum (gdbarch
, M68K_FP_REGNUM
);
949 set_gdbarch_pc_regnum (gdbarch
, M68K_PC_REGNUM
);
950 set_gdbarch_ps_regnum (gdbarch
, M68K_PS_REGNUM
);
951 set_gdbarch_fp0_regnum (gdbarch
, M68K_FP0_REGNUM
);
953 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch
, 0);
954 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
955 set_gdbarch_deprecated_call_dummy_breakpoint_offset (gdbarch
, 24);
956 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_on_stack
);
957 set_gdbarch_deprecated_call_dummy_length (gdbarch
, 28);
958 set_gdbarch_deprecated_call_dummy_start_offset (gdbarch
, 12);
960 set_gdbarch_deprecated_call_dummy_words (gdbarch
, call_dummy_words
);
961 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, sizeof (call_dummy_words
));
962 set_gdbarch_deprecated_fix_call_dummy (gdbarch
, m68k_fix_call_dummy
);
963 set_gdbarch_deprecated_push_dummy_frame (gdbarch
, m68k_push_dummy_frame
);
964 set_gdbarch_deprecated_pop_frame (gdbarch
, m68k_pop_frame
);
966 /* Should be using push_dummy_call. */
967 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
970 set_gdbarch_print_insn (gdbarch
, print_insn_m68k
);
972 #if defined JB_PC && defined JB_ELEMENT_SIZE
974 tdep
->jb_elt_size
= JB_ELEMENT_SIZE
;
979 /* Hook in ABI-specific overrides, if they have been registered. */
980 gdbarch_init_osabi (info
, gdbarch
);
982 /* Now we have tuned the configuration, set a few final things,
983 based on what the OS ABI has told us. */
985 if (tdep
->jb_pc
>= 0)
986 set_gdbarch_get_longjmp_target (gdbarch
, m68k_get_longjmp_target
);
993 m68k_dump_tdep (struct gdbarch
*current_gdbarch
, struct ui_file
*file
)
995 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
1002 _initialize_m68k_tdep (void)
1004 gdbarch_register (bfd_arch_m68k
, m68k_gdbarch_init
, m68k_dump_tdep
);