1 /* Native-dependent code for Alpha BSD's.
3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
27 #include "alpha-tdep.h"
28 #include "alphabsd-tdep.h"
29 #include "inf-ptrace.h"
31 #include <sys/types.h>
32 #include <sys/ptrace.h>
33 #include <machine/reg.h>
35 #ifdef HAVE_SYS_PROCFS_H
36 #include <sys/procfs.h>
39 #ifndef HAVE_GREGSET_T
40 typedef struct reg gregset_t;
43 #ifndef HAVE_FPREGSET_T
44 typedef struct fpreg fpregset_t;
49 /* Provide *regset() wrappers around the generic Alpha BSD register
50 supply/fill routines. */
53 supply_gregset (gregset_t *gregsetp)
55 alphabsd_supply_reg (current_regcache, (char *) gregsetp, -1);
59 fill_gregset (gregset_t *gregsetp, int regno)
61 alphabsd_fill_reg (current_regcache, (char *) gregsetp, regno);
65 supply_fpregset (fpregset_t *fpregsetp)
67 alphabsd_supply_fpreg (current_regcache, (char *) fpregsetp, -1);
71 fill_fpregset (fpregset_t *fpregsetp, int regno)
73 alphabsd_fill_fpreg (current_regcache, (char *) fpregsetp, regno);
76 /* Determine if PT_GETREGS fetches this register. */
79 getregs_supplies (int regno)
81 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
82 || regno >= ALPHA_PC_REGNUM);
85 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
86 for all registers (including the floating point registers). */
89 alphabsd_fetch_inferior_registers (int regno)
91 if (regno == -1 || getregs_supplies (regno))
95 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
96 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
97 perror_with_name (_("Couldn't get registers"));
99 alphabsd_supply_reg (current_regcache, (char *) &gregs, regno);
104 if (regno == -1 || regno >= FP0_REGNUM)
108 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
109 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
110 perror_with_name (_("Couldn't get floating point status"));
112 alphabsd_supply_fpreg (current_regcache, (char *) &fpregs, regno);
116 /* Store register REGNO back into the inferior. If REGNO is -1, do
117 this for all registers (including the floating point registers). */
120 alphabsd_store_inferior_registers (int regno)
122 if (regno == -1 || getregs_supplies (regno))
125 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
126 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
127 perror_with_name (_("Couldn't get registers"));
129 alphabsd_fill_reg (current_regcache, (char *) &gregs, regno);
131 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
132 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
133 perror_with_name (_("Couldn't write registers"));
139 if (regno == -1 || regno >= FP0_REGNUM)
143 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
144 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
145 perror_with_name (_("Couldn't get floating point status"));
147 alphabsd_fill_fpreg (current_regcache, (char *) &fpregs, regno);
149 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
150 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
151 perror_with_name (_("Couldn't write floating point status"));
156 /* Support for debugging kernel virtual memory images. */
158 #include <sys/types.h>
159 #include <sys/signal.h>
160 #include <machine/pcb.h>
165 alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
169 /* The following is true for OpenBSD 3.9:
171 The pcb contains the register state at the context switch inside
174 /* The stack pointer shouldn't be zero. */
175 if (pcb->pcb_hw.apcb_ksp == 0)
178 regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
180 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
181 regcache_raw_supply (regcache, regnum,
182 &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
183 regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
189 /* Provide a prototype to silence -Wmissing-prototypes. */
190 void _initialize_alphabsd_nat (void);
193 _initialize_alphabsd_nat (void)
195 struct target_ops *t;
197 t = inf_ptrace_target ();
198 t->to_fetch_registers = alphabsd_fetch_inferior_registers;
199 t->to_store_registers = alphabsd_store_inferior_registers;
202 /* Support debugging kernel virtual memory images. */
203 bsd_kvm_add_target (alphabsd_supply_pcb);