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