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

Global variables defined

Functions defined

Macros defined

Source code

  1. /* GNU/Linux/m68k specific low level interface, for the remote server for GDB.
  2.    Copyright (C) 1995-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. /* Defined in auto-generated file reg-m68k.c.  */
  17. void init_registers_m68k (void);
  18. extern const struct target_desc *tdesc_m68k;

  19. #ifdef HAVE_SYS_REG_H
  20. #include <sys/reg.h>
  21. #endif

  22. #define m68k_num_regs 29
  23. #define m68k_num_gregs 18

  24. /* This table must line up with REGISTER_NAMES in tm-m68k.h */
  25. static int m68k_regmap[] =
  26. {
  27. #ifdef PT_D0
  28.   PT_D0 * 4, PT_D1 * 4, PT_D2 * 4, PT_D3 * 4,
  29.   PT_D4 * 4, PT_D5 * 4, PT_D6 * 4, PT_D7 * 4,
  30.   PT_A0 * 4, PT_A1 * 4, PT_A2 * 4, PT_A3 * 4,
  31.   PT_A4 * 4, PT_A5 * 4, PT_A6 * 4, PT_USP * 4,
  32.   PT_SR * 4, PT_PC * 4,
  33. #else
  34.   14 * 4, 0 * 4, 1 * 4, 2 * 4, 3 * 4, 4 * 4, 5 * 4, 6 * 4,
  35.   7 * 4, 8 * 4, 9 * 4, 10 * 4, 11 * 4, 12 * 4, 13 * 4, 15 * 4,
  36.   17 * 4, 18 * 4,
  37. #endif
  38. #ifdef PT_FP0
  39.   PT_FP0 * 4, PT_FP1 * 4, PT_FP2 * 4, PT_FP3 * 4,
  40.   PT_FP4 * 4, PT_FP5 * 4, PT_FP6 * 4, PT_FP7 * 4,
  41.   PT_FPCR * 4, PT_FPSR * 4, PT_FPIAR * 4
  42. #else
  43.   21 * 4, 24 * 4, 27 * 4, 30 * 4, 33 * 4, 36 * 4,
  44.   39 * 4, 42 * 4, 45 * 4, 46 * 4, 47 * 4
  45. #endif
  46. };

  47. static int
  48. m68k_cannot_store_register (int regno)
  49. {
  50.   return (regno >= m68k_num_regs);
  51. }

  52. static int
  53. m68k_cannot_fetch_register (int regno)
  54. {
  55.   return (regno >= m68k_num_regs);
  56. }

  57. #ifdef HAVE_PTRACE_GETREGS
  58. #include <sys/procfs.h>
  59. #include <sys/ptrace.h>

  60. static void
  61. m68k_fill_gregset (struct regcache *regcache, void *buf)
  62. {
  63.   int i;

  64.   for (i = 0; i < m68k_num_gregs; i++)
  65.     collect_register (regcache, i, (char *) buf + m68k_regmap[i]);
  66. }

  67. static void
  68. m68k_store_gregset (struct regcache *regcache, const void *buf)
  69. {
  70.   int i;

  71.   for (i = 0; i < m68k_num_gregs; i++)
  72.     supply_register (regcache, i, (const char *) buf + m68k_regmap[i]);
  73. }

  74. static void
  75. m68k_fill_fpregset (struct regcache *regcache, void *buf)
  76. {
  77.   int i;

  78.   for (i = m68k_num_gregs; i < m68k_num_regs; i++)
  79.     collect_register (regcache, i, ((char *) buf
  80.                          + (m68k_regmap[i] - m68k_regmap[m68k_num_gregs])));
  81. }

  82. static void
  83. m68k_store_fpregset (struct regcache *regcache, const void *buf)
  84. {
  85.   int i;

  86.   for (i = m68k_num_gregs; i < m68k_num_regs; i++)
  87.     supply_register (regcache, i, ((const char *) buf
  88.                          + (m68k_regmap[i] - m68k_regmap[m68k_num_gregs])));
  89. }

  90. #endif /* HAVE_PTRACE_GETREGS */

  91. static struct regset_info m68k_regsets[] = {
  92. #ifdef HAVE_PTRACE_GETREGS
  93.   { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t),
  94.     GENERAL_REGS,
  95.     m68k_fill_gregset, m68k_store_gregset },
  96.   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, 0, sizeof (elf_fpregset_t),
  97.     FP_REGS,
  98.     m68k_fill_fpregset, m68k_store_fpregset },
  99. #endif /* HAVE_PTRACE_GETREGS */
  100.   { 0, 0, 0, -1, -1, NULL, NULL }
  101. };

  102. static const unsigned char m68k_breakpoint[] = { 0x4E, 0x4F };
  103. #define m68k_breakpoint_len 2

  104. static CORE_ADDR
  105. m68k_get_pc (struct regcache *regcache)
  106. {
  107.   unsigned long pc;

  108.   collect_register_by_name (regcache, "pc", &pc);
  109.   return pc;
  110. }

  111. static void
  112. m68k_set_pc (struct regcache *regcache, CORE_ADDR value)
  113. {
  114.   unsigned long newpc = value;

  115.   supply_register_by_name (regcache, "pc", &newpc);
  116. }

  117. static int
  118. m68k_breakpoint_at (CORE_ADDR pc)
  119. {
  120.   unsigned char c[2];

  121.   read_inferior_memory (pc, c, 2);
  122.   if (c[0] == 0x4E && c[1] == 0x4F)
  123.     return 1;

  124.   return 0;
  125. }

  126. #include <asm/ptrace.h>

  127. #ifdef PTRACE_GET_THREAD_AREA
  128. /* Fetch the thread-local storage pointer for libthread_db.  */

  129. ps_err_e
  130. ps_get_thread_area (const struct ps_prochandle *ph,
  131.                     lwpid_t lwpid, int idx, void **base)
  132. {
  133.   if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
  134.     return PS_ERR;

  135.   /* IDX is the bias from the thread pointer to the beginning of the
  136.      thread descriptor.  It has to be subtracted due to implementation
  137.      quirks in libthread_db.  */
  138.   *base = (void *) ((char *)*base - idx);

  139.   return PS_OK;
  140. }
  141. #endif /* PTRACE_GET_THREAD_AREA */

  142. static struct regsets_info m68k_regsets_info =
  143.   {
  144.     m68k_regsets, /* regsets */
  145.     0, /* num_regsets */
  146.     NULL, /* disabled_regsets */
  147.   };

  148. static struct usrregs_info m68k_usrregs_info =
  149.   {
  150.     m68k_num_regs,
  151.     m68k_regmap,
  152.   };

  153. static struct regs_info regs_info =
  154.   {
  155.     NULL, /* regset_bitmap */
  156.     &m68k_usrregs_info,
  157.     &m68k_regsets_info
  158.   };

  159. static const struct regs_info *
  160. m68k_regs_info (void)
  161. {
  162.   return &regs_info;
  163. }

  164. static void
  165. m68k_arch_setup (void)
  166. {
  167.   current_process ()->tdesc = tdesc_m68k;
  168. }

  169. struct linux_target_ops the_low_target = {
  170.   m68k_arch_setup,
  171.   m68k_regs_info,
  172.   m68k_cannot_fetch_register,
  173.   m68k_cannot_store_register,
  174.   NULL, /* fetch_register */
  175.   m68k_get_pc,
  176.   m68k_set_pc,
  177.   m68k_breakpoint,
  178.   m68k_breakpoint_len,
  179.   NULL,
  180.   2,
  181.   m68k_breakpoint_at,
  182. };

  183. void
  184. initialize_low_arch (void)
  185. {
  186.   /* Initialize the Linux target descriptions.  */
  187.   init_registers_m68k ();

  188.   initialize_regsets_info (&m68k_regsets_info);
  189. }