aboutsummaryrefslogtreecommitdiff
path: root/devel/gdb/files/patch-armfbsd
blob: 4223d2da0858cfee7fb5b20360eefc508e0096cd (plain) (blame)
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
diff --git gdb/armfbsd-nat.c gdb/armfbsd-nat.c
new file mode 100644
index 0000000..b883411
--- /dev/null
+++ gdb/armfbsd-nat.c
@@ -0,0 +1,215 @@
+/* Native-dependent code for BSD Unix running on ARM's, for GDB.
+
+   Copyright (C) 1988-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "gdbcore.h"
+#include "inferior.h"
+#include "regcache.h"
+#include "target.h"
+#include "gregset.h"
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <machine/reg.h>
+#include <machine/frame.h>
+
+#include "fbsd-nat.h"
+#include "arm-tdep.h"
+#include "inf-ptrace.h"
+
+extern int arm_apcs_32;
+
+static pid_t
+ptrace_pid (ptid_t ptid)
+{
+  pid_t pid;
+
+#ifdef __FreeBSD__
+  pid = ptid_get_lwp (ptid);
+  if (pid == 0)
+#endif
+    pid = ptid_get_pid (ptid);
+  return pid;
+}
+
+static void
+arm_supply_gregset (struct regcache *regcache, const gregset_t *gregset, int regnum)
+{
+  int r;
+  CORE_ADDR r_pc;
+
+  /* Integer registers.  */
+  for (r = ARM_A1_REGNUM; r < ARM_SP_REGNUM; r++)
+    if ((r == regnum) || (regnum == -1))
+      regcache_raw_supply (regcache, r, (char *) &gregset->r[r]);
+
+  if ((regnum == ARM_SP_REGNUM) || (regnum == -1))
+    regcache_raw_supply (regcache, ARM_SP_REGNUM,
+		       (char *) &gregset->r_sp);
+  if ((regnum == ARM_LR_REGNUM) || (regnum == -1))
+    regcache_raw_supply (regcache, ARM_LR_REGNUM,
+		       (char *) &gregset->r_lr);
+  /* This is ok: we're running native...  */
+  if ((regnum == ARM_PC_REGNUM) || (regnum == -1))
+    {
+      r_pc = gdbarch_addr_bits_remove (get_regcache_arch (regcache), gregset->r_pc);
+      regcache_raw_supply (regcache, ARM_PC_REGNUM, (char *) &r_pc);
+    }
+
+  if ((regnum == ARM_PS_REGNUM) || (regnum == -1))
+    {
+      if (arm_apcs_32)
+        regcache_raw_supply (regcache, ARM_PS_REGNUM,
+			 (char *) &gregset->r_cpsr);
+      else
+        regcache_raw_supply (regcache, ARM_PS_REGNUM,
+			 (char *) &gregset->r_pc);
+    }
+}
+
+static void
+armbsd_collect_gregset (const struct regcache *regcache, gregset_t *gregset, int regnum)
+{
+  int ret;
+  int r;
+
+  for (r = ARM_A1_REGNUM; r < ARM_SP_REGNUM; r++)
+    if ((regnum == r) || (regnum == -1))
+      regcache_raw_collect (regcache, r,
+			  (char *) &gregset->r[r]);
+
+  if ((regnum == ARM_SP_REGNUM) || (regnum == -1))
+    regcache_raw_collect (regcache, ARM_SP_REGNUM,
+			(char *) &gregset->r_sp);
+  if ((regnum == ARM_LR_REGNUM) || (regnum == -1))
+    regcache_raw_collect (regcache, ARM_LR_REGNUM,
+			(char *) &gregset->r_lr);
+
+
+  if ((regnum == ARM_PC_REGNUM) || (regnum == -1))
+    regcache_raw_collect (regcache, ARM_PC_REGNUM,
+			(char *) &gregset->r_pc);
+  if ((regnum == ARM_PS_REGNUM) || (regnum == -1))
+    {
+      if (arm_apcs_32)
+        {
+          regcache_raw_collect (regcache, ARM_PS_REGNUM,
+			    (char *) &gregset->r_cpsr);
+        }
+      else
+        {
+          unsigned psr_val;
+
+          regcache_raw_collect (regcache, ARM_PS_REGNUM,
+			   (char *) &psr_val);
+
+          psr_val ^= gdbarch_addr_bits_remove (get_regcache_arch (regcache), psr_val);
+          gregset->r_pc = gdbarch_addr_bits_remove
+    			   (get_regcache_arch (regcache), gregset->r_pc);
+          gregset->r_pc |= psr_val;
+        }
+    }
+}
+
+/* Fill GDB's register array with the general-purpose register values
+   in *GREGSETP.  */
+
+void
+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
+{
+  arm_supply_gregset (regcache, gregsetp, -1);
+}
+
+/* Fill register REGNUM (if it is a general-purpose register) in
+   *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
+   do this for all registers.  */
+
+void
+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
+{
+  armbsd_collect_gregset (regcache, gregsetp, regnum);
+}
+
+/* Fill GDB's register array with the floating-point register values
+   in *FPREGSETP.  */
+
+void
+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
+{
+}
+
+/* Fill register REGNUM (if it is a floating-point register) in
+   *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
+   do this for all registers.  */
+
+void
+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
+{
+}
+
+/* Fetch register REGNO from the child process. If REGNO is -1, do it
+   for all registers.  */
+
+static void
+armfbsd_fetch_inferior_registers (struct target_ops *ops,
+				  struct regcache *regcache, int regno)
+{
+  gdb_gregset_t regs;
+
+  if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
+	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+    perror_with_name (_("Couldn't get registers"));
+
+  arm_supply_gregset (regcache, &regs, regno);
+  /* TODO: fpregs */
+}
+
+/* Store register REGNO back into the child process. If REGNO is -1,
+   do this for all registers.  */
+
+static void
+armfbsd_store_inferior_registers (struct target_ops *ops,
+				  struct regcache *regcache, int regno)
+{
+  gdb_gregset_t regs;
+
+  if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid),
+	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+    perror_with_name (_("Couldn't get registers"));
+
+  fill_gregset (regcache, &regs, regno);
+
+  if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid),
+	      (PTRACE_TYPE_ARG3) &regs, 0) == -1)
+    perror_with_name (_("Couldn't write registers"));
+  /* TODO: FP regs */
+}
+
+void _initialize_armfbsd_nat (void);
+
+void
+_initialize_armfbsd_nat (void)
+{
+  struct target_ops *t;
+
+  /* Add in local overrides.  */
+  t = inf_ptrace_target ();
+  t->to_fetch_registers = armfbsd_fetch_inferior_registers;
+  t->to_store_registers = armfbsd_store_inferior_registers;
+  fbsd_nat_add_target (t);
+}
diff --git gdb/armfbsd-tdep.c gdb/armfbsd-tdep.c
new file mode 100644
index 0000000..f58c323
--- /dev/null
+++ gdb/armfbsd-tdep.c
@@ -0,0 +1,109 @@
+/* Target-dependent code for PowerPC systems running FreeBSD.
+
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "arch-utils.h"
+#include "frame.h"
+#include "gdbcore.h"
+#include "frame-unwind.h"
+#include "gdbtypes.h"
+#include "osabi.h"
+#include "regcache.h"
+#include "regset.h"
+#include "symtab.h"
+#include "target.h"
+#include "trad-frame.h"
+
+#include "arm-tdep.h"
+#include "solib-svr4.h"
+
+/* Description of the longjmp buffer.  */
+#define ARM_FBSD_JB_PC 24
+#define ARM_FBSD_JB_ELEMENT_SIZE INT_REGISTER_SIZE
+
+/* For compatibility with previous implemenations of GDB on arm/FreeBSD,
+   override the default little-endian breakpoint.  */
+static const gdb_byte arm_fbsd_arm_le_breakpoint[] = {0x11, 0x00, 0x00, 0xe6};
+static const gdb_byte arm_fbsd_arm_be_breakpoint[] = {0xe6, 0x00, 0x00, 0x11};
+static const gdb_byte arm_fbsd_thumb_le_breakpoint[] = {0xfe, 0xde};
+static const gdb_byte arm_fbsd_thumb_be_breakpoint[] = {0xde, 0xfe};
+
+static void
+arm_freebsd_init_abi_common (struct gdbarch_info info,
+			    struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  tdep->lowest_pc = 0x8000;
+  switch (info.byte_order)
+    {
+    case BFD_ENDIAN_LITTLE:
+      tdep->arm_breakpoint = arm_fbsd_arm_le_breakpoint;
+      tdep->thumb_breakpoint = arm_fbsd_thumb_le_breakpoint;
+      tdep->arm_breakpoint_size = sizeof (arm_fbsd_arm_le_breakpoint);
+      tdep->thumb_breakpoint_size = sizeof (arm_fbsd_thumb_le_breakpoint);
+      break;
+
+    case BFD_ENDIAN_BIG:
+      tdep->arm_breakpoint = arm_fbsd_arm_be_breakpoint;
+      tdep->thumb_breakpoint = arm_fbsd_thumb_be_breakpoint;
+      tdep->arm_breakpoint_size = sizeof (arm_fbsd_arm_be_breakpoint);
+      tdep->thumb_breakpoint_size = sizeof (arm_fbsd_thumb_be_breakpoint);
+      break;
+
+    default:
+      internal_error (__FILE__, __LINE__,
+		      _("arm_gdbarch_init: bad byte order for float format"));
+    }
+
+  tdep->jb_pc = ARM_FBSD_JB_PC;
+  tdep->jb_elt_size = ARM_FBSD_JB_ELEMENT_SIZE;
+
+  /* Single stepping.  */
+  set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
+}
+
+static void
+arm_freebsd_elf_init_abi (struct gdbarch_info info,
+			 struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  arm_freebsd_init_abi_common (info, gdbarch);
+  if (tdep->fp_model == ARM_FLOAT_AUTO)
+    tdep->fp_model = ARM_FLOAT_SOFT_VFP;
+
+  /* NetBSD ELF uses SVR4-style shared libraries.  */
+  set_solib_svr4_fetch_link_map_offsets
+    (gdbarch, svr4_ilp32_fetch_link_map_offsets);
+}
+
+
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+
+void _initialize_armfbsd_tdep (void);
+
+void
+_initialize_armfbsd_tdep (void)
+{
+
+  gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_FREEBSD_ELF,
+                          arm_freebsd_elf_init_abi);
+}
diff --git gdb/config/arm/fbsd.mh gdb/config/arm/fbsd.mh
new file mode 100644
index 0000000..0a2d8b1
--- /dev/null
+++ gdb/config/arm/fbsd.mh
@@ -0,0 +1,3 @@
+# Host: FreeBSD/arm
+NATDEPFILES= armfbsd-nat.o fbsd-nat.o fork-child.o inf-ptrace.o
+HAVE_NATIVE_GCORE_HOST = 1
diff --git gdb/Makefile.in gdb/Makefile.in
index dfaa8a3..ddad28d 100644
--- gdb/Makefile.in
+++ gdb/Makefile.in
@@ -659,7 +659,7 @@
 ALL_TARGET_OBS = \
 	armbsd-tdep.o arm.o arm-linux.o arm-linux-tdep.o \
 	arm-get-next-pcs.o arm-symbian-tdep.o \
-	armnbsd-tdep.o armobsd-tdep.o \
+	armnbsd-tdep.o armobsd-tdep.o armfbsd-tdep.o \
 	arm-tdep.o arm-wince-tdep.o \
 	avr-tdep.o \
 	bfin-linux-tdep.o bfin-tdep.o \
@@ -1666,7 +1666,7 @@
 	arm.c arm-get-next-pcs.c \
 	arm-linux.c arm-linux-nat.c arm-linux-tdep.c \
 	arm-symbian-tdep.c arm-tdep.c \
-	armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \
+	armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c armfbsd-tdep.c \
 	avr-tdep.c \
 	bfin-linux-tdep.c bfin-tdep.c \
 	bsd-uthread.c bsd-kvm.c \