gdb/gdbserver/linux-tile-low.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* GNU/Linux/TILE-Gx specific low level interface, GDBserver.

  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 "server.h"
  15. #include "linux-low.h"

  16. #include <arch/abi.h>
  17. #include <sys/ptrace.h>

  18. /* Defined in auto-generated file reg-tilegx.c.  */
  19. void init_registers_tilegx (void);
  20. extern const struct target_desc *tdesc_tilegx;

  21. /* Defined in auto-generated file reg-tilegx32.c.  */
  22. void init_registers_tilegx32 (void);
  23. extern const struct target_desc *tdesc_tilegx32;

  24. #define tile_num_regs 65

  25. static int tile_regmap[] =
  26. {
  27.    01234567,
  28.    89, 10, 11, 12, 13, 14, 15,
  29.   16, 17, 18, 19, 20, 21, 22, 23,
  30.   24, 25, 26, 27, 28, 29, 30, 31,
  31.   32, 33, 34, 35, 36, 37, 38, 39,
  32.   40, 41, 42, 43, 44, 45, 46, 47,
  33.   48, 49, 50, 51, 52, 53, 54, 55,
  34.   -1, -1, -1, -1, -1, -1, -1, -1,
  35.   56
  36. };

  37. static int
  38. tile_cannot_fetch_register (int regno)
  39. {
  40.   if (regno >= 0 && regno < 56)
  41.     return 0;
  42.   else if (regno == 64)
  43.     return 0;
  44.   else
  45.     return 1;
  46. }

  47. static int
  48. tile_cannot_store_register (int regno)
  49. {
  50.   if (regno >= 0 && regno < 56)
  51.     return 0;
  52.   else if (regno == 64)
  53.     return 0;
  54.   else
  55.     return 1;
  56. }

  57. static CORE_ADDR
  58. tile_get_pc (struct regcache *regcache)
  59. {
  60.   unsigned long pc;

  61.   collect_register_by_name (regcache, "pc", &pc);
  62.   return pc;
  63. }

  64. static void
  65. tile_set_pc (struct regcache *regcache, CORE_ADDR pc)
  66. {
  67.   unsigned long newpc = pc;

  68.   supply_register_by_name (regcache, "pc", &newpc);
  69. }

  70. static uint64_t tile_breakpoint = 0x400b3cae70166000ULL;
  71. #define tile_breakpoint_len 8

  72. static int
  73. tile_breakpoint_at (CORE_ADDR where)
  74. {
  75.   uint64_t insn;

  76.   (*the_target->read_memory) (where, (unsigned char *) &insn, 8);
  77.   if (insn == tile_breakpoint)
  78.     return 1;

  79.   /* If necessary, recognize more trap instructions here.  GDB only uses the
  80.      one.  */
  81.   return 0;
  82. }

  83. static void
  84. tile_fill_gregset (struct regcache *regcache, void *buf)
  85. {
  86.   int i;

  87.   for (i = 0; i < tile_num_regs; i++)
  88.     if (tile_regmap[i] != -1)
  89.       collect_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
  90. }

  91. static void
  92. tile_store_gregset (struct regcache *regcache, const void *buf)
  93. {
  94.   int i;

  95.   for (i = 0; i < tile_num_regs; i++)
  96.     if (tile_regmap[i] != -1)
  97.       supply_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
  98. }

  99. static struct regset_info tile_regsets[] =
  100. {
  101.   { PTRACE_GETREGS, PTRACE_SETREGS, 0, tile_num_regs * 8,
  102.     GENERAL_REGS, tile_fill_gregset, tile_store_gregset },
  103.   { 0, 0, 0, -1, -1, NULL, NULL }
  104. };

  105. static struct regsets_info tile_regsets_info =
  106.   {
  107.     tile_regsets, /* regsets */
  108.     0, /* num_regsets */
  109.     NULL, /* disabled_regsets */
  110.   };

  111. static struct usrregs_info tile_usrregs_info =
  112.   {
  113.     tile_num_regs,
  114.     tile_regmap,
  115.   };

  116. static struct regs_info regs_info =
  117.   {
  118.     NULL, /* regset_bitmap */
  119.     &tile_usrregs_info,
  120.     &tile_regsets_info,
  121.   };

  122. static const struct regs_info *
  123. tile_regs_info (void)
  124. {
  125.   return &regs_info;
  126. }

  127. static void
  128. tile_arch_setup (void)
  129. {
  130.   int pid = pid_of (current_thread);
  131.   unsigned int machine;
  132.   int is_elf64 = linux_pid_exe_is_elf_64_file (pid, &machine);

  133.   if (sizeof (void *) == 4)
  134.     if (is_elf64 > 0)
  135.       error (_("Can't debug 64-bit process with 32-bit GDBserver"));

  136.   if (!is_elf64)
  137.     current_process ()->tdesc = tdesc_tilegx32;
  138.   else
  139.     current_process ()->tdesc = tdesc_tilegx;
  140. }


  141. struct linux_target_ops the_low_target =
  142. {
  143.   tile_arch_setup,
  144.   tile_regs_info,
  145.   tile_cannot_fetch_register,
  146.   tile_cannot_store_register,
  147.   NULL,
  148.   tile_get_pc,
  149.   tile_set_pc,
  150.   (const unsigned char *) &tile_breakpoint,
  151.   tile_breakpoint_len,
  152.   NULL,
  153.   0,
  154.   tile_breakpoint_at,
  155. };

  156. void
  157. initialize_low_arch (void)
  158. {
  159.   init_registers_tilegx32();
  160.   init_registers_tilegx();

  161.   initialize_regsets_info (&tile_regsets_info);
  162. }