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