gdb/gdbserver/lynx-ppc-low.c - gdb

Global variables defined

Data types defined

Functions defined

Macros defined

Source code

  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.

  2.    This file is part of GDB.

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

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

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

  13. #include "server.h"
  14. #include "lynx-low.h"

  15. #include <stdint.h>
  16. #include <limits.h>
  17. #include <sys/ptrace.h>

  18. /* The following two typedefs are defined in a .h file which is not
  19.    in the standard include path (/sys/include/family/ppc/ucontext.h),
  20.    so we just duplicate them here.  */

  21. /* General register context */
  22. typedef struct usr_econtext_s
  23. {
  24.         uint32_t        uec_iregs[32];
  25.         uint32_t        uec_inum;
  26.         uint32_t        uec_srr0;
  27.         uint32_t        uec_srr1;
  28.         uint32_t        uec_lr;
  29.         uint32_t        uec_ctr;
  30.         uint32_t        uec_cr;
  31.         uint32_t        uec_xer;
  32.         uint32_t        uec_dar;
  33.         uint32_t        uec_mq;
  34.         uint32_t        uec_msr;
  35.         uint32_t        uec_sregs[16];
  36.         uint32_t        uec_ss_count;
  37.         uint32_t        uec_ss_addr1;
  38.         uint32_t        uec_ss_addr2;
  39.         uint32_t        uec_ss_code1;
  40.         uint32_t        uec_ss_code2;
  41. } usr_econtext_t;

  42. /* Floating point register context */
  43. typedef struct usr_fcontext_s
  44. {
  45.         uint64_t        ufc_freg[32];
  46.         uint32_t        ufc_fpscr[2];
  47. } usr_fcontext_t;

  48. /* Index of for various registers inside the regcache.  */
  49. #define R0_REGNUM    0
  50. #define F0_REGNUM    32
  51. #define PC_REGNUM    64
  52. #define MSR_REGNUM   65
  53. #define CR_REGNUM    66
  54. #define LR_REGNUM    67
  55. #define CTR_REGNUM   68
  56. #define XER_REGNUM   69
  57. #define FPSCR_REGNUM 70

  58. /* Defined in auto-generated file powerpc-32.c.  */
  59. extern void init_registers_powerpc_32 (void);
  60. extern const struct target_desc *tdesc_powerpc_32;

  61. /* The fill_function for the general-purpose register set.  */

  62. static void
  63. lynx_ppc_fill_gregset (struct regcache *regcache, char *buf)
  64. {
  65.   int i;

  66.   /* r0 - r31 */
  67.   for (i = 0; i < 32; i++)
  68.     collect_register (regcache, R0_REGNUM + i,
  69.                       buf + offsetof (usr_econtext_t, uec_iregs[i]));

  70.   /* The other registers provided in the GP register context.  */
  71.   collect_register (regcache, PC_REGNUM,
  72.                     buf + offsetof (usr_econtext_t, uec_srr0));
  73.   collect_register (regcache, MSR_REGNUM,
  74.                     buf + offsetof (usr_econtext_t, uec_srr1));
  75.   collect_register (regcache, CR_REGNUM,
  76.                     buf + offsetof (usr_econtext_t, uec_cr));
  77.   collect_register (regcache, LR_REGNUM,
  78.                     buf + offsetof (usr_econtext_t, uec_lr));
  79.   collect_register (regcache, CTR_REGNUM,
  80.                     buf + offsetof (usr_econtext_t, uec_ctr));
  81.   collect_register (regcache, XER_REGNUM,
  82.                     buf + offsetof (usr_econtext_t, uec_xer));
  83. }

  84. /* The store_function for the general-purpose register set.  */

  85. static void
  86. lynx_ppc_store_gregset (struct regcache *regcache, const char *buf)
  87. {
  88.   int i;

  89.   /* r0 - r31 */
  90.   for (i = 0; i < 32; i++)
  91.     supply_register (regcache, R0_REGNUM + i,
  92.                       buf + offsetof (usr_econtext_t, uec_iregs[i]));

  93.   /* The other registers provided in the GP register context.  */
  94.   supply_register (regcache, PC_REGNUM,
  95.                    buf + offsetof (usr_econtext_t, uec_srr0));
  96.   supply_register (regcache, MSR_REGNUM,
  97.                    buf + offsetof (usr_econtext_t, uec_srr1));
  98.   supply_register (regcache, CR_REGNUM,
  99.                    buf + offsetof (usr_econtext_t, uec_cr));
  100.   supply_register (regcache, LR_REGNUM,
  101.                    buf + offsetof (usr_econtext_t, uec_lr));
  102.   supply_register (regcache, CTR_REGNUM,
  103.                    buf + offsetof (usr_econtext_t, uec_ctr));
  104.   supply_register (regcache, XER_REGNUM,
  105.                    buf + offsetof (usr_econtext_t, uec_xer));
  106. }

  107. /* The fill_function for the floating-point register set.  */

  108. static void
  109. lynx_ppc_fill_fpregset (struct regcache *regcache, char *buf)
  110. {
  111.   int i;

  112.   /* f0 - f31 */
  113.   for (i = 0; i < 32; i++)
  114.     collect_register (regcache, F0_REGNUM + i,
  115.                       buf + offsetof (usr_fcontext_t, ufc_freg[i]));

  116.   /* fpscr */
  117.   collect_register (regcache, FPSCR_REGNUM,
  118.                     buf + offsetof (usr_fcontext_t, ufc_fpscr));
  119. }

  120. /* The store_function for the floating-point register set.  */

  121. static void
  122. lynx_ppc_store_fpregset (struct regcache *regcache, const char *buf)
  123. {
  124.   int i;

  125.   /* f0 - f31 */
  126.   for (i = 0; i < 32; i++)
  127.     supply_register (regcache, F0_REGNUM + i,
  128.                      buf + offsetof (usr_fcontext_t, ufc_freg[i]));

  129.   /* fpscr */
  130.   supply_register (regcache, FPSCR_REGNUM,
  131.                    buf + offsetof (usr_fcontext_t, ufc_fpscr));
  132. }

  133. /* Implements the lynx_target_ops.arch_setup routine.  */

  134. static void
  135. lynx_ppc_arch_setup (void)
  136. {
  137.   init_registers_powerpc_32 ();
  138.   lynx_tdesc = tdesc_powerpc_32;
  139. }

  140. /* Description of all the powerpc-lynx register sets.  */

  141. struct lynx_regset_info lynx_target_regsets[] = {
  142.   /* General Purpose Registers.  */
  143.   {PTRACE_GETREGS, PTRACE_SETREGS, sizeof(usr_econtext_t),
  144.    lynx_ppc_fill_gregset, lynx_ppc_store_gregset},
  145.   /* Floating Point Registers.  */
  146.   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof(usr_fcontext_t),
  147.     lynx_ppc_fill_fpregset, lynx_ppc_store_fpregset },
  148.   /* End of list marker.  */
  149.   {0, 0, -1, NULL, NULL }
  150. };

  151. /* The lynx_target_ops vector for powerpc-lynxos.  */

  152. struct lynx_target_ops the_low_target = {
  153.   lynx_ppc_arch_setup,
  154. };