gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / alpha-bsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
07681759 2
b811d2c2 3 Copyright (C) 2000-2020 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 19
2190cf06
KR
20/* We define this to get types like register_t. */
21#define _KERNTYPES
448628fe 22#include "defs.h"
4de283e4
TT
23#include "inferior.h"
24#include "regcache.h"
448628fe 25
4de283e4
TT
26#include "alpha-tdep.h"
27#include "alpha-bsd-tdep.h"
28#include "inf-ptrace.h"
4fed520b 29#include "nbsd-nat.h"
4de283e4
TT
30
31#include <sys/types.h>
32#include <sys/ptrace.h>
448628fe 33#include <machine/reg.h>
4de283e4 34
4fed520b 35struct alpha_bsd_nat_target final : public nbsd_nat_target
f6ac5f3d
PA
36{
37 void fetch_registers (struct regcache *, int) override;
38 void store_registers (struct regcache *, int) override;
39};
40
41static alpha_bsd_nat_target the_alpha_bsd_nat_target;
42
e771a871
JT
43/* Determine if PT_GETREGS fetches this register. */
44
45static int
46getregs_supplies (int regno)
47{
dc129d82 48 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
07681759 49 || regno >= ALPHA_PC_REGNUM);
e771a871
JT
50}
51
448628fe
MK
52/* Fetch register REGNO from the inferior. If REGNO is -1, do this
53 for all registers (including the floating point registers). */
54
f6ac5f3d
PA
55void
56alpha_bsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
448628fe 57{
6def66f1
KR
58 int lwp = regcache->ptid ().lwp ();
59
e771a871
JT
60 if (regno == -1 || getregs_supplies (regno))
61 {
12bcb0fe 62 struct reg gregs;
e771a871 63
e99b03dc 64 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
6def66f1 65 (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
edefbb7c 66 perror_with_name (_("Couldn't get registers"));
448628fe 67
56be3814 68 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
e771a871
JT
69 if (regno != -1)
70 return;
71 }
448628fe 72
0963b4bd 73 if (regno == -1
ac7936df 74 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
448628fe 75 {
12bcb0fe 76 struct fpreg fpregs;
448628fe 77
e99b03dc 78 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
6def66f1 79 (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
edefbb7c 80 perror_with_name (_("Couldn't get floating point status"));
448628fe 81
56be3814 82 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
448628fe 83 }
448628fe
MK
84}
85
86/* Store register REGNO back into the inferior. If REGNO is -1, do
87 this for all registers (including the floating point registers). */
88
f6ac5f3d
PA
89void
90alpha_bsd_nat_target::store_registers (struct regcache *regcache, int regno)
448628fe 91{
6def66f1
KR
92 int lwp = regcache->ptid ().lwp ();
93
e771a871
JT
94 if (regno == -1 || getregs_supplies (regno))
95 {
12bcb0fe 96 struct reg gregs;
e99b03dc 97 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
6def66f1 98 (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
edefbb7c 99 perror_with_name (_("Couldn't get registers"));
e771a871 100
56be3814 101 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
448628fe 102
e99b03dc 103 if (ptrace (PT_SETREGS, regcache->ptid ().pid (),
6def66f1 104 (PTRACE_TYPE_ARG3) &gregs, lwp) == -1)
edefbb7c 105 perror_with_name (_("Couldn't write registers"));
448628fe 106
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 (),
6def66f1 117 (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
edefbb7c 118 perror_with_name (_("Couldn't get floating point status"));
448628fe 119
56be3814 120 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
448628fe 121
e99b03dc 122 if (ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
6def66f1 123 (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
edefbb7c 124 perror_with_name (_("Couldn't write floating point status"));
448628fe
MK
125 }
126}
4816ec69
MK
127\f
128
129/* Support for debugging kernel virtual memory images. */
130
4816ec69
MK
131#include <sys/signal.h>
132#include <machine/pcb.h>
133
134#include "bsd-kvm.h"
135
136static int
137alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
138{
139 int regnum;
140
141 /* The following is true for OpenBSD 3.9:
142
143 The pcb contains the register state at the context switch inside
144 cpu_switch(). */
145
146 /* The stack pointer shouldn't be zero. */
147 if (pcb->pcb_hw.apcb_ksp == 0)
148 return 0;
149
73e1c03f 150 regcache->raw_supply (ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
4816ec69
MK
151
152 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
73e1c03f
SM
153 regcache->raw_supply (regnum, &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
154 regcache->raw_supply (ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
4816ec69
MK
155
156 return 1;
157}
158\f
0d6e4ad7 159
6c265988 160void _initialize_alphabsd_nat ();
0d6e4ad7 161void
6c265988 162_initialize_alphabsd_nat ()
0d6e4ad7 163{
d9f719f1 164 add_inf_child_target (&the_alpha_bsd_nat_target);
4816ec69
MK
165
166 /* Support debugging kernel virtual memory images. */
167 bsd_kvm_add_target (alphabsd_supply_pcb);
0d6e4ad7 168}
This page took 1.146146 seconds and 4 git commands to generate.