X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fm32r-tdep.c;h=e504f371d755faf99f99a83aa7ad936bdd08b7e0;hb=50a6759f0f541ea965c7330bfbfe335cb8d66af8;hp=f629ca1b5f48086dd4678f67942ad657bf3ce5db;hpb=025bb325db8dce957db69eaf148c5bec373d4bb6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/m32r-tdep.c b/gdb/m32r-tdep.c index f629ca1b5f..e504f371d7 100644 --- a/gdb/m32r-tdep.c +++ b/gdb/m32r-tdep.c @@ -1,7 +1,6 @@ /* Target-dependent code for Renesas M32R, for GDB. - Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, - 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1996-2021 Free Software Foundation, Inc. This file is part of GDB. @@ -26,7 +25,6 @@ #include "gdbtypes.h" #include "gdbcmd.h" #include "gdbcore.h" -#include "gdb_string.h" #include "value.h" #include "inferior.h" #include "symfile.h" @@ -37,14 +35,13 @@ #include "regcache.h" #include "trad-frame.h" #include "dis-asm.h" - -#include "gdb_assert.h" - #include "m32r-tdep.h" +#include -/* Local functions */ +/* The size of the argument registers (r0 - r3) in bytes. */ +#define M32R_ARG_REGISTER_SIZE 4 -extern void _initialize_m32r_tdep (void); +/* Local functions */ static CORE_ADDR m32r_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) @@ -82,10 +79,10 @@ static int m32r_memory_insert_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { - CORE_ADDR addr = bp_tgt->placed_address; + CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address; int val; gdb_byte buf[4]; - gdb_byte *contents_cache = bp_tgt->shadow_contents; + gdb_byte contents_cache[4]; gdb_byte bp_entry[] = { 0x10, 0xf1 }; /* dpt */ /* Save the memory contents. */ @@ -93,7 +90,8 @@ m32r_memory_insert_breakpoint (struct gdbarch *gdbarch, if (val != 0) return val; /* return error */ - bp_tgt->placed_size = bp_tgt->shadow_len = 4; + memcpy (bp_tgt->shadow_contents, contents_cache, 4); + bp_tgt->shadow_len = 4; /* Determine appropriate breakpoint contents and size for this address. */ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) @@ -163,13 +161,25 @@ m32r_memory_remove_breakpoint (struct gdbarch *gdbarch, } /* Write contents. */ - val = target_write_memory (addr & 0xfffffffc, buf, 4); + val = target_write_raw_memory (addr & 0xfffffffc, buf, 4); return val; } +/* Implement the breakpoint_kind_from_pc gdbarch method. */ + +static int +m32r_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) +{ + if ((*pcptr & 3) == 0) + return 4; + else + return 2; +} + +/* Implement the sw_breakpoint_from_kind gdbarch method. */ + static const gdb_byte * -m32r_breakpoint_from_pc (struct gdbarch *gdbarch, - CORE_ADDR *pcptr, int *lenptr) +m32r_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) { static gdb_byte be_bp_entry[] = { 0x10, 0xf1, 0x70, 0x00 @@ -177,41 +187,22 @@ m32r_breakpoint_from_pc (struct gdbarch *gdbarch, static gdb_byte le_bp_entry[] = { 0x00, 0x70, 0xf1, 0x10 }; /* dpt -> nop */ - gdb_byte *bp; + + *size = kind; /* Determine appropriate breakpoint. */ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) - { - if ((*pcptr & 3) == 0) - { - bp = be_bp_entry; - *lenptr = 4; - } - else - { - bp = be_bp_entry; - *lenptr = 2; - } - } + return be_bp_entry; else { - if ((*pcptr & 3) == 0) - { - bp = le_bp_entry; - *lenptr = 4; - } + if (kind == 4) + return le_bp_entry; else - { - bp = le_bp_entry + 2; - *lenptr = 2; - } + return le_bp_entry + 2; } - - return bp; } - -char *m32r_register_names[] = { +static const char * const m32r_register_names[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "fp", "lr", "sp", "psw", "cbr", "spi", "spu", "bpc", "pc", "accl", "acch", @@ -251,9 +242,9 @@ m32r_register_type (struct gdbarch *gdbarch, int reg_nr) static void m32r_store_return_value (struct type *type, struct regcache *regcache, - const void *valbuf) + const gdb_byte *valbuf) { - struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch *gdbarch = regcache->arch (); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); CORE_ADDR regval; int len = TYPE_LENGTH (type); @@ -263,7 +254,7 @@ m32r_store_return_value (struct type *type, struct regcache *regcache, if (len > 4) { - regval = extract_unsigned_integer ((gdb_byte *) valbuf + 4, + regval = extract_unsigned_integer (valbuf + 4, len - 4, byte_order); regcache_cooked_write_unsigned (regcache, RET1_REGNUM + 1, regval); } @@ -302,7 +293,7 @@ decode_prologue (struct gdbarch *gdbarch, break; /* If this is a 32 bit instruction, we dont want to examine its - immediate data as though it were an instruction. */ + immediate data as though it were an instruction. */ if (current_pc & 0x02) { /* Decode this instruction further. */ @@ -357,9 +348,7 @@ decode_prologue (struct gdbarch *gdbarch, if ((insn & 0xf0ff) == 0x207f) { /* st reg, @-sp */ - int regno; framesize += 4; - regno = ((insn >> 8) & 0xf); after_prologue = 0; continue; } @@ -378,7 +367,7 @@ decode_prologue (struct gdbarch *gdbarch, framesize -= stack_adjust; after_prologue = 0; /* A frameless function may have no "mv fp, sp". - In that case, this is the end of the prologue. */ + In that case, this is the end of the prologue. */ after_stack_adjust = current_pc + 2; } continue; @@ -488,7 +477,7 @@ m32r_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) the end of the function. In this case, there probably isn't a prologue. */ { - func_end = min (func_end, func_addr + DEFAULT_SEARCH_LIMIT); + func_end = std::min (func_end, func_addr + DEFAULT_SEARCH_LIMIT); } } else @@ -520,7 +509,7 @@ struct m32r_unwind_cache LONGEST r13_offset; int uses_frame; /* Table indicating the location of each and every register. */ - struct trad_frame_saved_reg *saved_regs; + trad_frame_saved_reg *saved_regs; }; /* Put here the code to store, into fi->saved_regs, the addresses of @@ -536,13 +525,13 @@ m32r_frame_unwind_cache (struct frame_info *this_frame, CORE_ADDR pc, scan_limit; ULONGEST prev_sp; ULONGEST this_base; - unsigned long op, op2; + unsigned long op; int i; struct m32r_unwind_cache *info; if ((*this_prologue_cache)) - return (*this_prologue_cache); + return (struct m32r_unwind_cache *) (*this_prologue_cache); info = FRAME_OBSTACK_ZALLOC (struct m32r_unwind_cache); (*this_prologue_cache) = info; @@ -592,7 +581,7 @@ m32r_frame_unwind_cache (struct frame_info *this_frame, /* st rn, @-sp */ int regno = ((op >> 8) & 0xf); info->sp_offset -= 4; - info->saved_regs[regno].addr = info->sp_offset; + info->saved_regs[regno].set_addr (info->sp_offset); } else if ((op & 0xff00) == 0x4f00) { @@ -621,17 +610,17 @@ m32r_frame_unwind_cache (struct frame_info *this_frame, if (info->uses_frame) { /* The SP was moved to the FP. This indicates that a new frame - was created. Get THIS frame's FP value by unwinding it from - the next frame. */ + was created. Get THIS frame's FP value by unwinding it from + the next frame. */ this_base = get_frame_register_unsigned (this_frame, M32R_FP_REGNUM); /* The FP points at the last saved register. Adjust the FP back - to before the first saved register giving the SP. */ + to before the first saved register giving the SP. */ prev_sp = this_base + info->size; } else { /* Assume that the FP is this frame's SP but with that pushed - stack space added back. */ + stack space added back. */ this_base = get_frame_register_unsigned (this_frame, M32R_SP_REGNUM); prev_sp = this_base + info->size; } @@ -643,8 +632,9 @@ m32r_frame_unwind_cache (struct frame_info *this_frame, /* Adjust all the saved registers so that they contain addresses and not offsets. */ for (i = 0; i < gdbarch_num_regs (get_frame_arch (this_frame)) - 1; i++) - if (trad_frame_addr_p (info->saved_regs, i)) - info->saved_regs[i].addr = (info->prev_sp + info->saved_regs[i].addr); + if (info->saved_regs[i].is_addr ()) + info->saved_regs[i].set_addr (info->prev_sp + + info->saved_regs[i].addr ()); /* The call instruction moves the caller's PC in the callee's LR. Since this is an unwind, do the reverse. Copy the location of LR @@ -654,36 +644,16 @@ m32r_frame_unwind_cache (struct frame_info *this_frame, /* The previous frame's SP needed to be computed. Save the computed value. */ - trad_frame_set_value (info->saved_regs, M32R_SP_REGNUM, prev_sp); + info->saved_regs[M32R_SP_REGNUM].set_value (prev_sp); return info; } -static CORE_ADDR -m32r_read_pc (struct regcache *regcache) -{ - ULONGEST pc; - regcache_cooked_read_unsigned (regcache, M32R_PC_REGNUM, &pc); - return pc; -} - -static void -m32r_write_pc (struct regcache *regcache, CORE_ADDR val) -{ - regcache_cooked_write_unsigned (regcache, M32R_PC_REGNUM, val); -} - -static CORE_ADDR -m32r_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) -{ - return frame_unwind_register_unsigned (next_frame, M32R_SP_REGNUM); -} - - static CORE_ADDR m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, - struct value **args, CORE_ADDR sp, int struct_return, + struct value **args, CORE_ADDR sp, + function_call_return_method return_method, CORE_ADDR struct_addr) { enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); @@ -694,9 +664,8 @@ m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function, enum type_code typecode; CORE_ADDR regval; gdb_byte *val; - gdb_byte valbuf[MAX_REGISTER_SIZE]; + gdb_byte valbuf[M32R_ARG_REGISTER_SIZE]; int len; - int odd_sized_struct; /* First force sp to a 4-byte alignment. */ sp = sp & ~3; @@ -708,7 +677,7 @@ m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* If STRUCT_RETURN is true, then the struct return address (in STRUCT_ADDR) will consume the first argument-passing register. Both adjust the register count and store that value. */ - if (struct_return) + if (return_method == return_method_struct) { regcache_cooked_write_unsigned (regcache, argreg, struct_addr); argreg++; @@ -722,7 +691,7 @@ m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function, for (argnum = 0, stack_offset = 0; argnum < nargs; argnum++) { type = value_type (args[argnum]); - typecode = TYPE_CODE (type); + typecode = type->code (); len = TYPE_LENGTH (type); memset (valbuf, 0, sizeof (valbuf)); @@ -785,30 +754,29 @@ m32r_push_dummy_call (struct gdbarch *gdbarch, struct value *function, static void m32r_extract_return_value (struct type *type, struct regcache *regcache, - void *dst) + gdb_byte *dst) { - struct gdbarch *gdbarch = get_regcache_arch (regcache); + struct gdbarch *gdbarch = regcache->arch (); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - bfd_byte *valbuf = dst; int len = TYPE_LENGTH (type); ULONGEST tmp; /* By using store_unsigned_integer we avoid having to do anything special for small big-endian values. */ regcache_cooked_read_unsigned (regcache, RET1_REGNUM, &tmp); - store_unsigned_integer (valbuf, (len > 4 ? len - 4 : len), byte_order, tmp); + store_unsigned_integer (dst, (len > 4 ? len - 4 : len), byte_order, tmp); /* Ignore return values more than 8 bytes in size because the m32r returns anything more than 8 bytes in the stack. */ if (len > 4) { regcache_cooked_read_unsigned (regcache, RET1_REGNUM + 1, &tmp); - store_unsigned_integer (valbuf + len - 4, 4, byte_order, tmp); + store_unsigned_integer (dst + len - 4, 4, byte_order, tmp); } } static enum return_value_convention -m32r_return_value (struct gdbarch *gdbarch, struct type *func_type, +m32r_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf) { @@ -824,14 +792,6 @@ m32r_return_value (struct gdbarch *gdbarch, struct type *func_type, } } - - -static CORE_ADDR -m32r_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) -{ - return frame_unwind_register_unsigned (next_frame, M32R_PC_REGNUM); -} - /* Given a GDB frame, determine the address of the calling function's frame. This will be used to create a new GDB frame struct. */ @@ -843,7 +803,7 @@ m32r_frame_this_id (struct frame_info *this_frame, = m32r_frame_unwind_cache (this_frame, this_prologue_cache); CORE_ADDR base; CORE_ADDR func; - struct minimal_symbol *msym_stack; + struct bound_minimal_symbol msym_stack; struct frame_id id; /* The FUNC is easy. */ @@ -851,7 +811,7 @@ m32r_frame_this_id (struct frame_info *this_frame, /* Check if the stack is empty. */ msym_stack = lookup_minimal_symbol ("_stack", NULL, NULL); - if (msym_stack && info->base == SYMBOL_VALUE_ADDRESS (msym_stack)) + if (msym_stack.minsym && info->base == BMSYMBOL_VALUE_ADDRESS (msym_stack)) return; /* Hopefully the prologue analysis either correctly determined the @@ -876,6 +836,7 @@ m32r_frame_prev_register (struct frame_info *this_frame, static const struct frame_unwind m32r_frame_unwind = { NORMAL_FRAME, + default_frame_unwind_stop_reason, m32r_frame_this_id, m32r_frame_prev_register, NULL, @@ -897,18 +858,6 @@ static const struct frame_base m32r_frame_base = { m32r_frame_base_address }; -/* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy - frame. The frame ID's base needs to match the TOS value saved by - save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint. */ - -static struct frame_id -m32r_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) -{ - CORE_ADDR sp = get_frame_register_unsigned (this_frame, M32R_SP_REGNUM); - return frame_id_build (sp, get_frame_pc (this_frame)); -} - - static gdbarch_init_ftype m32r_gdbarch_init; static struct gdbarch * @@ -923,14 +872,14 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) return arches->gdbarch; /* Allocate space for the new architecture. */ - tdep = XMALLOC (struct gdbarch_tdep); + tdep = XCNEW (struct gdbarch_tdep); gdbarch = gdbarch_alloc (&info, tdep); - set_gdbarch_read_pc (gdbarch, m32r_read_pc); - set_gdbarch_write_pc (gdbarch, m32r_write_pc); - set_gdbarch_unwind_sp (gdbarch, m32r_unwind_sp); - + set_gdbarch_wchar_bit (gdbarch, 16); + set_gdbarch_wchar_signed (gdbarch, 0); + set_gdbarch_num_regs (gdbarch, M32R_NUM_REGS); + set_gdbarch_pc_regnum (gdbarch, M32R_PC_REGNUM); set_gdbarch_sp_regnum (gdbarch, M32R_SP_REGNUM); set_gdbarch_register_name (gdbarch, m32r_register_name); set_gdbarch_register_type (gdbarch, m32r_register_type); @@ -940,7 +889,8 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_skip_prologue (gdbarch, m32r_skip_prologue); set_gdbarch_inner_than (gdbarch, core_addr_lessthan); - set_gdbarch_breakpoint_from_pc (gdbarch, m32r_breakpoint_from_pc); + set_gdbarch_breakpoint_kind_from_pc (gdbarch, m32r_breakpoint_kind_from_pc); + set_gdbarch_sw_breakpoint_from_kind (gdbarch, m32r_sw_breakpoint_from_kind); set_gdbarch_memory_insert_breakpoint (gdbarch, m32r_memory_insert_breakpoint); set_gdbarch_memory_remove_breakpoint (gdbarch, @@ -950,16 +900,6 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) frame_base_set_default (gdbarch, &m32r_frame_base); - /* Methods for saving / extracting a dummy frame's ID. The ID's - stack address must match the SP value returned by - PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */ - set_gdbarch_dummy_id (gdbarch, m32r_dummy_id); - - /* Return the unwound PC value. */ - set_gdbarch_unwind_pc (gdbarch, m32r_unwind_pc); - - set_gdbarch_print_insn (gdbarch, print_insn_m32r); - /* Hook in ABI-specific overrides, if they have been registered. */ gdbarch_init_osabi (info, gdbarch); @@ -972,8 +912,9 @@ m32r_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) return gdbarch; } +void _initialize_m32r_tdep (); void -_initialize_m32r_tdep (void) +_initialize_m32r_tdep () { register_gdbarch_init (bfd_arch_m32r, m32r_gdbarch_init); }