blob: cb2eec18022fad6a9ac786edd3c8f102d9e51870 [file] [log] [blame]
Brad Bishop286d45c2018-10-02 15:21:57 -04001From 2112c9ded01ddd08f0e31e5ce23eecac6c04e8c4 Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@petalogix.com>
3Date: Mon, 6 Feb 2012 10:28:29 +1000
4Subject: [PATCH 06/16] [Patch, microblaze]: Add initial port of linux
5 gdbserver
6
7add gdb_proc_service_h to gdbserver microblaze-linux
8
9gdbserver needs to initialise the microblaze registers
10
11other archs use this step to run a *_arch_setup() to carry out all
12architecture specific setup - may need to add in future
13
14 * add linux-ptrace.o to gdbserver configure
15 * gdb/configure.tgt: Set build_gdbserver=yes
16 * Update breakpoint opcode
17 * fix segfault on connecting gdbserver
18 * add microblaze_linux_memory_remove_breakpoint
19 * add set_solib_svr4_fetch_link_map_offsets
20 * add set_gdbarch_fetch_tls_load_module_address
21 * Force reading of r0 as 0, prevent stores
22
23Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
24Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
25Upstream-Status: Pending
26---
27 gdb/configure.host | 3 +
28 gdb/configure.tgt | 1 +
29 gdb/gdbserver/Makefile.in | 4 +
30 gdb/gdbserver/configure.srv | 6 +
31 gdb/gdbserver/linux-microblaze-low.c | 228 +++++++++++++++++++++++++++++++++++
32 gdb/microblaze-linux-tdep.c | 25 +++-
33 gdb/microblaze-tdep.c | 45 ++++++-
34 gdb/microblaze-tdep.h | 3 +-
35 gdb/regformats/reg-microblaze.dat | 39 ++++++
36 9 files changed, 348 insertions(+), 6 deletions(-)
37 create mode 100644 gdb/gdbserver/linux-microblaze-low.c
38 create mode 100644 gdb/regformats/reg-microblaze.dat
39
40diff --git a/gdb/configure.host b/gdb/configure.host
41index 15a8288..76cc5fe 100644
42--- a/gdb/configure.host
43+++ b/gdb/configure.host
44@@ -59,6 +59,7 @@ i[34567]86*) gdb_host_cpu=i386 ;;
45 m68*) gdb_host_cpu=m68k ;;
46 m88*) gdb_host_cpu=m88k ;;
47 mips*) gdb_host_cpu=mips ;;
48+microblaze*) gdb_host_cpu=microblaze ;;
49 powerpc* | rs6000) gdb_host_cpu=powerpc ;;
50 sparcv9 | sparc64) gdb_host_cpu=sparc ;;
51 s390*) gdb_host_cpu=s390 ;;
52@@ -133,6 +134,8 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu)
53 gdb_host=nbsd ;;
54 mips64*-*-openbsd*) gdb_host=obsd64 ;;
55
56+microblaze*-*linux*) gdb_host=linux ;;
57+
58 powerpc-*-aix* | rs6000-*-* | powerpc64-*-aix*)
59 gdb_host=aix ;;
60 powerpc*-*-freebsd*) gdb_host=fbsd ;;
61diff --git a/gdb/configure.tgt b/gdb/configure.tgt
62index 9297c56..3a7951a 100644
63--- a/gdb/configure.tgt
64+++ b/gdb/configure.tgt
65@@ -343,6 +343,7 @@ microblaze*-linux-*|microblaze*-*-linux*)
66 gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o microblaze-rom.o glibc-tdep.o \
67 monitor.o dsrec.o solib-svr4.o symfile-mem.o linux-tdep.o"
68 gdb_sim=../sim/microblaze/libsim.a
69+ build_gdbserver=yes
70 ;;
71 microblaze*-*-*)
72 # Target: Xilinx MicroBlaze running standalone
73diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
74index f773fa2..a11ace1 100644
75--- a/gdb/gdbserver/Makefile.in
76+++ b/gdb/gdbserver/Makefile.in
77@@ -148,6 +148,7 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
78 $(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \
79 $(srcdir)/linux-m32r-low.c \
80 $(srcdir)/linux-m68k-low.c $(srcdir)/linux-mips-low.c \
81+ $(srcdir)/linux-microblaze-low.c \
82 $(srcdir)/linux-nios2-low.c \
83 $(srcdir)/linux-ppc-low.c \
84 $(srcdir)/linux-s390-low.c \
85@@ -329,6 +330,7 @@ clean:
86 rm -f arm-with-iwmmxt.c
87 rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
88 rm -f mips-linux.c mips64-linux.c
89+ rm -f microblaze-linux.c
90 rm -f nios2-linux.c
91 rm -f powerpc-32.c powerpc-32l.c powerpc-64l.c powerpc-e500l.c
92 rm -f powerpc-altivec32l.c powerpc-cell32l.c powerpc-vsx32l.c
93@@ -612,6 +614,8 @@ reg-m68k.c : $(srcdir)/../regformats/reg-m68k.dat $(regdat_sh)
94 $(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-m68k.dat reg-m68k.c
95 reg-cf.c : $(srcdir)/../regformats/reg-cf.dat $(regdat_sh)
96 $(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-cf.dat reg-cf.c
97+microblaze-linux.c : $(srcdir)/../regformats/reg-microblaze.dat $(regdat_sh)
98+ $(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-microblaze.dat microblaze-linux.c
99 mips-linux.c : $(srcdir)/../regformats/mips-linux.dat $(regdat_sh)
100 $(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips-linux.dat mips-linux.c
101 mips-dsp-linux.c : $(srcdir)/../regformats/mips-dsp-linux.dat $(regdat_sh)
102diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
103index cc4f53d..359c756 100644
104--- a/gdb/gdbserver/configure.srv
105+++ b/gdb/gdbserver/configure.srv
106@@ -198,6 +198,12 @@ case "${target}" in
107 srv_linux_usrregs=yes
108 srv_linux_thread_db=yes
109 ;;
110+ microblaze*-*-linux*) srv_regobj=microblaze-linux.o
111+ srv_tgtobj="$srv_linux_obj linux-microblaze-low.o"
112+ srv_linux_usrregs=yes
113+ srv_linux_regsets=yes
114+ srv_linux_thread_db=yes
115+ ;;
116 nios2*-*-linux*) srv_regobj="nios2-linux.o"
117 srv_tgtobj="$srv_linux_obj linux-nios2-low.o"
118 srv_xmlfiles="nios2-linux.xml"
119diff --git a/gdb/gdbserver/linux-microblaze-low.c b/gdb/gdbserver/linux-microblaze-low.c
120new file mode 100644
121index 0000000..279df9f
122--- /dev/null
123+++ b/gdb/gdbserver/linux-microblaze-low.c
124@@ -0,0 +1,228 @@
125+/* GNU/Linux/Microblaze specific low level interface, for the remote server for
126+ GDB.
127+ Copyright (C) 1995-2013 Free Software Foundation, Inc.
128+
129+ This file is part of GDB.
130+
131+ This program is free software; you can redistribute it and/or modify
132+ it under the terms of the GNU General Public License as published by
133+ the Free Software Foundation; either version 3 of the License, or
134+ (at your option) any later version.
135+
136+ This program is distributed in the hope that it will be useful,
137+ but WITHOUT ANY WARRANTY; without even the implied warranty of
138+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139+ GNU General Public License for more details.
140+
141+ You should have received a copy of the GNU General Public License
142+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
143+
144+#include "server.h"
145+#include "linux-low.h"
146+
147+#include <asm/ptrace.h>
148+#include <sys/procfs.h>
149+#include <sys/ptrace.h>
150+
151+#include "gdb_proc_service.h"
152+
153+static int microblaze_regmap[] =
154+ {PT_GPR(0), PT_GPR(1), PT_GPR(2), PT_GPR(3),
155+ PT_GPR(4), PT_GPR(5), PT_GPR(6), PT_GPR(7),
156+ PT_GPR(8), PT_GPR(9), PT_GPR(10), PT_GPR(11),
157+ PT_GPR(12), PT_GPR(13), PT_GPR(14), PT_GPR(15),
158+ PT_GPR(16), PT_GPR(17), PT_GPR(18), PT_GPR(19),
159+ PT_GPR(20), PT_GPR(21), PT_GPR(22), PT_GPR(23),
160+ PT_GPR(24), PT_GPR(25), PT_GPR(26), PT_GPR(27),
161+ PT_GPR(28), PT_GPR(29), PT_GPR(30), PT_GPR(31),
162+ PT_PC, PT_MSR, PT_EAR, PT_ESR,
163+ PT_FSR
164+ };
165+
166+#define microblaze_num_regs (sizeof microblaze_regmap / sizeof microblaze_regmap[0])
167+
168+/* Defined in auto-generated file microblaze-linux.c. */
169+void init_registers_microblaze (void);
170+extern const struct target_desc *tdesc_microblaze;
171+
172+static int
173+microblaze_cannot_store_register (int regno)
174+{
175+ if (microblaze_regmap[regno] == -1 || regno == 0)
176+ return 1;
177+
178+ return 0;
179+}
180+
181+static int
182+microblaze_cannot_fetch_register (int regno)
183+{
184+ return 0;
185+}
186+
187+static CORE_ADDR
188+microblaze_get_pc (struct regcache *regcache)
189+{
190+ unsigned long pc;
191+
192+ collect_register_by_name (regcache, "pc", &pc);
193+ return (CORE_ADDR) pc;
194+}
195+
196+static void
197+microblaze_set_pc (struct regcache *regcache, CORE_ADDR pc)
198+{
199+ unsigned long newpc = pc;
200+
201+ supply_register_by_name (regcache, "pc", &newpc);
202+}
203+
204+/* dbtrap insn */
205+/* brki r16, 0x18; */
206+static const unsigned long microblaze_breakpoint = 0xba0c0018;
207+#define microblaze_breakpoint_len 4
208+
209+static int
210+microblaze_breakpoint_at (CORE_ADDR where)
211+{
212+ unsigned long insn;
213+
214+ (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
215+ if (insn == microblaze_breakpoint)
216+ return 1;
217+ /* If necessary, recognize more trap instructions here. GDB only uses the
218+ one. */
219+ return 0;
220+}
221+
222+static CORE_ADDR
223+microblaze_reinsert_addr (struct regcache *regcache)
224+{
225+ unsigned long pc;
226+ collect_register_by_name (regcache, "r15", &pc);
227+ return pc;
228+}
229+
230+#ifdef HAVE_PTRACE_GETREGS
231+
232+static void
233+microblaze_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
234+{
235+ int size = register_size (regcache->tdesc, regno);
236+
237+ memset (buf, 0, sizeof (long));
238+
239+ if (size < sizeof (long))
240+ collect_register (regcache, regno, buf + sizeof (long) - size);
241+ else
242+ collect_register (regcache, regno, buf);
243+}
244+
245+static void
246+microblaze_supply_ptrace_register (struct regcache *regcache,
247+ int regno, const char *buf)
248+{
249+ int size = register_size (regcache->tdesc, regno);
250+
251+ if (regno == 0) {
252+ unsigned long regbuf_0 = 0;
253+ /* clobbering r0 so that it is always 0 as enforced by hardware */
254+ supply_register (regcache, regno, (const char*)&regbuf_0);
255+ } else {
256+ if (size < sizeof (long))
257+ supply_register (regcache, regno, buf + sizeof (long) - size);
258+ else
259+ supply_register (regcache, regno, buf);
260+ }
261+}
262+
263+/* Provide only a fill function for the general register set. ps_lgetregs
264+ will use this for NPTL support. */
265+
266+static void microblaze_fill_gregset (struct regcache *regcache, void *buf)
267+{
268+ int i;
269+
270+ for (i = 0; i < 32; i++)
271+ microblaze_collect_ptrace_register (regcache, i, (char *) buf + microblaze_regmap[i]);
272+}
273+
274+static void
275+microblaze_store_gregset (struct regcache *regcache, const void *buf)
276+{
277+ int i;
278+
279+ for (i = 0; i < 32; i++)
280+ supply_register (regcache, i, (char *) buf + microblaze_regmap[i]);
281+}
282+
283+#endif /* HAVE_PTRACE_GETREGS */
284+
285+static struct regset_info microblaze_regsets[] = {
286+#ifdef HAVE_PTRACE_GETREGS
287+ { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t), GENERAL_REGS, microblaze_fill_gregset, microblaze_store_gregset },
288+ { 0, 0, 0, -1, -1, NULL, NULL },
289+#endif /* HAVE_PTRACE_GETREGS */
290+ { 0, 0, 0, -1, -1, NULL, NULL }
291+};
292+
293+static struct regsets_info microblaze_regsets_info =
294+ {
295+ microblaze_regsets, /* regsets */
296+ 0, /* num_regsets */
297+ NULL, /* disabled_regsets */
298+ };
299+
300+static struct usrregs_info microblaze_usrregs_info =
301+ {
302+ microblaze_num_regs,
303+ microblaze_regmap,
304+ };
305+
306+static struct regs_info regs_info =
307+ {
308+ NULL, /* regset_bitmap */
309+ &microblaze_usrregs_info,
310+ &microblaze_regsets_info
311+ };
312+
313+static const struct regs_info *
314+microblaze_regs_info (void)
315+{
316+ return &regs_info;
317+}
318+
319+static void
320+microblaze_arch_setup (void)
321+{
322+ current_process ()->tdesc = tdesc_microblaze;
323+}
324+
325+struct linux_target_ops the_low_target = {
326+ microblaze_arch_setup,
327+ microblaze_regs_info,
328+ microblaze_cannot_fetch_register,
329+ microblaze_cannot_store_register,
330+ NULL, /* fetch_register */
331+ microblaze_get_pc,
332+ microblaze_set_pc,
333+ (const unsigned char *) &microblaze_breakpoint,
334+ microblaze_breakpoint_len,
335+ microblaze_reinsert_addr,
336+ 0,
337+ microblaze_breakpoint_at,
338+ NULL,
339+ NULL,
340+ NULL,
341+ NULL,
342+ microblaze_collect_ptrace_register,
343+ microblaze_supply_ptrace_register,
344+};
345+
346+void
347+initialize_low_arch (void)
348+{
349+ init_registers_microblaze ();
350+
351+ initialize_regsets_info (&microblaze_regsets_info);
352+}
353\ No newline at end of file
354diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
355index 7e6b61b..cf58e21 100644
356--- a/gdb/microblaze-linux-tdep.c
357+++ b/gdb/microblaze-linux-tdep.c
358@@ -38,6 +38,22 @@
359 #include "tramp-frame.h"
360 #include "linux-tdep.h"
361
362+static int microblaze_debug_flag = 0;
363+
364+static void
365+microblaze_debug (const char *fmt, ...)
366+{
367+ if (microblaze_debug_flag)
368+ {
369+ va_list args;
370+
371+ va_start (args, fmt);
372+ printf_unfiltered ("MICROBLAZE LINUX: ");
373+ vprintf_unfiltered (fmt, args);
374+ va_end (args);
375+ }
376+}
377+
378 static int
379 microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
380 struct bp_target_info *bp_tgt)
381@@ -47,20 +63,27 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
382 int val;
383 int bplen;
384 gdb_byte old_contents[BREAKPOINT_MAX];
385+ struct cleanup *cleanup;
386
387 /* Determine appropriate breakpoint contents and size for this address. */
388 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
389 if (bp == NULL)
390 error (_("Software breakpoints not implemented for this target."));
391
392+ /* Make sure we see the memory breakpoints. */
393+ cleanup = make_show_memory_breakpoints_cleanup (1);
394 val = target_read_memory (addr, old_contents, bplen);
395
396 /* If our breakpoint is no longer at the address, this means that the
397 program modified the code on us, so it is wrong to put back the
398 old value. */
399 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
400- val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
401+ {
402+ val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
403+ microblaze_debug ("microblaze_linux_memory_remove_breakpoint writing back to memory at addr 0x%lx\n", addr);
404+ }
405
406+ do_cleanups (cleanup);
407 return val;
408 }
409
410diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
411index 50b68d2..1c6dbfe 100644
412--- a/gdb/microblaze-tdep.c
413+++ b/gdb/microblaze-tdep.c
414@@ -164,6 +164,39 @@ microblaze_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
415 return sp;
416 }
417
418+static int
419+microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
420+ struct bp_target_info *bp_tgt)
421+{
422+ CORE_ADDR addr = bp_tgt->placed_address;
423+ const unsigned char *bp;
424+ int val;
425+ int bplen;
426+ gdb_byte old_contents[BREAKPOINT_MAX];
427+ struct cleanup *cleanup;
428+
429+ /* Determine appropriate breakpoint contents and size for this address. */
430+ bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
431+ if (bp == NULL)
432+ error (_("Software breakpoints not implemented for this target."));
433+
434+ /* Make sure we see the memory breakpoints. */
435+ cleanup = make_show_memory_breakpoints_cleanup (1);
436+ val = target_read_memory (addr, old_contents, bplen);
437+
438+ /* If our breakpoint is no longer at the address, this means that the
439+ program modified the code on us, so it is wrong to put back the
440+ old value. */
441+ if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
442+ {
443+ val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
444+ microblaze_debug ("microblaze_linux_memory_remove_breakpoint writing back to memory at addr 0x%lx\n", addr);
445+ }
446+
447+ do_cleanups (cleanup);
448+ return val;
449+}
450+
451 static const gdb_byte *
452 microblaze_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc,
453 int *len)
454@@ -291,8 +324,8 @@ microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
455
456 for (addr = func_addr; addr < stop; addr += INST_WORD_SIZE)
457 {
458- //insn = microblaze_fetch_instruction (addr);
459- insn = insn_block[(addr - func_addr) / INST_WORD_SIZE];
460+ insn = microblaze_fetch_instruction (addr);
461+ //insn = insn_block[(addr - func_addr) / INST_WORD_SIZE];
462 op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
463 microblaze_debug ("%s %08lx op=%x r%d r%d imm=%d\n", paddress (gdbarch, addr), insn, op, rd, ra, imm);
464
465@@ -724,13 +757,15 @@ microblaze_software_single_step (struct frame_info *frame)
466 rb = get_frame_register_unsigned (frame, lrb);
467 else
468 rb = 0;
469+
470 stepbreaks[1].address = microblaze_get_target_address (insn, immfound, imm, pc, ra, rb, &targetvalid, &unconditionalbranch);
471- microblaze_debug ("single-step uncondbr=%d targetvalid=%d target=%x\n", unconditionalbranch, targetvalid, stepbreaks[1].address);
472+ microblaze_debug ("single-step uncondbr=%d targetvalid=%d target=%x\n", unconditionalbranch, targetvalid, stepbreaks[1].address);
473+
474 if (unconditionalbranch)
475 stepbreaks[0].valid = FALSE; /* This is a unconditional branch: will not come to the next address */
476 if (targetvalid && (stepbreaks[0].valid == FALSE ||
477 (stepbreaks[0].address != stepbreaks[1].address))
478- && (stepbreaks[1].address != pc)) {
479+ && (stepbreaks[1].address != pc)) {
480 stepbreaks[1].valid = TRUE;
481 } else {
482 stepbreaks[1].valid = FALSE;
483@@ -900,6 +935,8 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
484 /* Stack grows downward. */
485 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
486
487+ set_gdbarch_memory_remove_breakpoint (gdbarch, microblaze_linux_memory_remove_breakpoint);
488+
489 set_gdbarch_breakpoint_from_pc (gdbarch, microblaze_breakpoint_from_pc);
490 set_gdbarch_software_single_step (gdbarch, microblaze_software_single_step);
491
492diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
493index fec24b9..98aa0f5 100644
494--- a/gdb/microblaze-tdep.h
495+++ b/gdb/microblaze-tdep.h
496@@ -129,7 +129,8 @@ enum microblaze_regnum
497
498 /* MICROBLAZE_BREAKPOINT defines the breakpoint that should be used.
499 Only used for native debugging. */
500-#define MICROBLAZE_BREAKPOINT {0xb9, 0xcc, 0x00, 0x60}
501+#define MICROBLAZE_BREAKPOINT {0xba, 0x0c, 0x00, 0x18}
502+#define MICROBLAZE_BREAKPOINT_LE {0x18, 0x00, 0x0c, 0xba}
503
504 extern void microblaze_supply_gregset (const struct microblaze_gregset *gregset,
505 struct regcache *regcache,
506diff --git a/gdb/regformats/reg-microblaze.dat b/gdb/regformats/reg-microblaze.dat
507new file mode 100644
508index 0000000..a5dd0a0
509--- /dev/null
510+++ b/gdb/regformats/reg-microblaze.dat
511@@ -0,0 +1,39 @@
512+name:microblaze
513+expedite:r1,pc
514+32:r0
515+32:r1
516+32:r2
517+32:r3
518+32:r4
519+32:r5
520+32:r6
521+32:r7
522+32:r8
523+32:r9
524+32:r10
525+32:r11
526+32:r12
527+32:r13
528+32:r14
529+32:r15
530+32:r16
531+32:r17
532+32:r18
533+32:r19
534+32:r20
535+32:r21
536+32:r22
537+32:r23
538+32:r24
539+32:r25
540+32:r26
541+32:r27
542+32:r28
543+32:r29
544+32:r30
545+32:r31
546+32:pc
547+32:msr
548+32:ear
549+32:esr
550+32:fsr
551--
5521.9.0
553