gdb/microblaze-tdep.c - gdb
Global variables defined
Functions defined
Macros defined
Source code
- #include "defs.h"
- #include "arch-utils.h"
- #include "dis-asm.h"
- #include "frame.h"
- #include "trad-frame.h"
- #include "symtab.h"
- #include "value.h"
- #include "gdbcmd.h"
- #include "breakpoint.h"
- #include "inferior.h"
- #include "regcache.h"
- #include "target.h"
- #include "frame-base.h"
- #include "frame-unwind.h"
- #include "dwarf2-frame.h"
- #include "osabi.h"
- #include "target-descriptions.h"
- #include "opcodes/microblaze-opcm.h"
- #include "opcodes/microblaze-dis.h"
- #include "microblaze-tdep.h"
- #include "remote.h"
- #include "features/microblaze-with-stack-protect.c"
- #include "features/microblaze.c"
- #define IS_RETURN(op) (op == rtsd || op == rtid)
- #define IS_UPDATE_SP(op, rd, ra) \
- ((op == addik || op == addi) && rd == REG_SP && ra == REG_SP)
- #define IS_SPILL_SP(op, rd, ra) \
- ((op == swi || op == sw) && rd == REG_SP && ra == REG_SP)
- #define IS_SPILL_REG(op, rd, ra) \
- ((op == swi || op == sw) && rd != REG_SP && ra == REG_SP)
- #define IS_ALSO_SPILL_REG(op, rd, ra, rb) \
- ((op == swi || op == sw) && rd != REG_SP && ra == 0 && rb == REG_SP)
- #define IS_SETUP_FP(op, ra, rb) \
- ((op == add || op == addik || op == addk) && ra == REG_SP && rb == 0)
- #define IS_SPILL_REG_FP(op, rd, ra, fpregnum) \
- ((op == swi || op == sw) && rd != REG_SP && ra == fpregnum && ra != 0)
- #define IS_SAVE_HIDDEN_PTR(op, rd, ra, rb) \
- ((op == add || op == addik) && ra == MICROBLAZE_FIRST_ARGREG && rb == 0)
- static const char *microblaze_register_names[] =
- {
- "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
- "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
- "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
- "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
- "rpc", "rmsr", "rear", "resr", "rfsr", "rbtr",
- "rpvr0", "rpvr1", "rpvr2", "rpvr3", "rpvr4", "rpvr5", "rpvr6",
- "rpvr7", "rpvr8", "rpvr9", "rpvr10", "rpvr11",
- "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi",
- "rslr", "rshr"
- };
- #define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
- static unsigned int microblaze_debug_flag = 0;
- static void
- microblaze_debug (const char *fmt, ...)
- {
- if (microblaze_debug_flag)
- {
- va_list args;
- va_start (args, fmt);
- printf_unfiltered ("MICROBLAZE: ");
- vprintf_unfiltered (fmt, args);
- va_end (args);
- }
- }
- static const char *
- microblaze_register_name (struct gdbarch *gdbarch, int regnum)
- {
- if (regnum >= 0 && regnum < MICROBLAZE_NUM_REGS)
- return microblaze_register_names[regnum];
- return NULL;
- }
- static struct type *
- microblaze_register_type (struct gdbarch *gdbarch, int regnum)
- {
- if (regnum == MICROBLAZE_SP_REGNUM)
- return builtin_type (gdbarch)->builtin_data_ptr;
- if (regnum == MICROBLAZE_PC_REGNUM)
- return builtin_type (gdbarch)->builtin_func_ptr;
- return builtin_type (gdbarch)->builtin_int;
- }
- static unsigned long
- microblaze_fetch_instruction (CORE_ADDR pc)
- {
- enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
- gdb_byte buf[4];
-
- if (target_read_code (pc, buf, sizeof (buf)))
- return 0;
- return extract_unsigned_integer (buf, 4, byte_order);
- }
- static CORE_ADDR
- microblaze_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
- CORE_ADDR funcaddr,
- struct value **args, int nargs,
- struct type *value_type,
- CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
- struct regcache *regcache)
- {
- error (_("push_dummy_code not implemented"));
- return sp;
- }
- static CORE_ADDR
- microblaze_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, CORE_ADDR struct_addr)
- {
- error (_("store_arguments not implemented"));
- return sp;
- }
- static const gdb_byte *
- microblaze_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc,
- int *len)
- {
- static gdb_byte break_insn[] = MICROBLAZE_BREAKPOINT;
- *len = sizeof (break_insn);
- return break_insn;
- }
- static struct microblaze_frame_cache *
- microblaze_alloc_frame_cache (void)
- {
- struct microblaze_frame_cache *cache;
- cache = FRAME_OBSTACK_ZALLOC (struct microblaze_frame_cache);
-
- cache->base = 0;
- cache->pc = 0;
-
- cache->frameless_p = 1;
- return cache;
- }
- #define MICROBLAZE_MY_FRAME_IN_SP 0x1
- #define MICROBLAZE_MY_FRAME_IN_FP 0x2
- static CORE_ADDR
- microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
- CORE_ADDR current_pc,
- struct microblaze_frame_cache *cache)
- {
- const char *name;
- CORE_ADDR func_addr, func_end, addr, stop, prologue_end_addr = 0;
- unsigned long insn;
- int rd, ra, rb, imm;
- enum microblaze_instr op;
- int flags = 0;
- int save_hidden_pointer_found = 0;
- int non_stack_instruction_found = 0;
-
- find_pc_partial_function (pc, &name, &func_addr, &func_end);
- if (func_addr < pc)
- pc = func_addr;
- if (current_pc < pc)
- return current_pc;
-
- cache->framesize = 0;
- cache->fp_regnum = MICROBLAZE_SP_REGNUM;
- cache->frameless_p = 1;
-
-
- insn = microblaze_fetch_instruction (pc);
- op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
- if (IS_RETURN(op))
- return pc;
-
- stop = (current_pc < func_end ? current_pc : func_end);
- microblaze_debug ("Scanning prologue: name=%s, func_addr=%s, stop=%s\n",
- name, paddress (gdbarch, func_addr),
- paddress (gdbarch, stop));
- for (addr = func_addr; addr < stop; addr += INST_WORD_SIZE)
- {
- insn = microblaze_fetch_instruction (addr);
- op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
- microblaze_debug ("%s %08lx\n", paddress (gdbarch, pc), insn);
-
- if (IS_UPDATE_SP(op, rd, ra))
- {
- microblaze_debug ("got addi r1,r1,%d; contnuing\n", imm);
- if (cache->framesize)
- break;
- cache->framesize = -imm;
- cache->frameless_p = 0;
- save_hidden_pointer_found = 0;
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_SPILL_SP(op, rd, ra))
- {
-
- cache->register_offsets[rd] = imm;
- microblaze_debug ("swi r1 r1 %d, continuing\n", imm);
- save_hidden_pointer_found = 0;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_SPILL_REG(op, rd, ra))
- {
-
- cache->register_offsets[rd] = imm - cache->framesize;
- microblaze_debug ("swi %d r1 %d, continuing\n", rd, imm);
- save_hidden_pointer_found = 0;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_ALSO_SPILL_REG(op, rd, ra, rb))
- {
-
- cache->register_offsets[rd] = 0 - cache->framesize;
- microblaze_debug ("sw %d r0 r1, continuing\n", rd);
- save_hidden_pointer_found = 0;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_SETUP_FP(op, ra, rb))
- {
-
- flags |= MICROBLAZE_MY_FRAME_IN_FP;
- flags &= ~MICROBLAZE_MY_FRAME_IN_SP;
- cache->fp_regnum = rd;
- microblaze_debug ("Found a frame pointer: r%d\n", cache->fp_regnum);
- save_hidden_pointer_found = 0;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_SPILL_REG_FP(op, rd, ra, cache->fp_regnum))
- {
-
- cache->register_offsets[rd] = imm - cache->framesize;
- microblaze_debug ("swi %d %d %d, continuing\n", rd, ra, imm);
- save_hidden_pointer_found = 0;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
- else if (IS_SAVE_HIDDEN_PTR(op, rd, ra, rb))
- {
-
- microblaze_debug ("add %d %d %d, continuing\n", rd, ra, rb);
- save_hidden_pointer_found = 1;
- if (!cache->framesize)
- non_stack_instruction_found = 0;
- continue;
- }
-
- if (!non_stack_instruction_found)
- prologue_end_addr = addr;
- non_stack_instruction_found = 1;
-
- {
- unsigned op = (unsigned)insn >> 26;
-
- if (op != 0x26 && op != 0x27 && op != 0x2d && op != 0x2e && op != 0x2f)
- continue;
- else if (op == 0x2c)
- continue;
- }
-
- microblaze_debug ("insn is not a prologue insn -- ending scan\n");
- break;
- }
- microblaze_debug ("done analyzing prologue\n");
- microblaze_debug ("prologue end = 0x%x\n", (int) addr);
-
- if (save_hidden_pointer_found)
- prologue_end_addr -= INST_WORD_SIZE;
- return prologue_end_addr;
- }
- static CORE_ADDR
- microblaze_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
- {
- gdb_byte buf[4];
- CORE_ADDR pc;
- frame_unwind_register (next_frame, MICROBLAZE_PC_REGNUM, buf);
- pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
-
- if (frame_relative_level (next_frame) >= 0)
- pc += 8;
- return pc;
- }
- static CORE_ADDR
- microblaze_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
- {
- struct symtab_and_line sal;
- CORE_ADDR func_start, func_end, ostart_pc;
- struct microblaze_frame_cache cache;
-
- if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
- {
- sal = find_pc_line (func_start, 0);
- if (sal.end < func_end
- && start_pc <= sal.end)
- start_pc = sal.end;
- }
- ostart_pc = microblaze_analyze_prologue (gdbarch, func_start, 0xffffffffUL,
- &cache);
- if (ostart_pc > start_pc)
- return ostart_pc;
- return start_pc;
- }
- static struct microblaze_frame_cache *
- microblaze_frame_cache (struct frame_info *next_frame, void **this_cache)
- {
- struct microblaze_frame_cache *cache;
- struct gdbarch *gdbarch = get_frame_arch (next_frame);
- CORE_ADDR func;
- int rn;
- if (*this_cache)
- return *this_cache;
- cache = microblaze_alloc_frame_cache ();
- *this_cache = cache;
- cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
-
- for (rn = 0; rn < gdbarch_num_regs (gdbarch); rn++)
- cache->register_offsets[rn] = -1;
- func = get_frame_func (next_frame);
- cache->pc = get_frame_address_in_block (next_frame);
- return cache;
- }
- static void
- microblaze_frame_this_id (struct frame_info *next_frame, void **this_cache,
- struct frame_id *this_id)
- {
- struct microblaze_frame_cache *cache =
- microblaze_frame_cache (next_frame, this_cache);
-
- if (cache->base == 0)
- return;
- (*this_id) = frame_id_build (cache->base, cache->pc);
- }
- static struct value *
- microblaze_frame_prev_register (struct frame_info *this_frame,
- void **this_cache, int regnum)
- {
- struct microblaze_frame_cache *cache =
- microblaze_frame_cache (this_frame, this_cache);
- if (cache->frameless_p)
- {
- if (regnum == MICROBLAZE_PC_REGNUM)
- regnum = 15;
- if (regnum == MICROBLAZE_SP_REGNUM)
- regnum = 1;
- return trad_frame_get_prev_register (this_frame,
- cache->saved_regs, regnum);
- }
- else
- return trad_frame_get_prev_register (this_frame, cache->saved_regs,
- regnum);
- }
- static const struct frame_unwind microblaze_frame_unwind =
- {
- NORMAL_FRAME,
- default_frame_unwind_stop_reason,
- microblaze_frame_this_id,
- microblaze_frame_prev_register,
- NULL,
- default_frame_sniffer
- };
- static CORE_ADDR
- microblaze_frame_base_address (struct frame_info *next_frame,
- void **this_cache)
- {
- struct microblaze_frame_cache *cache =
- microblaze_frame_cache (next_frame, this_cache);
- return cache->base;
- }
- static const struct frame_base microblaze_frame_base =
- {
- µblaze_frame_unwind,
- microblaze_frame_base_address,
- microblaze_frame_base_address,
- microblaze_frame_base_address
- };
- static void
- microblaze_extract_return_value (struct type *type, struct regcache *regcache,
- gdb_byte *valbuf)
- {
- gdb_byte buf[8];
-
- switch (TYPE_LENGTH (type))
- {
- case 1:
- regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
- memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 1, 1);
- return;
- case 2:
- regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
- memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 2, 2);
- return;
- case 4:
- case 8:
- regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
- regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM+1, buf+4);
- memcpy (valbuf, buf, TYPE_LENGTH (type));
- return;
- default:
- internal_error (__FILE__, __LINE__,
- _("Unsupported return value size requested"));
- }
- }
- static void
- microblaze_store_return_value (struct type *type, struct regcache *regcache,
- const gdb_byte *valbuf)
- {
- int len = TYPE_LENGTH (type);
- gdb_byte buf[8];
- memset (buf, 0, sizeof(buf));
-
- if (len > 4)
- {
- gdb_assert (len == 8);
- memcpy (buf, valbuf, 8);
- regcache_cooked_write (regcache, MICROBLAZE_RETVAL_REGNUM+1, buf + 4);
- }
- else
-
- memcpy (buf + 4 - len, valbuf, len);
- regcache_cooked_write (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
- }
- static enum return_value_convention
- microblaze_return_value (struct gdbarch *gdbarch, struct value *function,
- struct type *type, struct regcache *regcache,
- gdb_byte *readbuf, const gdb_byte *writebuf)
- {
- if (readbuf)
- microblaze_extract_return_value (type, regcache, readbuf);
- if (writebuf)
- microblaze_store_return_value (type, regcache, writebuf);
- return RETURN_VALUE_REGISTER_CONVENTION;
- }
- static int
- microblaze_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
- {
- return (TYPE_LENGTH (type) == 16);
- }
- static void
- microblaze_write_pc (struct regcache *regcache, CORE_ADDR pc)
- {
- regcache_cooked_write_unsigned (regcache, MICROBLAZE_PC_REGNUM, pc);
- }
- static int dwarf2_to_reg_map[78] =
- { 0 , 1 , 2 , 3 ,
- 4 , 5 , 6 , 7 ,
- 8 , 9 , 10 , 11 ,
- 12 , 13 , 14 , 15 ,
- 16 , 17 , 18 , 19 ,
- 20 , 21 , 22 , 23 ,
- 24 , 25 , 26 , 27 ,
- 28 , 29 , 30 , 31 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , 33 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1 , -1 , -1 ,
- -1 , -1
- };
- static int
- microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
- {
- gdb_assert ((size_t) reg < sizeof (dwarf2_to_reg_map));
- return dwarf2_to_reg_map[reg];
- }
- static void
- microblaze_register_g_packet_guesses (struct gdbarch *gdbarch)
- {
- register_remote_g_packet_guess (gdbarch,
- 4 * MICROBLAZE_NUM_CORE_REGS,
- tdesc_microblaze);
- register_remote_g_packet_guess (gdbarch,
- 4 * MICROBLAZE_NUM_REGS,
- tdesc_microblaze_with_stack_protect);
- }
- static struct gdbarch *
- microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
- {
- struct gdbarch_tdep *tdep;
- struct gdbarch *gdbarch;
- struct tdesc_arch_data *tdesc_data = NULL;
- const struct target_desc *tdesc = info.target_desc;
-
- arches = gdbarch_list_lookup_by_info (arches, &info);
- if (arches != NULL)
- return arches->gdbarch;
- if (tdesc == NULL)
- tdesc = tdesc_microblaze;
-
- if (tdesc_has_registers (tdesc))
- {
- const struct tdesc_feature *feature;
- int valid_p;
- int i;
- feature = tdesc_find_feature (tdesc,
- "org.gnu.gdb.microblaze.core");
- if (feature == NULL)
- return NULL;
- tdesc_data = tdesc_data_alloc ();
- valid_p = 1;
- for (i = 0; i < MICROBLAZE_NUM_CORE_REGS; i++)
- valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
- microblaze_register_names[i]);
- feature = tdesc_find_feature (tdesc,
- "org.gnu.gdb.microblaze.stack-protect");
- if (feature != NULL)
- {
- valid_p = 1;
- valid_p &= tdesc_numbered_register (feature, tdesc_data,
- MICROBLAZE_SLR_REGNUM,
- "rslr");
- valid_p &= tdesc_numbered_register (feature, tdesc_data,
- MICROBLAZE_SHR_REGNUM,
- "rshr");
- }
- if (!valid_p)
- {
- tdesc_data_cleanup (tdesc_data);
- return NULL;
- }
- }
-
- tdep = XNEW (struct gdbarch_tdep);
- gdbarch = gdbarch_alloc (&info, tdep);
- set_gdbarch_long_double_bit (gdbarch, 128);
- set_gdbarch_num_regs (gdbarch, MICROBLAZE_NUM_REGS);
- set_gdbarch_register_name (gdbarch, microblaze_register_name);
- set_gdbarch_register_type (gdbarch, microblaze_register_type);
-
- set_gdbarch_sp_regnum (gdbarch, MICROBLAZE_SP_REGNUM);
- set_gdbarch_pc_regnum (gdbarch, MICROBLAZE_PC_REGNUM);
-
- set_gdbarch_dwarf2_reg_to_regnum (gdbarch, microblaze_dwarf2_reg_to_regnum);
-
- set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
- set_gdbarch_push_dummy_code (gdbarch, microblaze_push_dummy_code);
- set_gdbarch_push_dummy_call (gdbarch, microblaze_push_dummy_call);
- set_gdbarch_return_value (gdbarch, microblaze_return_value);
- set_gdbarch_stabs_argument_has_addr
- (gdbarch, microblaze_stabs_argument_has_addr);
- set_gdbarch_skip_prologue (gdbarch, microblaze_skip_prologue);
-
- set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
- set_gdbarch_breakpoint_from_pc (gdbarch, microblaze_breakpoint_from_pc);
- set_gdbarch_frame_args_skip (gdbarch, 8);
- set_gdbarch_print_insn (gdbarch, print_insn_microblaze);
- set_gdbarch_write_pc (gdbarch, microblaze_write_pc);
- set_gdbarch_unwind_pc (gdbarch, microblaze_unwind_pc);
- microblaze_register_g_packet_guesses (gdbarch);
- frame_base_set_default (gdbarch, µblaze_frame_base);
-
- gdbarch_init_osabi (info, gdbarch);
-
- dwarf2_append_unwinders (gdbarch);
- frame_unwind_append_unwinder (gdbarch, µblaze_frame_unwind);
- frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
- if (tdesc_data != NULL)
- tdesc_use_registers (gdbarch, tdesc, tdesc_data);
- return gdbarch;
- }
- void _initialize_microblaze_tdep (void);
- void
- _initialize_microblaze_tdep (void)
- {
- register_gdbarch_init (bfd_arch_microblaze, microblaze_gdbarch_init);
- initialize_tdesc_microblaze_with_stack_protect ();
- initialize_tdesc_microblaze ();
-
- add_setshow_zuinteger_cmd ("microblaze", class_maintenance,
- µblaze_debug_flag, _("\
- Set microblaze debugging."), _("\
- Show microblaze debugging."), _("\
- When non-zero, microblaze specific debugging is enabled."),
- NULL,
- NULL,
- &setdebuglist, &showdebuglist);
- }