summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/gdb/gdb/0007-Patch-MicroBlaze-Added-m64-abi-for-64-bit-target-des.patch
blob: 59449bfa0cdef344867f5c024dea96806a36b6de (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
From d2f145ec8e4e149e055adc74e92016447af91806 Mon Sep 17 00:00:00 2001
From: Mahesh Bodapati <mbodapat@xilinx.com>
Date: Tue, 9 Nov 2021 16:19:17 +0530
Subject: [PATCH 7/8] [Patch,MicroBlaze] : Added m64 abi for 64 bit target
 descriptions. set m64 abi for 64 bit elf.

Conflicts:
	gdb/microblaze-tdep.c
	gdb/microblaze-tdep.h
---
 gdb/features/microblaze64.xml |   1 +
 gdb/microblaze-tdep.c         | 159 ++++++++++++++++++++++++++++++++--
 gdb/microblaze-tdep.h         |  13 ++-
 3 files changed, 165 insertions(+), 8 deletions(-)

diff --git a/gdb/features/microblaze64.xml b/gdb/features/microblaze64.xml
index 515d18e65cf..9c1b7d22003 100644
--- a/gdb/features/microblaze64.xml
+++ b/gdb/features/microblaze64.xml
@@ -7,5 +7,6 @@
 
 <!DOCTYPE target SYSTEM "gdb-target.dtd">
 <target>
+  <architecture>microblaze64</architecture>
   <xi:include href="microblaze64-core.xml"/>
 </target>
diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
index c347bb9516b..d83072cdaef 100644
--- a/gdb/microblaze-tdep.c
+++ b/gdb/microblaze-tdep.c
@@ -65,8 +65,95 @@
 #define IS_SAVE_HIDDEN_PTR(op, rd, ra, rb) \
   ((op == add || op == addik) && ra == MICROBLAZE_FIRST_ARGREG && rb == 0)
 
+static const char *microblaze_abi_string;
+
+static const char *const microblaze_abi_strings[] = {
+  "auto",
+  "m64",
+};
+
+enum microblaze_abi
+microblaze_abi (struct gdbarch *gdbarch)
+{
+  microblaze_gdbarch_tdep *tdep = (microblaze_gdbarch_tdep *) gdbarch_tdep (gdbarch);
+  return tdep->microblaze_abi;
+}
 /* The registers of the Xilinx microblaze processor.  */
 
+ static struct cmd_list_element *setmicroblazecmdlist = NULL;
+ static struct cmd_list_element *showmicroblazecmdlist = NULL;
+
+static void
+microblaze_abi_update (const char *ignore_args,
+                 int from_tty, struct cmd_list_element *c)
+{
+  struct gdbarch_info info;
+
+  /* Force the architecture to update, and (if it's a microblaze architecture)
+ *      microblaze_gdbarch_init will take care of the rest.  */
+//  gdbarch_info_init (&info);
+  gdbarch_update_p (info);
+}
+
+
+static enum microblaze_abi
+global_microblaze_abi (void)
+{
+  int i;
+
+  for (i = 0; microblaze_abi_strings[i] != NULL; i++)
+    if (microblaze_abi_strings[i] == microblaze_abi_string)
+      return (enum microblaze_abi) i;
+
+//  internal_error (__FILE__, __LINE__, _("unknown ABI string"));
+}
+
+static void
+show_microblaze_abi (struct ui_file *file,
+               int from_tty,
+               struct cmd_list_element *ignored_cmd,
+               const char *ignored_value)
+{
+      enum microblaze_abi global_abi = global_microblaze_abi ();
+      enum microblaze_abi actual_abi = microblaze_abi (target_gdbarch ());
+      const char *actual_abi_str = microblaze_abi_strings[actual_abi];
+
+#if 1 
+      if (global_abi == MICROBLAZE_ABI_AUTO)
+        fprintf_filtered
+          (file,
+           "The microblaze ABI is set automatically (currently \"%s\").\n",
+           actual_abi_str);	
+      else if (global_abi == actual_abi)
+        fprintf_filtered
+          (file,
+           "The microblaze ABI is assumed to be \"%s\" (due to user setting).\n",
+           actual_abi_str);
+      else
+        {
+#endif
+          /* Probably shouldn't happen...  */
+          fprintf_filtered (file,
+                            "The (auto detected) microblaze ABI \"%s\" is in use "
+                            "even though the user setting was \"%s\".\n",
+             actual_abi_str, microblaze_abi_strings[global_abi]);
+        }
+}		   
+
+static void
+show_microblaze_command (const char *args, int from_tty)
+{
+  help_list (showmicroblazecmdlist, "show microblaze ", all_commands, gdb_stdout);
+}
+
+static void
+set_microblaze_command (const char *args, int from_tty)
+{
+  printf_unfiltered
+    ("\"set microblaze\" must be followed by an appropriate subcommand.\n");
+  help_list (setmicroblazecmdlist, "set microblaze ", all_commands, gdb_stdout);
+}
+
 static const char * const microblaze_register_names[] =
 {
   "r0",   "r1",  "r2",    "r3",   "r4",   "r5",   "r6",   "r7",
@@ -85,9 +172,21 @@ static const char * const microblaze_register_names[] =
 static unsigned int microblaze_debug_flag = 0;
 int reg_size = 4;
 
+unsigned int
+microblaze_abi_regsize (struct gdbarch *gdbarch)
+{
+  switch (microblaze_abi (gdbarch))
+    {
+    case MICROBLAZE_ABI_M64:
+      return 8;
+    default:
+      return 4;
+    }
+}
+
 #define microblaze_debug(fmt, ...) \
   debug_prefixed_printf_cond_nofunc (microblaze_debug_flag, "MICROBLAZE", \
-				     fmt, ## __VA_ARGS__)
+                                     fmt, ## __VA_ARGS__)
 
 
 /* Return the name of register REGNUM.  */
@@ -868,15 +967,30 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 {
   struct gdbarch *gdbarch;
   tdesc_arch_data_up tdesc_data;
+  enum microblaze_abi microblaze_abi, found_abi, wanted_abi;
   const struct target_desc *tdesc = info.target_desc;
 
+ /* What has the user specified from the command line?  */
+  wanted_abi = global_microblaze_abi ();
+  if (gdbarch_debug)
+    fprintf_unfiltered (gdb_stdlog, "microblaze_gdbarch_init: wanted_abi = %d\n",
+                        wanted_abi);
+  if (wanted_abi != MICROBLAZE_ABI_AUTO)
+    microblaze_abi = wanted_abi;
+
   /* If there is already a candidate, use it.  */
   arches = gdbarch_list_lookup_by_info (arches, &info);
-  if (arches != NULL)
+  if ((arches != NULL) && (microblaze_abi != MICROBLAZE_ABI_M64))
     return arches->gdbarch;
+
+  if (microblaze_abi == MICROBLAZE_ABI_M64)
+    {
+          tdesc = tdesc_microblaze64;
+          reg_size = 8;
+    }
   if (tdesc == NULL)
     {
-      if (info.bfd_arch_info->mach == bfd_mach_microblaze64) 
+      if ((info.bfd_arch_info->mach == bfd_mach_microblaze64) || (microblaze_abi == MICROBLAZE_ABI_M64)) 
         {
     	  tdesc = tdesc_microblaze64;
           reg_size = 8;
@@ -891,7 +1005,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       int valid_p;
       int i;
 
-      if (info.bfd_arch_info->mach == bfd_mach_microblaze64)
+      if ((info.bfd_arch_info->mach == bfd_mach_microblaze64) || (microblaze_abi == MICROBLAZE_ABI_M64))
         feature = tdesc_find_feature (tdesc,
                                     "org.gnu.gdb.microblaze64.core");
       else
@@ -905,7 +1019,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       for (i = 0; i < MICROBLAZE_NUM_REGS; i++)
         valid_p &= tdesc_numbered_register (feature, tdesc_data.get(), i,
                                             microblaze_register_names[i]);
-      if (info.bfd_arch_info->mach == bfd_mach_microblaze64)
+      if ((info.bfd_arch_info->mach == bfd_mach_microblaze64) || (microblaze_abi == MICROBLAZE_ABI_M64))
         feature = tdesc_find_feature (tdesc,
                                     "org.gnu.gdb.microblaze64.stack-protect");
       else
@@ -955,7 +1069,8 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
       set_gdbarch_ptr_bit (gdbarch, 64);
     break;
     }
-
+  if(microblaze_abi == MICROBLAZE_ABI_M64)
+    set_gdbarch_ptr_bit (gdbarch, 64);
   
   /* Map Dwarf2 registers to GDB registers.  */
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, microblaze_dwarf2_reg_to_regnum);
@@ -1014,7 +1129,38 @@ void
 _initialize_microblaze_tdep ()
 {
   register_gdbarch_init (bfd_arch_microblaze, microblaze_gdbarch_init);
+// static struct cmd_list_element *setmicroblazecmdlist = NULL;
+// static struct cmd_list_element *showmicroblazecmdlist = NULL;
+
+  /* Add root prefix command for all "set microblaze"/"show microblaze" commands.  */
 
+  add_setshow_prefix_cmd ("microblaze", no_class,
+			 _("Various microblaze specific commands."),
+			 _("Various microblaze specific commands."),
+			 &setmicroblazecmdlist,&showmicroblazecmdlist,
+			 &setlist,&showlist);
+#if 0
+  add_prefix_cmd ("microblaze", no_class, set_microblaze_command,
+                  _("Various microblaze specific commands."),
+                  &setmicroblazecmdlist, "set microblaze ", 0, &setlist);
+
+  add_prefix_cmd ("microblaze", no_class, show_microblaze_command,
+                  _("Various microblaze specific commands."),
+                  &showmicroblazecmdlist, "show microblaze ", 0, &showlist);
+#endif
+
+  /* Allow the user to override the ABI.  */
+  add_setshow_enum_cmd ("abi", class_obscure, microblaze_abi_strings,
+                        &microblaze_abi_string, _("\
+Set the microblaze ABI used by this program."), _("\
+Show the microblaze ABI used by this program."), _("\
+This option can be set to one of:\n\
+  auto  - the default ABI associated with the current binary\n\
+  m64"),
+                       microblaze_abi_update,
+		       show_microblaze_abi,
+                       &setmicroblazecmdlist, &showmicroblazecmdlist);
+  
   initialize_tdesc_microblaze_with_stack_protect ();
   initialize_tdesc_microblaze ();
   initialize_tdesc_microblaze64_with_stack_protect ();
@@ -1029,5 +1175,4 @@ When non-zero, microblaze specific debugging is enabled."),
 			     NULL,
 			     &setdebuglist, &showdebuglist);
 
-
 }
diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
index f4d810303ca..babd6c36926 100644
--- a/gdb/microblaze-tdep.h
+++ b/gdb/microblaze-tdep.h
@@ -19,9 +19,17 @@
 
 #ifndef MICROBLAZE_TDEP_H
 #define MICROBLAZE_TDEP_H 1
-
+#include "objfiles.h"
 #include "gdbarch.h"
 
+struct gdbarch;
+enum microblaze_abi
+  {
+    MICROBLAZE_ABI_AUTO = 0,
+    MICROBLAZE_ABI_M64,
+ };
+
+enum microblaze_abi microblaze_abi (struct gdbarch *gdbarch);
 /* Microblaze architecture-specific information.  */
 struct microblaze_gregset
 {
@@ -35,11 +43,14 @@ struct microblaze_gdbarch_tdep : gdbarch_tdep
 {
   int dummy;		// declare something.
 
+  enum microblaze_abi microblaze_abi {};
+  enum microblaze_abi found_abi {};
   /* Register sets.  */
   struct regset *gregset;
   size_t sizeof_gregset;
   struct regset *fpregset;
   size_t sizeof_fpregset;
+  int register_size;
 };
 
 /* Register numbers.  */
-- 
2.37.1 (Apple Git-137.1)