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
47 E_FP_REGNUM = 14, /* Contains address of executing stack frame */
48 E_SP_REGNUM = 15, /* Contains address of top of stack */
49 E_PS_REGNUM = 16, /* Contains processor status */
50 E_PC_REGNUM = 17, /* Contains program counter */
51 E_FP0_REGNUM = 18 /* Floating point register 0 */
54 void m68k_frame_init_saved_regs (struct frame_info *frame_info);
57 m68k_register_bytes_ok (numbytes)
59 return ((numbytes == REGISTER_BYTES_FP)
60 || (numbytes == REGISTER_BYTES_NOFP));
63 /* Number of bytes of storage in the actual machine representation
64 for register regnum. On the 68000, all regs are 4 bytes
65 except the floating point regs which are 12 bytes. */
66 /* Note that the unsigned cast here forces the result of the
67 subtraction to very high positive values if regnum < FP0_REGNUM */
70 m68k_register_raw_size (int regnum)
72 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
75 /* Number of bytes of storage in the program's representation
76 for register regnum. On the 68000, all regs are 4 bytes
77 except the floating point regs which are 12-byte long doubles. */
80 m68k_register_virtual_size (int regnum)
82 return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
85 /* Return the GDB type object for the "standard" data type of data
86 in register N. This should be int for D0-D7, long double for FP0-FP7,
87 and void pointer for all others (A0-A7, PC, SR, FPCONTROL etc).
88 Note, for registers which contain addresses return pointer to void,
89 not pointer to char, because we don't want to attempt to print
90 the string after printing the address. */
93 m68k_register_virtual_type (int regnum)
95 if ((unsigned) regnum >= FPC_REGNUM)
96 return lookup_pointer_type (builtin_type_void);
97 else if ((unsigned) regnum >= FP0_REGNUM)
98 return builtin_type_long_double;
99 else if ((unsigned) regnum >= A0_REGNUM)
100 return lookup_pointer_type (builtin_type_void);
102 return builtin_type_int;
105 /* Function: m68k_register_name
106 Returns the name of the standard m68k register regnum. */
109 m68k_register_name (int regnum)
111 static char *register_names[] = {
112 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
113 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
115 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
116 "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
120 regnum >= sizeof (register_names) / sizeof (register_names[0]))
121 internal_error (__FILE__, __LINE__,
122 "m68k_register_name: illegal register number %d", regnum);
124 return register_names[regnum];
127 /* Stack must be kept short aligned when doing function calls. */
130 m68k_stack_align (CORE_ADDR addr)
132 return ((addr + 1) & ~1);
135 /* Index within `registers' of the first byte of the space for
139 m68k_register_byte (int regnum)
141 if (regnum >= FPC_REGNUM)
142 return (((regnum - FPC_REGNUM) * 4) + 168);
143 else if (regnum >= FP0_REGNUM)
144 return (((regnum - FP0_REGNUM) * 12) + 72);
149 /* Store the address of the place in which to copy the structure the
150 subroutine will return. This is called from call_function. */
153 m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
155 write_register (A1_REGNUM, addr);
158 /* Extract from an array regbuf containing the (raw) register state
159 a function return value of type type, and copy that, in virtual format,
160 into valbuf. This is assuming that floating point values are returned
161 as doubles in d0/d1. */
164 m68k_deprecated_extract_return_value (struct type *type, char *regbuf,
168 int typeLength = TYPE_LENGTH (type);
171 offset = 4 - typeLength;
173 memcpy (valbuf, regbuf + offset, typeLength);
177 m68k_deprecated_extract_struct_value_address (char *regbuf)
179 return (*(CORE_ADDR *) (regbuf));
182 /* Write into appropriate registers a function return value
183 of type TYPE, given in virtual format. Assumes floats are passed
187 m68k_store_return_value (struct type *type, char *valbuf)
189 write_register_bytes (0, valbuf, TYPE_LENGTH (type));
192 /* Describe the pointer in each stack frame to the previous stack frame
195 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
197 In the case of the 68000, the frame's nominal address
198 is the address of a 4-byte word containing the calling frame's address. */
200 /* If we are chaining from sigtramp, then manufacture a sigtramp frame
201 (which isn't really on the stack. I'm not sure this is right for anything
202 but BSD4.3 on an hp300. */
205 m68k_frame_chain (struct frame_info *thisframe)
207 if (thisframe->signal_handler_caller)
208 return thisframe->frame;
209 else if (!inside_entry_file ((thisframe)->pc))
210 return read_memory_integer ((thisframe)->frame, 4);
215 /* A function that tells us whether the function invocation represented
216 by fi does not have a frame on the stack associated with it. If it
217 does not, FRAMELESS is set to 1, else 0. */
220 m68k_frameless_function_invocation (struct frame_info *fi)
222 if (fi->signal_handler_caller)
225 return frameless_look_for_prologue (fi);
229 m68k_frame_saved_pc (struct frame_info *frame)
231 if (frame->signal_handler_caller)
234 return read_memory_integer (frame->next->frame + SIG_PC_FP_OFFSET, 4);
236 return read_memory_integer (read_register (SP_REGNUM)
237 + SIG_PC_FP_OFFSET - 8, 4);
240 return read_memory_integer (frame->frame + 4, 4);
244 /* The only reason this is here is the tm-altos.h reference below. It
245 was moved back here from tm-m68k.h. FIXME? */
248 altos_skip_prologue (CORE_ADDR pc)
250 register int op = read_memory_integer (pc, 2);
251 if (op == P_LINKW_FP)
252 pc += 4; /* Skip link #word */
253 else if (op == P_LINKL_FP)
254 pc += 6; /* Skip link #long */
255 /* Not sure why branches are here. */
256 /* From tm-altos.h */
257 else if (op == 0060000)
258 pc += 4; /* Skip bra #word */
259 else if (op == 00600377)
260 pc += 6; /* skip bra #long */
261 else if ((op & 0177400) == 0060000)
262 pc += 2; /* skip bra #char */
267 delta68_in_sigtramp (CORE_ADDR pc, char *name)
270 return strcmp (name, "_sigcode") == 0;
276 delta68_frame_args_address (struct frame_info *frame_info)
278 /* we assume here that the only frameless functions are the system calls
279 or other functions who do not put anything on the stack. */
280 if (frame_info->signal_handler_caller)
281 return frame_info->frame + 12;
282 else if (frameless_look_for_prologue (frame_info))
284 /* Check for an interrupted system call */
285 if (frame_info->next && frame_info->next->signal_handler_caller)
286 return frame_info->next->frame + 16;
288 return frame_info->frame + 4;
291 return frame_info->frame;
295 delta68_frame_saved_pc (struct frame_info *frame_info)
297 return read_memory_integer (delta68_frame_args_address (frame_info) + 4, 4);
300 /* Return number of args passed to a frame.
301 Can return -1, meaning no way to tell. */
304 isi_frame_num_args (struct frame_info *fi)
307 CORE_ADDR pc = FRAME_SAVED_PC (fi);
308 int insn = 0177777 & read_memory_integer (pc, 2);
310 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
311 val = read_memory_integer (pc + 2, 2);
312 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
313 || (insn & 0170777) == 0050117) /* addqw */
315 val = (insn >> 9) & 7;
319 else if (insn == 0157774) /* addal #WW, sp */
320 val = read_memory_integer (pc + 2, 4);
326 delta68_frame_num_args (struct frame_info *fi)
329 CORE_ADDR pc = FRAME_SAVED_PC (fi);
330 int insn = 0177777 & read_memory_integer (pc, 2);
332 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
333 val = read_memory_integer (pc + 2, 2);
334 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
335 || (insn & 0170777) == 0050117) /* addqw */
337 val = (insn >> 9) & 7;
341 else if (insn == 0157774) /* addal #WW, sp */
342 val = read_memory_integer (pc + 2, 4);
348 news_frame_num_args (struct frame_info *fi)
351 CORE_ADDR pc = FRAME_SAVED_PC (fi);
352 int insn = 0177777 & read_memory_integer (pc, 2);
354 if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
355 val = read_memory_integer (pc + 2, 2);
356 else if ((insn & 0170777) == 0050217 /* addql #N, sp */
357 || (insn & 0170777) == 0050117) /* addqw */
359 val = (insn >> 9) & 7;
363 else if (insn == 0157774) /* addal #WW, sp */
364 val = read_memory_integer (pc + 2, 4);
369 /* Insert the specified number of args and function address
370 into a call sequence of the above form stored at DUMMYNAME.
371 We use the BFD routines to store a big-endian value of known size. */
374 m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
375 struct value **args, struct type *type, int gcc_p)
377 bfd_putb32 (fun, (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 2);
378 bfd_putb32 (nargs * 4,
379 (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 8);
383 /* Push an empty stack frame, to record the current PC, etc. */
386 m68k_push_dummy_frame (void)
388 register CORE_ADDR sp = read_register (SP_REGNUM);
392 sp = push_word (sp, read_register (PC_REGNUM));
393 sp = push_word (sp, read_register (FP_REGNUM));
394 write_register (FP_REGNUM, sp);
396 /* Always save the floating-point registers, whether they exist on
397 this target or not. */
398 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
400 read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
401 sp = push_bytes (sp, raw_buffer, 12);
404 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
406 sp = push_word (sp, read_register (regnum));
408 sp = push_word (sp, read_register (PS_REGNUM));
409 write_register (SP_REGNUM, sp);
412 /* Discard from the stack the innermost frame,
413 restoring all saved registers. */
416 m68k_pop_frame (void)
418 register struct frame_info *frame = get_current_frame ();
419 register CORE_ADDR fp;
423 fp = FRAME_FP (frame);
424 m68k_frame_init_saved_regs (frame);
425 for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--)
427 if (frame->saved_regs[regnum])
429 read_memory (frame->saved_regs[regnum], raw_buffer, 12);
430 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12);
433 for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)
435 if (frame->saved_regs[regnum])
437 write_register (regnum,
438 read_memory_integer (frame->saved_regs[regnum], 4));
441 if (frame->saved_regs[PS_REGNUM])
443 write_register (PS_REGNUM,
444 read_memory_integer (frame->saved_regs[PS_REGNUM], 4));
446 write_register (FP_REGNUM, read_memory_integer (fp, 4));
447 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
448 write_register (SP_REGNUM, fp + 8);
449 flush_cached_frames ();
453 /* Given an ip value corresponding to the start of a function,
454 return the ip of the first instruction after the function
455 prologue. This is the generic m68k support. Machines which
456 require something different can override the SKIP_PROLOGUE
457 macro to point elsewhere.
459 Some instructions which typically may appear in a function
462 A link instruction, word form:
464 link.w %a6,&0 4e56 XXXX
466 A link instruction, long form:
468 link.l %fp,&F%1 480e XXXX XXXX
470 A movm instruction to preserve integer regs:
472 movm.l &M%1,(4,%sp) 48ef XXXX XXXX
474 A fmovm instruction to preserve float regs:
476 fmovm &FPM%1,(FPO%1,%sp) f237 XXXX XXXX XXXX XXXX
478 Some profiling setup code (FIXME, not recognized yet):
480 lea.l (.L3,%pc),%a1 43fb XXXX XXXX XXXX
481 bsr _mcount 61ff XXXX XXXX
486 m68k_skip_prologue (CORE_ADDR ip)
488 register CORE_ADDR limit;
489 struct symtab_and_line sal;
492 /* Find out if there is a known limit for the extent of the prologue.
493 If so, ensure we don't go past it. If not, assume "infinity". */
495 sal = find_pc_line (ip, 0);
496 limit = (sal.end) ? sal.end : (CORE_ADDR) ~0;
500 op = read_memory_integer (ip, 2);
503 if (op == P_LINKW_FP)
504 ip += 4; /* Skip link.w */
505 else if (op == P_PEA_FP)
506 ip += 2; /* Skip pea %fp */
507 else if (op == P_MOVL_SP_FP)
508 ip += 2; /* Skip move.l %sp, %fp */
509 else if (op == P_LINKL_FP)
510 ip += 6; /* Skip link.l */
511 else if (op == P_MOVML)
512 ip += 6; /* Skip movm.l */
513 else if (op == P_FMOVM)
514 ip += 10; /* Skip fmovm */
516 break; /* Found unknown code, bail out. */
521 /* Store the addresses of the saved registers of the frame described by
522 FRAME_INFO in its saved_regs field.
523 This includes special registers such as pc and fp saved in special
524 ways in the stack frame. sp is even more special:
525 the address we return for it IS the sp for the next frame. */
528 m68k_frame_init_saved_regs (struct frame_info *frame_info)
531 register int regmask;
532 register CORE_ADDR next_addr;
533 register CORE_ADDR pc;
535 /* First possible address for a pc in a call dummy for this frame. */
536 CORE_ADDR possible_call_dummy_start =
537 (frame_info)->frame - 28 - FP_REGNUM * 4 - 4 - 8 * 12;
541 if (frame_info->saved_regs)
544 frame_saved_regs_zalloc (frame_info);
546 memset (frame_info->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS);
548 if ((frame_info)->pc >= possible_call_dummy_start
549 && (frame_info)->pc <= (frame_info)->frame)
552 /* It is a call dummy. We could just stop now, since we know
553 what the call dummy saves and where. But this code proceeds
554 to parse the "prologue" which is part of the call dummy.
555 This is needlessly complex and confusing. FIXME. */
557 next_addr = (frame_info)->frame;
558 pc = possible_call_dummy_start;
562 pc = get_pc_function_start ((frame_info)->pc);
564 nextinsn = read_memory_integer (pc, 2);
565 if (P_PEA_FP == nextinsn
566 && P_MOVL_SP_FP == read_memory_integer (pc + 2, 2))
570 next_addr = frame_info->frame;
573 else if (P_LINKL_FP == nextinsn)
575 /* Find the address above the saved
576 regs using the amount of storage from the link instruction. */
578 next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 4);
581 else if (P_LINKW_FP == nextinsn)
583 /* Find the address above the saved
584 regs using the amount of storage from the link instruction. */
586 next_addr = (frame_info)->frame + read_memory_integer (pc + 2, 2);
592 /* If have an addal #-n, sp next, adjust next_addr. */
593 if ((0177777 & read_memory_integer (pc, 2)) == 0157774)
594 next_addr += read_memory_integer (pc += 2, 4), pc += 4;
599 nextinsn = 0xffff & read_memory_integer (pc, 2);
600 regmask = read_memory_integer (pc + 2, 2);
601 /* fmovemx to -(sp) */
602 if (0xf227 == nextinsn && (regmask & 0xff00) == 0xe000)
604 /* Regmask's low bit is for register fp7, the first pushed */
605 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
607 frame_info->saved_regs[regnum] = (next_addr -= 12);
610 /* fmovemx to (fp + displacement) */
611 else if (0171056 == nextinsn && (regmask & 0xff00) == 0xf000)
613 register CORE_ADDR addr;
615 addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
616 /* Regmask's low bit is for register fp7, the first pushed */
617 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
620 frame_info->saved_regs[regnum] = addr;
626 else if (0044327 == nextinsn)
628 /* Regmask's low bit is for register 0, the first written */
629 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
632 frame_info->saved_regs[regnum] = next_addr;
637 /* moveml to (fp + displacement) */
638 else if (0044356 == nextinsn)
640 register CORE_ADDR addr;
642 addr = (frame_info)->frame + read_memory_integer (pc + 4, 2);
643 /* Regmask's low bit is for register 0, the first written */
644 for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)
647 frame_info->saved_regs[regnum] = addr;
652 /* moveml to -(sp) */
653 else if (0044347 == nextinsn)
655 /* Regmask's low bit is for register 15, the first pushed */
656 for (regnum = 16; --regnum >= 0; regmask >>= 1)
658 frame_info->saved_regs[regnum] = (next_addr -= 4);
662 else if (0x2f00 == (0xfff0 & nextinsn))
664 regnum = 0xf & nextinsn;
665 frame_info->saved_regs[regnum] = (next_addr -= 4);
668 /* fmovemx to index of sp */
669 else if (0xf236 == nextinsn && (regmask & 0xff00) == 0xf000)
671 /* Regmask's low bit is for register fp0, the first written */
672 for (regnum = FP0_REGNUM + 8; --regnum >= FP0_REGNUM; regmask >>= 1)
675 frame_info->saved_regs[regnum] = next_addr;
680 /* clrw -(sp); movw ccr,-(sp) */
681 else if (0x4267 == nextinsn && 0x42e7 == regmask)
683 frame_info->saved_regs[PS_REGNUM] = (next_addr -= 4);
690 frame_info->saved_regs[SP_REGNUM] = (frame_info)->frame + 8;
691 frame_info->saved_regs[FP_REGNUM] = (frame_info)->frame;
692 frame_info->saved_regs[PC_REGNUM] = (frame_info)->frame + 4;
693 #ifdef SIG_SP_FP_OFFSET
694 /* Adjust saved SP_REGNUM for fake _sigtramp frames. */
695 if (frame_info->signal_handler_caller && frame_info->next)
696 frame_info->saved_regs[SP_REGNUM] =
697 frame_info->next->frame + SIG_SP_FP_OFFSET;
702 #ifdef USE_PROC_FS /* Target dependent support for /proc */
704 #include <sys/procfs.h>
706 /* Prototypes for supply_gregset etc. */
709 /* The /proc interface divides the target machine's register set up into
710 two different sets, the general register set (gregset) and the floating
711 point register set (fpregset). For each set, there is an ioctl to get
712 the current register set and another ioctl to set the current values.
714 The actual structure passed through the ioctl interface is, of course,
715 naturally machine dependent, and is different for each set of registers.
716 For the m68k for example, the general register set is typically defined
719 typedef int gregset_t[18];
725 and the floating point set by:
727 typedef struct fpregset {
731 int f_fpregs[8][3]; (8 regs, 96 bits each)
734 These routines provide the packing and unpacking of gregset_t and
735 fpregset_t formatted data.
739 /* Atari SVR4 has R_SR but not R_PS */
741 #if !defined (R_PS) && defined (R_SR)
745 /* Given a pointer to a general register set in /proc format (gregset_t *),
746 unpack the register contents and supply them as gdb's idea of the current
750 supply_gregset (gregset_t *gregsetp)
753 register greg_t *regp = (greg_t *) gregsetp;
755 for (regi = 0; regi < R_PC; regi++)
757 supply_register (regi, (char *) (regp + regi));
759 supply_register (PS_REGNUM, (char *) (regp + R_PS));
760 supply_register (PC_REGNUM, (char *) (regp + R_PC));
764 fill_gregset (gregset_t *gregsetp, int regno)
767 register greg_t *regp = (greg_t *) gregsetp;
769 for (regi = 0; regi < R_PC; regi++)
771 if ((regno == -1) || (regno == regi))
773 *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)];
776 if ((regno == -1) || (regno == PS_REGNUM))
778 *(regp + R_PS) = *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)];
780 if ((regno == -1) || (regno == PC_REGNUM))
782 *(regp + R_PC) = *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)];
786 #if defined (FP0_REGNUM)
788 /* Given a pointer to a floating point register set in /proc format
789 (fpregset_t *), unpack the register contents and supply them as gdb's
790 idea of the current floating point register values. */
793 supply_fpregset (fpregset_t *fpregsetp)
798 for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
800 from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
801 supply_register (regi, from);
803 supply_register (FPC_REGNUM, (char *) &(fpregsetp->f_pcr));
804 supply_register (FPS_REGNUM, (char *) &(fpregsetp->f_psr));
805 supply_register (FPI_REGNUM, (char *) &(fpregsetp->f_fpiaddr));
808 /* Given a pointer to a floating point register set in /proc format
809 (fpregset_t *), update the register specified by REGNO from gdb's idea
810 of the current floating point register set. If REGNO is -1, update
814 fill_fpregset (fpregset_t *fpregsetp, int regno)
820 for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
822 if ((regno == -1) || (regno == regi))
824 from = (char *) ®isters[REGISTER_BYTE (regi)];
825 to = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]);
826 memcpy (to, from, REGISTER_RAW_SIZE (regi));
829 if ((regno == -1) || (regno == FPC_REGNUM))
831 fpregsetp->f_pcr = *(int *) ®isters[REGISTER_BYTE (FPC_REGNUM)];
833 if ((regno == -1) || (regno == FPS_REGNUM))
835 fpregsetp->f_psr = *(int *) ®isters[REGISTER_BYTE (FPS_REGNUM)];
837 if ((regno == -1) || (regno == FPI_REGNUM))
839 fpregsetp->f_fpiaddr = *(int *) ®isters[REGISTER_BYTE (FPI_REGNUM)];
843 #endif /* defined (FP0_REGNUM) */
845 #endif /* USE_PROC_FS */
847 /* Figure out where the longjmp will land. Slurp the args out of the stack.
848 We expect the first arg to be a pointer to the jmp_buf structure from which
849 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
850 This routine returns true on success. */
852 /* NOTE: cagney/2000-11-08: For this function to be fully multi-arched
853 the macro's JB_PC and JB_ELEMENT_SIZE would need to be moved into
854 the ``struct gdbarch_tdep'' object and then set on a target ISA/ABI
858 m68k_get_longjmp_target (CORE_ADDR *pc)
860 #if defined (JB_PC) && defined (JB_ELEMENT_SIZE)
862 CORE_ADDR sp, jb_addr;
864 buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT);
865 sp = read_register (SP_REGNUM);
867 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
868 buf, TARGET_PTR_BIT / TARGET_CHAR_BIT))
871 jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
873 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
874 TARGET_PTR_BIT / TARGET_CHAR_BIT))
877 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
881 internal_error (__FILE__, __LINE__,
882 "m68k_get_longjmp_target: not implemented");
887 /* Immediately after a function call, return the saved pc before the frame
888 is setup. For sun3's, we check for the common case of being inside of a
889 system call, and if so, we know that Sun pushes the call # on the stack
890 prior to doing the trap. */
893 m68k_saved_pc_after_call (struct frame_info *frame)
898 op = read_memory_integer (frame->pc - SYSCALL_TRAP_OFFSET, 2);
900 if (op == SYSCALL_TRAP)
901 return read_memory_integer (read_register (SP_REGNUM) + 4, 4);
903 #endif /* SYSCALL_TRAP */
904 return read_memory_integer (read_register (SP_REGNUM), 4);
907 /* Function: m68k_gdbarch_init
908 Initializer function for the m68k gdbarch vector.
909 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
911 static struct gdbarch *
912 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
914 static LONGEST call_dummy_words[7] = { 0xf227e0ff, 0x48e7fffc, 0x426742e7,
915 0x4eb93232, 0x3232dffc, 0x69696969,
916 (0x4e404e71 | (BPT_VECTOR << 16))
918 struct gdbarch_tdep *tdep = NULL;
919 struct gdbarch *gdbarch;
921 /* find a candidate among the list of pre-declared architectures. */
922 arches = gdbarch_list_lookup_by_info (arches, &info);
924 return (arches->gdbarch);
927 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
930 gdbarch = gdbarch_alloc (&info, 0);
932 set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext);
933 set_gdbarch_long_double_bit (gdbarch, 96);
935 set_gdbarch_function_start_offset (gdbarch, 0);
937 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
938 set_gdbarch_saved_pc_after_call (gdbarch, m68k_saved_pc_after_call);
940 /* Stack grows down. */
941 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
942 set_gdbarch_stack_align (gdbarch, m68k_stack_align);
945 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
946 set_gdbarch_decr_pc_after_break (gdbarch, 2);
948 set_gdbarch_store_struct_return (gdbarch, m68k_store_struct_return);
949 set_gdbarch_deprecated_extract_return_value (gdbarch,
950 m68k_deprecated_extract_return_value);
951 set_gdbarch_store_return_value (gdbarch, m68k_store_return_value);
953 set_gdbarch_frame_chain (gdbarch, m68k_frame_chain);
954 set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
955 set_gdbarch_frame_saved_pc (gdbarch, m68k_frame_saved_pc);
956 set_gdbarch_frame_init_saved_regs (gdbarch, m68k_frame_init_saved_regs);
957 set_gdbarch_frameless_function_invocation (gdbarch,
958 m68k_frameless_function_invocation);
959 /* OK to default this value to 'unknown'. */
960 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
961 set_gdbarch_frame_args_skip (gdbarch, 8);
962 set_gdbarch_frame_args_address (gdbarch, default_frame_address);
963 set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
965 set_gdbarch_register_raw_size (gdbarch, m68k_register_raw_size);
966 set_gdbarch_register_virtual_size (gdbarch, m68k_register_virtual_size);
967 set_gdbarch_max_register_raw_size (gdbarch, 12);
968 set_gdbarch_max_register_virtual_size (gdbarch, 12);
969 set_gdbarch_register_virtual_type (gdbarch, m68k_register_virtual_type);
970 set_gdbarch_register_name (gdbarch, m68k_register_name);
971 set_gdbarch_register_size (gdbarch, 4);
972 set_gdbarch_register_byte (gdbarch, m68k_register_byte);
973 set_gdbarch_num_regs (gdbarch, 29);
974 set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok);
975 set_gdbarch_register_bytes (gdbarch, (16 * 4 + 8 + 8 * 12 + 3 * 4));
976 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
977 set_gdbarch_fp_regnum (gdbarch, E_FP_REGNUM);
978 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
979 set_gdbarch_ps_regnum (gdbarch, E_PS_REGNUM);
980 set_gdbarch_fp0_regnum (gdbarch, E_FP0_REGNUM);
982 set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
983 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
984 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
985 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 24);
986 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
987 set_gdbarch_call_dummy_p (gdbarch, 1);
988 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
989 set_gdbarch_call_dummy_length (gdbarch, 28);
990 set_gdbarch_call_dummy_start_offset (gdbarch, 12);
992 set_gdbarch_call_dummy_words (gdbarch, call_dummy_words);
993 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (call_dummy_words));
994 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
995 set_gdbarch_fix_call_dummy (gdbarch, m68k_fix_call_dummy);
996 set_gdbarch_push_dummy_frame (gdbarch, m68k_push_dummy_frame);
997 set_gdbarch_pop_frame (gdbarch, m68k_pop_frame);
1004 m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
1010 _initialize_m68k_tdep (void)
1012 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
1013 tm_print_insn = print_insn_m68k;