1 /* Native-dependent code for Alpha BSD's.
3 Copyright (C) 2000-2013 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 "alphabsd-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 /* Provide *regset() wrappers around the generic Alpha BSD register
47 supply/fill routines. */
50 supply_gregset (struct regcache
*regcache
, const gregset_t
*gregsetp
)
52 alphabsd_supply_reg (regcache
, (const char *) gregsetp
, -1);
56 fill_gregset (const struct regcache
*regcache
, gregset_t
*gregsetp
, int regno
)
58 alphabsd_fill_reg (regcache
, (char *) gregsetp
, regno
);
62 supply_fpregset (struct regcache
*regcache
, const fpregset_t
*fpregsetp
)
64 alphabsd_supply_fpreg (regcache
, (const char *) fpregsetp
, -1);
68 fill_fpregset (const struct regcache
*regcache
,
69 fpregset_t
*fpregsetp
, int regno
)
71 alphabsd_fill_fpreg (regcache
, (char *) fpregsetp
, regno
);
74 /* Determine if PT_GETREGS fetches this register. */
77 getregs_supplies (int regno
)
79 return ((regno
>= ALPHA_V0_REGNUM
&& regno
<= ALPHA_ZERO_REGNUM
)
80 || regno
>= ALPHA_PC_REGNUM
);
83 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
84 for all registers (including the floating point registers). */
87 alphabsd_fetch_inferior_registers (struct target_ops
*ops
,
88 struct regcache
*regcache
, int regno
)
90 if (regno
== -1 || getregs_supplies (regno
))
94 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
95 (PTRACE_TYPE_ARG3
) &gregs
, 0) == -1)
96 perror_with_name (_("Couldn't get registers"));
98 alphabsd_supply_reg (regcache
, (char *) &gregs
, regno
);
104 || regno
>= gdbarch_fp0_regnum (get_regcache_arch (regcache
)))
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 (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 (struct target_ops
*ops
,
121 struct regcache
*regcache
, int regno
)
123 if (regno
== -1 || getregs_supplies (regno
))
126 if (ptrace (PT_GETREGS
, PIDGET (inferior_ptid
),
127 (PTRACE_TYPE_ARG3
) &gregs
, 0) == -1)
128 perror_with_name (_("Couldn't get registers"));
130 alphabsd_fill_reg (regcache
, (char *) &gregs
, regno
);
132 if (ptrace (PT_SETREGS
, PIDGET (inferior_ptid
),
133 (PTRACE_TYPE_ARG3
) &gregs
, 0) == -1)
134 perror_with_name (_("Couldn't write registers"));
141 || regno
>= gdbarch_fp0_regnum (get_regcache_arch (regcache
)))
145 if (ptrace (PT_GETFPREGS
, PIDGET (inferior_ptid
),
146 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
147 perror_with_name (_("Couldn't get floating point status"));
149 alphabsd_fill_fpreg (regcache
, (char *) &fpregs
, regno
);
151 if (ptrace (PT_SETFPREGS
, PIDGET (inferior_ptid
),
152 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
153 perror_with_name (_("Couldn't write floating point status"));
158 /* Support for debugging kernel virtual memory images. */
160 #include <sys/types.h>
161 #include <sys/signal.h>
162 #include <machine/pcb.h>
167 alphabsd_supply_pcb (struct regcache
*regcache
, struct pcb
*pcb
)
171 /* The following is true for OpenBSD 3.9:
173 The pcb contains the register state at the context switch inside
176 /* The stack pointer shouldn't be zero. */
177 if (pcb
->pcb_hw
.apcb_ksp
== 0)
180 regcache_raw_supply (regcache
, ALPHA_SP_REGNUM
, &pcb
->pcb_hw
.apcb_ksp
);
182 for (regnum
= ALPHA_S0_REGNUM
; regnum
< ALPHA_A0_REGNUM
; regnum
++)
183 regcache_raw_supply (regcache
, regnum
,
184 &pcb
->pcb_context
[regnum
- ALPHA_S0_REGNUM
]);
185 regcache_raw_supply (regcache
, ALPHA_RA_REGNUM
, &pcb
->pcb_context
[7]);
191 /* Provide a prototype to silence -Wmissing-prototypes. */
192 void _initialize_alphabsd_nat (void);
195 _initialize_alphabsd_nat (void)
197 struct target_ops
*t
;
199 t
= inf_ptrace_target ();
200 t
->to_fetch_registers
= alphabsd_fetch_inferior_registers
;
201 t
->to_store_registers
= alphabsd_store_inferior_registers
;
204 /* Support debugging kernel virtual memory images. */
205 bsd_kvm_add_target (alphabsd_supply_pcb
);