1 /* Native-dependent code for Alpha BSD's.
3 Copyright (C) 2000-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
24 #include "alpha-tdep.h"
25 #include "alpha-bsd-tdep.h"
26 #include "inf-ptrace.h"
28 #include <sys/types.h>
29 #include <sys/ptrace.h>
30 #include <machine/reg.h>
32 #ifdef HAVE_SYS_PROCFS_H
33 #include <sys/procfs.h>
36 #ifndef HAVE_GREGSET_T
37 typedef struct reg gregset_t;
40 #ifndef HAVE_FPREGSET_T
41 typedef struct fpreg fpregset_t;
46 struct alpha_bsd_nat_target final : public inf_ptrace_target
48 void fetch_registers (struct regcache *, int) override;
49 void store_registers (struct regcache *, int) override;
52 static alpha_bsd_nat_target the_alpha_bsd_nat_target;
54 /* Provide *regset() wrappers around the generic Alpha BSD register
55 supply/fill routines. */
58 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
60 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
64 fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
66 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
70 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
72 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
76 fill_fpregset (const struct regcache *regcache,
77 fpregset_t *fpregsetp, int regno)
79 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
82 /* Determine if PT_GETREGS fetches this register. */
85 getregs_supplies (int regno)
87 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
88 || regno >= ALPHA_PC_REGNUM);
91 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
92 for all registers (including the floating point registers). */
95 alpha_bsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
97 if (regno == -1 || getregs_supplies (regno))
101 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
102 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
103 perror_with_name (_("Couldn't get registers"));
105 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
111 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
115 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
116 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
117 perror_with_name (_("Couldn't get floating point status"));
119 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
123 /* Store register REGNO back into the inferior. If REGNO is -1, do
124 this for all registers (including the floating point registers). */
127 alpha_bsd_nat_target::store_registers (struct regcache *regcache, int regno)
129 if (regno == -1 || getregs_supplies (regno))
132 if (ptrace (PT_GETREGS, regcache->ptid ().pid (),
133 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
134 perror_with_name (_("Couldn't get registers"));
136 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
138 if (ptrace (PT_SETREGS, regcache->ptid ().pid (),
139 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
140 perror_with_name (_("Couldn't write registers"));
147 || regno >= gdbarch_fp0_regnum (regcache->arch ()))
151 if (ptrace (PT_GETFPREGS, regcache->ptid ().pid (),
152 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
153 perror_with_name (_("Couldn't get floating point status"));
155 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
157 if (ptrace (PT_SETFPREGS, regcache->ptid ().pid (),
158 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
159 perror_with_name (_("Couldn't write floating point status"));
164 /* Support for debugging kernel virtual memory images. */
166 #include <sys/signal.h>
167 #include <machine/pcb.h>
172 alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
176 /* The following is true for OpenBSD 3.9:
178 The pcb contains the register state at the context switch inside
181 /* The stack pointer shouldn't be zero. */
182 if (pcb->pcb_hw.apcb_ksp == 0)
185 regcache->raw_supply (ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
187 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
188 regcache->raw_supply (regnum, &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
189 regcache->raw_supply (ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
196 _initialize_alphabsd_nat (void)
198 add_inf_child_target (&the_alpha_bsd_nat_target);
200 /* Support debugging kernel virtual memory images. */
201 bsd_kvm_add_target (alphabsd_supply_pcb);