* defs.h (extract_signed_integer, extract_unsigned_integer,
[deliverable/binutils-gdb.git] / gdb / arm-linux-tdep.c
CommitLineData
faf5f7ad 1/* GNU/Linux on ARM target support.
0fd88904 2
0fb0cc75
JB
3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 2009 Free Software Foundation, Inc.
faf5f7ad
SB
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
faf5f7ad
SB
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
faf5f7ad
SB
20
21#include "defs.h"
c20f6dea
SB
22#include "target.h"
23#include "value.h"
faf5f7ad 24#include "gdbtypes.h"
134e61c4 25#include "floatformat.h"
2a451106
KB
26#include "gdbcore.h"
27#include "frame.h"
4e052eda 28#include "regcache.h"
d16aafd8 29#include "doublest.h"
7aa1783e 30#include "solib-svr4.h"
4be87837 31#include "osabi.h"
cb587d83 32#include "regset.h"
8e9d1a24
DJ
33#include "trad-frame.h"
34#include "tramp-frame.h"
daddc3c1 35#include "breakpoint.h"
faf5f7ad 36
34e8f22d 37#include "arm-tdep.h"
cb587d83 38#include "arm-linux-tdep.h"
4aa995e1 39#include "linux-tdep.h"
0670c0aa 40#include "glibc-tdep.h"
a52e6aac 41
8e9d1a24
DJ
42#include "gdb_string.h"
43
cb587d83
DJ
44extern int arm_apcs_32;
45
fdf39c9a
RE
46/* Under ARM GNU/Linux the traditional way of performing a breakpoint
47 is to execute a particular software interrupt, rather than use a
48 particular undefined instruction to provoke a trap. Upon exection
49 of the software interrupt the kernel stops the inferior with a
498b1f87 50 SIGTRAP, and wakes the debugger. */
66e810cd 51
2ef47cd0
DJ
52static const char arm_linux_arm_le_breakpoint[] = { 0x01, 0x00, 0x9f, 0xef };
53
54static const char arm_linux_arm_be_breakpoint[] = { 0xef, 0x9f, 0x00, 0x01 };
66e810cd 55
c75a2cc8
DJ
56/* However, the EABI syscall interface (new in Nov. 2005) does not look at
57 the operand of the swi if old-ABI compatibility is disabled. Therefore,
58 use an undefined instruction instead. This is supported as of kernel
59 version 2.5.70 (May 2003), so should be a safe assumption for EABI
60 binaries. */
61
62static const char eabi_linux_arm_le_breakpoint[] = { 0xf0, 0x01, 0xf0, 0xe7 };
63
64static const char eabi_linux_arm_be_breakpoint[] = { 0xe7, 0xf0, 0x01, 0xf0 };
65
66/* All the kernels which support Thumb support using a specific undefined
67 instruction for the Thumb breakpoint. */
68
498b1f87
DJ
69static const char arm_linux_thumb_be_breakpoint[] = {0xde, 0x01};
70
71static const char arm_linux_thumb_le_breakpoint[] = {0x01, 0xde};
72
9df628e0 73/* Description of the longjmp buffer. */
7a5ea0d4 74#define ARM_LINUX_JB_ELEMENT_SIZE INT_REGISTER_SIZE
a6cdd8c5 75#define ARM_LINUX_JB_PC 21
faf5f7ad 76
f38e884d 77/*
fdf39c9a
RE
78 Dynamic Linking on ARM GNU/Linux
79 --------------------------------
f38e884d
SB
80
81 Note: PLT = procedure linkage table
82 GOT = global offset table
83
84 As much as possible, ELF dynamic linking defers the resolution of
85 jump/call addresses until the last minute. The technique used is
86 inspired by the i386 ELF design, and is based on the following
87 constraints.
88
89 1) The calling technique should not force a change in the assembly
90 code produced for apps; it MAY cause changes in the way assembly
91 code is produced for position independent code (i.e. shared
92 libraries).
93
94 2) The technique must be such that all executable areas must not be
95 modified; and any modified areas must not be executed.
96
97 To do this, there are three steps involved in a typical jump:
98
99 1) in the code
100 2) through the PLT
101 3) using a pointer from the GOT
102
103 When the executable or library is first loaded, each GOT entry is
104 initialized to point to the code which implements dynamic name
105 resolution and code finding. This is normally a function in the
fdf39c9a
RE
106 program interpreter (on ARM GNU/Linux this is usually
107 ld-linux.so.2, but it does not have to be). On the first
108 invocation, the function is located and the GOT entry is replaced
109 with the real function address. Subsequent calls go through steps
110 1, 2 and 3 and end up calling the real code.
f38e884d
SB
111
112 1) In the code:
113
114 b function_call
115 bl function_call
116
117 This is typical ARM code using the 26 bit relative branch or branch
118 and link instructions. The target of the instruction
119 (function_call is usually the address of the function to be called.
120 In position independent code, the target of the instruction is
121 actually an entry in the PLT when calling functions in a shared
122 library. Note that this call is identical to a normal function
123 call, only the target differs.
124
125 2) In the PLT:
126
127 The PLT is a synthetic area, created by the linker. It exists in
128 both executables and libraries. It is an array of stubs, one per
129 imported function call. It looks like this:
130
131 PLT[0]:
132 str lr, [sp, #-4]! @push the return address (lr)
133 ldr lr, [pc, #16] @load from 6 words ahead
134 add lr, pc, lr @form an address for GOT[0]
135 ldr pc, [lr, #8]! @jump to the contents of that addr
136
137 The return address (lr) is pushed on the stack and used for
138 calculations. The load on the second line loads the lr with
139 &GOT[3] - . - 20. The addition on the third leaves:
140
141 lr = (&GOT[3] - . - 20) + (. + 8)
142 lr = (&GOT[3] - 12)
143 lr = &GOT[0]
144
145 On the fourth line, the pc and lr are both updated, so that:
146
147 pc = GOT[2]
148 lr = &GOT[0] + 8
149 = &GOT[2]
150
151 NOTE: PLT[0] borrows an offset .word from PLT[1]. This is a little
152 "tight", but allows us to keep all the PLT entries the same size.
153
154 PLT[n+1]:
155 ldr ip, [pc, #4] @load offset from gotoff
156 add ip, pc, ip @add the offset to the pc
157 ldr pc, [ip] @jump to that address
158 gotoff: .word GOT[n+3] - .
159
160 The load on the first line, gets an offset from the fourth word of
161 the PLT entry. The add on the second line makes ip = &GOT[n+3],
162 which contains either a pointer to PLT[0] (the fixup trampoline) or
163 a pointer to the actual code.
164
165 3) In the GOT:
166
167 The GOT contains helper pointers for both code (PLT) fixups and
168 data fixups. The first 3 entries of the GOT are special. The next
169 M entries (where M is the number of entries in the PLT) belong to
170 the PLT fixups. The next D (all remaining) entries belong to
171 various data fixups. The actual size of the GOT is 3 + M + D.
172
173 The GOT is also a synthetic area, created by the linker. It exists
174 in both executables and libraries. When the GOT is first
175 initialized , all the GOT entries relating to PLT fixups are
176 pointing to code back at PLT[0].
177
178 The special entries in the GOT are:
179
180 GOT[0] = linked list pointer used by the dynamic loader
181 GOT[1] = pointer to the reloc table for this module
182 GOT[2] = pointer to the fixup/resolver code
183
184 The first invocation of function call comes through and uses the
185 fixup/resolver code. On the entry to the fixup/resolver code:
186
187 ip = &GOT[n+3]
188 lr = &GOT[2]
189 stack[0] = return address (lr) of the function call
190 [r0, r1, r2, r3] are still the arguments to the function call
191
192 This is enough information for the fixup/resolver code to work
193 with. Before the fixup/resolver code returns, it actually calls
194 the requested function and repairs &GOT[n+3]. */
195
2a451106
KB
196/* The constants below were determined by examining the following files
197 in the linux kernel sources:
198
199 arch/arm/kernel/signal.c
200 - see SWI_SYS_SIGRETURN and SWI_SYS_RT_SIGRETURN
201 include/asm-arm/unistd.h
202 - see __NR_sigreturn, __NR_rt_sigreturn, and __NR_SYSCALL_BASE */
203
204#define ARM_LINUX_SIGRETURN_INSTR 0xef900077
205#define ARM_LINUX_RT_SIGRETURN_INSTR 0xef9000ad
206
edfb1a26
DJ
207/* For ARM EABI, the syscall number is not in the SWI instruction
208 (instead it is loaded into r7). We recognize the pattern that
209 glibc uses... alternatively, we could arrange to do this by
210 function name, but they are not always exported. */
8e9d1a24
DJ
211#define ARM_SET_R7_SIGRETURN 0xe3a07077
212#define ARM_SET_R7_RT_SIGRETURN 0xe3a070ad
213#define ARM_EABI_SYSCALL 0xef000000
2a451106 214
8e9d1a24 215static void
a262aec2 216arm_linux_sigtramp_cache (struct frame_info *this_frame,
8e9d1a24
DJ
217 struct trad_frame_cache *this_cache,
218 CORE_ADDR func, int regs_offset)
2a451106 219{
a262aec2 220 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
8e9d1a24
DJ
221 CORE_ADDR base = sp + regs_offset;
222 int i;
2a451106 223
8e9d1a24
DJ
224 for (i = 0; i < 16; i++)
225 trad_frame_set_reg_addr (this_cache, i, base + i * 4);
2a451106 226
8e9d1a24 227 trad_frame_set_reg_addr (this_cache, ARM_PS_REGNUM, base + 16 * 4);
2a451106 228
8e9d1a24
DJ
229 /* The VFP or iWMMXt registers may be saved on the stack, but there's
230 no reliable way to restore them (yet). */
2a451106 231
8e9d1a24
DJ
232 /* Save a frame ID. */
233 trad_frame_set_id (this_cache, frame_id_build (sp, func));
234}
2a451106 235
edfb1a26
DJ
236/* There are a couple of different possible stack layouts that
237 we need to support.
238
239 Before version 2.6.18, the kernel used completely independent
240 layouts for non-RT and RT signals. For non-RT signals the stack
241 began directly with a struct sigcontext. For RT signals the stack
242 began with two redundant pointers (to the siginfo and ucontext),
243 and then the siginfo and ucontext.
244
245 As of version 2.6.18, the non-RT signal frame layout starts with
246 a ucontext and the RT signal frame starts with a siginfo and then
247 a ucontext. Also, the ucontext now has a designated save area
248 for coprocessor registers.
249
250 For RT signals, it's easy to tell the difference: we look for
251 pinfo, the pointer to the siginfo. If it has the expected
252 value, we have an old layout. If it doesn't, we have the new
253 layout.
254
255 For non-RT signals, it's a bit harder. We need something in one
256 layout or the other with a recognizable offset and value. We can't
257 use the return trampoline, because ARM usually uses SA_RESTORER,
258 in which case the stack return trampoline is not filled in.
259 We can't use the saved stack pointer, because sigaltstack might
260 be in use. So for now we guess the new layout... */
261
262/* There are three words (trap_no, error_code, oldmask) in
263 struct sigcontext before r0. */
264#define ARM_SIGCONTEXT_R0 0xc
265
266/* There are five words (uc_flags, uc_link, and three for uc_stack)
267 in the ucontext_t before the sigcontext. */
268#define ARM_UCONTEXT_SIGCONTEXT 0x14
269
270/* There are three elements in an rt_sigframe before the ucontext:
271 pinfo, puc, and info. The first two are pointers and the third
272 is a struct siginfo, with size 128 bytes. We could follow puc
273 to the ucontext, but it's simpler to skip the whole thing. */
274#define ARM_OLD_RT_SIGFRAME_SIGINFO 0x8
275#define ARM_OLD_RT_SIGFRAME_UCONTEXT 0x88
276
277#define ARM_NEW_RT_SIGFRAME_UCONTEXT 0x80
278
279#define ARM_NEW_SIGFRAME_MAGIC 0x5ac3c35a
280
8e9d1a24
DJ
281static void
282arm_linux_sigreturn_init (const struct tramp_frame *self,
a262aec2 283 struct frame_info *this_frame,
8e9d1a24
DJ
284 struct trad_frame_cache *this_cache,
285 CORE_ADDR func)
2a451106 286{
e17a4113
UW
287 struct gdbarch *gdbarch = get_frame_arch (this_frame);
288 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
a262aec2 289 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
e17a4113 290 ULONGEST uc_flags = read_memory_unsigned_integer (sp, 4, byte_order);
edfb1a26
DJ
291
292 if (uc_flags == ARM_NEW_SIGFRAME_MAGIC)
a262aec2 293 arm_linux_sigtramp_cache (this_frame, this_cache, func,
edfb1a26
DJ
294 ARM_UCONTEXT_SIGCONTEXT
295 + ARM_SIGCONTEXT_R0);
296 else
a262aec2 297 arm_linux_sigtramp_cache (this_frame, this_cache, func,
edfb1a26 298 ARM_SIGCONTEXT_R0);
8e9d1a24 299}
2a451106 300
8e9d1a24
DJ
301static void
302arm_linux_rt_sigreturn_init (const struct tramp_frame *self,
a262aec2 303 struct frame_info *this_frame,
8e9d1a24
DJ
304 struct trad_frame_cache *this_cache,
305 CORE_ADDR func)
306{
e17a4113
UW
307 struct gdbarch *gdbarch = get_frame_arch (this_frame);
308 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
a262aec2 309 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
e17a4113 310 ULONGEST pinfo = read_memory_unsigned_integer (sp, 4, byte_order);
edfb1a26
DJ
311
312 if (pinfo == sp + ARM_OLD_RT_SIGFRAME_SIGINFO)
a262aec2 313 arm_linux_sigtramp_cache (this_frame, this_cache, func,
edfb1a26
DJ
314 ARM_OLD_RT_SIGFRAME_UCONTEXT
315 + ARM_UCONTEXT_SIGCONTEXT
316 + ARM_SIGCONTEXT_R0);
317 else
a262aec2 318 arm_linux_sigtramp_cache (this_frame, this_cache, func,
edfb1a26
DJ
319 ARM_NEW_RT_SIGFRAME_UCONTEXT
320 + ARM_UCONTEXT_SIGCONTEXT
321 + ARM_SIGCONTEXT_R0);
2a451106
KB
322}
323
8e9d1a24
DJ
324static struct tramp_frame arm_linux_sigreturn_tramp_frame = {
325 SIGTRAMP_FRAME,
326 4,
327 {
328 { ARM_LINUX_SIGRETURN_INSTR, -1 },
329 { TRAMP_SENTINEL_INSN }
330 },
331 arm_linux_sigreturn_init
332};
333
334static struct tramp_frame arm_linux_rt_sigreturn_tramp_frame = {
335 SIGTRAMP_FRAME,
336 4,
337 {
338 { ARM_LINUX_RT_SIGRETURN_INSTR, -1 },
339 { TRAMP_SENTINEL_INSN }
340 },
341 arm_linux_rt_sigreturn_init
342};
343
344static struct tramp_frame arm_eabi_linux_sigreturn_tramp_frame = {
345 SIGTRAMP_FRAME,
346 4,
347 {
348 { ARM_SET_R7_SIGRETURN, -1 },
349 { ARM_EABI_SYSCALL, -1 },
350 { TRAMP_SENTINEL_INSN }
351 },
352 arm_linux_sigreturn_init
353};
354
355static struct tramp_frame arm_eabi_linux_rt_sigreturn_tramp_frame = {
356 SIGTRAMP_FRAME,
357 4,
358 {
359 { ARM_SET_R7_RT_SIGRETURN, -1 },
360 { ARM_EABI_SYSCALL, -1 },
361 { TRAMP_SENTINEL_INSN }
362 },
363 arm_linux_rt_sigreturn_init
364};
365
cb587d83
DJ
366/* Core file and register set support. */
367
368#define ARM_LINUX_SIZEOF_GREGSET (18 * INT_REGISTER_SIZE)
369
370void
371arm_linux_supply_gregset (const struct regset *regset,
372 struct regcache *regcache,
373 int regnum, const void *gregs_buf, size_t len)
374{
e17a4113
UW
375 struct gdbarch *gdbarch = get_regcache_arch (regcache);
376 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
cb587d83
DJ
377 const gdb_byte *gregs = gregs_buf;
378 int regno;
379 CORE_ADDR reg_pc;
380 gdb_byte pc_buf[INT_REGISTER_SIZE];
381
382 for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
383 if (regnum == -1 || regnum == regno)
384 regcache_raw_supply (regcache, regno,
385 gregs + INT_REGISTER_SIZE * regno);
386
387 if (regnum == ARM_PS_REGNUM || regnum == -1)
388 {
389 if (arm_apcs_32)
390 regcache_raw_supply (regcache, ARM_PS_REGNUM,
17c12639 391 gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM);
cb587d83
DJ
392 else
393 regcache_raw_supply (regcache, ARM_PS_REGNUM,
394 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
395 }
396
397 if (regnum == ARM_PC_REGNUM || regnum == -1)
398 {
399 reg_pc = extract_unsigned_integer (gregs
400 + INT_REGISTER_SIZE * ARM_PC_REGNUM,
e17a4113
UW
401 INT_REGISTER_SIZE, byte_order);
402 reg_pc = gdbarch_addr_bits_remove (gdbarch, reg_pc);
403 store_unsigned_integer (pc_buf, INT_REGISTER_SIZE, byte_order, reg_pc);
cb587d83
DJ
404 regcache_raw_supply (regcache, ARM_PC_REGNUM, pc_buf);
405 }
406}
407
408void
409arm_linux_collect_gregset (const struct regset *regset,
410 const struct regcache *regcache,
411 int regnum, void *gregs_buf, size_t len)
412{
413 gdb_byte *gregs = gregs_buf;
414 int regno;
415
416 for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
417 if (regnum == -1 || regnum == regno)
418 regcache_raw_collect (regcache, regno,
419 gregs + INT_REGISTER_SIZE * regno);
420
421 if (regnum == ARM_PS_REGNUM || regnum == -1)
422 {
423 if (arm_apcs_32)
424 regcache_raw_collect (regcache, ARM_PS_REGNUM,
17c12639 425 gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM);
cb587d83
DJ
426 else
427 regcache_raw_collect (regcache, ARM_PS_REGNUM,
428 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
429 }
430
431 if (regnum == ARM_PC_REGNUM || regnum == -1)
432 regcache_raw_collect (regcache, ARM_PC_REGNUM,
433 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
434}
435
436/* Support for register format used by the NWFPE FPA emulator. */
437
438#define typeNone 0x00
439#define typeSingle 0x01
440#define typeDouble 0x02
441#define typeExtended 0x03
442
443void
444supply_nwfpe_register (struct regcache *regcache, int regno,
445 const gdb_byte *regs)
446{
447 const gdb_byte *reg_data;
448 gdb_byte reg_tag;
449 gdb_byte buf[FP_REGISTER_SIZE];
450
451 reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE;
452 reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET];
453 memset (buf, 0, FP_REGISTER_SIZE);
454
455 switch (reg_tag)
456 {
457 case typeSingle:
458 memcpy (buf, reg_data, 4);
459 break;
460 case typeDouble:
461 memcpy (buf, reg_data + 4, 4);
462 memcpy (buf + 4, reg_data, 4);
463 break;
464 case typeExtended:
465 /* We want sign and exponent, then least significant bits,
466 then most significant. NWFPE does sign, most, least. */
467 memcpy (buf, reg_data, 4);
468 memcpy (buf + 4, reg_data + 8, 4);
469 memcpy (buf + 8, reg_data + 4, 4);
470 break;
471 default:
472 break;
473 }
474
475 regcache_raw_supply (regcache, regno, buf);
476}
477
478void
479collect_nwfpe_register (const struct regcache *regcache, int regno,
480 gdb_byte *regs)
481{
482 gdb_byte *reg_data;
483 gdb_byte reg_tag;
484 gdb_byte buf[FP_REGISTER_SIZE];
485
486 regcache_raw_collect (regcache, regno, buf);
487
488 /* NOTE drow/2006-06-07: This code uses the tag already in the
489 register buffer. I've preserved that when moving the code
490 from the native file to the target file. But this doesn't
491 always make sense. */
492
493 reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE;
494 reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET];
495
496 switch (reg_tag)
497 {
498 case typeSingle:
499 memcpy (reg_data, buf, 4);
500 break;
501 case typeDouble:
502 memcpy (reg_data, buf + 4, 4);
503 memcpy (reg_data + 4, buf, 4);
504 break;
505 case typeExtended:
506 memcpy (reg_data, buf, 4);
507 memcpy (reg_data + 4, buf + 8, 4);
508 memcpy (reg_data + 8, buf + 4, 4);
509 break;
510 default:
511 break;
512 }
513}
514
515void
516arm_linux_supply_nwfpe (const struct regset *regset,
517 struct regcache *regcache,
518 int regnum, const void *regs_buf, size_t len)
519{
520 const gdb_byte *regs = regs_buf;
521 int regno;
522
523 if (regnum == ARM_FPS_REGNUM || regnum == -1)
524 regcache_raw_supply (regcache, ARM_FPS_REGNUM,
525 regs + NWFPE_FPSR_OFFSET);
526
527 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
528 if (regnum == -1 || regnum == regno)
529 supply_nwfpe_register (regcache, regno, regs);
530}
531
532void
533arm_linux_collect_nwfpe (const struct regset *regset,
534 const struct regcache *regcache,
535 int regnum, void *regs_buf, size_t len)
536{
537 gdb_byte *regs = regs_buf;
538 int regno;
539
540 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
541 if (regnum == -1 || regnum == regno)
542 collect_nwfpe_register (regcache, regno, regs);
543
544 if (regnum == ARM_FPS_REGNUM || regnum == -1)
545 regcache_raw_collect (regcache, ARM_FPS_REGNUM,
546 regs + INT_REGISTER_SIZE * ARM_FPS_REGNUM);
547}
548
549/* Return the appropriate register set for the core section identified
550 by SECT_NAME and SECT_SIZE. */
551
552static const struct regset *
553arm_linux_regset_from_core_section (struct gdbarch *gdbarch,
554 const char *sect_name, size_t sect_size)
555{
556 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
557
558 if (strcmp (sect_name, ".reg") == 0
559 && sect_size == ARM_LINUX_SIZEOF_GREGSET)
560 {
561 if (tdep->gregset == NULL)
562 tdep->gregset = regset_alloc (gdbarch, arm_linux_supply_gregset,
563 arm_linux_collect_gregset);
564 return tdep->gregset;
565 }
566
567 if (strcmp (sect_name, ".reg2") == 0
568 && sect_size == ARM_LINUX_SIZEOF_NWFPE)
569 {
570 if (tdep->fpregset == NULL)
571 tdep->fpregset = regset_alloc (gdbarch, arm_linux_supply_nwfpe,
572 arm_linux_collect_nwfpe);
573 return tdep->fpregset;
574 }
575
576 return NULL;
577}
578
daddc3c1
DJ
579/* Insert a single step breakpoint at the next executed instruction. */
580
63807e1d 581static int
daddc3c1
DJ
582arm_linux_software_single_step (struct frame_info *frame)
583{
a6d9a66e 584 struct gdbarch *gdbarch = get_frame_arch (frame);
daddc3c1
DJ
585 CORE_ADDR next_pc = arm_get_next_pc (frame, get_frame_pc (frame));
586
587 /* The Linux kernel offers some user-mode helpers in a high page. We can
588 not read this page (as of 2.6.23), and even if we could then we couldn't
589 set breakpoints in it, and even if we could then the atomic operations
590 would fail when interrupted. They are all called as functions and return
591 to the address in LR, so step to there instead. */
592 if (next_pc > 0xffff0000)
593 next_pc = get_frame_register_unsigned (frame, ARM_LR_REGNUM);
594
a6d9a66e 595 insert_single_step_breakpoint (gdbarch, next_pc);
daddc3c1
DJ
596
597 return 1;
598}
599
97e03143
RE
600static void
601arm_linux_init_abi (struct gdbarch_info info,
602 struct gdbarch *gdbarch)
603{
604 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
605
606 tdep->lowest_pc = 0x8000;
2ef47cd0 607 if (info.byte_order == BFD_ENDIAN_BIG)
498b1f87 608 {
c75a2cc8
DJ
609 if (tdep->arm_abi == ARM_ABI_AAPCS)
610 tdep->arm_breakpoint = eabi_linux_arm_be_breakpoint;
611 else
612 tdep->arm_breakpoint = arm_linux_arm_be_breakpoint;
498b1f87
DJ
613 tdep->thumb_breakpoint = arm_linux_thumb_be_breakpoint;
614 }
2ef47cd0 615 else
498b1f87 616 {
c75a2cc8
DJ
617 if (tdep->arm_abi == ARM_ABI_AAPCS)
618 tdep->arm_breakpoint = eabi_linux_arm_le_breakpoint;
619 else
620 tdep->arm_breakpoint = arm_linux_arm_le_breakpoint;
498b1f87
DJ
621 tdep->thumb_breakpoint = arm_linux_thumb_le_breakpoint;
622 }
66e810cd 623 tdep->arm_breakpoint_size = sizeof (arm_linux_arm_le_breakpoint);
498b1f87 624 tdep->thumb_breakpoint_size = sizeof (arm_linux_thumb_le_breakpoint);
9df628e0 625
28e97307
DJ
626 if (tdep->fp_model == ARM_FLOAT_AUTO)
627 tdep->fp_model = ARM_FLOAT_FPA;
fd50bc42 628
a6cdd8c5
RE
629 tdep->jb_pc = ARM_LINUX_JB_PC;
630 tdep->jb_elt_size = ARM_LINUX_JB_ELEMENT_SIZE;
19d3fc80 631
7aa1783e 632 set_solib_svr4_fetch_link_map_offsets
76a9d10f 633 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
7aa1783e 634
190dce09 635 /* Single stepping. */
daddc3c1 636 set_gdbarch_software_single_step (gdbarch, arm_linux_software_single_step);
190dce09 637
0e18d038 638 /* Shared library handling. */
0e18d038 639 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
bb41a796 640 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
b2756930
KB
641
642 /* Enable TLS support. */
643 set_gdbarch_fetch_tls_load_module_address (gdbarch,
644 svr4_fetch_objfile_link_map);
8e9d1a24
DJ
645
646 tramp_frame_prepend_unwinder (gdbarch,
647 &arm_linux_sigreturn_tramp_frame);
648 tramp_frame_prepend_unwinder (gdbarch,
649 &arm_linux_rt_sigreturn_tramp_frame);
650 tramp_frame_prepend_unwinder (gdbarch,
651 &arm_eabi_linux_sigreturn_tramp_frame);
652 tramp_frame_prepend_unwinder (gdbarch,
653 &arm_eabi_linux_rt_sigreturn_tramp_frame);
cb587d83
DJ
654
655 /* Core file support. */
656 set_gdbarch_regset_from_core_section (gdbarch,
657 arm_linux_regset_from_core_section);
4aa995e1
PA
658
659 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
97e03143
RE
660}
661
63807e1d
PA
662/* Provide a prototype to silence -Wmissing-prototypes. */
663extern initialize_file_ftype _initialize_arm_linux_tdep;
664
faf5f7ad
SB
665void
666_initialize_arm_linux_tdep (void)
667{
05816f70
MK
668 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_LINUX,
669 arm_linux_init_abi);
faf5f7ad 670}
This page took 0.550987 seconds and 4 git commands to generate.