]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/alpha-bsd-nat.c
Remove ptid_get_pid
[thirdparty/binutils-gdb.git] / gdb / alpha-bsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
07681759 2
e2882c85 3 Copyright (C) 2000-2018 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
f6ac5f3d
PA
46struct alpha_bsd_nat_target final : public inf_ptrace_target
47{
48 void fetch_registers (struct regcache *, int) override;
49 void store_registers (struct regcache *, int) override;
50};
51
52static alpha_bsd_nat_target the_alpha_bsd_nat_target;
53
12bcb0fe
JT
54/* Provide *regset() wrappers around the generic Alpha BSD register
55 supply/fill routines. */
448628fe
MK
56
57void
7f7fe91e 58supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
448628fe 59{
7f7fe91e 60 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
448628fe
MK
61}
62
448628fe 63void
7f7fe91e 64fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
448628fe 65{
7f7fe91e 66 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
448628fe
MK
67}
68
448628fe 69void
7f7fe91e 70supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
448628fe 71{
7f7fe91e 72 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
448628fe
MK
73}
74
448628fe 75void
0963b4bd
MS
76fill_fpregset (const struct regcache *regcache,
77 fpregset_t *fpregsetp, int regno)
448628fe 78{
7f7fe91e 79 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
448628fe 80}
12bcb0fe 81\f
e771a871
JT
82/* Determine if PT_GETREGS fetches this register. */
83
84static int
85getregs_supplies (int regno)
86{
dc129d82 87 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
07681759 88 || regno >= ALPHA_PC_REGNUM);
e771a871
JT
89}
90
448628fe
MK
91/* Fetch register REGNO from the inferior. If REGNO is -1, do this
92 for all registers (including the floating point registers). */
93
f6ac5f3d
PA
94void
95alpha_bsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
448628fe 96{
e771a871
JT
97 if (regno == -1 || getregs_supplies (regno))
98 {
12bcb0fe 99 struct reg gregs;
e771a871 100
e99b03dc 101 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
9f8e0089 102 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 103 perror_with_name (_("Couldn't get registers"));
448628fe 104
56be3814 105 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
e771a871
JT
106 if (regno != -1)
107 return;
108 }
448628fe 109
0963b4bd 110 if (regno == -1
ac7936df 111 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
448628fe 112 {
12bcb0fe 113 struct fpreg fpregs;
448628fe 114
e99b03dc 115 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
9f8e0089 116 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 117 perror_with_name (_("Couldn't get floating point status"));
448628fe 118
56be3814 119 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
448628fe 120 }
448628fe
MK
121}
122
123/* Store register REGNO back into the inferior. If REGNO is -1, do
124 this for all registers (including the floating point registers). */
125
f6ac5f3d
PA
126void
127alpha_bsd_nat_target::store_registers (struct regcache *regcache, int regno)
448628fe 128{
e771a871
JT
129 if (regno == -1 || getregs_supplies (regno))
130 {
12bcb0fe 131 struct reg gregs;
e99b03dc 132 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
9f8e0089 133 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 134 perror_with_name (_("Couldn't get registers"));
e771a871 135
56be3814 136 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
448628fe 137
e99b03dc 138 if (ptrace (PT_SETREGS, regcache->ptid ().pid (),
9f8e0089 139 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 140 perror_with_name (_("Couldn't write registers"));
448628fe 141
e771a871
JT
142 if (regno != -1)
143 return;
144 }
448628fe 145
0963b4bd 146 if (regno == -1
ac7936df 147 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
448628fe 148 {
12bcb0fe 149 struct fpreg fpregs;
448628fe 150
e99b03dc 151 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
9f8e0089 152 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 153 perror_with_name (_("Couldn't get floating point status"));
448628fe 154
56be3814 155 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
448628fe 156
e99b03dc 157 if (ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
9f8e0089 158 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 159 perror_with_name (_("Couldn't write floating point status"));
448628fe
MK
160 }
161}
4816ec69
MK
162\f
163
164/* Support for debugging kernel virtual memory images. */
165
4816ec69
MK
166#include <sys/signal.h>
167#include <machine/pcb.h>
168
169#include "bsd-kvm.h"
170
171static int
172alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
173{
174 int regnum;
175
176 /* The following is true for OpenBSD 3.9:
177
178 The pcb contains the register state at the context switch inside
179 cpu_switch(). */
180
181 /* The stack pointer shouldn't be zero. */
182 if (pcb->pcb_hw.apcb_ksp == 0)
183 return 0;
184
73e1c03f 185 regcache->raw_supply (ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
4816ec69
MK
186
187 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
73e1c03f
SM
188 regcache->raw_supply (regnum, &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
189 regcache->raw_supply (ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
4816ec69
MK
190
191 return 1;
192}
193\f
0d6e4ad7 194
0d6e4ad7
MK
195void
196_initialize_alphabsd_nat (void)
197{
d9f719f1 198 add_inf_child_target (&the_alpha_bsd_nat_target);
4816ec69
MK
199
200 /* Support debugging kernel virtual memory images. */
201 bsd_kvm_add_target (alphabsd_supply_pcb);
0d6e4ad7 202}