gdb/arm-linux-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* GNU/Linux on ARM target support.

  2.    Copyright (C) 1999-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "target.h"
  16. #include "value.h"
  17. #include "gdbtypes.h"
  18. #include "floatformat.h"
  19. #include "gdbcore.h"
  20. #include "frame.h"
  21. #include "regcache.h"
  22. #include "doublest.h"
  23. #include "solib-svr4.h"
  24. #include "osabi.h"
  25. #include "regset.h"
  26. #include "trad-frame.h"
  27. #include "tramp-frame.h"
  28. #include "breakpoint.h"
  29. #include "auxv.h"
  30. #include "xml-syscall.h"

  31. #include "arm-tdep.h"
  32. #include "arm-linux-tdep.h"
  33. #include "linux-tdep.h"
  34. #include "glibc-tdep.h"
  35. #include "arch-utils.h"
  36. #include "inferior.h"
  37. #include "infrun.h"
  38. #include "gdbthread.h"
  39. #include "symfile.h"

  40. #include "record-full.h"
  41. #include "linux-record.h"

  42. #include "cli/cli-utils.h"
  43. #include "stap-probe.h"
  44. #include "parser-defs.h"
  45. #include "user-regs.h"
  46. #include <ctype.h>
  47. #include "elf/common.h"
  48. extern int arm_apcs_32;

  49. /* Under ARM GNU/Linux the traditional way of performing a breakpoint
  50.    is to execute a particular software interrupt, rather than use a
  51.    particular undefined instruction to provoke a trap.  Upon exection
  52.    of the software interrupt the kernel stops the inferior with a
  53.    SIGTRAP, and wakes the debugger.  */

  54. static const gdb_byte arm_linux_arm_le_breakpoint[] = { 0x01, 0x00, 0x9f, 0xef };

  55. static const gdb_byte arm_linux_arm_be_breakpoint[] = { 0xef, 0x9f, 0x00, 0x01 };

  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. static const gdb_byte eabi_linux_arm_le_breakpoint[] = { 0xf0, 0x01, 0xf0, 0xe7 };

  62. static const gdb_byte eabi_linux_arm_be_breakpoint[] = { 0xe7, 0xf0, 0x01, 0xf0 };

  63. /* All the kernels which support Thumb support using a specific undefined
  64.    instruction for the Thumb breakpoint.  */

  65. static const gdb_byte arm_linux_thumb_be_breakpoint[] = {0xde, 0x01};

  66. static const gdb_byte arm_linux_thumb_le_breakpoint[] = {0x01, 0xde};

  67. /* Because the 16-bit Thumb breakpoint is affected by Thumb-2 IT blocks,
  68.    we must use a length-appropriate breakpoint for 32-bit Thumb
  69.    instructions.  See also thumb_get_next_pc.  */

  70. static const gdb_byte arm_linux_thumb2_be_breakpoint[] = { 0xf7, 0xf0, 0xa0, 0x00 };

  71. static const gdb_byte arm_linux_thumb2_le_breakpoint[] = { 0xf0, 0xf7, 0x00, 0xa0 };

  72. /* Description of the longjmp buffer.  The buffer is treated as an array of
  73.    elements of size ARM_LINUX_JB_ELEMENT_SIZE.

  74.    The location of saved registers in this buffer (in particular the PC
  75.    to use after longjmp is called) varies depending on the ABI (in
  76.    particular the FP model) and also (possibly) the C Library.

  77.    For glibc, eglibc, and uclibc the following holds:  If the FP model is
  78.    SoftVFP or VFP (which implies EABI) then the PC is at offset 9 in the
  79.    buffer.  This is also true for the SoftFPA model.  However, for the FPA
  80.    model the PC is at offset 21 in the buffer.  */
  81. #define ARM_LINUX_JB_ELEMENT_SIZE        INT_REGISTER_SIZE
  82. #define ARM_LINUX_JB_PC_FPA                21
  83. #define ARM_LINUX_JB_PC_EABI                9

  84. /*
  85.    Dynamic Linking on ARM GNU/Linux
  86.    --------------------------------

  87.    Note: PLT = procedure linkage table
  88.    GOT = global offset table

  89.    As much as possible, ELF dynamic linking defers the resolution of
  90.    jump/call addresses until the last minute.  The technique used is
  91.    inspired by the i386 ELF design, and is based on the following
  92.    constraints.

  93.    1) The calling technique should not force a change in the assembly
  94.    code produced for apps; it MAY cause changes in the way assembly
  95.    code is produced for position independent code (i.e. shared
  96.    libraries).

  97.    2) The technique must be such that all executable areas must not be
  98.    modified; and any modified areas must not be executed.

  99.    To do this, there are three steps involved in a typical jump:

  100.    1) in the code
  101.    2) through the PLT
  102.    3) using a pointer from the GOT

  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
  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.

  111.    1) In the code:

  112.    b    function_call
  113.    bl   function_call

  114.    This is typical ARM code using the 26 bit relative branch or branch
  115.    and link instructions.  The target of the instruction
  116.    (function_call is usually the address of the function to be called.
  117.    In position independent code, the target of the instruction is
  118.    actually an entry in the PLT when calling functions in a shared
  119.    library.  Note that this call is identical to a normal function
  120.    call, only the target differs.

  121.    2) In the PLT:

  122.    The PLT is a synthetic area, created by the linker.  It exists in
  123.    both executables and libraries.  It is an array of stubs, one per
  124.    imported function call.  It looks like this:

  125.    PLT[0]:
  126.    str     lr, [sp, #-4]!       @push the return address (lr)
  127.    ldr     lr, [pc, #16]   @load from 6 words ahead
  128.    add     lr, pc, lr      @form an address for GOT[0]
  129.    ldr     pc, [lr, #8]!   @jump to the contents of that addr

  130.    The return address (lr) is pushed on the stack and used for
  131.    calculations.  The load on the second line loads the lr with
  132.    &GOT[3] - . - 20.  The addition on the third leaves:

  133.    lr = (&GOT[3] - . - 20) + (. + 8)
  134.    lr = (&GOT[3] - 12)
  135.    lr = &GOT[0]

  136.    On the fourth line, the pc and lr are both updated, so that:

  137.    pc = GOT[2]
  138.    lr = &GOT[0] + 8
  139.    = &GOT[2]

  140.    NOTE: PLT[0] borrows an offset .word from PLT[1].  This is a little
  141.    "tight", but allows us to keep all the PLT entries the same size.

  142.    PLT[n+1]:
  143.    ldr     ip, [pc, #4]    @load offset from gotoff
  144.    add     ip, pc, ip      @add the offset to the pc
  145.    ldr     pc, [ip]        @jump to that address
  146.    gotoff: .word   GOT[n+3] - .

  147.    The load on the first line, gets an offset from the fourth word of
  148.    the PLT entry.  The add on the second line makes ip = &GOT[n+3],
  149.    which contains either a pointer to PLT[0] (the fixup trampoline) or
  150.    a pointer to the actual code.

  151.    3) In the GOT:

  152.    The GOT contains helper pointers for both code (PLT) fixups and
  153.    data fixups.  The first 3 entries of the GOT are special.  The next
  154.    M entries (where M is the number of entries in the PLT) belong to
  155.    the PLT fixups.  The next D (all remaining) entries belong to
  156.    various data fixups.  The actual size of the GOT is 3 + M + D.

  157.    The GOT is also a synthetic area, created by the linker.  It exists
  158.    in both executables and libraries.  When the GOT is first
  159.    initialized , all the GOT entries relating to PLT fixups are
  160.    pointing to code back at PLT[0].

  161.    The special entries in the GOT are:

  162.    GOT[0] = linked list pointer used by the dynamic loader
  163.    GOT[1] = pointer to the reloc table for this module
  164.    GOT[2] = pointer to the fixup/resolver code

  165.    The first invocation of function call comes through and uses the
  166.    fixup/resolver code.  On the entry to the fixup/resolver code:

  167.    ip = &GOT[n+3]
  168.    lr = &GOT[2]
  169.    stack[0] = return address (lr) of the function call
  170.    [r0, r1, r2, r3] are still the arguments to the function call

  171.    This is enough information for the fixup/resolver code to work
  172.    with.  Before the fixup/resolver code returns, it actually calls
  173.    the requested function and repairs &GOT[n+3].  */

  174. /* The constants below were determined by examining the following files
  175.    in the linux kernel sources:

  176.       arch/arm/kernel/signal.c
  177.           - see SWI_SYS_SIGRETURN and SWI_SYS_RT_SIGRETURN
  178.       include/asm-arm/unistd.h
  179.           - see __NR_sigreturn, __NR_rt_sigreturn, and __NR_SYSCALL_BASE */

  180. #define ARM_LINUX_SIGRETURN_INSTR        0xef900077
  181. #define ARM_LINUX_RT_SIGRETURN_INSTR        0xef9000ad

  182. /* For ARM EABI, the syscall number is not in the SWI instruction
  183.    (instead it is loaded into r7).  We recognize the pattern that
  184.    glibc uses...  alternatively, we could arrange to do this by
  185.    function name, but they are not always exported.  */
  186. #define ARM_SET_R7_SIGRETURN                0xe3a07077
  187. #define ARM_SET_R7_RT_SIGRETURN                0xe3a070ad
  188. #define ARM_EABI_SYSCALL                0xef000000

  189. /* Equivalent patterns for Thumb2.  */
  190. #define THUMB2_SET_R7_SIGRETURN1        0xf04f
  191. #define THUMB2_SET_R7_SIGRETURN2        0x0777
  192. #define THUMB2_SET_R7_RT_SIGRETURN1        0xf04f
  193. #define THUMB2_SET_R7_RT_SIGRETURN2        0x07ad
  194. #define THUMB2_EABI_SYSCALL                0xdf00

  195. /* OABI syscall restart trampoline, used for EABI executables too
  196.    whenever OABI support has been enabled in the kernel.  */
  197. #define ARM_OABI_SYSCALL_RESTART_SYSCALL 0xef900000
  198. #define ARM_LDR_PC_SP_12                0xe49df00c
  199. #define ARM_LDR_PC_SP_4                        0xe49df004

  200. static void
  201. arm_linux_sigtramp_cache (struct frame_info *this_frame,
  202.                           struct trad_frame_cache *this_cache,
  203.                           CORE_ADDR func, int regs_offset)
  204. {
  205.   CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
  206.   CORE_ADDR base = sp + regs_offset;
  207.   int i;

  208.   for (i = 0; i < 16; i++)
  209.     trad_frame_set_reg_addr (this_cache, i, base + i * 4);

  210.   trad_frame_set_reg_addr (this_cache, ARM_PS_REGNUM, base + 16 * 4);

  211.   /* The VFP or iWMMXt registers may be saved on the stack, but there's
  212.      no reliable way to restore them (yet).  */

  213.   /* Save a frame ID.  */
  214.   trad_frame_set_id (this_cache, frame_id_build (sp, func));
  215. }

  216. /* There are a couple of different possible stack layouts that
  217.    we need to support.

  218.    Before version 2.6.18, the kernel used completely independent
  219.    layouts for non-RT and RT signals.  For non-RT signals the stack
  220.    began directly with a struct sigcontext.  For RT signals the stack
  221.    began with two redundant pointers (to the siginfo and ucontext),
  222.    and then the siginfo and ucontext.

  223.    As of version 2.6.18, the non-RT signal frame layout starts with
  224.    a ucontext and the RT signal frame starts with a siginfo and then
  225.    a ucontext.  Also, the ucontext now has a designated save area
  226.    for coprocessor registers.

  227.    For RT signals, it's easy to tell the difference: we look for
  228.    pinfo, the pointer to the siginfo.  If it has the expected
  229.    value, we have an old layout.  If it doesn't, we have the new
  230.    layout.

  231.    For non-RT signals, it's a bit harder.  We need something in one
  232.    layout or the other with a recognizable offset and value.  We can't
  233.    use the return trampoline, because ARM usually uses SA_RESTORER,
  234.    in which case the stack return trampoline is not filled in.
  235.    We can't use the saved stack pointer, because sigaltstack might
  236.    be in use.  So for now we guess the new layout...  */

  237. /* There are three words (trap_no, error_code, oldmask) in
  238.    struct sigcontext before r0.  */
  239. #define ARM_SIGCONTEXT_R0 0xc

  240. /* There are five words (uc_flags, uc_link, and three for uc_stack)
  241.    in the ucontext_t before the sigcontext.  */
  242. #define ARM_UCONTEXT_SIGCONTEXT 0x14

  243. /* There are three elements in an rt_sigframe before the ucontext:
  244.    pinfo, puc, and info.  The first two are pointers and the third
  245.    is a struct siginfo, with size 128 bytes.  We could follow puc
  246.    to the ucontext, but it's simpler to skip the whole thing.  */
  247. #define ARM_OLD_RT_SIGFRAME_SIGINFO 0x8
  248. #define ARM_OLD_RT_SIGFRAME_UCONTEXT 0x88

  249. #define ARM_NEW_RT_SIGFRAME_UCONTEXT 0x80

  250. #define ARM_NEW_SIGFRAME_MAGIC 0x5ac3c35a

  251. static void
  252. arm_linux_sigreturn_init (const struct tramp_frame *self,
  253.                           struct frame_info *this_frame,
  254.                           struct trad_frame_cache *this_cache,
  255.                           CORE_ADDR func)
  256. {
  257.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  258.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  259.   CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
  260.   ULONGEST uc_flags = read_memory_unsigned_integer (sp, 4, byte_order);

  261.   if (uc_flags == ARM_NEW_SIGFRAME_MAGIC)
  262.     arm_linux_sigtramp_cache (this_frame, this_cache, func,
  263.                               ARM_UCONTEXT_SIGCONTEXT
  264.                               + ARM_SIGCONTEXT_R0);
  265.   else
  266.     arm_linux_sigtramp_cache (this_frame, this_cache, func,
  267.                               ARM_SIGCONTEXT_R0);
  268. }

  269. static void
  270. arm_linux_rt_sigreturn_init (const struct tramp_frame *self,
  271.                           struct frame_info *this_frame,
  272.                           struct trad_frame_cache *this_cache,
  273.                           CORE_ADDR func)
  274. {
  275.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  276.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  277.   CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
  278.   ULONGEST pinfo = read_memory_unsigned_integer (sp, 4, byte_order);

  279.   if (pinfo == sp + ARM_OLD_RT_SIGFRAME_SIGINFO)
  280.     arm_linux_sigtramp_cache (this_frame, this_cache, func,
  281.                               ARM_OLD_RT_SIGFRAME_UCONTEXT
  282.                               + ARM_UCONTEXT_SIGCONTEXT
  283.                               + ARM_SIGCONTEXT_R0);
  284.   else
  285.     arm_linux_sigtramp_cache (this_frame, this_cache, func,
  286.                               ARM_NEW_RT_SIGFRAME_UCONTEXT
  287.                               + ARM_UCONTEXT_SIGCONTEXT
  288.                               + ARM_SIGCONTEXT_R0);
  289. }

  290. static void
  291. arm_linux_restart_syscall_init (const struct tramp_frame *self,
  292.                                 struct frame_info *this_frame,
  293.                                 struct trad_frame_cache *this_cache,
  294.                                 CORE_ADDR func)
  295. {
  296.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  297.   CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM);
  298.   CORE_ADDR pc = get_frame_memory_unsigned (this_frame, sp, 4);
  299.   CORE_ADDR cpsr = get_frame_register_unsigned (this_frame, ARM_PS_REGNUM);
  300.   ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
  301.   int sp_offset;

  302.   /* There are two variants of this trampoline; with older kernels, the
  303.      stub is placed on the stack, while newer kernels use the stub from
  304.      the vector page.  They are identical except that the older version
  305.      increments SP by 12 (to skip stored PC and the stub itself), while
  306.      the newer version increments SP only by 4 (just the stored PC).  */
  307.   if (self->insn[1].bytes == ARM_LDR_PC_SP_4)
  308.     sp_offset = 4;
  309.   else
  310.     sp_offset = 12;

  311.   /* Update Thumb bit in CPSR.  */
  312.   if (pc & 1)
  313.     cpsr |= t_bit;
  314.   else
  315.     cpsr &= ~t_bit;

  316.   /* Remove Thumb bit from PC.  */
  317.   pc = gdbarch_addr_bits_remove (gdbarch, pc);

  318.   /* Save previous register values.  */
  319.   trad_frame_set_reg_value (this_cache, ARM_SP_REGNUM, sp + sp_offset);
  320.   trad_frame_set_reg_value (this_cache, ARM_PC_REGNUM, pc);
  321.   trad_frame_set_reg_value (this_cache, ARM_PS_REGNUM, cpsr);

  322.   /* Save a frame ID.  */
  323.   trad_frame_set_id (this_cache, frame_id_build (sp, func));
  324. }

  325. static struct tramp_frame arm_linux_sigreturn_tramp_frame = {
  326.   SIGTRAMP_FRAME,
  327.   4,
  328.   {
  329.     { ARM_LINUX_SIGRETURN_INSTR, -1 },
  330.     { TRAMP_SENTINEL_INSN }
  331.   },
  332.   arm_linux_sigreturn_init
  333. };

  334. static 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. static struct tramp_frame arm_eabi_linux_sigreturn_tramp_frame = {
  344.   SIGTRAMP_FRAME,
  345.   4,
  346.   {
  347.     { ARM_SET_R7_SIGRETURN, -1 },
  348.     { ARM_EABI_SYSCALL, -1 },
  349.     { TRAMP_SENTINEL_INSN }
  350.   },
  351.   arm_linux_sigreturn_init
  352. };

  353. static struct tramp_frame arm_eabi_linux_rt_sigreturn_tramp_frame = {
  354.   SIGTRAMP_FRAME,
  355.   4,
  356.   {
  357.     { ARM_SET_R7_RT_SIGRETURN, -1 },
  358.     { ARM_EABI_SYSCALL, -1 },
  359.     { TRAMP_SENTINEL_INSN }
  360.   },
  361.   arm_linux_rt_sigreturn_init
  362. };

  363. static struct tramp_frame thumb2_eabi_linux_sigreturn_tramp_frame = {
  364.   SIGTRAMP_FRAME,
  365.   2,
  366.   {
  367.     { THUMB2_SET_R7_SIGRETURN1, -1 },
  368.     { THUMB2_SET_R7_SIGRETURN2, -1 },
  369.     { THUMB2_EABI_SYSCALL, -1 },
  370.     { TRAMP_SENTINEL_INSN }
  371.   },
  372.   arm_linux_sigreturn_init
  373. };

  374. static struct tramp_frame thumb2_eabi_linux_rt_sigreturn_tramp_frame = {
  375.   SIGTRAMP_FRAME,
  376.   2,
  377.   {
  378.     { THUMB2_SET_R7_RT_SIGRETURN1, -1 },
  379.     { THUMB2_SET_R7_RT_SIGRETURN2, -1 },
  380.     { THUMB2_EABI_SYSCALL, -1 },
  381.     { TRAMP_SENTINEL_INSN }
  382.   },
  383.   arm_linux_rt_sigreturn_init
  384. };

  385. static struct tramp_frame arm_linux_restart_syscall_tramp_frame = {
  386.   NORMAL_FRAME,
  387.   4,
  388.   {
  389.     { ARM_OABI_SYSCALL_RESTART_SYSCALL, -1 },
  390.     { ARM_LDR_PC_SP_12, -1 },
  391.     { TRAMP_SENTINEL_INSN }
  392.   },
  393.   arm_linux_restart_syscall_init
  394. };

  395. static struct tramp_frame arm_kernel_linux_restart_syscall_tramp_frame = {
  396.   NORMAL_FRAME,
  397.   4,
  398.   {
  399.     { ARM_OABI_SYSCALL_RESTART_SYSCALL, -1 },
  400.     { ARM_LDR_PC_SP_4, -1 },
  401.     { TRAMP_SENTINEL_INSN }
  402.   },
  403.   arm_linux_restart_syscall_init
  404. };

  405. /* Core file and register set support.  */

  406. #define ARM_LINUX_SIZEOF_GREGSET (18 * INT_REGISTER_SIZE)

  407. void
  408. arm_linux_supply_gregset (const struct regset *regset,
  409.                           struct regcache *regcache,
  410.                           int regnum, const void *gregs_buf, size_t len)
  411. {
  412.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  413.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  414.   const gdb_byte *gregs = gregs_buf;
  415.   int regno;
  416.   CORE_ADDR reg_pc;
  417.   gdb_byte pc_buf[INT_REGISTER_SIZE];

  418.   for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
  419.     if (regnum == -1 || regnum == regno)
  420.       regcache_raw_supply (regcache, regno,
  421.                            gregs + INT_REGISTER_SIZE * regno);

  422.   if (regnum == ARM_PS_REGNUM || regnum == -1)
  423.     {
  424.       if (arm_apcs_32)
  425.         regcache_raw_supply (regcache, ARM_PS_REGNUM,
  426.                              gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM);
  427.       else
  428.         regcache_raw_supply (regcache, ARM_PS_REGNUM,
  429.                              gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
  430.     }

  431.   if (regnum == ARM_PC_REGNUM || regnum == -1)
  432.     {
  433.       reg_pc = extract_unsigned_integer (gregs
  434.                                          + INT_REGISTER_SIZE * ARM_PC_REGNUM,
  435.                                          INT_REGISTER_SIZE, byte_order);
  436.       reg_pc = gdbarch_addr_bits_remove (gdbarch, reg_pc);
  437.       store_unsigned_integer (pc_buf, INT_REGISTER_SIZE, byte_order, reg_pc);
  438.       regcache_raw_supply (regcache, ARM_PC_REGNUM, pc_buf);
  439.     }
  440. }

  441. void
  442. arm_linux_collect_gregset (const struct regset *regset,
  443.                            const struct regcache *regcache,
  444.                            int regnum, void *gregs_buf, size_t len)
  445. {
  446.   gdb_byte *gregs = gregs_buf;
  447.   int regno;

  448.   for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++)
  449.     if (regnum == -1 || regnum == regno)
  450.       regcache_raw_collect (regcache, regno,
  451.                             gregs + INT_REGISTER_SIZE * regno);

  452.   if (regnum == ARM_PS_REGNUM || regnum == -1)
  453.     {
  454.       if (arm_apcs_32)
  455.         regcache_raw_collect (regcache, ARM_PS_REGNUM,
  456.                               gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM);
  457.       else
  458.         regcache_raw_collect (regcache, ARM_PS_REGNUM,
  459.                               gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
  460.     }

  461.   if (regnum == ARM_PC_REGNUM || regnum == -1)
  462.     regcache_raw_collect (regcache, ARM_PC_REGNUM,
  463.                           gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM);
  464. }

  465. /* Support for register format used by the NWFPE FPA emulator.  */

  466. #define typeNone                0x00
  467. #define typeSingle                0x01
  468. #define typeDouble                0x02
  469. #define typeExtended                0x03

  470. void
  471. supply_nwfpe_register (struct regcache *regcache, int regno,
  472.                        const gdb_byte *regs)
  473. {
  474.   const gdb_byte *reg_data;
  475.   gdb_byte reg_tag;
  476.   gdb_byte buf[FP_REGISTER_SIZE];

  477.   reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE;
  478.   reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET];
  479.   memset (buf, 0, FP_REGISTER_SIZE);

  480.   switch (reg_tag)
  481.     {
  482.     case typeSingle:
  483.       memcpy (buf, reg_data, 4);
  484.       break;
  485.     case typeDouble:
  486.       memcpy (buf, reg_data + 4, 4);
  487.       memcpy (buf + 4, reg_data, 4);
  488.       break;
  489.     case typeExtended:
  490.       /* We want sign and exponent, then least significant bits,
  491.          then most significant.  NWFPE does sign, most, least.  */
  492.       memcpy (buf, reg_data, 4);
  493.       memcpy (buf + 4, reg_data + 8, 4);
  494.       memcpy (buf + 8, reg_data + 4, 4);
  495.       break;
  496.     default:
  497.       break;
  498.     }

  499.   regcache_raw_supply (regcache, regno, buf);
  500. }

  501. void
  502. collect_nwfpe_register (const struct regcache *regcache, int regno,
  503.                         gdb_byte *regs)
  504. {
  505.   gdb_byte *reg_data;
  506.   gdb_byte reg_tag;
  507.   gdb_byte buf[FP_REGISTER_SIZE];

  508.   regcache_raw_collect (regcache, regno, buf);

  509.   /* NOTE drow/2006-06-07: This code uses the tag already in the
  510.      register bufferI've preserved that when moving the code
  511.      from the native file to the target file.  But this doesn't
  512.      always make sense.  */

  513.   reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE;
  514.   reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET];

  515.   switch (reg_tag)
  516.     {
  517.     case typeSingle:
  518.       memcpy (reg_data, buf, 4);
  519.       break;
  520.     case typeDouble:
  521.       memcpy (reg_data, buf + 4, 4);
  522.       memcpy (reg_data + 4, buf, 4);
  523.       break;
  524.     case typeExtended:
  525.       memcpy (reg_data, buf, 4);
  526.       memcpy (reg_data + 4, buf + 8, 4);
  527.       memcpy (reg_data + 8, buf + 4, 4);
  528.       break;
  529.     default:
  530.       break;
  531.     }
  532. }

  533. void
  534. arm_linux_supply_nwfpe (const struct regset *regset,
  535.                         struct regcache *regcache,
  536.                         int regnum, const void *regs_buf, size_t len)
  537. {
  538.   const gdb_byte *regs = regs_buf;
  539.   int regno;

  540.   if (regnum == ARM_FPS_REGNUM || regnum == -1)
  541.     regcache_raw_supply (regcache, ARM_FPS_REGNUM,
  542.                          regs + NWFPE_FPSR_OFFSET);

  543.   for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
  544.     if (regnum == -1 || regnum == regno)
  545.       supply_nwfpe_register (regcache, regno, regs);
  546. }

  547. void
  548. arm_linux_collect_nwfpe (const struct regset *regset,
  549.                          const struct regcache *regcache,
  550.                          int regnum, void *regs_buf, size_t len)
  551. {
  552.   gdb_byte *regs = regs_buf;
  553.   int regno;

  554.   for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++)
  555.     if (regnum == -1 || regnum == regno)
  556.       collect_nwfpe_register (regcache, regno, regs);

  557.   if (regnum == ARM_FPS_REGNUM || regnum == -1)
  558.     regcache_raw_collect (regcache, ARM_FPS_REGNUM,
  559.                           regs + INT_REGISTER_SIZE * ARM_FPS_REGNUM);
  560. }

  561. /* Support VFP register format.  */

  562. #define ARM_LINUX_SIZEOF_VFP (32 * 8 + 4)

  563. static void
  564. arm_linux_supply_vfp (const struct regset *regset,
  565.                       struct regcache *regcache,
  566.                       int regnum, const void *regs_buf, size_t len)
  567. {
  568.   const gdb_byte *regs = regs_buf;
  569.   int regno;

  570.   if (regnum == ARM_FPSCR_REGNUM || regnum == -1)
  571.     regcache_raw_supply (regcache, ARM_FPSCR_REGNUM, regs + 32 * 8);

  572.   for (regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++)
  573.     if (regnum == -1 || regnum == regno)
  574.       regcache_raw_supply (regcache, regno,
  575.                            regs + (regno - ARM_D0_REGNUM) * 8);
  576. }

  577. static void
  578. arm_linux_collect_vfp (const struct regset *regset,
  579.                          const struct regcache *regcache,
  580.                          int regnum, void *regs_buf, size_t len)
  581. {
  582.   gdb_byte *regs = regs_buf;
  583.   int regno;

  584.   if (regnum == ARM_FPSCR_REGNUM || regnum == -1)
  585.     regcache_raw_collect (regcache, ARM_FPSCR_REGNUM, regs + 32 * 8);

  586.   for (regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++)
  587.     if (regnum == -1 || regnum == regno)
  588.       regcache_raw_collect (regcache, regno,
  589.                             regs + (regno - ARM_D0_REGNUM) * 8);
  590. }

  591. static const struct regset arm_linux_gregset =
  592.   {
  593.     NULL, arm_linux_supply_gregset, arm_linux_collect_gregset
  594.   };

  595. static const struct regset arm_linux_fpregset =
  596.   {
  597.     NULL, arm_linux_supply_nwfpe, arm_linux_collect_nwfpe
  598.   };

  599. static const struct regset arm_linux_vfpregset =
  600.   {
  601.     NULL, arm_linux_supply_vfp, arm_linux_collect_vfp
  602.   };

  603. /* Iterate over core file register note sections.  */

  604. static void
  605. arm_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  606.                                         iterate_over_regset_sections_cb *cb,
  607.                                         void *cb_data,
  608.                                         const struct regcache *regcache)
  609. {
  610.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  611.   cb (".reg", ARM_LINUX_SIZEOF_GREGSET, &arm_linux_gregset, NULL, cb_data);

  612.   if (tdep->have_vfp_registers)
  613.     cb (".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, &arm_linux_vfpregset,
  614.         "VFP floating-point", cb_data);
  615.   else if (tdep->have_fpa_registers)
  616.     cb (".reg2", ARM_LINUX_SIZEOF_NWFPE, &arm_linux_fpregset,
  617.         "FPA floating-point", cb_data);
  618. }

  619. /* Determine target description from core file.  */

  620. static const struct target_desc *
  621. arm_linux_core_read_description (struct gdbarch *gdbarch,
  622.                                  struct target_ops *target,
  623.                                  bfd *abfd)
  624. {
  625.   CORE_ADDR arm_hwcap = 0;

  626.   if (target_auxv_search (target, AT_HWCAP, &arm_hwcap) != 1)
  627.     return NULL;

  628.   if (arm_hwcap & HWCAP_VFP)
  629.     {
  630.       /* NEON implies VFPv3-D32 or no-VFP unit.  Say that we only support
  631.          Neon with VFPv3-D32.  */
  632.       if (arm_hwcap & HWCAP_NEON)
  633.         return tdesc_arm_with_neon;
  634.       else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
  635.         return tdesc_arm_with_vfpv3;
  636.       else
  637.         return tdesc_arm_with_vfpv2;
  638.     }

  639.   return NULL;
  640. }


  641. /* Copy the value of next pc of sigreturn and rt_sigrturn into PC,
  642.    return 1.  In addition, set IS_THUMB depending on whether we
  643.    will return to ARM or Thumb code.  Return 0 if it is not a
  644.    rt_sigreturn/sigreturn syscall.  */
  645. static int
  646. arm_linux_sigreturn_return_addr (struct frame_info *frame,
  647.                                  unsigned long svc_number,
  648.                                  CORE_ADDR *pc, int *is_thumb)
  649. {
  650.   /* Is this a sigreturn or rt_sigreturn syscall?  */
  651.   if (svc_number == 119 || svc_number == 173)
  652.     {
  653.       if (get_frame_type (frame) == SIGTRAMP_FRAME)
  654.         {
  655.           ULONGEST t_bit = arm_psr_thumb_bit (frame_unwind_arch (frame));
  656.           CORE_ADDR cpsr
  657.             = frame_unwind_register_unsigned (frame, ARM_PS_REGNUM);

  658.           *is_thumb = (cpsr & t_bit) != 0;
  659.           *pc = frame_unwind_caller_pc (frame);
  660.           return 1;
  661.         }
  662.     }
  663.   return 0;
  664. }

  665. /* At a ptrace syscall-stop, return the syscall number.  This either
  666.    comes from the SWI instruction (OABI) or from r7 (EABI).

  667.    When the function fails, it should return -1.  */

  668. static LONGEST
  669. arm_linux_get_syscall_number (struct gdbarch *gdbarch,
  670.                               ptid_t ptid)
  671. {
  672.   struct regcache *regs = get_thread_regcache (ptid);
  673.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  674.   ULONGEST pc;
  675.   ULONGEST cpsr;
  676.   ULONGEST t_bit = arm_psr_thumb_bit (gdbarch);
  677.   int is_thumb;
  678.   ULONGEST svc_number = -1;

  679.   regcache_cooked_read_unsigned (regs, ARM_PC_REGNUM, &pc);
  680.   regcache_cooked_read_unsigned (regs, ARM_PS_REGNUM, &cpsr);
  681.   is_thumb = (cpsr & t_bit) != 0;

  682.   if (is_thumb)
  683.     {
  684.       regcache_cooked_read_unsigned (regs, 7, &svc_number);
  685.     }
  686.   else
  687.     {
  688.       enum bfd_endian byte_order_for_code =
  689.         gdbarch_byte_order_for_code (gdbarch);

  690.       /* PC gets incremented before the syscall-stop, so read the
  691.          previous instruction.  */
  692.       unsigned long this_instr =
  693.         read_memory_unsigned_integer (pc - 4, 4, byte_order_for_code);

  694.       unsigned long svc_operand = (0x00ffffff & this_instr);

  695.       if (svc_operand)
  696.         {
  697.           /* OABI */
  698.           svc_number = svc_operand - 0x900000;
  699.         }
  700.       else
  701.         {
  702.           /* EABI */
  703.           regcache_cooked_read_unsigned (regs, 7, &svc_number);
  704.         }
  705.     }

  706.   return svc_number;
  707. }

  708. /* When FRAME is at a syscall instruction, return the PC of the next
  709.    instruction to be executed.  */

  710. static CORE_ADDR
  711. arm_linux_syscall_next_pc (struct frame_info *frame)
  712. {
  713.   CORE_ADDR pc = get_frame_pc (frame);
  714.   CORE_ADDR return_addr = 0;
  715.   int is_thumb = arm_frame_is_thumb (frame);
  716.   ULONGEST svc_number = 0;

  717.   if (is_thumb)
  718.     {
  719.       svc_number = get_frame_register_unsigned (frame, 7);
  720.       return_addr = pc + 2;
  721.     }
  722.   else
  723.     {
  724.       struct gdbarch *gdbarch = get_frame_arch (frame);
  725.       enum bfd_endian byte_order_for_code =
  726.         gdbarch_byte_order_for_code (gdbarch);
  727.       unsigned long this_instr =
  728.         read_memory_unsigned_integer (pc, 4, byte_order_for_code);

  729.       unsigned long svc_operand = (0x00ffffff & this_instr);
  730.       if (svc_operand)  /* OABI.  */
  731.         {
  732.           svc_number = svc_operand - 0x900000;
  733.         }
  734.       else /* EABI.  */
  735.         {
  736.           svc_number = get_frame_register_unsigned (frame, 7);
  737.         }

  738.       return_addr = pc + 4;
  739.     }

  740.   arm_linux_sigreturn_return_addr (frame, svc_number, &return_addr, &is_thumb);

  741.   /* Addresses for calling Thumb functions have the bit 0 set.  */
  742.   if (is_thumb)
  743.     return_addr |= 1;

  744.   return return_addr;
  745. }


  746. /* Insert a single step breakpoint at the next executed instruction.  */

  747. static int
  748. arm_linux_software_single_step (struct frame_info *frame)
  749. {
  750.   struct gdbarch *gdbarch = get_frame_arch (frame);
  751.   struct address_space *aspace = get_frame_address_space (frame);
  752.   CORE_ADDR next_pc;

  753.   if (arm_deal_with_atomic_sequence (frame))
  754.     return 1;

  755.   next_pc = arm_get_next_pc (frame, get_frame_pc (frame));

  756.   /* The Linux kernel offers some user-mode helpers in a high page.  We can
  757.      not read this page (as of 2.6.23), and even if we could then we couldn't
  758.      set breakpoints in it, and even if we could then the atomic operations
  759.      would fail when interrupted.  They are all called as functions and return
  760.      to the address in LR, so step to there instead.  */
  761.   if (next_pc > 0xffff0000)
  762.     next_pc = get_frame_register_unsigned (frame, ARM_LR_REGNUM);

  763.   arm_insert_single_step_breakpoint (gdbarch, aspace, next_pc);

  764.   return 1;
  765. }

  766. /* Support for displaced stepping of Linux SVC instructions.  */

  767. static void
  768. arm_linux_cleanup_svc (struct gdbarch *gdbarch,
  769.                        struct regcache *regs,
  770.                        struct displaced_step_closure *dsc)
  771. {
  772.   CORE_ADDR from = dsc->insn_addr;
  773.   ULONGEST apparent_pc;
  774.   int within_scratch;

  775.   regcache_cooked_read_unsigned (regs, ARM_PC_REGNUM, &apparent_pc);

  776.   within_scratch = (apparent_pc >= dsc->scratch_base
  777.                     && apparent_pc < (dsc->scratch_base
  778.                                       + DISPLACED_MODIFIED_INSNS * 4 + 4));

  779.   if (debug_displaced)
  780.     {
  781.       fprintf_unfiltered (gdb_stdlog, "displaced: PC is apparently %.8lx after "
  782.                           "SVC step ", (unsigned long) apparent_pc);
  783.       if (within_scratch)
  784.         fprintf_unfiltered (gdb_stdlog, "(within scratch space)\n");
  785.       else
  786.         fprintf_unfiltered (gdb_stdlog, "(outside scratch space)\n");
  787.     }

  788.   if (within_scratch)
  789.     displaced_write_reg (regs, dsc, ARM_PC_REGNUM, from + 4, BRANCH_WRITE_PC);
  790. }

  791. static int
  792. arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs,
  793.                     struct displaced_step_closure *dsc)
  794. {
  795.   CORE_ADDR return_to = 0;

  796.   struct frame_info *frame;
  797.   unsigned int svc_number = displaced_read_reg (regs, dsc, 7);
  798.   int is_sigreturn = 0;
  799.   int is_thumb;

  800.   frame = get_current_frame ();

  801.   is_sigreturn = arm_linux_sigreturn_return_addr(frame, svc_number,
  802.                                                  &return_to, &is_thumb);
  803.   if (is_sigreturn)
  804.     {
  805.           struct symtab_and_line sal;

  806.           if (debug_displaced)
  807.             fprintf_unfiltered (gdb_stdlog, "displaced: found "
  808.               "sigreturn/rt_sigreturn SVC call.  PC in frame = %lx\n",
  809.               (unsigned long) get_frame_pc (frame));

  810.           if (debug_displaced)
  811.             fprintf_unfiltered (gdb_stdlog, "displaced: unwind pc = %lx.  "
  812.               "Setting momentary breakpoint.\n", (unsigned long) return_to);

  813.           gdb_assert (inferior_thread ()->control.step_resume_breakpoint
  814.                       == NULL);

  815.           sal = find_pc_line (return_to, 0);
  816.           sal.pc = return_to;
  817.           sal.section = find_pc_overlay (return_to);
  818.           sal.explicit_pc = 1;

  819.           frame = get_prev_frame (frame);

  820.           if (frame)
  821.             {
  822.               inferior_thread ()->control.step_resume_breakpoint
  823.                 = set_momentary_breakpoint (gdbarch, sal, get_frame_id (frame),
  824.                                             bp_step_resume);

  825.               /* set_momentary_breakpoint invalidates FRAME.  */
  826.               frame = NULL;

  827.               /* We need to make sure we actually insert the momentary
  828.                  breakpoint set above.  */
  829.               insert_breakpoints ();
  830.             }
  831.           else if (debug_displaced)
  832.             fprintf_unfiltered (gdb_stderr, "displaced: couldn't find previous "
  833.                                 "frame to set momentary breakpoint for "
  834.                                 "sigreturn/rt_sigreturn\n");
  835.         }
  836.       else if (debug_displaced)
  837.         fprintf_unfiltered (gdb_stdlog, "displaced: sigreturn/rt_sigreturn "
  838.                             "SVC call not in signal trampoline frame\n");


  839.   /* Preparation: If we detect sigreturn, set momentary breakpoint at resume
  840.                   location, else nothing.
  841.      Insn: unmodified svc.
  842.      Cleanup: if pc lands in scratch space, pc <- insn_addr + 4
  843.               else leave pc alone.  */


  844.   dsc->cleanup = &arm_linux_cleanup_svc;
  845.   /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next
  846.      instruction.  */
  847.   dsc->wrote_to_pc = 1;

  848.   return 0;
  849. }


  850. /* The following two functions implement single-stepping over calls to Linux
  851.    kernel helper routines, which perform e.g. atomic operations on architecture
  852.    variants which don't support them natively.

  853.    When this function is called, the PC will be pointing at the kernel helper
  854.    (at an address inaccessible to GDB), and r14 will point to the return
  855.    address.  Displaced stepping always executes code in the copy area:
  856.    so, make the copy-area instruction branch back to the kernel helper (the
  857.    "from" address), and make r14 point to the breakpoint in the copy area.  In
  858.    that way, we regain control once the kernel helper returns, and can clean
  859.    up appropriately (as if we had just returned from the kernel helper as it
  860.    would have been called from the non-displaced location).  */

  861. static void
  862. cleanup_kernel_helper_return (struct gdbarch *gdbarch,
  863.                               struct regcache *regs,
  864.                               struct displaced_step_closure *dsc)
  865. {
  866.   displaced_write_reg (regs, dsc, ARM_LR_REGNUM, dsc->tmp[0], CANNOT_WRITE_PC);
  867.   displaced_write_reg (regs, dsc, ARM_PC_REGNUM, dsc->tmp[0], BRANCH_WRITE_PC);
  868. }

  869. static void
  870. arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from,
  871.                                 CORE_ADDR to, struct regcache *regs,
  872.                                 struct displaced_step_closure *dsc)
  873. {
  874.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);

  875.   dsc->numinsns = 1;
  876.   dsc->insn_addr = from;
  877.   dsc->cleanup = &cleanup_kernel_helper_return;
  878.   /* Say we wrote to the PC, else cleanup will set PC to the next
  879.      instruction in the helper, which isn't helpful.  */
  880.   dsc->wrote_to_pc = 1;

  881.   /* Preparation: tmp[0] <- r14
  882.                   r14 <- <scratch space>+4
  883.                   *(<scratch space>+8) <- from
  884.      Insn: ldr pc, [r14, #4]
  885.      Cleanup: r14 <- tmp[0], pc <- tmp[0].  */

  886.   dsc->tmp[0] = displaced_read_reg (regs, dsc, ARM_LR_REGNUM);
  887.   displaced_write_reg (regs, dsc, ARM_LR_REGNUM, (ULONGEST) to + 4,
  888.                        CANNOT_WRITE_PC);
  889.   write_memory_unsigned_integer (to + 8, 4, byte_order, from);

  890.   dsc->modinsn[0] = 0xe59ef004/* ldr pc, [lr, #4].  */
  891. }

  892. /* Linux-specific displaced step instruction copying function.  Detects when
  893.    the program has stepped into a Linux kernel helper routine (which must be
  894.    handled as a special case), falling back to arm_displaced_step_copy_insn()
  895.    if it hasn't.  */

  896. static struct displaced_step_closure *
  897. arm_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
  898.                                     CORE_ADDR from, CORE_ADDR to,
  899.                                     struct regcache *regs)
  900. {
  901.   struct displaced_step_closure *dsc
  902.     = xmalloc (sizeof (struct displaced_step_closure));

  903.   /* Detect when we enter an (inaccessible by GDB) Linux kernel helper, and
  904.      stop at the return location.  */
  905.   if (from > 0xffff0000)
  906.     {
  907.       if (debug_displaced)
  908.         fprintf_unfiltered (gdb_stdlog, "displaced: detected kernel helper "
  909.                             "at %.8lx\n", (unsigned long) from);

  910.       arm_catch_kernel_helper_return (gdbarch, from, to, regs, dsc);
  911.     }
  912.   else
  913.     {
  914.       /* Override the default handling of SVC instructions.  */
  915.       dsc->u.svc.copy_svc_os = arm_linux_copy_svc;

  916.       arm_process_displaced_insn (gdbarch, from, to, regs, dsc);
  917.     }

  918.   arm_displaced_init_closure (gdbarch, from, to, dsc);

  919.   return dsc;
  920. }

  921. /* Implementation of `gdbarch_stap_is_single_operand', as defined in
  922.    gdbarch.h.  */

  923. static int
  924. arm_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
  925. {
  926.   return (*s == '#' || *s == '$' || isdigit (*s) /* Literal number.  */
  927.           || *s == '[' /* Register indirection or
  928.                           displacement.  */
  929.           || isalpha (*s)); /* Register value.  */
  930. }

  931. /* This routine is used to parse a special token in ARM's assembly.

  932.    The special tokens parsed by it are:

  933.       - Register displacement (e.g, [fp, #-8])

  934.    It returns one if the special token has been parsed successfully,
  935.    or zero if the current token is not considered special.  */

  936. static int
  937. arm_stap_parse_special_token (struct gdbarch *gdbarch,
  938.                               struct stap_parse_info *p)
  939. {
  940.   if (*p->arg == '[')
  941.     {
  942.       /* Temporary holder for lookahead.  */
  943.       const char *tmp = p->arg;
  944.       char *endp;
  945.       /* Used to save the register name.  */
  946.       const char *start;
  947.       char *regname;
  948.       int len, offset;
  949.       int got_minus = 0;
  950.       long displacement;
  951.       struct stoken str;

  952.       ++tmp;
  953.       start = tmp;

  954.       /* Register name.  */
  955.       while (isalnum (*tmp))
  956.         ++tmp;

  957.       if (*tmp != ',')
  958.         return 0;

  959.       len = tmp - start;
  960.       regname = alloca (len + 2);

  961.       offset = 0;
  962.       if (isdigit (*start))
  963.         {
  964.           /* If we are dealing with a register whose name begins with a
  965.              digit, it means we should prefix the name with the letter
  966.              `r', because GDB expects this name pattern.  Otherwise (e.g.,
  967.              we are dealing with the register `fp'), we don't need to
  968.              add such a prefix.  */
  969.           regname[0] = 'r';
  970.           offset = 1;
  971.         }

  972.       strncpy (regname + offset, start, len);
  973.       len += offset;
  974.       regname[len] = '\0';

  975.       if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
  976.         error (_("Invalid register name `%s' on expression `%s'."),
  977.                regname, p->saved_arg);

  978.       ++tmp;
  979.       tmp = skip_spaces_const (tmp);
  980.       if (*tmp == '#' || *tmp == '$')
  981.         ++tmp;

  982.       if (*tmp == '-')
  983.         {
  984.           ++tmp;
  985.           got_minus = 1;
  986.         }

  987.       displacement = strtol (tmp, &endp, 10);
  988.       tmp = endp;

  989.       /* Skipping last `]'.  */
  990.       if (*tmp++ != ']')
  991.         return 0;

  992.       /* The displacement.  */
  993.       write_exp_elt_opcode (&p->pstate, OP_LONG);
  994.       write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
  995.       write_exp_elt_longcst (&p->pstate, displacement);
  996.       write_exp_elt_opcode (&p->pstate, OP_LONG);
  997.       if (got_minus)
  998.         write_exp_elt_opcode (&p->pstate, UNOP_NEG);

  999.       /* The register name.  */
  1000.       write_exp_elt_opcode (&p->pstate, OP_REGISTER);
  1001.       str.ptr = regname;
  1002.       str.length = len;
  1003.       write_exp_string (&p->pstate, str);
  1004.       write_exp_elt_opcode (&p->pstate, OP_REGISTER);

  1005.       write_exp_elt_opcode (&p->pstate, BINOP_ADD);

  1006.       /* Casting to the expected type.  */
  1007.       write_exp_elt_opcode (&p->pstate, UNOP_CAST);
  1008.       write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
  1009.       write_exp_elt_opcode (&p->pstate, UNOP_CAST);

  1010.       write_exp_elt_opcode (&p->pstate, UNOP_IND);

  1011.       p->arg = tmp;
  1012.     }
  1013.   else
  1014.     return 0;

  1015.   return 1;
  1016. }

  1017. /* ARM process record-replay constructs: syscall, signal etc.  */

  1018. struct linux_record_tdep arm_linux_record_tdep;

  1019. /* arm_canonicalize_syscall maps from the native arm Linux set
  1020.    of syscall ids into a canonical set of syscall ids used by
  1021.    process record.  */

  1022. static enum gdb_syscall
  1023. arm_canonicalize_syscall (int syscall)
  1024. {
  1025.   enum { sys_process_vm_writev = 377 };

  1026.   if (syscall <= gdb_sys_sched_getaffinity)
  1027.     return syscall;
  1028.   else if (syscall >= 243 && syscall <= 247)
  1029.     return syscall + 2;
  1030.   else if (syscall >= 248 && syscall <= 253)
  1031.     return syscall + 4;

  1032.   return -1;
  1033. }

  1034. /* Record all registers but PC register for process-record.  */

  1035. static int
  1036. arm_all_but_pc_registers_record (struct regcache *regcache)
  1037. {
  1038.   int i;

  1039.   for (i = 0; i < ARM_PC_REGNUM; i++)
  1040.     {
  1041.       if (record_full_arch_list_add_reg (regcache, ARM_A1_REGNUM + i))
  1042.         return -1;
  1043.     }

  1044.   if (record_full_arch_list_add_reg (regcache, ARM_PS_REGNUM))
  1045.     return -1;

  1046.   return 0;
  1047. }

  1048. /* Handler for arm system call instruction recording.  */

  1049. static int
  1050. arm_linux_syscall_record (struct regcache *regcache, unsigned long svc_number)
  1051. {
  1052.   int ret = 0;
  1053.   enum gdb_syscall syscall_gdb;

  1054.   syscall_gdb = arm_canonicalize_syscall (svc_number);

  1055.   if (syscall_gdb < 0)
  1056.     {
  1057.       printf_unfiltered (_("Process record and replay target doesn't "
  1058.                            "support syscall number %s\n"),
  1059.                            plongest (svc_number));
  1060.       return -1;
  1061.     }

  1062.   if (syscall_gdb == gdb_sys_sigreturn
  1063.       || syscall_gdb == gdb_sys_rt_sigreturn)
  1064.    {
  1065.      if (arm_all_but_pc_registers_record (regcache))
  1066.        return -1;
  1067.      return 0;
  1068.    }

  1069.   ret = record_linux_system_call (syscall_gdb, regcache,
  1070.                                   &arm_linux_record_tdep);
  1071.   if (ret != 0)
  1072.     return ret;

  1073.   /* Record the return value of the system call.  */
  1074.   if (record_full_arch_list_add_reg (regcache, ARM_A1_REGNUM))
  1075.     return -1;
  1076.   /* Record LR.  */
  1077.   if (record_full_arch_list_add_reg (regcache, ARM_LR_REGNUM))
  1078.     return -1;
  1079.   /* Record CPSR.  */
  1080.   if (record_full_arch_list_add_reg (regcache, ARM_PS_REGNUM))
  1081.     return -1;

  1082.   return 0;
  1083. }

  1084. /* Implement the skip_trampoline_code gdbarch method.  */

  1085. static CORE_ADDR
  1086. arm_linux_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  1087. {
  1088.   CORE_ADDR target_pc = arm_skip_stub (frame, pc);

  1089.   if (target_pc != 0)
  1090.     return target_pc;

  1091.   return find_solib_trampoline_target (frame, pc);
  1092. }

  1093. static void
  1094. arm_linux_init_abi (struct gdbarch_info info,
  1095.                     struct gdbarch *gdbarch)
  1096. {
  1097.   static const char *const stap_integer_prefixes[] = { "#", "$", "", NULL };
  1098.   static const char *const stap_register_prefixes[] = { "r", NULL };
  1099.   static const char *const stap_register_indirection_prefixes[] = { "[",
  1100.                                                                     NULL };
  1101.   static const char *const stap_register_indirection_suffixes[] = { "]",
  1102.                                                                     NULL };
  1103.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  1104.   linux_init_abi (info, gdbarch);

  1105.   tdep->lowest_pc = 0x8000;
  1106.   if (info.byte_order_for_code == BFD_ENDIAN_BIG)
  1107.     {
  1108.       if (tdep->arm_abi == ARM_ABI_AAPCS)
  1109.         tdep->arm_breakpoint = eabi_linux_arm_be_breakpoint;
  1110.       else
  1111.         tdep->arm_breakpoint = arm_linux_arm_be_breakpoint;
  1112.       tdep->thumb_breakpoint = arm_linux_thumb_be_breakpoint;
  1113.       tdep->thumb2_breakpoint = arm_linux_thumb2_be_breakpoint;
  1114.     }
  1115.   else
  1116.     {
  1117.       if (tdep->arm_abi == ARM_ABI_AAPCS)
  1118.         tdep->arm_breakpoint = eabi_linux_arm_le_breakpoint;
  1119.       else
  1120.         tdep->arm_breakpoint = arm_linux_arm_le_breakpoint;
  1121.       tdep->thumb_breakpoint = arm_linux_thumb_le_breakpoint;
  1122.       tdep->thumb2_breakpoint = arm_linux_thumb2_le_breakpoint;
  1123.     }
  1124.   tdep->arm_breakpoint_size = sizeof (arm_linux_arm_le_breakpoint);
  1125.   tdep->thumb_breakpoint_size = sizeof (arm_linux_thumb_le_breakpoint);
  1126.   tdep->thumb2_breakpoint_size = sizeof (arm_linux_thumb2_le_breakpoint);

  1127.   if (tdep->fp_model == ARM_FLOAT_AUTO)
  1128.     tdep->fp_model = ARM_FLOAT_FPA;

  1129.   switch (tdep->fp_model)
  1130.     {
  1131.     case ARM_FLOAT_FPA:
  1132.       tdep->jb_pc = ARM_LINUX_JB_PC_FPA;
  1133.       break;
  1134.     case ARM_FLOAT_SOFT_FPA:
  1135.     case ARM_FLOAT_SOFT_VFP:
  1136.     case ARM_FLOAT_VFP:
  1137.       tdep->jb_pc = ARM_LINUX_JB_PC_EABI;
  1138.       break;
  1139.     default:
  1140.       internal_error
  1141.         (__FILE__, __LINE__,
  1142.          _("arm_linux_init_abi: Floating point model not supported"));
  1143.       break;
  1144.     }
  1145.   tdep->jb_elt_size = ARM_LINUX_JB_ELEMENT_SIZE;

  1146.   set_solib_svr4_fetch_link_map_offsets
  1147.     (gdbarch, svr4_ilp32_fetch_link_map_offsets);

  1148.   /* Single stepping.  */
  1149.   set_gdbarch_software_single_step (gdbarch, arm_linux_software_single_step);

  1150.   /* Shared library handling.  */
  1151.   set_gdbarch_skip_trampoline_code (gdbarch, arm_linux_skip_trampoline_code);
  1152.   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);

  1153.   /* Enable TLS support.  */
  1154.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  1155.                                              svr4_fetch_objfile_link_map);

  1156.   tramp_frame_prepend_unwinder (gdbarch,
  1157.                                 &arm_linux_sigreturn_tramp_frame);
  1158.   tramp_frame_prepend_unwinder (gdbarch,
  1159.                                 &arm_linux_rt_sigreturn_tramp_frame);
  1160.   tramp_frame_prepend_unwinder (gdbarch,
  1161.                                 &arm_eabi_linux_sigreturn_tramp_frame);
  1162.   tramp_frame_prepend_unwinder (gdbarch,
  1163.                                 &arm_eabi_linux_rt_sigreturn_tramp_frame);
  1164.   tramp_frame_prepend_unwinder (gdbarch,
  1165.                                 &thumb2_eabi_linux_sigreturn_tramp_frame);
  1166.   tramp_frame_prepend_unwinder (gdbarch,
  1167.                                 &thumb2_eabi_linux_rt_sigreturn_tramp_frame);
  1168.   tramp_frame_prepend_unwinder (gdbarch,
  1169.                                 &arm_linux_restart_syscall_tramp_frame);
  1170.   tramp_frame_prepend_unwinder (gdbarch,
  1171.                                 &arm_kernel_linux_restart_syscall_tramp_frame);

  1172.   /* Core file support.  */
  1173.   set_gdbarch_iterate_over_regset_sections
  1174.     (gdbarch, arm_linux_iterate_over_regset_sections);
  1175.   set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description);

  1176.   set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);

  1177.   /* Displaced stepping.  */
  1178.   set_gdbarch_displaced_step_copy_insn (gdbarch,
  1179.                                         arm_linux_displaced_step_copy_insn);
  1180.   set_gdbarch_displaced_step_fixup (gdbarch, arm_displaced_step_fixup);
  1181.   set_gdbarch_displaced_step_free_closure (gdbarch,
  1182.                                            simple_displaced_step_free_closure);
  1183.   set_gdbarch_displaced_step_location (gdbarch, displaced_step_at_entry_point);

  1184.   /* Reversible debugging, process record.  */
  1185.   set_gdbarch_process_record (gdbarch, arm_process_record);

  1186.   /* SystemTap functions.  */
  1187.   set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
  1188.   set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
  1189.   set_gdbarch_stap_register_indirection_prefixes (gdbarch,
  1190.                                           stap_register_indirection_prefixes);
  1191.   set_gdbarch_stap_register_indirection_suffixes (gdbarch,
  1192.                                           stap_register_indirection_suffixes);
  1193.   set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
  1194.   set_gdbarch_stap_is_single_operand (gdbarch, arm_stap_is_single_operand);
  1195.   set_gdbarch_stap_parse_special_token (gdbarch,
  1196.                                         arm_stap_parse_special_token);

  1197.   tdep->syscall_next_pc = arm_linux_syscall_next_pc;

  1198.   /* `catch syscall' */
  1199.   set_xml_syscall_file_name (gdbarch, "syscalls/arm-linux.xml");
  1200.   set_gdbarch_get_syscall_number (gdbarch, arm_linux_get_syscall_number);

  1201.   /* Syscall record.  */
  1202.   tdep->arm_syscall_record = arm_linux_syscall_record;

  1203.   /* Initialize the arm_linux_record_tdep.  */
  1204.   /* These values are the size of the type that will be used in a system
  1205.      call.  They are obtained from Linux Kernel source.  */
  1206.   arm_linux_record_tdep.size_pointer
  1207.     = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
  1208.   arm_linux_record_tdep.size__old_kernel_stat = 32;
  1209.   arm_linux_record_tdep.size_tms = 16;
  1210.   arm_linux_record_tdep.size_loff_t = 8;
  1211.   arm_linux_record_tdep.size_flock = 16;
  1212.   arm_linux_record_tdep.size_oldold_utsname = 45;
  1213.   arm_linux_record_tdep.size_ustat = 20;
  1214.   arm_linux_record_tdep.size_old_sigaction = 140;
  1215.   arm_linux_record_tdep.size_old_sigset_t = 128;
  1216.   arm_linux_record_tdep.size_rlimit = 8;
  1217.   arm_linux_record_tdep.size_rusage = 72;
  1218.   arm_linux_record_tdep.size_timeval = 8;
  1219.   arm_linux_record_tdep.size_timezone = 8;
  1220.   arm_linux_record_tdep.size_old_gid_t = 2;
  1221.   arm_linux_record_tdep.size_old_uid_t = 2;
  1222.   arm_linux_record_tdep.size_fd_set = 128;
  1223.   arm_linux_record_tdep.size_dirent = 268;
  1224.   arm_linux_record_tdep.size_dirent64 = 276;
  1225.   arm_linux_record_tdep.size_statfs = 64;
  1226.   arm_linux_record_tdep.size_statfs64 = 84;
  1227.   arm_linux_record_tdep.size_sockaddr = 16;
  1228.   arm_linux_record_tdep.size_int
  1229.     = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
  1230.   arm_linux_record_tdep.size_long
  1231.     = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
  1232.   arm_linux_record_tdep.size_ulong
  1233.     = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
  1234.   arm_linux_record_tdep.size_msghdr = 28;
  1235.   arm_linux_record_tdep.size_itimerval = 16;
  1236.   arm_linux_record_tdep.size_stat = 88;
  1237.   arm_linux_record_tdep.size_old_utsname = 325;
  1238.   arm_linux_record_tdep.size_sysinfo = 64;
  1239.   arm_linux_record_tdep.size_msqid_ds = 88;
  1240.   arm_linux_record_tdep.size_shmid_ds = 84;
  1241.   arm_linux_record_tdep.size_new_utsname = 390;
  1242.   arm_linux_record_tdep.size_timex = 128;
  1243.   arm_linux_record_tdep.size_mem_dqinfo = 24;
  1244.   arm_linux_record_tdep.size_if_dqblk = 68;
  1245.   arm_linux_record_tdep.size_fs_quota_stat = 68;
  1246.   arm_linux_record_tdep.size_timespec = 8;
  1247.   arm_linux_record_tdep.size_pollfd = 8;
  1248.   arm_linux_record_tdep.size_NFS_FHSIZE = 32;
  1249.   arm_linux_record_tdep.size_knfsd_fh = 132;
  1250.   arm_linux_record_tdep.size_TASK_COMM_LEN = 16;
  1251.   arm_linux_record_tdep.size_sigaction = 140;
  1252.   arm_linux_record_tdep.size_sigset_t = 8;
  1253.   arm_linux_record_tdep.size_siginfo_t = 128;
  1254.   arm_linux_record_tdep.size_cap_user_data_t = 12;
  1255.   arm_linux_record_tdep.size_stack_t = 12;
  1256.   arm_linux_record_tdep.size_off_t = arm_linux_record_tdep.size_long;
  1257.   arm_linux_record_tdep.size_stat64 = 96;
  1258.   arm_linux_record_tdep.size_gid_t = 2;
  1259.   arm_linux_record_tdep.size_uid_t = 2;
  1260.   arm_linux_record_tdep.size_PAGE_SIZE = 4096;
  1261.   arm_linux_record_tdep.size_flock64 = 24;
  1262.   arm_linux_record_tdep.size_user_desc = 16;
  1263.   arm_linux_record_tdep.size_io_event = 32;
  1264.   arm_linux_record_tdep.size_iocb = 64;
  1265.   arm_linux_record_tdep.size_epoll_event = 12;
  1266.   arm_linux_record_tdep.size_itimerspec
  1267.     = arm_linux_record_tdep.size_timespec * 2;
  1268.   arm_linux_record_tdep.size_mq_attr = 32;
  1269.   arm_linux_record_tdep.size_siginfo = 128;
  1270.   arm_linux_record_tdep.size_termios = 36;
  1271.   arm_linux_record_tdep.size_termios2 = 44;
  1272.   arm_linux_record_tdep.size_pid_t = 4;
  1273.   arm_linux_record_tdep.size_winsize = 8;
  1274.   arm_linux_record_tdep.size_serial_struct = 60;
  1275.   arm_linux_record_tdep.size_serial_icounter_struct = 80;
  1276.   arm_linux_record_tdep.size_hayes_esp_config = 12;
  1277.   arm_linux_record_tdep.size_size_t = 4;
  1278.   arm_linux_record_tdep.size_iovec = 8;

  1279.   /* These values are the second argument of system call "sys_ioctl".
  1280.      They are obtained from Linux Kernel source.  */
  1281.   arm_linux_record_tdep.ioctl_TCGETS = 0x5401;
  1282.   arm_linux_record_tdep.ioctl_TCSETS = 0x5402;
  1283.   arm_linux_record_tdep.ioctl_TCSETSW = 0x5403;
  1284.   arm_linux_record_tdep.ioctl_TCSETSF = 0x5404;
  1285.   arm_linux_record_tdep.ioctl_TCGETA = 0x5405;
  1286.   arm_linux_record_tdep.ioctl_TCSETA = 0x5406;
  1287.   arm_linux_record_tdep.ioctl_TCSETAW = 0x5407;
  1288.   arm_linux_record_tdep.ioctl_TCSETAF = 0x5408;
  1289.   arm_linux_record_tdep.ioctl_TCSBRK = 0x5409;
  1290.   arm_linux_record_tdep.ioctl_TCXONC = 0x540a;
  1291.   arm_linux_record_tdep.ioctl_TCFLSH = 0x540b;
  1292.   arm_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
  1293.   arm_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
  1294.   arm_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
  1295.   arm_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
  1296.   arm_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
  1297.   arm_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
  1298.   arm_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
  1299.   arm_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
  1300.   arm_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
  1301.   arm_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
  1302.   arm_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
  1303.   arm_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
  1304.   arm_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
  1305.   arm_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
  1306.   arm_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
  1307.   arm_linux_record_tdep.ioctl_FIONREAD = 0x541b;
  1308.   arm_linux_record_tdep.ioctl_TIOCINQ = arm_linux_record_tdep.ioctl_FIONREAD;
  1309.   arm_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
  1310.   arm_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
  1311.   arm_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
  1312.   arm_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
  1313.   arm_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
  1314.   arm_linux_record_tdep.ioctl_FIONBIO = 0x5421;
  1315.   arm_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
  1316.   arm_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
  1317.   arm_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
  1318.   arm_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
  1319.   arm_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
  1320.   arm_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
  1321.   arm_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
  1322.   arm_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
  1323.   arm_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
  1324.   arm_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
  1325.   arm_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
  1326.   arm_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
  1327.   arm_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
  1328.   arm_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
  1329.   arm_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
  1330.   arm_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
  1331.   arm_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
  1332.   arm_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
  1333.   arm_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
  1334.   arm_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
  1335.   arm_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
  1336.   arm_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
  1337.   arm_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
  1338.   arm_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
  1339.   arm_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
  1340.   arm_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
  1341.   arm_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
  1342.   arm_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
  1343.   arm_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
  1344.   arm_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
  1345.   arm_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;

  1346.   /* These values are the second argument of system call "sys_fcntl"
  1347.      and "sys_fcntl64".  They are obtained from Linux Kernel source.  */
  1348.   arm_linux_record_tdep.fcntl_F_GETLK = 5;
  1349.   arm_linux_record_tdep.fcntl_F_GETLK64 = 12;
  1350.   arm_linux_record_tdep.fcntl_F_SETLK64 = 13;
  1351.   arm_linux_record_tdep.fcntl_F_SETLKW64 = 14;

  1352.   arm_linux_record_tdep.arg1 = ARM_A1_REGNUM + 1;
  1353.   arm_linux_record_tdep.arg2 = ARM_A1_REGNUM + 2;
  1354.   arm_linux_record_tdep.arg3 = ARM_A1_REGNUM + 3;
  1355.   arm_linux_record_tdep.arg4 = ARM_A1_REGNUM + 3;
  1356. }

  1357. /* Provide a prototype to silence -Wmissing-prototypes.  */
  1358. extern initialize_file_ftype _initialize_arm_linux_tdep;

  1359. void
  1360. _initialize_arm_linux_tdep (void)
  1361. {
  1362.   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_LINUX,
  1363.                           arm_linux_init_abi);
  1364. }