/* Target-dependent code for Mitsubishi D10V, for GDB.
- Copyright 1996, 1997, 1998, 1999, 2000, 2001
- Free Software Foundation, Inc.
+
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
+ Foundation, Inc.
This file is part of GDB.
#include "floatformat.h"
#include "sim-d10v.h"
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
struct frame_extra_info
{
CORE_ADDR return_pc;
/* These are the addresses the D10V-EVA board maps data and
instruction memory to. */
-#define DMEM_START 0x2000000
-#define IMEM_START 0x1000000
-#define STACK_START 0x0007ffe
+enum memspace {
+ DMEM_START = 0x2000000,
+ IMEM_START = 0x1000000,
+ STACK_START = 0x200bffe
+};
/* d10v register names. */
enum
{
R0_REGNUM = 0,
+ R3_REGNUM = 3,
+ _FP_REGNUM = 11,
LR_REGNUM = 13,
+ _SP_REGNUM = 15,
PSW_REGNUM = 16,
+ _PC_REGNUM = 18,
NR_IMAP_REGS = 2,
- NR_A_REGS = 2
+ NR_A_REGS = 2,
+ TS2_NUM_REGS = 37,
+ TS3_NUM_REGS = 42,
+ /* d10v calling convention. */
+ ARG1_REGNUM = R0_REGNUM,
+ ARGN_REGNUM = R3_REGNUM,
+ RET1_REGNUM = R0_REGNUM,
};
+
#define NR_DMAP_REGS (gdbarch_tdep (current_gdbarch)->nr_dmap_regs)
#define A0_REGNUM (gdbarch_tdep (current_gdbarch)->a0_regnum)
-/* d10v calling convention. */
-
-#define ARG1_REGNUM R0_REGNUM
-#define ARGN_REGNUM 3
-#define RET1_REGNUM R0_REGNUM
-
/* Local functions */
extern void _initialize_d10v_tdep (void);
static int
d10v_frame_chain_valid (CORE_ADDR chain, struct frame_info *frame)
{
- return ((chain) != 0 && (frame) != 0 && (frame)->pc > IMEM_START);
+ if (chain != 0 && frame != NULL)
+ {
+ if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
+ return 1; /* Path back from a call dummy must be valid. */
+ return ((frame)->pc > IMEM_START
+ && !inside_main_func (frame->pc));
+ }
+ else return 0;
}
static CORE_ADDR
static int
d10v_use_struct_convention (int gcc_p, struct type *type)
{
- return (TYPE_LENGTH (type) > 8);
+ long alignment;
+ int i;
+ /* The d10v only passes a struct in a register when that structure
+ has an alignment that matches the size of a register. */
+ /* If the structure doesn't fit in 4 registers, put it on the
+ stack. */
+ if (TYPE_LENGTH (type) > 8)
+ return 1;
+ /* If the struct contains only one field, don't put it on the stack
+ - gcc can fit it in one or more registers. */
+ if (TYPE_NFIELDS (type) == 1)
+ return 0;
+ alignment = TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
+ for (i = 1; i < TYPE_NFIELDS (type); i++)
+ {
+ /* If the alignment changes, just assume it goes on the
+ stack. */
+ if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)) != alignment)
+ return 1;
+ }
+ /* If the alignment is suitable for the d10v's 16 bit registers,
+ don't put it on the stack. */
+ if (alignment == 2 || alignment == 4)
+ return 0;
+ return 1;
}
-static unsigned char *
+static const unsigned char *
d10v_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
{
static unsigned char breakpoint[] =
return 2;
}
-/* Number of bytes of storage in the program's representation
- for register N. */
-
-static int
-d10v_register_virtual_size (int reg_nr)
-{
- return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (reg_nr));
-}
-
/* Return the GDB type object for the "standard" data type
of data in register N. */
return builtin_type_int16;
}
-static CORE_ADDR
-d10v_make_daddr (CORE_ADDR x)
-{
- return ((x) | DMEM_START);
-}
-
-static CORE_ADDR
-d10v_make_iaddr (CORE_ADDR x)
-{
- return (((x) << 2) | IMEM_START);
-}
-
static int
d10v_daddr_p (CORE_ADDR x)
{
return (((x) & 0x3000000) == IMEM_START);
}
+static CORE_ADDR
+d10v_make_daddr (CORE_ADDR x)
+{
+ return ((x) | DMEM_START);
+}
+
+static CORE_ADDR
+d10v_make_iaddr (CORE_ADDR x)
+{
+ if (d10v_iaddr_p (x))
+ return x; /* Idempotency -- x is already in the IMEM space. */
+ else
+ return (((x) << 2) | IMEM_START);
+}
static CORE_ADDR
d10v_convert_iaddr_to_raw (CORE_ADDR x)
if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
{
-#if 0
- if (! d10v_iaddr_p (addr))
- {
- warning_begin ();
- fprintf_unfiltered (gdb_stderr, "address `");
- print_address_numeric (addr, 1, gdb_stderr);
- fprintf_unfiltered (gdb_stderr, "' is not a code address\n");
- }
-#endif
-
store_unsigned_integer (buf, TYPE_LENGTH (type),
d10v_convert_iaddr_to_raw (addr));
}
/* Is it a code address? */
if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
- || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD ||
- (TYPE_FLAGS (TYPE_TARGET_TYPE (type)) & TYPE_FLAG_CODE_SPACE) != 0)
+ || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
+ || TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
return d10v_make_iaddr (addr);
else
return d10v_make_daddr (addr);
static CORE_ADDR
d10v_frame_saved_pc (struct frame_info *frame)
{
- return ((frame)->extra_info->return_pc);
+ if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
+ return d10v_make_iaddr (generic_read_register_dummy (frame->pc,
+ frame->frame,
+ PC_REGNUM));
+ else
+ return ((frame)->extra_info->return_pc);
}
/* Immediately after a function call, return the saved pc. We can't
static CORE_ADDR
d10v_frame_chain (struct frame_info *fi)
{
+ CORE_ADDR addr;
+
+ /* A generic call dummy's frame is the same as caller's. */
+ if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
+ return fi->frame;
+
d10v_frame_init_saved_regs (fi);
+
if (fi->extra_info->return_pc == IMEM_START
|| inside_entry_file (fi->extra_info->return_pc))
- return (CORE_ADDR) 0;
+ {
+ /* This is meant to halt the backtrace at "_start".
+ Make sure we don't halt it at a generic dummy frame. */
+ if (!PC_IN_CALL_DUMMY (fi->extra_info->return_pc, 0, 0))
+ return (CORE_ADDR) 0;
+ }
if (!fi->saved_regs[FP_REGNUM])
{
return fi->saved_regs[SP_REGNUM];
}
- if (!read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
- REGISTER_RAW_SIZE (FP_REGNUM)))
+ addr = read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
+ REGISTER_RAW_SIZE (FP_REGNUM));
+ if (addr == 0)
return (CORE_ADDR) 0;
- return d10v_make_daddr (read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM],
- REGISTER_RAW_SIZE (FP_REGNUM)));
+ return d10v_make_daddr (addr);
}
static int next_addr, uses_frame;
op1 = (op & 0x3FFF8000) >> 15;
op2 = op & 0x7FFF;
}
- if (!prologue_find_regs (op1, fi, pc) || !prologue_find_regs (op2, fi, pc))
+ if (!prologue_find_regs (op1, fi, pc)
+ || !prologue_find_regs (op2, fi, pc))
break;
}
pc += 4;
if (fi->saved_regs[LR_REGNUM])
{
- CORE_ADDR return_pc = read_memory_unsigned_integer (fi->saved_regs[LR_REGNUM], REGISTER_RAW_SIZE (LR_REGNUM));
+ CORE_ADDR return_pc
+ = read_memory_unsigned_integer (fi->saved_regs[LR_REGNUM],
+ REGISTER_RAW_SIZE (LR_REGNUM));
fi->extra_info->return_pc = d10v_make_iaddr (return_pc);
}
else
fi->extra_info->return_pc = d10v_make_iaddr (read_register (LR_REGNUM));
}
- /* th SP is not normally (ever?) saved, but check anyway */
+ /* The SP is not normally (ever?) saved, but check anyway */
if (!fi->saved_regs[SP_REGNUM])
{
/* if the FP was saved, that means the current FP is valid, */
/* otherwise, it isn't being used, so we use the SP instead */
if (uses_frame)
- fi->saved_regs[SP_REGNUM] = read_register (FP_REGNUM) + fi->extra_info->size;
+ fi->saved_regs[SP_REGNUM]
+ = read_register (FP_REGNUM) + fi->extra_info->size;
else
{
fi->saved_regs[SP_REGNUM] = fp + fi->extra_info->size;
fi->extra_info->size = 0;
fi->extra_info->return_pc = 0;
+ /* If fi->pc is zero, but this is not the outermost frame,
+ then let's snatch the return_pc from the callee, so that
+ PC_IN_CALL_DUMMY will work. */
+ if (fi->pc == 0 && fi->level != 0 && fi->next != NULL)
+ fi->pc = d10v_frame_saved_pc (fi->next);
+
/* The call dummy doesn't save any registers on the stack, so we can
return now. */
if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
write_register (SP_REGNUM, d10v_convert_daddr_to_raw (val));
}
-static void
-d10v_write_fp (CORE_ADDR val)
-{
- write_register (FP_REGNUM, d10v_convert_daddr_to_raw (val));
-}
-
static CORE_ADDR
d10v_read_fp (void)
{
struct type *type = check_typedef (VALUE_TYPE (arg));
char *contents = VALUE_CONTENTS (arg);
int len = TYPE_LENGTH (type);
- /* printf ("push: type=%d len=%d\n", type->code, len); */
+ /* printf ("push: type=%d len=%d\n", TYPE_CODE (type), len); */
{
int aligned_regnum = (regnum + 1) & ~1;
if (len <= 2 && regnum <= ARGN_REGNUM)
char *valbuf)
{
int len;
- /* printf("RET: TYPE=%d len=%d r%d=0x%x\n",type->code, TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM, (int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM))); */
+ /* printf("RET: TYPE=%d len=%d r%d=0x%x\n", TYPE_CODE (type), TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM, (int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM))); */
{
len = TYPE_LENGTH (type);
if (len == 1)
internal_error (__FILE__, __LINE__,
"print_insn: no disassembler");
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
tm_print_insn_info.endian = BFD_ENDIAN_BIG;
else
tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
set_gdbarch_read_pc (gdbarch, d10v_read_pc);
set_gdbarch_write_pc (gdbarch, d10v_write_pc);
set_gdbarch_read_fp (gdbarch, d10v_read_fp);
- set_gdbarch_write_fp (gdbarch, d10v_write_fp);
set_gdbarch_read_sp (gdbarch, d10v_read_sp);
set_gdbarch_write_sp (gdbarch, d10v_write_sp);
set_gdbarch_register_byte (gdbarch, d10v_register_byte);
set_gdbarch_register_raw_size (gdbarch, d10v_register_raw_size);
set_gdbarch_max_register_raw_size (gdbarch, 8);
- set_gdbarch_register_virtual_size (gdbarch, d10v_register_virtual_size);
+ set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
set_gdbarch_max_register_virtual_size (gdbarch, 8);
set_gdbarch_register_virtual_type (gdbarch, d10v_register_virtual_type);
set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
- set_gdbarch_long_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
+ set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
/* NOTE: The d10v as a 32 bit ``float'' and ``double''. ``long
double'' is 64 bits. */
set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
switch (info.byte_order)
{
- case BIG_ENDIAN:
+ case BFD_ENDIAN_BIG:
set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_big);
set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_big);
set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
break;
- case LITTLE_ENDIAN:
+ case BFD_ENDIAN_LITTLE:
set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_little);
set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_little);
set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_little);