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