Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / alpha-bsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
07681759 2
42a4f53d 3 Copyright (C) 2000-2019 Free Software Foundation, Inc.
448628fe
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
448628fe
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
448628fe
MK
19
20#include "defs.h"
448628fe 21
d55e5aa6 22/* Standard C includes. */
448628fe 23#include <machine/reg.h>
448628fe
MK
24#ifdef HAVE_SYS_PROCFS_H
25#include <sys/procfs.h>
26#endif
d55e5aa6
TT
27#include <sys/ptrace.h>
28#include <sys/types.h>
29
30/* Local non-gdb includes. */
31#include "alpha-bsd-tdep.h"
32#include "alpha-tdep.h"
33#include "inf-ptrace.h"
34#include "inferior.h"
35#include "regcache.h"
448628fe
MK
36
37#ifndef HAVE_GREGSET_T
38typedef struct reg gregset_t;
39#endif
40
12bcb0fe
JT
41#ifndef HAVE_FPREGSET_T
42typedef struct fpreg fpregset_t;
43#endif
448628fe
MK
44
45#include "gregset.h"
46
f6ac5f3d
PA
47struct alpha_bsd_nat_target final : public inf_ptrace_target
48{
49 void fetch_registers (struct regcache *, int) override;
50 void store_registers (struct regcache *, int) override;
51};
52
53static alpha_bsd_nat_target the_alpha_bsd_nat_target;
54
12bcb0fe
JT
55/* Provide *regset() wrappers around the generic Alpha BSD register
56 supply/fill routines. */
448628fe
MK
57
58void
7f7fe91e 59supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
448628fe 60{
7f7fe91e 61 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
448628fe
MK
62}
63
448628fe 64void
7f7fe91e 65fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
448628fe 66{
7f7fe91e 67 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
448628fe
MK
68}
69
448628fe 70void
7f7fe91e 71supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
448628fe 72{
7f7fe91e 73 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
448628fe
MK
74}
75
448628fe 76void
0963b4bd
MS
77fill_fpregset (const struct regcache *regcache,
78 fpregset_t *fpregsetp, int regno)
448628fe 79{
7f7fe91e 80 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
448628fe 81}
12bcb0fe 82\f
e771a871
JT
83/* Determine if PT_GETREGS fetches this register. */
84
85static int
86getregs_supplies (int regno)
87{
dc129d82 88 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
07681759 89 || regno >= ALPHA_PC_REGNUM);
e771a871
JT
90}
91
448628fe
MK
92/* Fetch register REGNO from the inferior. If REGNO is -1, do this
93 for all registers (including the floating point registers). */
94
f6ac5f3d
PA
95void
96alpha_bsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
448628fe 97{
e771a871
JT
98 if (regno == -1 || getregs_supplies (regno))
99 {
12bcb0fe 100 struct reg gregs;
e771a871 101
e99b03dc 102 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
9f8e0089 103 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 104 perror_with_name (_("Couldn't get registers"));
448628fe 105
56be3814 106 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
e771a871
JT
107 if (regno != -1)
108 return;
109 }
448628fe 110
0963b4bd 111 if (regno == -1
ac7936df 112 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
448628fe 113 {
12bcb0fe 114 struct fpreg fpregs;
448628fe 115
e99b03dc 116 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
9f8e0089 117 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 118 perror_with_name (_("Couldn't get floating point status"));
448628fe 119
56be3814 120 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
448628fe 121 }
448628fe
MK
122}
123
124/* Store register REGNO back into the inferior. If REGNO is -1, do
125 this for all registers (including the floating point registers). */
126
f6ac5f3d
PA
127void
128alpha_bsd_nat_target::store_registers (struct regcache *regcache, int regno)
448628fe 129{
e771a871
JT
130 if (regno == -1 || getregs_supplies (regno))
131 {
12bcb0fe 132 struct reg gregs;
e99b03dc 133 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
9f8e0089 134 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 135 perror_with_name (_("Couldn't get registers"));
e771a871 136
56be3814 137 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
448628fe 138
e99b03dc 139 if (ptrace (PT_SETREGS, regcache->ptid ().pid (),
9f8e0089 140 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 141 perror_with_name (_("Couldn't write registers"));
448628fe 142
e771a871
JT
143 if (regno != -1)
144 return;
145 }
448628fe 146
0963b4bd 147 if (regno == -1
ac7936df 148 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
448628fe 149 {
12bcb0fe 150 struct fpreg fpregs;
448628fe 151
e99b03dc 152 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
9f8e0089 153 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 154 perror_with_name (_("Couldn't get floating point status"));
448628fe 155
56be3814 156 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
448628fe 157
e99b03dc 158 if (ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
9f8e0089 159 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 160 perror_with_name (_("Couldn't write floating point status"));
448628fe
MK
161 }
162}
4816ec69
MK
163\f
164
165/* Support for debugging kernel virtual memory images. */
166
4816ec69
MK
167#include <sys/signal.h>
168#include <machine/pcb.h>
169
170#include "bsd-kvm.h"
171
172static int
173alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
174{
175 int regnum;
176
177 /* The following is true for OpenBSD 3.9:
178
179 The pcb contains the register state at the context switch inside
180 cpu_switch(). */
181
182 /* The stack pointer shouldn't be zero. */
183 if (pcb->pcb_hw.apcb_ksp == 0)
184 return 0;
185
73e1c03f 186 regcache->raw_supply (ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
4816ec69
MK
187
188 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
73e1c03f
SM
189 regcache->raw_supply (regnum, &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
190 regcache->raw_supply (ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
4816ec69
MK
191
192 return 1;
193}
194\f
0d6e4ad7 195
0d6e4ad7
MK
196void
197_initialize_alphabsd_nat (void)
198{
d9f719f1 199 add_inf_child_target (&the_alpha_bsd_nat_target);
4816ec69
MK
200
201 /* Support debugging kernel virtual memory images. */
202 bsd_kvm_add_target (alphabsd_supply_pcb);
0d6e4ad7 203}
This page took 1.087589 seconds and 4 git commands to generate.