1 /* Native-dependent code for HP PA-RISC BSD's. 2 3 Copyright 2004, 2005 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, 20 Boston, MA 02111-1307, USA. */ 21 22 #include "defs.h" 23 #include "inferior.h" 24 #include "regcache.h" 25 #include "target.h" 26 27 #include <sys/types.h> 28 #include <sys/ptrace.h> 29 #include <machine/reg.h> 30 31 #include "hppa-tdep.h" 32 #include "inf-ptrace.h" 33 34 static int 35 hppabsd_gregset_supplies_p (int regnum) 36 { 37 return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_PCOQ_TAIL_REGNUM); 38 } 39 40 static int 41 hppabsd_fpregset_supplies_p (int regnum) 42 { 43 return (regnum >= HPPA_FP0_REGNUM && regnum < HPPA_FP0_REGNUM + 32 * 2); 44 } 45 46 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */ 47 48 static void 49 hppabsd_supply_gregset (struct regcache *regcache, const void *gregs) 50 { 51 const char *regs = gregs; 52 int regnum; 53 54 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++) 55 regcache_raw_supply (regcache, regnum, regs + regnum * 4); 56 57 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs); 58 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); 59 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); 60 } 61 62 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */ 63 64 static void 65 hppabsd_supply_fpregset (struct regcache *regcache, const void *fpregs) 66 { 67 const char *regs = fpregs; 68 int regnum; 69 70 for (regnum = HPPA_FP0_REGNUM; regnum < HPPA_FP0_REGNUM + 32 * 2; regnum++) 71 regcache_raw_supply (regcache, regnum, 72 regs + (regnum - HPPA_FP0_REGNUM) * 4); 73 } 74 75 /* Collect the general-purpose registers from REGCACHE and store them 76 in GREGS. */ 77 78 static void 79 hppabsd_collect_gregset (const struct regcache *regcache, 80 void *gregs, int regnum) 81 { 82 char *regs = gregs; 83 int i; 84 85 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++) 86 { 87 if (regnum == -1 || regnum == i) 88 regcache_raw_collect (regcache, i, regs + i * 4); 89 } 90 91 if (regnum == -1 || regnum == HPPA_SAR_REGNUM) 92 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs); 93 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) 94 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); 95 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) 96 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); 97 } 98 99 /* Collect the floating-point registers from REGCACHE and store them 100 in FPREGS. */ 101 102 static void 103 hppabsd_collect_fpregset (struct regcache *regcache, 104 void *fpregs, int regnum) 105 { 106 char *regs = fpregs; 107 int i; 108 109 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32 * 2; i++) 110 { 111 if (regnum == -1 || regnum == i) 112 regcache_raw_collect (regcache, i, regs + (i - HPPA_FP0_REGNUM) * 4); 113 } 114 } 115 116 117 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this 118 for all registers (including the floating-point registers). */ 119 120 static void 121 hppabsd_fetch_registers (int regnum) 122 { 123 struct regcache *regcache = current_regcache; 124 125 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum)) 126 { 127 struct reg regs; 128 129 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), 130 (PTRACE_TYPE_ARG3) ®s, 0) == -1) 131 perror_with_name (_("Couldn't get registers")); 132 133 hppabsd_supply_gregset (regcache, ®s); 134 } 135 136 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum)) 137 { 138 struct fpreg fpregs; 139 140 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), 141 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) 142 perror_with_name (_("Couldn't get floating point status")); 143 144 hppabsd_supply_fpregset (current_regcache, &fpregs); 145 } 146 } 147 148 /* Store register REGNUM back into the inferior. If REGNUM is -1, do 149 this for all registers (including the floating-point registers). */ 150 151 static void 152 hppabsd_store_registers (int regnum) 153 { 154 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum)) 155 { 156 struct reg regs; 157 158 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), 159 (PTRACE_TYPE_ARG3) ®s, 0) == -1) 160 perror_with_name (_("Couldn't get registers")); 161 162 hppabsd_collect_gregset (current_regcache, ®s, regnum); 163 164 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), 165 (PTRACE_TYPE_ARG3) ®s, 0) == -1) 166 perror_with_name (_("Couldn't write registers")); 167 } 168 169 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum)) 170 { 171 struct fpreg fpregs; 172 173 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), 174 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) 175 perror_with_name (_("Couldn't get floating point status")); 176 177 hppabsd_collect_fpregset (current_regcache, &fpregs, regnum); 178 179 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), 180 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) 181 perror_with_name (_("Couldn't write floating point status")); 182 } 183 } 184 185 /* Provide a prototype to silence -Wmissing-prototypes. */ 186 void _initialize_hppabsd_nat (void); 187 188 void 189 _initialize_hppabsd_nat (void) 190 { 191 struct target_ops *t; 192 193 /* Add in local overrides. */ 194 t = inf_ptrace_target (); 195 t->to_fetch_registers = hppabsd_fetch_registers; 196 t->to_store_registers = hppabsd_store_registers; 197 add_target (t); 198 } 199