GDB (API)
/home/stan/gdb/src/gdb/hppanbsd-nat.c
Go to the documentation of this file.
00001 /* Native-dependent code for NetBSD/hppa.
00002 
00003    Copyright (C) 2008-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"
00022 #include "regcache.h"
00023 
00024 #include <sys/types.h>
00025 #include <sys/ptrace.h>
00026 #include <machine/reg.h>
00027 
00028 #include "hppa-tdep.h"
00029 #include "inf-ptrace.h"
00030 
00031 #include "nbsd-nat.h"
00032 
00033 static int
00034 hppanbsd_gregset_supplies_p (int regnum)
00035 {
00036   return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
00037           (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
00038           regnum == HPPA_IPSW_REGNUM ||
00039           (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
00040 }
00041 
00042 static int
00043 hppanbsd_fpregset_supplies_p (int regnum)
00044 {
00045   return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
00046 }
00047 
00048 /* Supply the general-purpose registers stored in GREGS to REGCACHE.  */
00049 
00050 static void
00051 hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
00052 {
00053   const char *regs = gregs;
00054   const int *r = gregs;
00055   int regnum;
00056 
00057   for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
00058     regcache_raw_supply (regcache, regnum, regs + regnum * 4);
00059 
00060   regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
00061   regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
00062   regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
00063   regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
00064   regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
00065   regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
00066   regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
00067   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
00068   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
00069   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
00070   regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
00071 }
00072 
00073 /* Supply the floating-point registers stored in FPREGS to REGCACHE.  */
00074 
00075 static void
00076 hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
00077 {
00078   const char *regs = fpregs;
00079   int regnum;
00080 
00081   for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
00082        regnum += 2, regs += 8)
00083     {
00084       regcache_raw_supply (regcache, regnum, regs);
00085       regcache_raw_supply (regcache, regnum + 1, regs + 4);
00086     }
00087 }
00088 
00089 /* Collect the general-purpose registers from REGCACHE and store them
00090    in GREGS.  */
00091 
00092 static void
00093 hppanbsd_collect_gregset (const struct regcache *regcache,
00094                           void *gregs, int regnum)
00095 {
00096   char *regs = gregs;
00097   int *r = gregs;
00098   int i;
00099 
00100   for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
00101     {
00102       if (regnum == -1 || regnum == i)
00103         regcache_raw_collect (regcache, i, regs + i * 4);
00104     }
00105 
00106   if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
00107     regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
00108   if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
00109     regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
00110   if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
00111     regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
00112 
00113   if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
00114     regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
00115   if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
00116     regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
00117   if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
00118     regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
00119   if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
00120     regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
00121   if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
00122     regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
00123   if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
00124     regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
00125   if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
00126     regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
00127   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
00128     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
00129   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
00130     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
00131   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
00132     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
00133   if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
00134     regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
00135 }
00136 
00137 /* Collect the floating-point registers from REGCACHE and store them
00138    in FPREGS.  */
00139 
00140 static void
00141 hppanbsd_collect_fpregset (struct regcache *regcache,
00142                           void *fpregs, int regnum)
00143 {
00144   char *regs = fpregs;
00145   int i;
00146 
00147   for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
00148     {
00149       if (regnum == -1 || regnum == i || regnum == i + 1)
00150         {
00151           regcache_raw_collect (regcache, i, regs);
00152           regcache_raw_collect (regcache, i + 1, regs + 4);
00153         }
00154     }
00155 }
00156 
00157 
00158 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
00159    for all registers (including the floating-point registers).  */
00160 
00161 static void
00162 hppanbsd_fetch_registers (struct target_ops *ops,
00163                           struct regcache *regcache, int regnum)
00164 
00165 {
00166   if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
00167     {
00168       struct reg regs;
00169 
00170       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00171                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00172         perror_with_name (_("Couldn't get registers"));
00173 
00174       hppanbsd_supply_gregset (regcache, &regs);
00175     }
00176 
00177   if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
00178     {
00179       struct fpreg fpregs;
00180 
00181       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
00182                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
00183         perror_with_name (_("Couldn't get floating point status"));
00184 
00185       hppanbsd_supply_fpregset (regcache, &fpregs);
00186     }
00187 }
00188 
00189 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
00190    this for all registers (including the floating-point registers).  */
00191 
00192 static void
00193 hppanbsd_store_registers (struct target_ops *ops,
00194                           struct regcache *regcache, int regnum)
00195 {
00196   if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
00197     {
00198       struct reg regs;
00199 
00200       if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
00201                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00202         perror_with_name (_("Couldn't get registers"));
00203 
00204       hppanbsd_collect_gregset (regcache, &regs, regnum);
00205 
00206       if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
00207                   (PTRACE_TYPE_ARG3) &regs, 0) == -1)
00208         perror_with_name (_("Couldn't write registers"));
00209     }
00210 
00211   if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
00212     {
00213       struct fpreg fpregs;
00214 
00215       if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
00216                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
00217         perror_with_name (_("Couldn't get floating point status"));
00218 
00219       hppanbsd_collect_fpregset (regcache, &fpregs, regnum);
00220 
00221       if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
00222                   (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
00223         perror_with_name (_("Couldn't write floating point status"));
00224     }
00225 }
00226 
00227 
00228 /* Provide a prototype to silence -Wmissing-prototypes.  */
00229 void _initialize_hppanbsd_nat (void);
00230 
00231 void
00232 _initialize_hppanbsd_nat (void)
00233 {
00234   struct target_ops *t;
00235 
00236   /* Add some extra features to the ptrace target.  */
00237   t = inf_ptrace_target ();
00238 
00239   t->to_fetch_registers = hppanbsd_fetch_registers;
00240   t->to_store_registers = hppanbsd_store_registers;
00241 
00242   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
00243 
00244   add_target (t);
00245 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines