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