]>
Commit | Line | Data |
---|---|---|
448628fe | 1 | /* Native-dependent code for Alpha BSD's. |
07681759 | 2 | |
4816ec69 MK |
3 | Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 |
4 | Free Software Foundation, Inc. | |
448628fe MK |
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 2 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, write to the Free Software | |
197e01b6 EZ |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
448628fe MK |
22 | |
23 | #include "defs.h" | |
24 | #include "inferior.h" | |
4e052eda | 25 | #include "regcache.h" |
448628fe | 26 | |
dc129d82 | 27 | #include "alpha-tdep.h" |
12bcb0fe | 28 | #include "alphabsd-tdep.h" |
0d6e4ad7 | 29 | #include "inf-ptrace.h" |
dc129d82 | 30 | |
448628fe MK |
31 | #include <sys/types.h> |
32 | #include <sys/ptrace.h> | |
33 | #include <machine/reg.h> | |
34 | ||
35 | #ifdef HAVE_SYS_PROCFS_H | |
36 | #include <sys/procfs.h> | |
37 | #endif | |
38 | ||
39 | #ifndef HAVE_GREGSET_T | |
40 | typedef struct reg gregset_t; | |
41 | #endif | |
42 | ||
12bcb0fe JT |
43 | #ifndef HAVE_FPREGSET_T |
44 | typedef struct fpreg fpregset_t; | |
45 | #endif | |
448628fe MK |
46 | |
47 | #include "gregset.h" | |
48 | ||
12bcb0fe JT |
49 | /* Provide *regset() wrappers around the generic Alpha BSD register |
50 | supply/fill routines. */ | |
448628fe MK |
51 | |
52 | void | |
53 | supply_gregset (gregset_t *gregsetp) | |
54 | { | |
12bcb0fe | 55 | alphabsd_supply_reg ((char *) gregsetp, -1); |
448628fe MK |
56 | } |
57 | ||
448628fe MK |
58 | void |
59 | fill_gregset (gregset_t *gregsetp, int regno) | |
60 | { | |
12bcb0fe | 61 | alphabsd_fill_reg ((char *) gregsetp, regno); |
448628fe MK |
62 | } |
63 | ||
448628fe MK |
64 | void |
65 | supply_fpregset (fpregset_t *fpregsetp) | |
66 | { | |
12bcb0fe | 67 | alphabsd_supply_fpreg ((char *) fpregsetp, -1); |
448628fe MK |
68 | } |
69 | ||
448628fe MK |
70 | void |
71 | fill_fpregset (fpregset_t *fpregsetp, int regno) | |
72 | { | |
12bcb0fe | 73 | alphabsd_fill_fpreg ((char *) fpregsetp, regno); |
448628fe | 74 | } |
12bcb0fe | 75 | \f |
e771a871 JT |
76 | /* Determine if PT_GETREGS fetches this register. */ |
77 | ||
78 | static int | |
79 | getregs_supplies (int regno) | |
80 | { | |
dc129d82 | 81 | return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM) |
07681759 | 82 | || regno >= ALPHA_PC_REGNUM); |
e771a871 JT |
83 | } |
84 | ||
448628fe MK |
85 | /* Fetch register REGNO from the inferior. If REGNO is -1, do this |
86 | for all registers (including the floating point registers). */ | |
87 | ||
0d6e4ad7 MK |
88 | static void |
89 | alphabsd_fetch_inferior_registers (int regno) | |
448628fe | 90 | { |
e771a871 JT |
91 | if (regno == -1 || getregs_supplies (regno)) |
92 | { | |
12bcb0fe | 93 | struct reg gregs; |
e771a871 JT |
94 | |
95 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 96 | (PTRACE_TYPE_ARG3) &gregs, 0) == -1) |
edefbb7c | 97 | perror_with_name (_("Couldn't get registers")); |
448628fe | 98 | |
12bcb0fe | 99 | alphabsd_supply_reg ((char *) &gregs, regno); |
e771a871 JT |
100 | if (regno != -1) |
101 | return; | |
102 | } | |
448628fe MK |
103 | |
104 | if (regno == -1 || regno >= FP0_REGNUM) | |
105 | { | |
12bcb0fe | 106 | struct fpreg fpregs; |
448628fe | 107 | |
39f77062 | 108 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), |
9f8e0089 | 109 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
edefbb7c | 110 | perror_with_name (_("Couldn't get floating point status")); |
448628fe | 111 | |
12bcb0fe | 112 | alphabsd_supply_fpreg ((char *) &fpregs, regno); |
448628fe | 113 | } |
448628fe MK |
114 | } |
115 | ||
116 | /* Store register REGNO back into the inferior. If REGNO is -1, do | |
117 | this for all registers (including the floating point registers). */ | |
118 | ||
0d6e4ad7 MK |
119 | static void |
120 | alphabsd_store_inferior_registers (int regno) | |
448628fe | 121 | { |
e771a871 JT |
122 | if (regno == -1 || getregs_supplies (regno)) |
123 | { | |
12bcb0fe | 124 | struct reg gregs; |
e771a871 | 125 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), |
9f8e0089 | 126 | (PTRACE_TYPE_ARG3) &gregs, 0) == -1) |
edefbb7c | 127 | perror_with_name (_("Couldn't get registers")); |
e771a871 | 128 | |
12bcb0fe | 129 | alphabsd_fill_reg ((char *) &gregs, regno); |
448628fe | 130 | |
e771a871 | 131 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), |
9f8e0089 | 132 | (PTRACE_TYPE_ARG3) &gregs, 0) == -1) |
edefbb7c | 133 | perror_with_name (_("Couldn't write registers")); |
448628fe | 134 | |
e771a871 JT |
135 | if (regno != -1) |
136 | return; | |
137 | } | |
448628fe MK |
138 | |
139 | if (regno == -1 || regno >= FP0_REGNUM) | |
140 | { | |
12bcb0fe | 141 | struct fpreg fpregs; |
448628fe | 142 | |
39f77062 | 143 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), |
9f8e0089 | 144 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
edefbb7c | 145 | perror_with_name (_("Couldn't get floating point status")); |
448628fe | 146 | |
12bcb0fe | 147 | alphabsd_fill_fpreg ((char *) &fpregs, regno); |
448628fe | 148 | |
39f77062 | 149 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), |
9f8e0089 | 150 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
edefbb7c | 151 | perror_with_name (_("Couldn't write floating point status")); |
448628fe MK |
152 | } |
153 | } | |
4816ec69 MK |
154 | \f |
155 | ||
156 | /* Support for debugging kernel virtual memory images. */ | |
157 | ||
158 | #include <sys/types.h> | |
159 | #include <sys/signal.h> | |
160 | #include <machine/pcb.h> | |
161 | ||
162 | #include "bsd-kvm.h" | |
163 | ||
164 | static int | |
165 | alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
166 | { | |
167 | int regnum; | |
168 | ||
169 | /* The following is true for OpenBSD 3.9: | |
170 | ||
171 | The pcb contains the register state at the context switch inside | |
172 | cpu_switch(). */ | |
173 | ||
174 | /* The stack pointer shouldn't be zero. */ | |
175 | if (pcb->pcb_hw.apcb_ksp == 0) | |
176 | return 0; | |
177 | ||
178 | regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp); | |
179 | ||
180 | for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++) | |
181 | regcache_raw_supply (regcache, regnum, | |
182 | &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]); | |
183 | regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]); | |
184 | ||
185 | return 1; | |
186 | } | |
187 | \f | |
0d6e4ad7 MK |
188 | |
189 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
190 | void _initialize_alphabsd_nat (void); | |
191 | ||
192 | void | |
193 | _initialize_alphabsd_nat (void) | |
194 | { | |
195 | struct target_ops *t; | |
196 | ||
197 | t = inf_ptrace_target (); | |
198 | t->to_fetch_registers = alphabsd_fetch_inferior_registers; | |
199 | t->to_store_registers = alphabsd_store_inferior_registers; | |
200 | add_target (t); | |
4816ec69 MK |
201 | |
202 | /* Support debugging kernel virtual memory images. */ | |
203 | bsd_kvm_add_target (alphabsd_supply_pcb); | |
0d6e4ad7 | 204 | } |