+
+#define P_LINKL_FP 0x480e
+#define P_LINKW_FP 0x4e56
+#define P_PEA_FP 0x4856
+#define P_MOVL_SP_FP 0x2c4f
+#define P_MOVL 0x207c
+#define P_JSR 0x4eb9
+#define P_BSR 0x61ff
+#define P_LEAL 0x43fb
+#define P_MOVML 0x48ef
+#define P_FMOVM 0xf237
+#define P_TRAP 0x4e40
+
+
+#define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4)
+#define REGISTER_BYTES_NOFP (16*4 + 8)
+
+#define NUM_FREGS (NUM_REGS-24)
+
+/* Offset from SP to first arg on stack at first instruction of a function */
+
+#define SP_ARG0 (1 * 4)
+
+/* This was determined by experimentation on hp300 BSD 4.3. Perhaps
+ it corresponds to some offset in /usr/include/sys/user.h or
+ something like that. Using some system include file would
+ have the advantage of probably being more robust in the face
+ of OS upgrades, but the disadvantage of being wrong for
+ cross-debugging. */
+
+#define SIG_PC_FP_OFFSET 530
+
+#define TARGET_M68K
+
+
+#if !defined (BPT_VECTOR)
+#define BPT_VECTOR 0xf
+#endif
+
+#if !defined (REMOTE_BPT_VECTOR)
+#define REMOTE_BPT_VECTOR 1
+#endif
+
+
+void m68k_frame_init_saved_regs (struct frame_info *frame_info);
+
+
+/* gdbarch_breakpoint_from_pc is set to m68k_local_breakpoint_from_pc
+ so m68k_remote_breakpoint_from_pc is currently not used. */
+
+const static unsigned char *
+m68k_remote_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
+{
+ static unsigned char break_insn[] = {0x4e, (0x40 | REMOTE_BPT_VECTOR)};
+ *lenptr = sizeof (break_insn);
+ return break_insn;
+}
+
+const static unsigned char *
+m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
+{
+ static unsigned char break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
+ *lenptr = sizeof (break_insn);
+ return break_insn;
+}
+
+
+static int
+m68k_register_bytes_ok (long numbytes)
+{
+ return ((numbytes == REGISTER_BYTES_FP)
+ || (numbytes == REGISTER_BYTES_NOFP));
+}
+
+/* Number of bytes of storage in the actual machine representation
+ for register regnum. On the 68000, all regs are 4 bytes
+ except the floating point regs which are 12 bytes. */
+/* Note that the unsigned cast here forces the result of the
+ subtraction to very high positive values if regnum < FP0_REGNUM */
+
+static int
+m68k_register_raw_size (int regnum)
+{
+ return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
+}
+
+/* Number of bytes of storage in the program's representation
+ for register regnum. On the 68000, all regs are 4 bytes
+ except the floating point regs which are 12-byte long doubles. */
+
+static int
+m68k_register_virtual_size (int regnum)
+{
+ return (((unsigned) (regnum) - FP0_REGNUM) < 8 ? 12 : 4);
+}
+
+/* Return the GDB type object for the "standard" data type of data in
+ register N. This should be int for D0-D7, SR, FPCONTROL and
+ FPSTATUS, long double for FP0-FP7, and void pointer for all others
+ (A0-A7, PC, FPIADDR). Note, for registers which contain
+ addresses return pointer to void, not pointer to char, because we
+ don't want to attempt to print the string after printing the
+ address. */
+
+static struct type *
+m68k_register_virtual_type (int regnum)
+{
+ if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7)
+ return builtin_type_m68881_ext;
+
+ if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM)
+ return builtin_type_void_func_ptr;
+
+ if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM
+ || regnum == PS_REGNUM)
+ return builtin_type_int32;
+
+ if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
+ return builtin_type_void_data_ptr;
+
+ return builtin_type_int32;
+}
+
+/* Function: m68k_register_name
+ Returns the name of the standard m68k register regnum. */
+
+static const char *
+m68k_register_name (int regnum)
+{
+ static char *register_names[] = {
+ "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
+ "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
+ "ps", "pc",
+ "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
+ "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags"
+ };
+
+ if (regnum < 0 ||
+ regnum >= sizeof (register_names) / sizeof (register_names[0]))
+ internal_error (__FILE__, __LINE__,
+ "m68k_register_name: illegal register number %d", regnum);
+ else
+ return register_names[regnum];
+}
+
+/* Stack must be kept short aligned when doing function calls. */
+
+static CORE_ADDR
+m68k_stack_align (CORE_ADDR addr)
+{
+ return ((addr + 1) & ~1);
+}
+
+/* Index within `registers' of the first byte of the space for
+ register regnum. */
+
+static int
+m68k_register_byte (int regnum)
+{
+ if (regnum >= M68K_FPC_REGNUM)
+ return (((regnum - M68K_FPC_REGNUM) * 4) + 168);
+ else if (regnum >= FP0_REGNUM)
+ return (((regnum - FP0_REGNUM) * 12) + 72);
+ else
+ return (regnum * 4);
+}
+
+/* Store the address of the place in which to copy the structure the
+ subroutine will return. This is called from call_function. */
+
+static void
+m68k_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
+{
+ write_register (M68K_A1_REGNUM, addr);
+}
+
+/* Extract from an array regbuf containing the (raw) register state
+ a function return value of type type, and copy that, in virtual format,
+ into valbuf. This is assuming that floating point values are returned
+ as doubles in d0/d1. */
+
+static void
+m68k_deprecated_extract_return_value (struct type *type, char *regbuf,
+ char *valbuf)
+{
+ int offset = 0;
+ int typeLength = TYPE_LENGTH (type);
+
+ if (typeLength < 4)
+ offset = 4 - typeLength;
+
+ memcpy (valbuf, regbuf + offset, typeLength);
+}
+
+static CORE_ADDR
+m68k_deprecated_extract_struct_value_address (char *regbuf)
+{
+ return (*(CORE_ADDR *) (regbuf));
+}
+
+/* Write into appropriate registers a function return value
+ of type TYPE, given in virtual format. Assumes floats are passed
+ in d0/d1. */
+
+static void
+m68k_store_return_value (struct type *type, char *valbuf)
+{
+ deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
+}
+
+/* Describe the pointer in each stack frame to the previous stack frame
+ (its caller). */
+
+/* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and produces
+ the frame's chain-pointer. In the case of the 68000, the frame's
+ nominal address is the address of a 4-byte word containing the
+ calling frame's address. */
+
+/* If we are chaining from sigtramp, then manufacture a sigtramp frame
+ (which isn't really on the stack. I'm not sure this is right for anything
+ but BSD4.3 on an hp300. */
+
+static CORE_ADDR
+m68k_frame_chain (struct frame_info *thisframe)
+{
+ if (get_frame_type (thisframe) == SIGTRAMP_FRAME)
+ return get_frame_base (thisframe);
+ else if (!inside_entry_file (get_frame_pc (thisframe)))
+ return read_memory_unsigned_integer (get_frame_base (thisframe), 4);
+ else
+ return 0;
+}
+
+/* A function that tells us whether the function invocation represented
+ by fi does not have a frame on the stack associated with it. If it
+ does not, FRAMELESS is set to 1, else 0. */
+
+static int
+m68k_frameless_function_invocation (struct frame_info *fi)
+{
+ if (get_frame_type (fi) == SIGTRAMP_FRAME)
+ return 0;
+ else
+ return frameless_look_for_prologue (fi);
+}
+
+static CORE_ADDR
+m68k_frame_saved_pc (struct frame_info *frame)
+{
+ if (get_frame_type (frame) == SIGTRAMP_FRAME)
+ {
+ if (get_next_frame (frame))
+ return read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
+ + SIG_PC_FP_OFFSET, 4);
+ else
+ return read_memory_unsigned_integer (read_register (SP_REGNUM)
+ + SIG_PC_FP_OFFSET - 8, 4);
+ }
+ else
+ return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
+}
+
+
+/* The only reason this is here is the tm-altos.h reference below. It
+ was moved back here from tm-m68k.h. FIXME? */
+
+extern CORE_ADDR
+altos_skip_prologue (CORE_ADDR pc)
+{
+ register int op = read_memory_unsigned_integer (pc, 2);
+ if (op == P_LINKW_FP)
+ pc += 4; /* Skip link #word */
+ else if (op == P_LINKL_FP)
+ pc += 6; /* Skip link #long */
+ /* Not sure why branches are here. */
+ /* From tm-altos.h */
+ else if (op == 0060000)
+ pc += 4; /* Skip bra #word */
+ else if (op == 00600377)
+ pc += 6; /* skip bra #long */
+ else if ((op & 0177400) == 0060000)
+ pc += 2; /* skip bra #char */
+ return pc;
+}
+
+int
+delta68_in_sigtramp (CORE_ADDR pc, char *name)
+{
+ if (name != NULL)
+ return strcmp (name, "_sigcode") == 0;
+ else
+ return 0;
+}
+
+CORE_ADDR
+delta68_frame_args_address (struct frame_info *frame_info)
+{
+ /* we assume here that the only frameless functions are the system calls
+ or other functions who do not put anything on the stack. */
+ if (get_frame_type (frame_info) == SIGTRAMP_FRAME)
+ return get_frame_base (frame_info) + 12;
+ else if (frameless_look_for_prologue (frame_info))
+ {
+ /* Check for an interrupted system call */
+ if (get_next_frame (frame_info) && (get_frame_type (get_next_frame (frame_info)) == SIGTRAMP_FRAME))
+ return get_frame_base (get_next_frame (frame_info)) + 16;
+ else
+ return get_frame_base (frame_info) + 4;
+ }
+ else
+ return get_frame_base (frame_info);
+}
+
+CORE_ADDR
+delta68_frame_saved_pc (struct frame_info *frame_info)
+{
+ return read_memory_unsigned_integer (delta68_frame_args_address (frame_info)
+ + 4, 4);
+}
+
+/* Return number of args passed to a frame.
+ Can return -1, meaning no way to tell. */
+
+int
+isi_frame_num_args (struct frame_info *fi)
+{
+ int val;
+ CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
+ int insn = read_memory_unsigned_integer (pc, 2);
+ val = 0;
+ if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
+ val = read_memory_integer (pc + 2, 2);
+ else if ((insn & 0170777) == 0050217 /* addql #N, sp */
+ || (insn & 0170777) == 0050117) /* addqw */
+ {
+ val = (insn >> 9) & 7;
+ if (val == 0)
+ val = 8;
+ }
+ else if (insn == 0157774) /* addal #WW, sp */
+ val = read_memory_integer (pc + 2, 4);
+ val >>= 2;
+ return val;
+}
+
+int
+delta68_frame_num_args (struct frame_info *fi)
+{
+ int val;
+ CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
+ int insn = read_memory_unsigned_integer (pc, 2);
+ val = 0;
+ if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
+ val = read_memory_integer (pc + 2, 2);
+ else if ((insn & 0170777) == 0050217 /* addql #N, sp */
+ || (insn & 0170777) == 0050117) /* addqw */
+ {
+ val = (insn >> 9) & 7;
+ if (val == 0)
+ val = 8;
+ }
+ else if (insn == 0157774) /* addal #WW, sp */
+ val = read_memory_integer (pc + 2, 4);
+ val >>= 2;
+ return val;
+}
+
+int
+news_frame_num_args (struct frame_info *fi)
+{
+ int val;
+ CORE_ADDR pc = DEPRECATED_FRAME_SAVED_PC (fi);
+ int insn = read_memory_unsigned_integer (pc, 2);
+ val = 0;
+ if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */
+ val = read_memory_integer (pc + 2, 2);
+ else if ((insn & 0170777) == 0050217 /* addql #N, sp */
+ || (insn & 0170777) == 0050117) /* addqw */
+ {
+ val = (insn >> 9) & 7;
+ if (val == 0)
+ val = 8;
+ }
+ else if (insn == 0157774) /* addal #WW, sp */
+ val = read_memory_integer (pc + 2, 4);
+ val >>= 2;
+ return val;
+}
+
+/* Insert the specified number of args and function address
+ into a call sequence of the above form stored at DUMMYNAME.
+ We use the BFD routines to store a big-endian value of known size. */
+
+void
+m68k_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
+ struct value **args, struct type *type, int gcc_p)
+{
+ bfd_putb32 (fun, (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 2);
+ bfd_putb32 (nargs * 4,
+ (unsigned char *) dummy + CALL_DUMMY_START_OFFSET + 8);
+}
+
+