update copyright year range in GDB files
[deliverable/binutils-gdb.git] / gdb / alpha-bsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
07681759 2
61baf725 3 Copyright (C) 2000-2017 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"
21#include "inferior.h"
4e052eda 22#include "regcache.h"
448628fe 23
dc129d82 24#include "alpha-tdep.h"
03b62bbb 25#include "alpha-bsd-tdep.h"
0d6e4ad7 26#include "inf-ptrace.h"
dc129d82 27
448628fe
MK
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
37typedef struct reg gregset_t;
38#endif
39
12bcb0fe
JT
40#ifndef HAVE_FPREGSET_T
41typedef struct fpreg fpregset_t;
42#endif
448628fe
MK
43
44#include "gregset.h"
45
12bcb0fe
JT
46/* Provide *regset() wrappers around the generic Alpha BSD register
47 supply/fill routines. */
448628fe
MK
48
49void
7f7fe91e 50supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
448628fe 51{
7f7fe91e 52 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
448628fe
MK
53}
54
448628fe 55void
7f7fe91e 56fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
448628fe 57{
7f7fe91e 58 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
448628fe
MK
59}
60
448628fe 61void
7f7fe91e 62supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
448628fe 63{
7f7fe91e 64 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
448628fe
MK
65}
66
448628fe 67void
0963b4bd
MS
68fill_fpregset (const struct regcache *regcache,
69 fpregset_t *fpregsetp, int regno)
448628fe 70{
7f7fe91e 71 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
448628fe 72}
12bcb0fe 73\f
e771a871
JT
74/* Determine if PT_GETREGS fetches this register. */
75
76static int
77getregs_supplies (int regno)
78{
dc129d82 79 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
07681759 80 || regno >= ALPHA_PC_REGNUM);
e771a871
JT
81}
82
448628fe
MK
83/* Fetch register REGNO from the inferior. If REGNO is -1, do this
84 for all registers (including the floating point registers). */
85
0d6e4ad7 86static void
28439f5e
PA
87alphabsd_fetch_inferior_registers (struct target_ops *ops,
88 struct regcache *regcache, int regno)
448628fe 89{
e771a871
JT
90 if (regno == -1 || getregs_supplies (regno))
91 {
12bcb0fe 92 struct reg gregs;
e771a871 93
dfd4cc63 94 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 95 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 96 perror_with_name (_("Couldn't get registers"));
448628fe 97
56be3814 98 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
e771a871
JT
99 if (regno != -1)
100 return;
101 }
448628fe 102
0963b4bd
MS
103 if (regno == -1
104 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
448628fe 105 {
12bcb0fe 106 struct fpreg fpregs;
448628fe 107
dfd4cc63 108 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
9f8e0089 109 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 110 perror_with_name (_("Couldn't get floating point status"));
448628fe 111
56be3814 112 alphabsd_supply_fpreg (regcache, (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 119static void
28439f5e
PA
120alphabsd_store_inferior_registers (struct target_ops *ops,
121 struct regcache *regcache, int regno)
448628fe 122{
e771a871
JT
123 if (regno == -1 || getregs_supplies (regno))
124 {
12bcb0fe 125 struct reg gregs;
dfd4cc63 126 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 127 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 128 perror_with_name (_("Couldn't get registers"));
e771a871 129
56be3814 130 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
448628fe 131
dfd4cc63 132 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 133 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 134 perror_with_name (_("Couldn't write registers"));
448628fe 135
e771a871
JT
136 if (regno != -1)
137 return;
138 }
448628fe 139
0963b4bd
MS
140 if (regno == -1
141 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
448628fe 142 {
12bcb0fe 143 struct fpreg fpregs;
448628fe 144
dfd4cc63 145 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
9f8e0089 146 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 147 perror_with_name (_("Couldn't get floating point status"));
448628fe 148
56be3814 149 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
448628fe 150
dfd4cc63 151 if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
9f8e0089 152 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 153 perror_with_name (_("Couldn't write floating point status"));
448628fe
MK
154 }
155}
4816ec69
MK
156\f
157
158/* Support for debugging kernel virtual memory images. */
159
4816ec69
MK
160#include <sys/signal.h>
161#include <machine/pcb.h>
162
163#include "bsd-kvm.h"
164
165static int
166alphabsd_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
0d6e4ad7
MK
189
190/* Provide a prototype to silence -Wmissing-prototypes. */
191void _initialize_alphabsd_nat (void);
192
193void
194_initialize_alphabsd_nat (void)
195{
196 struct target_ops *t;
197
198 t = inf_ptrace_target ();
199 t->to_fetch_registers = alphabsd_fetch_inferior_registers;
200 t->to_store_registers = alphabsd_store_inferior_registers;
201 add_target (t);
4816ec69
MK
202
203 /* Support debugging kernel virtual memory images. */
204 bsd_kvm_add_target (alphabsd_supply_pcb);
0d6e4ad7 205}
This page took 0.934918 seconds and 4 git commands to generate.