1 /* Target dependent code for the Motorola 68000 series.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
30 #include "arch-utils.h"
33 #define P_LINKL_FP 0x480e
34 #define P_LINKW_FP 0x4e56
35 #define P_PEA_FP 0x4856
36 #define P_MOVL_SP_FP 0x2c4f
41 #define P_MOVML 0x48ef
42 #define P_FMOVM 0xf237
46 /* Register numbers of various important registers.
47 Note that some of these values are "real" register numbers,
48 and correspond to the general registers of the machine,
49 and some are "phony" register numbers which are too large
50 to be actual register numbers as far as the user is concerned
51 but do serve to get the desired values when passed to read_register. */
53 /* Note: Since they are used in files other than this (monitor files),
54 D0_REGNUM and A0_REGNUM are currently defined in tm-m68k.h. */
59 E_FP_REGNUM = 14, /* Contains address of executing stack frame */
60 E_SP_REGNUM = 15, /* Contains address of top of stack */
61 E_PS_REGNUM = 16, /* Contains processor status */
62 E_PC_REGNUM = 17, /* Contains program counter */
63 E_FP0_REGNUM = 18, /* Floating point register 0 */
64 E_FPC_REGNUM = 26, /* 68881 control register */
65 E_FPS_REGNUM = 27, /* 68881 status register */
69 #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
70 #define REGISTER_BYTES_NOFP (16*4 + 8)
72 #define NUM_FREGS (NUM_REGS-24)
74 /* Offset from SP to first arg on stack at first instruction of a function */
76 #define SP_ARG0 (1 * 4)
78 /* This was determined by experimentation on hp300 BSD 4.3. Perhaps
79 it corresponds to some offset in /usr/include/sys/user.h or
80 something like that. Using some system include file would
81 have the advantage of probably being more robust in the face
82 of OS upgrades, but the disadvantage of being wrong for
85 #define SIG_PC_FP_OFFSET 530
90 #if !defined (BPT_VECTOR)
91 #define BPT_VECTOR 0xf
94 #if !defined (REMOTE_BPT_VECTOR)
95 #define REMOTE_BPT_VECTOR 1
99 void m68k_frame_init_saved_regs (struct frame_info *frame_info);
102 /* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
103 so m68k_remote_breakpoint_from_pc is currently not used. */
105 const static unsigned char *
106 m68k_remote_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
108 static unsigned char break_insn[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR)};
109 *lenptr = sizeof (break_insn);
113 const static unsigned char *
114 m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
116 static unsigned char break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
117 *lenptr = sizeof (break_insn);
123 m68k_register_bytes_ok (long numbytes)
125 return ((numbytes == REGISTER_BYTES_FP)
126 || (numbytes == REGISTER_BYTES_NOFP));
129 /* Number of bytes of storage in the actual machine representation
130 for register regnum. On the 68000, all regs are 4 bytes
131 except the floating point regs which are 12 bytes. */
132 /* Note that the unsigned cast here forces the result of the
133 subtraction to very high positive values if regnum < FP0_REGNUM */
136 m68k_register_raw_size (int regnum)
138 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
141 /* Number of bytes of storage in the program's representation
142 for register regnum. On the 68000, all regs are 4 bytes
143 except the floating point regs which are 12-byte long doubles. */
146 m68k_register_virtual_size (int regnum)
148 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
151 /* Return the GDB type object for the "standard" data type of data
152 in register N. This should be int for D0-D7, long double for FP0-FP7,
153 and void pointer for all others (A0-A7, PC, SR, FPCONTROL etc).
154 Note, for registers which contain addresses return pointer to void,
155 not pointer to char, because we don't want to attempt to print
156 the string after printing the address. */
159 m68k_register_virtual_type (int regnum)
161 if ((unsigned) regnum >= E_FPC_REGNUM)
162 return lookup_pointer_type (builtin_type_void);
163 else if ((unsigned) regnum >= FP0_REGNUM)
164 return builtin_type_long_double;
165 else if ((unsigned) regnum >= A0_REGNUM)
166 return lookup_pointer_type (builtin_type_void);
168 return builtin_type_int;
171 /* Function: m68k_register_name
172 Returns the name of the standard m68k register regnum. */
175 m68k_register_name (int regnum)
177 static char *register_names[] = {
178 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
179 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
181 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
182 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
186 regnum >= sizeof (register_names) / sizeof (register_names[0]))
187 internal_error (__FILE__, __LINE__,
188 "m68k_register_name: illegal register number %d", regnum);
190 return register_names[regnum];
193 /* Stack must be kept short aligned when doing function calls. */
196 m68k_stack_align (CORE_ADDR addr)
198 return ((addr + 1) & ~1);
201 /* Index within `registers' of the first byte of the space for
205 m68k_register_byte (int regnum)
207 if (regnum >= E_FPC_REGNUM)
208 return (((regnum - E_FPC_REGNUM) * 4) + 168);
209 else if (regnum >= FP0_REGNUM)
210 return (((regnum - FP0_REGNUM) * 12) + 72);
215 /* Store the address of the place in which to copy the structure the
216 subroutine will return. This is called from call_function. */
219 m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
221 write_register (E_A1_REGNUM, addr);
224 /* Extract from an array regbuf containing the (raw) register state
225 a function return value of type type, and copy that, in virtual format,
226 into valbuf. This is assuming that floating point values are returned
227 as doubles in d0/d1. */
230 m68k_deprecated_extract_return_value (struct type *type, char *regbuf,
234 int typeLength = TYPE_LENGTH (type);
237 offset = 4 - typeLength;
239 memcpy (valbuf, regbuf + offset, typeLength);
243 m68k_deprecated_extract_struct_value_address (char *regbuf)
245 return (*(CORE_ADDR *) (regbuf));
248 /* Write into appropriate registers a function return value
249 of type TYPE, given in virtual format. Assumes floats are passed
253 m68k_store_return_value (struct type *type, char *valbuf)
255 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
258 /* Describe the pointer in each stack frame to the previous stack frame
261 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
263 In the case of the 68000, the frame's nominal address
264 is the address of a 4-byte word containing the calling frame's address. */
266 /* If we are chaining from sigtramp, then manufacture a sigtramp frame
267 (which isn't really on the stack. I'm not sure this is right for anything
268 but BSD4.3 on an hp300. */
271 m68k_frame_chain (struct frame_info *thisframe)
273 if (thisframe->signal_handler_caller)
274 return thisframe->frame;
275 else if (!inside_entry_file ((thisframe)->pc))
276 return read_memory_integer ((thisframe)->frame, 4);
281 /* A function that tells us whether the function invocation represented
282 by fi does not have a frame on the stack associated with it. If it
283 does not, FRAMELESS is set to 1, else 0. */
286 m68k_frameless_function_invocation (struct frame_info *fi)
288 if (fi->signal_handler_caller)
291 return frameless_look_for_prologue (fi);
295 m68k_frame_saved_pc (struct frame_info *frame)
297 if (frame->signal_handler_caller)
300 return read_memory_integer (frame->next->frame + SIG_PC_FP_OFFSET, 4);
302 return read_memory_integer (read_register (SP_REGNUM)
303 + SIG_PC_FP_OFFSET - 8, 4);
306 return read_memory_integer (frame->frame + 4, 4);
310 /* The only reason this is here is the tm-altos.h reference below. It
311 was moved back here from tm-m68k.h. FIXME? */
314 altos_skip_prologue (CORE_ADDR pc)
316 register int op = read_memory_integer (pc, 2);
317 if (op == P_LINKW_FP)
318 pc += 4; /* Skip link #word */
319 else if (op == P_LINKL_FP)
320 pc += 6; /* Skip link #long */
321 /* Not sure why branches are here. */
322 /* From tm-altos.h */
323 else if (op == 0060000)
324 pc += 4; /* Skip bra #word */
325 else if (op == 00600377)
326 pc += 6; /* skip bra #long */
327 else if ((op & 0177400) == 0060000)
328 pc += 2; /* skip bra #char */
333 delta68_in_sigtramp (CORE_ADDR pc, char *name)
336 return strcmp (name, "_sigcode") == 0;
342 delta68_frame_args_address (struct frame_info *frame_info)
344 /* we assume here that the only frameless functions are the system calls
345 or other functions who do not put anything on the stack. */
346 if (frame_info->signal_handler_caller)
347 return frame_info->frame + 12;
348 else if (frameless_look_for_prologue (frame_info))
350 /* Check for an interrupted system call */
351 if (frame_info->next && frame_info->next->signal_handler_caller)
352 return frame_info->next->frame + 16;
354 return frame_info->frame + 4;
357 return frame_info->frame;
361 delta68_frame_saved_pc (struct frame_info *frame_info)
363 return read_memory_integer (delta68_frame_args_address (frame_info) + 4, 4);
366 /* Return number of args passed to a frame.
367 Can return -1, meaning no way to tell. */
370 isi_frame_num_args (struct frame_info *fi)
373 CORE_ADDR pc = FRAME_SAVED_PC (fi);
374 int insn = 0177777 & read_memory_integer (pc, 2);
376 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
377 val = read_memory_integer (pc + 2, 2);
378 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
379 || (insn & 0170777) == 0050117) /* addqw */
381 val = (insn >> 9) & 7;
385 else if (insn == 0157774) /* addal #WW, sp */
386 val = read_memory_integer (pc + 2, 4);
392 delta68_frame_num_args (struct frame_info *fi)
395 CORE_ADDR pc = FRAME_SAVED_PC (fi);
396 int insn = 0177777 & read_memory_integer (pc, 2);
398 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
399 val = read_memory_integer (pc + 2, 2);
400 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
401 || (insn & 0170777) == 0050117) /* addqw */
403 val = (insn >> 9) & 7;
407 else if (insn == 0157774) /* addal #WW, sp */
408 val = read_memory_integer (pc + 2, 4);
414 news_frame_num_args (struct frame_info *fi)
417 CORE_ADDR pc = FRAME_SAVED_PC (fi);
418 int insn = 0177777 & read_memory_integer (pc, 2);
420 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
421 val = read_memory_integer (pc + 2, 2);
422 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
423 || (insn & 0170777) == 0050117) /* addqw */
425 val = (insn >> 9) & 7;
429 else if (insn == 0157774) /* addal #WW, sp */
430 val = read_memory_integer (pc + 2, 4);
435 /* Insert the specified number of args and function address
436 into a call sequence of the above form stored at DUMMYNAME.
437 We use the BFD routines to store a big-endian value of known size. */
440 m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
441 struct value **args, struct type *type, int gcc_p)
443 bfd_putb32 (fun, (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 2);
444 bfd_putb32 (nargs * 4,
445 (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 8);
449 /* Push an empty stack frame, to record the current PC, etc. */
452 m68k_push_dummy_frame (void)
454 register CORE_ADDR sp = read_register (SP_REGNUM);
458 sp = push_word (sp, read_register (PC_REGNUM));
459 sp = push_word (sp, read_register (FP_REGNUM));
460 write_register (FP_REGNUM, sp);
462 /* Always save the floating-point registers, whether they exist on
463 this target or not. */
464 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
466 deprecated_read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
467 sp = push_bytes (sp, raw_buffer, 12);
470 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
472 sp = push_word (sp, read_register (regnum));
474 sp = push_word (sp, read_register (PS_REGNUM));
475 write_register (SP_REGNUM, sp);
478 /* Discard from the stack the innermost frame,
479 restoring all saved registers. */
482 m68k_pop_frame (void)
484 register struct frame_info *frame = get_current_frame ();
485 register CORE_ADDR fp;
489 fp = FRAME_FP (frame);
490 m68k_frame_init_saved_regs (frame);
491 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
493 if (frame->saved_regs[regnum])
495 read_memory (frame->saved_regs[regnum], raw_buffer, 12);
496 deprecated_write_register_bytes (REGISTER_BYTE (regnum), raw_buffer,
500 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
502 if (frame->saved_regs[regnum])
504 write_register (regnum,
505 read_memory_integer (frame->saved_regs[regnum], 4));
508 if (frame->saved_regs[PS_REGNUM])
510 write_register (PS_REGNUM,
511 read_memory_integer (frame->saved_regs[PS_REGNUM], 4));
513 write_register (FP_REGNUM, read_memory_integer (fp, 4));
514 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
515 write_register (SP_REGNUM, fp + 8);
516 flush_cached_frames ();
520 /* Given an ip value corresponding to the start of a function,
521 return the ip of the first instruction after the function
522 prologue. This is the generic m68k support. Machines which
523 require something different can override the SKIP_PROLOGUE
524 macro to point elsewhere.
526 Some instructions which typically may appear in a function
529 A link instruction, word form:
531 link.w %a6,&0 4e56 XXXX
533 A link instruction, long form:
535 link.l %fp,&F%1 480e XXXX XXXX
537 A movm instruction to preserve integer regs:
539 movm.l &M%1,(4,%sp) 48ef XXXX XXXX
541 A fmovm instruction to preserve float regs:
543 fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
545 Some profiling setup code (FIXME, not recognized yet):
547 lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
548 bsr _mcount 61ff XXXX XXXX
553 m68k_skip_prologue (CORE_ADDR ip)
555 register CORE_ADDR limit;
556 struct symtab_and_line sal;
559 /* Find out if there is a known limit for the extent of the prologue.
560 If so, ensure we don't go past it. If not, assume "infinity". */
562 sal = find_pc_line (ip, 0);
563 limit = (sal.end) ? sal.end : (CORE_ADDR) ~0;
567 op = read_memory_integer (ip, 2);
570 if (op == P_LINKW_FP)
571 ip += 4; /* Skip link.w */
572 else if (op == P_PEA_FP)
573 ip += 2; /* Skip pea %fp */
574 else if (op == P_MOVL_SP_FP)
575 ip += 2; /* Skip move.l %sp, %fp */
576 else if (op == P_LINKL_FP)
577 ip += 6; /* Skip link.l */
578 else if (op == P_MOVML)
579 ip += 6; /* Skip movm.l */
580 else if (op == P_FMOVM)
581 ip += 10; /* Skip fmovm */
583 break; /* Found unknown code, bail out. */
588 /* Store the addresses of the saved registers of the frame described by
589 FRAME_INFO in its saved_regs field.
590 This includes special registers such as pc and fp saved in special
591 ways in the stack frame. sp is even more special:
592 the address we return for it IS the sp for the next frame. */
595 m68k_frame_init_saved_regs (struct frame_info *frame_info)
598 register int regmask;
599 register CORE_ADDR next_addr;
600 register CORE_ADDR pc;
602 /* First possible address for a pc in a call dummy for this frame. */
603 CORE_ADDR possible_call_dummy_start =
604 (frame_info)->frame - 28 - FP_REGNUM * 4 - 4 - 8 * 12;
608 if (frame_info->saved_regs)
611 frame_saved_regs_zalloc (frame_info);
613 memset (frame_info->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
615 if ((frame_info)->pc >= possible_call_dummy_start
616 && (frame_info)->pc <= (frame_info)->frame)
619 /* It is a call dummy. We could just stop now, since we know
620 what the call dummy saves and where. But this code proceeds
621 to parse the "prologue" which is part of the call dummy.
622 This is needlessly complex and confusing. FIXME. */
624 next_addr = (frame_info)->frame;
625 pc = possible_call_dummy_start;
629 pc = get_pc_function_start ((frame_info)->pc);
631 nextinsn = read_memory_integer (pc, 2);
632 if (P_PEA_FP == nextinsn
633 && P_MOVL_SP_FP == read_memory_integer (pc + 2, 2))
637 next_addr = frame_info->frame;
640 else if (P_LINKL_FP == nextinsn)
642 /* Find the address above the saved
643 regs using the amount of storage from the link instruction. */
645 next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 4);
648 else if (P_LINKW_FP == nextinsn)
650 /* Find the address above the saved
651 regs using the amount of storage from the link instruction. */
653 next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 2);
659 /* If have an addal #-n, sp next, adjust next_addr. */
660 if ((0177777 & read_memory_integer (pc, 2)) == 0157774)
661 next_addr += read_memory_integer (pc += 2, 4), pc += 4;
666 nextinsn = 0xffff & read_memory_integer (pc, 2);
667 regmask = read_memory_integer (pc + 2, 2);
668 /* fmovemx to -(sp) */
669 if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000)
671 /* Regmask's low bit is for register fp7, the first pushed */
672 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
674 frame_info->saved_regs[regnum] = (next_addr -= 12);
677 /* fmovemx to (fp + displacement) */
678 else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000)
680 register CORE_ADDR addr;
682 addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
683 /* Regmask's low bit is for register fp7, the first pushed */
684 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
687 frame_info->saved_regs[regnum] = addr;
693 else if (0044327 == nextinsn)
695 /* Regmask's low bit is for register 0, the first written */
696 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
699 frame_info->saved_regs[regnum] = next_addr;
704 /* moveml to (fp + displacement) */
705 else if (0044356 == nextinsn)
707 register CORE_ADDR addr;
709 addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
710 /* Regmask's low bit is for register 0, the first written */
711 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
714 frame_info->saved_regs[regnum] = addr;
719 /* moveml to -(sp) */
720 else if (0044347 == nextinsn)
722 /* Regmask's low bit is for register 15, the first pushed */
723 for (regnum = 16; --regnum >= 0; regmask >>= 1)
725 frame_info->saved_regs[regnum] = (next_addr -= 4);
729 else if (0x2f00 == (0xfff0 & nextinsn))
731 regnum = 0xf & nextinsn;
732 frame_info->saved_regs[regnum] = (next_addr -= 4);
735 /* fmovemx to index of sp */
736 else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000)
738 /* Regmask's low bit is for register fp0, the first written */
739 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
742 frame_info->saved_regs[regnum] = next_addr;
747 /* clrw -(sp); movw ccr,-(sp) */
748 else if (0x4267 == nextinsn && 0x42e7 == regmask)
750 frame_info->saved_regs[PS_REGNUM] = (next_addr -= 4);
757 frame_info->saved_regs[SP_REGNUM] = (frame_info)->frame + 8;
758 frame_info->saved_regs[FP_REGNUM] = (frame_info)->frame;
759 frame_info->saved_regs[PC_REGNUM] = (frame_info)->frame + 4;
760 #ifdef SIG_SP_FP_OFFSET
761 /* Adjust saved SP_REGNUM for fake _sigtramp frames. */
762 if (frame_info->signal_handler_caller && frame_info->next)
763 frame_info->saved_regs[SP_REGNUM] =
764 frame_info->next->frame + SIG_SP_FP_OFFSET;
769 #ifdef USE_PROC_FS /* Target dependent support for /proc */
771 #include <sys/procfs.h>
773 /* Prototypes for supply_gregset etc. */
776 /* The /proc interface divides the target machine's register set up into
777 two different sets, the general register set (gregset) and the floating
778 point register set (fpregset). For each set, there is an ioctl to get
779 the current register set and another ioctl to set the current values.
781 The actual structure passed through the ioctl interface is, of course,
782 naturally machine dependent, and is different for each set of registers.
783 For the m68k for example, the general register set is typically defined
786 typedef int gregset_t[18];
792 and the floating point set by:
794 typedef struct fpregset {
798 int f_fpregs[8][3]; (8 regs, 96 bits each)
801 These routines provide the packing and unpacking of gregset_t and
802 fpregset_t formatted data.
806 /* Atari SVR4 has R_SR but not R_PS */
808 #if !defined (R_PS) && defined (R_SR)
812 /* Given a pointer to a general register set in /proc format (gregset_t *),
813 unpack the register contents and supply them as gdb's idea of the current
817 supply_gregset (gregset_t *gregsetp)
820 register greg_t *regp = (greg_t *) gregsetp;
822 for (regi = 0; regi < R_PC; regi++)
824 supply_register (regi, (char *) (regp + regi));
826 supply_register (PS_REGNUM, (char *) (regp + R_PS));
827 supply_register (PC_REGNUM, (char *) (regp + R_PC));
831 fill_gregset (gregset_t *gregsetp, int regno)
834 register greg_t *regp = (greg_t *) gregsetp;
836 for (regi = 0; regi < R_PC; regi++)
838 if ((regno == -1) || (regno == regi))
840 *(regp + regi) = *(int *) &deprecated_registers[REGISTER_BYTE (regi)];
843 if ((regno == -1) || (regno == PS_REGNUM))
845 *(regp + R_PS) = *(int *) &deprecated_registers[REGISTER_BYTE (PS_REGNUM)];
847 if ((regno == -1) || (regno == PC_REGNUM))
849 *(regp + R_PC) = *(int *) &deprecated_registers[REGISTER_BYTE (PC_REGNUM)];
853 #if defined (FP0_REGNUM)
855 /* Given a pointer to a floating point register set in /proc format
856 (fpregset_t *), unpack the register contents and supply them as gdb's
857 idea of the current floating point register values. */
860 supply_fpregset (fpregset_t *fpregsetp)
865 for (regi = FP0_REGNUM; regi < E_FPC_REGNUM; regi++)
867 from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
868 supply_register (regi, from);
870 supply_register (E_FPC_REGNUM, (char *) &(fpregsetp->f_pcr));
871 supply_register (E_FPS_REGNUM, (char *) &(fpregsetp->f_psr));
872 supply_register (E_FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr));
875 /* Given a pointer to a floating point register set in /proc format
876 (fpregset_t *), update the register specified by REGNO from gdb's idea
877 of the current floating point register set. If REGNO is -1, update
881 fill_fpregset (fpregset_t *fpregsetp, int regno)
887 for (regi = FP0_REGNUM; regi < E_FPC_REGNUM; regi++)
889 if ((regno == -1) || (regno == regi))
891 from = (char *) &deprecated_registers[REGISTER_BYTE (regi)];
892 to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
893 memcpy (to, from, REGISTER_RAW_SIZE (regi));
896 if ((regno == -1) || (regno == E_FPC_REGNUM))
898 fpregsetp->f_pcr = *(int *) &deprecated_registers[REGISTER_BYTE (E_FPC_REGNUM)];
900 if ((regno == -1) || (regno == E_FPS_REGNUM))
902 fpregsetp->f_psr = *(int *) &deprecated_registers[REGISTER_BYTE (E_FPS_REGNUM)];
904 if ((regno == -1) || (regno == E_FPI_REGNUM))
906 fpregsetp->f_fpiaddr = *(int *) &deprecated_registers[REGISTER_BYTE (E_FPI_REGNUM)];
910 #endif /* defined (FP0_REGNUM) */
912 #endif /* USE_PROC_FS */
914 /* Figure out where the longjmp will land. Slurp the args out of the stack.
915 We expect the first arg to be a pointer to the jmp_buf structure from which
916 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
917 This routine returns true on success. */
919 /* NOTE: cagney/2000-11-08: For this function to be fully multi-arched
920 the macro's JB_PC and JB_ELEMENT_SIZE would need to be moved into
921 the ``struct gdbarch_tdep'' object and then set on a target ISA/ABI
925 m68k_get_longjmp_target (CORE_ADDR *pc)
927 #if defined (JB_PC) && defined (JB_ELEMENT_SIZE)
929 CORE_ADDR sp, jb_addr;
931 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
932 sp = read_register (SP_REGNUM);
934 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
935 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
938 jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
940 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
941 TARGET_PTR_BIT / TARGET_CHAR_BIT))
944 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
948 internal_error (__FILE__, __LINE__,
949 "m68k_get_longjmp_target: not implemented");
954 /* Immediately after a function call, return the saved pc before the frame
955 is setup. For sun3's, we check for the common case of being inside of a
956 system call, and if so, we know that Sun pushes the call # on the stack
957 prior to doing the trap. */
960 m68k_saved_pc_after_call (struct frame_info *frame)
965 op = read_memory_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2);
967 if (op == SYSCALL_TRAP)
968 return read_memory_integer (read_register (SP_REGNUM) + 4, 4);
970 #endif /* SYSCALL_TRAP */
971 return read_memory_integer (read_register (SP_REGNUM), 4);
974 /* Function: m68k_gdbarch_init
975 Initializer function for the m68k gdbarch vector.
976 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
978 static struct gdbarch *
979 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
981 static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
982 0x4eb93232, 0x3232dffc, 0x69696969,
983 (0x4e404e71 | (BPT_VECTOR << 16))
985 struct gdbarch_tdep *tdep = NULL;
986 struct gdbarch *gdbarch;
988 /* find a candidate among the list of pre-declared architectures. */
989 arches = gdbarch_list_lookup_by_info (arches, &info);
991 return (arches->gdbarch);
994 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
997 gdbarch = gdbarch_alloc (&info, 0);
999 set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
1000 set_gdbarch_long_double_bit (gdbarch, 96);
1002 set_gdbarch_function_start_offset (gdbarch, 0);
1004 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
1005 set_gdbarch_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call);
1006 set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc);
1008 /* Stack grows down. */
1009 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1010 set_gdbarch_stack_align (gdbarch, m68k_stack_align);
1013 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1014 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1016 set_gdbarch_store_struct_return (gdbarch, m68k_store_struct_return);
1017 set_gdbarch_deprecated_extract_return_value (gdbarch,
1018 m68k_deprecated_extract_return_value);
1019 set_gdbarch_deprecated_store_return_value (gdbarch, m68k_store_return_value);
1021 set_gdbarch_frame_chain (gdbarch, m68k_frame_chain);
1022 set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
1023 set_gdbarch_frame_saved_pc (gdbarch, m68k_frame_saved_pc);
1024 set_gdbarch_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs);
1025 set_gdbarch_frameless_function_invocation (gdbarch,
1026 m68k_frameless_function_invocation);
1027 /* OK to default this value to 'unknown'. */
1028 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1029 set_gdbarch_frame_args_skip (gdbarch, 8);
1030 set_gdbarch_frame_args_address (gdbarch, default_frame_address);
1031 set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
1033 set_gdbarch_register_raw_size (gdbarch, m68k_register_raw_size);
1034 set_gdbarch_register_virtual_size (gdbarch, m68k_register_virtual_size);
1035 set_gdbarch_max_register_raw_size (gdbarch, 12);
1036 set_gdbarch_max_register_virtual_size (gdbarch, 12);
1037 set_gdbarch_register_virtual_type (gdbarch, m68k_register_virtual_type);
1038 set_gdbarch_register_name (gdbarch, m68k_register_name);
1039 set_gdbarch_register_size (gdbarch, 4);
1040 set_gdbarch_register_byte (gdbarch, m68k_register_byte);
1041 set_gdbarch_num_regs (gdbarch, 29);
1042 set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
1043 set_gdbarch_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4));
1044 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
1045 set_gdbarch_fp_regnum (gdbarch, E_FP_REGNUM);
1046 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1047 set_gdbarch_ps_regnum (gdbarch, E_PS_REGNUM);
1048 set_gdbarch_fp0_regnum (gdbarch, E_FP0_REGNUM);
1050 set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
1051 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
1052 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
1053 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 24);
1054 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
1055 set_gdbarch_call_dummy_p (gdbarch, 1);
1056 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1057 set_gdbarch_call_dummy_length (gdbarch, 28);
1058 set_gdbarch_call_dummy_start_offset (gdbarch, 12);
1060 set_gdbarch_call_dummy_words (gdbarch, call_dummy_words);
1061 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words));
1062 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1063 set_gdbarch_fix_call_dummy (gdbarch, m68k_fix_call_dummy);
1064 set_gdbarch_push_dummy_frame (gdbarch, m68k_push_dummy_frame);
1065 set_gdbarch_pop_frame (gdbarch, m68k_pop_frame);
1072 m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1078 _initialize_m68k_tdep (void)
1080 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
1081 tm_print_insn = print_insn_m68k;