windows-nat: Cleanups in get_windows_debug_event
[deliverable/binutils-gdb.git] / gdb / microblaze-tdep.c
index ca6d1297bbacb5b209c5ce79ddee987139336818..d66914e2a3e11788c312876a6f4edbe82f289ca1 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for Xilinx MicroBlaze.
 
-   Copyright 2009-2012 Free Software Foundation, Inc.
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "inferior.h"
 #include "regcache.h"
 #include "target.h"
-#include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
 #include "dwarf2-frame.h"
 #include "osabi.h"
-
-#include "gdb_assert.h"
-#include "gdb_string.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"
 \f
 /* Instruction macros used for analyzing the prologue.  */
 /* This set of instruction macros need to be changed whenever the
@@ -74,14 +74,15 @@ static const char *microblaze_register_names[] =
   "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"
+  "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi",
+  "rslr", "rshr"
 };
 
 #define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
 \f
-static int microblaze_debug_flag = 0;
+static unsigned int microblaze_debug_flag = 0;
 
-void
+static void
 microblaze_debug (const char *fmt, ...)
 { 
   if (microblaze_debug_flag)
@@ -120,14 +121,14 @@ microblaze_register_type (struct gdbarch *gdbarch, int regnum)
 \f
 /* Fetch the instruction at PC.  */
 
-unsigned long
+static unsigned long
 microblaze_fetch_instruction (CORE_ADDR pc)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   gdb_byte buf[4];
 
   /* If we can't read the instruction at PC, return zero.  */
-  if (target_read_memory (pc, buf, sizeof (buf)))
+  if (target_read_code (pc, buf, sizeof (buf)))
     return 0;
 
   return extract_unsigned_integer (buf, 4, byte_order);
@@ -173,7 +174,6 @@ static struct microblaze_frame_cache *
 microblaze_alloc_frame_cache (void)
 {
   struct microblaze_frame_cache *cache;
-  int i;
 
   cache = FRAME_OBSTACK_ZALLOC (struct microblaze_frame_cache);
 
@@ -231,7 +231,7 @@ microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
   const char *name;
   CORE_ADDR func_addr, func_end, addr, stop, prologue_end_addr = 0;
   unsigned long insn;
-  int rn, rd, ra, rb, imm;
+  int rd, ra, rb, imm;
   enum microblaze_instr op;
   int flags = 0;
   int save_hidden_pointer_found = 0;
@@ -426,7 +426,7 @@ microblaze_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
 /* Return PC of first real instruction of the function starting at
    START_PC.  */
 
-CORE_ADDR
+static CORE_ADDR
 microblaze_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 {
   struct symtab_and_line sal;
@@ -456,12 +456,12 @@ microblaze_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
 
 /* Normal frames.  */
 
-struct microblaze_frame_cache *
+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, pc, fp;
+  CORE_ADDR func;
   int rn;
 
   if (*this_cache)
@@ -562,6 +562,7 @@ microblaze_extract_return_value (struct type *type, struct regcache *regcache,
        memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 1, 1);
        return;
       case 2:  /* return last 2 bytes in register.  */
+       regcache_cooked_read (regcache, MICROBLAZE_RETVAL_REGNUM, buf);
        memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 2, 2);
        return;
       case 4:  /* for sizes 4 or 8, copy the required length.  */
@@ -611,7 +612,7 @@ microblaze_store_return_value (struct type *type, struct regcache *regcache,
 }
 
 static enum return_value_convention
-microblaze_return_value (struct gdbarch *gdbarch, struct type *func_type,
+microblaze_return_value (struct gdbarch *gdbarch, struct value *function,
                         struct type *type, struct regcache *regcache,
                         gdb_byte *readbuf, const gdb_byte *writebuf)
 {
@@ -661,23 +662,76 @@ static int dwarf2_to_reg_map[78] =
 static int
 microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
 {
-  gdb_assert (reg < sizeof (dwarf2_to_reg_map));
+  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;
 
   /* If there is already a candidate, use it.  */
   arches = gdbarch_list_lookup_by_info (arches, &info);
   if (arches != NULL)
     return arches->gdbarch;
+  if (tdesc == NULL)
+    tdesc = tdesc_microblaze;
+
+  /* Check any target description for validity.  */
+  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;
+        }
+    }
 
   /* Allocate space for the new architecture.  */
-  tdep = XMALLOC (struct gdbarch_tdep);
+  tdep = XNEW (struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   set_gdbarch_long_double_bit (gdbarch, 128);
@@ -717,6 +771,8 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   set_gdbarch_unwind_pc (gdbarch, microblaze_unwind_pc);
 
+  microblaze_register_g_packet_guesses (gdbarch);
+
   frame_base_set_default (gdbarch, &microblaze_frame_base);
 
   /* Hook in ABI-specific overrides, if they have been registered.  */
@@ -726,6 +782,8 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   dwarf2_append_unwinders (gdbarch);
   frame_unwind_append_unwinder (gdbarch, &microblaze_frame_unwind);
   frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
+  if (tdesc_data != NULL)
+    tdesc_use_registers (gdbarch, tdesc, tdesc_data);
 
   return gdbarch;
 }
@@ -738,14 +796,16 @@ _initialize_microblaze_tdep (void)
 {
   register_gdbarch_init (bfd_arch_microblaze, microblaze_gdbarch_init);
 
+  initialize_tdesc_microblaze_with_stack_protect ();
+  initialize_tdesc_microblaze ();
   /* Debug this files internals.  */
-  add_setshow_zinteger_cmd ("microblaze", class_maintenance,
-                           &microblaze_debug_flag, _("\
+  add_setshow_zuinteger_cmd ("microblaze", class_maintenance,
+                            &microblaze_debug_flag, _("\
 Set microblaze debugging."), _("\
 Show microblaze debugging."), _("\
 When non-zero, microblaze specific debugging is enabled."),
-                           NULL,
-                           NULL, 
-                           &setdebuglist, &showdebuglist);
+                            NULL,
+                            NULL,
+                            &setdebuglist, &showdebuglist);
 
 }
This page took 0.029773 seconds and 4 git commands to generate.