From 1b2a5986de1db0b279eae4e8ded545dcf40edd3f Mon Sep 17 00:00:00 2001
From: Ajit Kumar Agarwal <ajitkum@xhdspdgnu.(none)>
Date: Tue, 24 Jun 2014 00:49:14 +0530
Subject: [PATCH] [Patch, microblaze]: Fix for remote G Packet message too long error for baremetal.

Prior to version MicroBlaze v8.10.a,EDK 13.1, XMD's gdbserver stub returned 57
registers in response to GDB's G request. Starting with version MicroBlaze
v8.10.a, EDK 13.1, XMD added the slr and shr register, for a count of 59
registers. This patch adds these registers to the expected G response. This patch
fixes the above problem for baremetal and also supports the backward compatibility.

ChangeLog:
2014-06-24  Ajit Agarwal  <ajitkum@xilinx.com>

	* microblaze-tdep.c (microblaze_register_names): Add
	the rshr and rslr register names.
	(microblaze_gdbarch_init): Use of tdesc_has_registers.
	Use of tdesc_find_feature. Use of tdesc_data_alloc.
	Use of tdesc_numbered_register. Use of
	microblaze_register_g_packet_guesses. Use of
	tdesc_use_registers. Use of set_gdbarch_register_type.
	(microblaze_register_g_packet_guesses): New.
	* microblaze-tdep.h (microblaze_reg_num): Add
	field MICROBLAZE_SLR_REGNUM MICROBLAZE_SHR_REGNUM
	MICROBLAZE_NUM_REGS and MICROBLAZE_NUM_CORE_REGS.
	(microblaze_frame_cache): Use of MICROBLAZE_NUM_REGS.
	* features/microblaze-core.xml: New file.
	* features/microblaze-stack-protect.xml: New file.
	* features/microblaze-with-stack-protect.c: New file.
	* features/microblaze-with-stack-protect.xml: New file.
	* features/microblaze.xml: New file.
	* features/microblaze.c: New file.
	* features/Makefile (microblaze-with-stack-protect): Add
	microblaze-with-stack-protect microblaze and
	microblaze-expedite.
	* regformats/microblaze-with-stack-protect.dat: New file.
	* regformats/microblaze.dat: New file.

Signed-off-by:Ajit Agarwal ajitkum@xilinx.com
---
 gdb/features/Makefile                            |    2 +
 gdb/features/microblaze-core.xml                 |   67 ++++++++++++++++++
 gdb/features/microblaze-stack-protect.xml        |   12 +++
 gdb/features/microblaze-with-stack-protect.c     |   79 ++++++++++++++++++++++
 gdb/features/microblaze-with-stack-protect.xml   |   12 +++
 gdb/features/microblaze.c                        |   75 ++++++++++++++++++++
 gdb/features/microblaze.xml                      |   11 +++
 gdb/microblaze-tdep.c                            |   64 +++++++++++++++++-
 gdb/microblaze-tdep.h                            |   48 +++++++------
 gdb/regformats/microblaze-with-stack-protect.dat |   63 +++++++++++++++++
 gdb/regformats/microblaze.dat                    |   61 +++++++++++++++++
 11 files changed, 468 insertions(+), 26 deletions(-)
 create mode 100644 gdb/features/microblaze-core.xml
 create mode 100644 gdb/features/microblaze-stack-protect.xml
 create mode 100644 gdb/features/microblaze-with-stack-protect.c
 create mode 100644 gdb/features/microblaze-with-stack-protect.xml
 create mode 100644 gdb/features/microblaze.c
 create mode 100644 gdb/features/microblaze.xml
 create mode 100644 gdb/regformats/microblaze-with-stack-protect.dat
 create mode 100644 gdb/regformats/microblaze.dat

diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index dbf4963..1c50419 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -46,6 +46,7 @@ WHICH = aarch64 \
 	i386/x32-avx i386/x32-avx-linux \
 	i386/x32-avx512 i386/x32-avx512-linux \
 	mips-linux mips-dsp-linux \
+	microblaze-with-stack-protect \
 	mips64-linux mips64-dsp-linux \
 	nios2-linux \
 	rs6000/powerpc-32 \
@@ -90,6 +91,7 @@ mips-expedite = r29,pc
 mips-dsp-expedite = r29,pc
 mips64-expedite = r29,pc
 mips64-dsp-expedite = r29,pc
+microblaze-expedite = r1,pc
 nios2-linux-expedite = sp,pc
 powerpc-expedite = r1,pc
 rs6000/powerpc-cell32l-expedite = r1,pc,r0,orig_r3,r4
diff --git a/gdb/features/microblaze-core.xml b/gdb/features/microblaze-core.xml
new file mode 100644
index 0000000..874b138
--- /dev/null
+++ b/gdb/features/microblaze-core.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.microblaze.core">
+  <reg name="r0" bitsize="32" regnum="0"/>
+  <reg name="r1" bitsize="32"/>
+  <reg name="r2" bitsize="32"/>
+  <reg name="r3" bitsize="32"/>
+  <reg name="r4" bitsize="32"/>
+  <reg name="r5" bitsize="32"/>
+  <reg name="r6" bitsize="32"/>
+  <reg name="r7" bitsize="32"/>
+  <reg name="r8" bitsize="32"/>
+  <reg name="r9" bitsize="32"/>
+  <reg name="r10" bitsize="32"/>
+  <reg name="r11" bitsize="32"/>
+  <reg name="r12" bitsize="32"/>
+  <reg name="r13" bitsize="32"/>
+  <reg name="r14" bitsize="32"/>
+  <reg name="r15" bitsize="32"/>
+  <reg name="r16" bitsize="32"/>
+  <reg name="r17" bitsize="32"/>
+  <reg name="r18" bitsize="32"/>
+  <reg name="r19" bitsize="32"/>
+  <reg name="r20" bitsize="32"/>
+  <reg name="r21" bitsize="32"/>
+  <reg name="r22" bitsize="32"/>
+  <reg name="r23" bitsize="32"/>
+  <reg name="r24" bitsize="32"/>
+  <reg name="r25" bitsize="32"/>
+  <reg name="r26" bitsize="32"/>
+  <reg name="r27" bitsize="32"/>
+  <reg name="r28" bitsize="32"/>
+  <reg name="r29" bitsize="32"/>
+  <reg name="r30" bitsize="32"/>
+  <reg name="r31" bitsize="32"/>
+  <reg name="rpc" bitsize="32"/>
+  <reg name="rmsr" bitsize="32"/>
+  <reg name="rear" bitsize="32"/>
+  <reg name="resr" bitsize="32"/>
+  <reg name="rfsr" bitsize="32"/>
+  <reg name="rbtr" bitsize="32"/>
+  <reg name="rpvr0" bitsize="32"/> 
+  <reg name="rpvr1" bitsize="32"/> 
+  <reg name="rpvr2" bitsize="32"/> 
+  <reg name="rpvr3" bitsize="32"/> 
+  <reg name="rpvr4" bitsize="32"/> 
+  <reg name="rpvr5" bitsize="32"/> 
+  <reg name="rpvr6" bitsize="32"/>
+  <reg name="rpvr7" bitsize="32"/> 
+  <reg name="rpvr8" bitsize="32"/> 
+  <reg name="rpvr9" bitsize="32"/> 
+  <reg name="rpvr10" bitsize="32"/> 
+  <reg name="rpvr11" bitsize="32"/>
+  <reg name="redr" bitsize="32"/> 
+  <reg name="rpid" bitsize="32"/> 
+  <reg name="rzpr" bitsize="32"/> 
+  <reg name="rtlbx" bitsize="32"/> 
+  <reg name="rtlbsx" bitsize="32"/> 
+  <reg name="rtlblo" bitsize="32"/> 
+  <reg name="rtlbhi" bitsize="32"/>
+</feature>
diff --git a/gdb/features/microblaze-stack-protect.xml b/gdb/features/microblaze-stack-protect.xml
new file mode 100644
index 0000000..d18bb0c
--- /dev/null
+++ b/gdb/features/microblaze-stack-protect.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.microblaze.stack-protect">
+  <reg name="rslr" bitsize="32"/>
+  <reg name="rshr" bitsize="32"/>
+</feature>
diff --git a/gdb/features/microblaze-with-stack-protect.c b/gdb/features/microblaze-with-stack-protect.c
new file mode 100644
index 0000000..ab162fd
--- /dev/null
+++ b/gdb/features/microblaze-with-stack-protect.c
@@ -0,0 +1,79 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: microblaze-with-stack-protect.xml */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+struct target_desc *tdesc_microblaze_with_stack_protect;
+static void
+initialize_tdesc_microblaze_with_stack_protect (void)
+{
+  struct target_desc *result = allocate_target_description ();
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.core");
+  tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", 5, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", 6, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", 7, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", 8, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", 9, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", 10, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", 11, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", 12, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", 13, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", 14, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", 15, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", 16, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", 17, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", 18, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", 19, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", 20, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", 21, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", 22, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", 23, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", 24, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", 25, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r26", 26, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r27", 27, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r28", 28, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r29", 29, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r30", 30, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r31", 31, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rear", 34, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rfsr", 36, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rbtr", 37, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr0", 38, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr1", 39, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr2", 40, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr3", 41, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr4", 42, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr5", 43, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr6", 44, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr7", 45, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr8", 46, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr9", 47, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr10", 48, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr11", 49, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "redr", 50, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpid", 51, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rzpr", 52, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbx", 53, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.stack-protect");
+  tdesc_create_reg (feature, "rslr", 57, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rshr", 58, 1, NULL, 32, "int");
+
+  tdesc_microblaze_with_stack_protect = result;
+}
diff --git a/gdb/features/microblaze-with-stack-protect.xml b/gdb/features/microblaze-with-stack-protect.xml
new file mode 100644
index 0000000..8f62a38
--- /dev/null
+++ b/gdb/features/microblaze-with-stack-protect.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<target>
+  <xi:include href="microblaze-core.xml"/>
+  <xi:include href="microblaze-stack-protect.xml"/>
+</target>
diff --git a/gdb/features/microblaze.c b/gdb/features/microblaze.c
new file mode 100644
index 0000000..b6c57b1
--- /dev/null
+++ b/gdb/features/microblaze.c
@@ -0,0 +1,75 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: microblaze.xml */
+
+#include "defs.h"
+#include "osabi.h"
+#include "target-descriptions.h"
+
+struct target_desc *tdesc_microblaze;
+static void
+initialize_tdesc_microblaze (void)
+{
+  struct target_desc *result = allocate_target_description ();
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.core");
+  tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", 5, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", 6, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", 7, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", 8, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", 9, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", 10, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", 11, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", 12, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", 13, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", 14, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", 15, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", 16, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", 17, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", 18, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", 19, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", 20, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", 21, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", 22, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", 23, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", 24, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", 25, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r26", 26, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r27", 27, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r28", 28, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r29", 29, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r30", 30, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r31", 31, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rear", 34, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rfsr", 36, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rbtr", 37, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr0", 38, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr1", 39, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr2", 40, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr3", 41, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr4", 42, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr5", 43, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr6", 44, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr7", 45, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr8", 46, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr9", 47, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr10", 48, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpvr11", 49, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "redr", 50, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rpid", 51, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rzpr", 52, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbx", 53, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
+
+  tdesc_microblaze = result;
+}
diff --git a/gdb/features/microblaze.xml b/gdb/features/microblaze.xml
new file mode 100644
index 0000000..571f17f
--- /dev/null
+++ b/gdb/features/microblaze.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<target>
+  <xi:include href="microblaze-core.xml"/>
+</target>
diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
index 14c1b52..c57437c 100644
--- a/gdb/microblaze-tdep.c
+++ b/gdb/microblaze-tdep.c
@@ -33,13 +33,15 @@
 #include "frame-unwind.h"
 #include "dwarf2-frame.h"
 #include "osabi.h"
-
+#include "features/microblaze-with-stack-protect.c"
+#include "features/microblaze.c"
 #include "gdb_assert.h"
 #include <string.h>
 #include "target-descriptions.h"
 #include "opcodes/microblaze-opcm.h"
 #include "opcodes/microblaze-dis.h"
 #include "microblaze-tdep.h"
+#include "remote.h"
 
 /* Instruction macros used for analyzing the prologue.  */
 /* This set of instruction macros need to be changed whenever the
@@ -73,7 +75,8 @@ 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)
@@ -663,17 +666,66 @@ microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   gdb_assert (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,
+                                  MICROBLAZE_NUM_CORE_REGS, 
+                                  tdesc_microblaze);
 
+  register_remote_g_packet_guess (gdbarch,
+                                  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_with_stack_protect;
+  /* 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");
+        }
+     }
+  tdep = xcalloc (1, sizeof (struct gdbarch_tdep));
+  gdbarch = gdbarch_alloc (&info, tdep);
+
+  microblaze_register_g_packet_guesses (gdbarch);
 
   /* Allocate space for the new architecture.  */
   tdep = XNEW (struct gdbarch_tdep);
@@ -725,7 +777,11 @@ 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);
+      set_gdbarch_register_type (gdbarch, microblaze_register_type);
+    }
   return gdbarch;
 }
 
@@ -737,6 +793,8 @@ _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_zuinteger_cmd ("microblaze", class_maintenance,
 			     &microblaze_debug_flag, _("\
diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
index a532092..cdb531b 100644
--- a/gdb/microblaze-tdep.h
+++ b/gdb/microblaze-tdep.h
@@ -26,28 +26,6 @@ struct gdbarch_tdep
 {
 };
 
-struct microblaze_frame_cache
-{
-  /* Base address.  */
-  CORE_ADDR base;
-  CORE_ADDR pc;
-
-  /* Do we have a frame?  */
-  int frameless_p;
-
-  /* Frame size.  */
-  int framesize;
-
-  /* Frame register.  */
-  int fp_regnum;
-
-  /* Offsets to saved registers.  */
-  int register_offsets[57];	/* Must match MICROBLAZE_NUM_REGS.  */
-
-  /* Table of saved registers.  */
-  struct trad_frame_saved_reg *saved_regs;
-};
-
 /* Register numbers.  */
 enum microblaze_regnum 
 {
@@ -107,9 +85,33 @@ enum microblaze_regnum
   MICROBLAZE_RTLBX_REGNUM,
   MICROBLAZE_RTLBSX_REGNUM,
   MICROBLAZE_RTLBLO_REGNUM,
-  MICROBLAZE_RTLBHI_REGNUM
+  MICROBLAZE_RTLBHI_REGNUM,
+  MICROBLAZE_SLR_REGNUM, MICROBLAZE_NUM_CORE_REGS = MICROBLAZE_SLR_REGNUM,
+  MICROBLAZE_SHR_REGNUM,
+  MICROBLAZE_NUM_REGS
 };
 
+struct microblaze_frame_cache
+{
+  /* Base address.  */
+  CORE_ADDR base;
+  CORE_ADDR pc;
+
+  /* Do we have a frame?  */
+  int frameless_p;
+
+  /* Frame size.  */
+  int framesize;
+
+  /* Frame register.  */
+  int fp_regnum;
+
+  /* Offsets to saved registers.  */
+  int register_offsets[MICROBLAZE_NUM_REGS];    /* Must match MICROBLAZE_NUM_REGS.  */
+
+  /* Table of saved registers.  */
+  struct trad_frame_saved_reg *saved_regs;
+};
 /* All registers are 32 bits.  */
 #define MICROBLAZE_REGISTER_SIZE 4
 
diff --git a/gdb/regformats/microblaze-with-stack-protect.dat b/gdb/regformats/microblaze-with-stack-protect.dat
new file mode 100644
index 0000000..14a174c
--- /dev/null
+++ b/gdb/regformats/microblaze-with-stack-protect.dat
@@ -0,0 +1,63 @@
+# DO NOT EDIT: generated from microblaze-linux.xml
+name:microblaze_with_stack_protect
+xmltarget:microblaze-with-stack-protect.xml
+expedite:r1,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:r26
+32:r27
+32:r28
+32:r29
+32:r30
+32:r31
+32:rpc
+32:rmsr
+32:rear
+32:resr
+32:rfsr
+32:rbtr
+32:rpvr0
+32:rpvr1
+32:rpvr2
+32:rpvr3
+32:rpvr4
+32:rpvr5
+32:rpvr6
+32:rpvr7
+32:rpvr8
+32:rpvr9
+32:rpvr10
+32:rpvr11
+32:redr
+32:rpid
+32:rzpr
+32:rtlbx
+32:rtlbsx
+32:rtlblo
+32:rtlbhi
+32:rslr
+32:rshr
diff --git a/gdb/regformats/microblaze.dat b/gdb/regformats/microblaze.dat
new file mode 100644
index 0000000..fbc3edb
--- /dev/null
+++ b/gdb/regformats/microblaze.dat
@@ -0,0 +1,61 @@
+# DO NOT EDIT: generated from microblaze.xml
+name:microblaze
+xmltarget:microblaze.xml
+expedite:r1,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:r26
+32:r27
+32:r28
+32:r29
+32:r30
+32:r31
+32:rpc
+32:rmsr
+32:rear
+32:resr
+32:rfsr
+32:rbtr
+32:rpvr0
+32:rpvr1
+32:rpvr2
+32:rpvr3
+32:rpvr4
+32:rpvr5
+32:rpvr6
+32:rpvr7
+32:rpvr8
+32:rpvr9
+32:rpvr10
+32:rpvr11
+32:redr
+32:rpid
+32:rzpr
+32:rtlbx
+32:rtlbsx
+32:rtlblo
+32:rtlbhi
-- 
1.7.1

