gdb/tilegx-linux-nat.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Native-dependent code for GNU/Linux TILE-Gx.

  2.    Copyright (C) 2012-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 "inferior.h"
  16. #include "gdbcore.h"
  17. #include "regcache.h"
  18. #include "linux-nat.h"

  19. #include <sys/ptrace.h>

  20. #include <sys/procfs.h>

  21. /* Defines ps_err_e, struct ps_prochandle.  */
  22. #include "gdb_proc_service.h"

  23. /* Prototypes for supply_gregset etc.  */
  24. #include "gregset.h"

  25. /* The register sets used in GNU/Linux ELF core-dumps are identical to
  26.    the register sets in `struct user' that is used for a.out
  27.    core-dumps, and is also used by `ptrace'.  The corresponding types
  28.    are `elf_gregset_t' for the general-purpose registers (with
  29.    `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
  30.    for the floating-point registers.

  31.    Those types used to be available under the names `gregset_t' and
  32.    `fpregset_t' too, and this file used those names in the past.  But
  33.    those names are now used for the register sets used in the
  34.    `mcontext_t' type, and have a different size and layout.  */

  35. /* Mapping between the general-purpose registers in `struct user'
  36.    format and GDB's register array layout.  Note that we map the
  37.    first 56 registers (0 thru 55) one-to-one.  GDB maps the pc to
  38.    slot 64, but ptrace returns it in slot 56.  */
  39. static const int regmap[] =
  40. {
  41.    01234567,
  42.    89, 10, 11, 12, 13, 14, 15,
  43.   16, 17, 18, 19, 20, 21, 22, 23,
  44.   24, 25, 26, 27, 28, 29, 30, 31,
  45.   32, 33, 34, 35, 36, 37, 38, 39,
  46.   40, 41, 42, 43, 44, 45, 46, 47,
  47.   48, 49, 50, 51, 52, 53, 54, 55,
  48.   -1, -1, -1, -1, -1, -1, -1, -1,
  49.   56, 58
  50. };

  51. /* Transfering the general-purpose registers between GDB, inferiors
  52.    and core files.  */

  53. /* Fill GDB's register array with the general-purpose register values
  54.    in *GREGSETP.  */

  55. void
  56. supply_gregset (struct regcache* regcache,
  57.                 const elf_gregset_t *gregsetp)
  58. {
  59.   elf_greg_t *regp = (elf_greg_t *) gregsetp;
  60.   int i;

  61.   for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
  62.     if (regmap[i] >= 0)
  63.       regcache_raw_supply (regcache, i, regp + regmap[i]);
  64. }

  65. /* Fill registers in *GREGSETPS with the values in GDB's
  66.    register array.  */

  67. void
  68. fill_gregset (const struct regcache* regcache,
  69.               elf_gregset_t *gregsetp, int regno)
  70. {
  71.   elf_greg_t *regp = (elf_greg_t *) gregsetp;
  72.   int i;

  73.   for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
  74.     if (regmap[i] >= 0)
  75.       regcache_raw_collect (regcache, i, regp + regmap[i]);
  76. }

  77. /* Transfering floating-point registers between GDB, inferiors and cores.  */

  78. /* Fill GDB's register array with the floating-point register values in
  79.    *FPREGSETP.  */

  80. void
  81. supply_fpregset (struct regcache *regcache,
  82.                  const elf_fpregset_t *fpregsetp)
  83. {
  84.   /* NOTE: There are no floating-point registers for TILE-Gx.  */
  85. }

  86. /* Fill register REGNO (if it is a floating-point register) in
  87.    *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
  88.    do this for all registers.  */

  89. void
  90. fill_fpregset (const struct regcache *regcache,
  91.                elf_fpregset_t *fpregsetp, int regno)
  92. {
  93.   /* NOTE: There are no floating-point registers for TILE-Gx.  */
  94. }

  95. /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
  96.    for all registers.  */

  97. static void
  98. fetch_inferior_registers (struct target_ops *ops,
  99.                           struct regcache *regcache, int regnum)
  100. {
  101.   elf_gregset_t regs;
  102.   int tid;

  103.   tid = ptid_get_lwp (inferior_ptid);
  104.   if (tid == 0)
  105.     tid = ptid_get_pid (inferior_ptid);

  106.   if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  107.     perror_with_name (_("Couldn't get registers"));

  108.   supply_gregset (regcache, (const elf_gregset_t *)&regs);
  109. }

  110. /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
  111.    this for all registers.  */

  112. static void
  113. store_inferior_registers (struct target_ops *ops,
  114.                           struct regcache *regcache, int regnum)
  115. {
  116.   elf_gregset_t regs;
  117.   int tid;

  118.   tid = ptid_get_lwp (inferior_ptid);
  119.   if (tid == 0)
  120.     tid = ptid_get_pid (inferior_ptid);

  121.   if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  122.     perror_with_name (_("Couldn't get registers"));

  123.   fill_gregset (regcache, &regs, regnum);

  124.   if (ptrace (PTRACE_SETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
  125.     perror_with_name (_("Couldn't write registers"));
  126. }


  127. extern initialize_file_ftype _initialize_tile_linux_nat;

  128. void
  129. _initialize_tile_linux_nat (void)
  130. {
  131.   struct target_ops *t;

  132.   /* Fill in the generic GNU/Linux methods.  */
  133.   t = linux_target ();

  134.   /* Add our register access methods.  */
  135.   t->to_fetch_registers = fetch_inferior_registers;
  136.   t->to_store_registers = store_inferior_registers;

  137.   /* Register the target.  */
  138.   linux_nat_add_target (t);
  139. }