]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/alphabsd-nat.c
Updated copyright notices for most files.
[thirdparty/binutils-gdb.git] / gdb / alphabsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
07681759 2
9b254dd1 3 Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
4816ec69 4 Free Software Foundation, Inc.
448628fe
MK
5
6 This file is part of GDB.
7
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
448628fe
MK
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
448628fe
MK
20
21#include "defs.h"
22#include "inferior.h"
4e052eda 23#include "regcache.h"
448628fe 24
dc129d82 25#include "alpha-tdep.h"
12bcb0fe 26#include "alphabsd-tdep.h"
0d6e4ad7 27#include "inf-ptrace.h"
dc129d82 28
448628fe
MK
29#include <sys/types.h>
30#include <sys/ptrace.h>
31#include <machine/reg.h>
32
33#ifdef HAVE_SYS_PROCFS_H
34#include <sys/procfs.h>
35#endif
36
37#ifndef HAVE_GREGSET_T
38typedef struct reg gregset_t;
39#endif
40
12bcb0fe
JT
41#ifndef HAVE_FPREGSET_T
42typedef struct fpreg fpregset_t;
43#endif
448628fe
MK
44
45#include "gregset.h"
46
12bcb0fe
JT
47/* Provide *regset() wrappers around the generic Alpha BSD register
48 supply/fill routines. */
448628fe
MK
49
50void
7f7fe91e 51supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
448628fe 52{
7f7fe91e 53 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
448628fe
MK
54}
55
448628fe 56void
7f7fe91e 57fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
448628fe 58{
7f7fe91e 59 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
448628fe
MK
60}
61
448628fe 62void
7f7fe91e 63supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
448628fe 64{
7f7fe91e 65 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
448628fe
MK
66}
67
448628fe 68void
7f7fe91e 69fill_fpregset (const struct regcache *regcache, fpregset_t *fpregsetp, int regno)
448628fe 70{
7f7fe91e 71 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
448628fe 72}
12bcb0fe 73\f
e771a871
JT
74/* Determine if PT_GETREGS fetches this register. */
75
76static int
77getregs_supplies (int regno)
78{
dc129d82 79 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
07681759 80 || regno >= ALPHA_PC_REGNUM);
e771a871
JT
81}
82
448628fe
MK
83/* Fetch register REGNO from the inferior. If REGNO is -1, do this
84 for all registers (including the floating point registers). */
85
0d6e4ad7 86static void
56be3814 87alphabsd_fetch_inferior_registers (struct regcache *regcache, int regno)
448628fe 88{
e771a871
JT
89 if (regno == -1 || getregs_supplies (regno))
90 {
12bcb0fe 91 struct reg gregs;
e771a871
JT
92
93 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 94 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 95 perror_with_name (_("Couldn't get registers"));
448628fe 96
56be3814 97 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
e771a871
JT
98 if (regno != -1)
99 return;
100 }
448628fe 101
600d293e 102 if (regno == -1 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
448628fe 103 {
12bcb0fe 104 struct fpreg fpregs;
448628fe 105
39f77062 106 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
9f8e0089 107 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 108 perror_with_name (_("Couldn't get floating point status"));
448628fe 109
56be3814 110 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
448628fe 111 }
448628fe
MK
112}
113
114/* Store register REGNO back into the inferior. If REGNO is -1, do
115 this for all registers (including the floating point registers). */
116
0d6e4ad7 117static void
56be3814 118alphabsd_store_inferior_registers (struct regcache *regcache, int regno)
448628fe 119{
e771a871
JT
120 if (regno == -1 || getregs_supplies (regno))
121 {
12bcb0fe 122 struct reg gregs;
e771a871 123 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 124 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 125 perror_with_name (_("Couldn't get registers"));
e771a871 126
56be3814 127 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
448628fe 128
e771a871 129 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
9f8e0089 130 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
edefbb7c 131 perror_with_name (_("Couldn't write registers"));
448628fe 132
e771a871
JT
133 if (regno != -1)
134 return;
135 }
448628fe 136
600d293e 137 if (regno == -1 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
448628fe 138 {
12bcb0fe 139 struct fpreg fpregs;
448628fe 140
39f77062 141 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
9f8e0089 142 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 143 perror_with_name (_("Couldn't get floating point status"));
448628fe 144
56be3814 145 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
448628fe 146
39f77062 147 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
9f8e0089 148 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
edefbb7c 149 perror_with_name (_("Couldn't write floating point status"));
448628fe
MK
150 }
151}
4816ec69
MK
152\f
153
154/* Support for debugging kernel virtual memory images. */
155
156#include <sys/types.h>
157#include <sys/signal.h>
158#include <machine/pcb.h>
159
160#include "bsd-kvm.h"
161
162static int
163alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
164{
165 int regnum;
166
167 /* The following is true for OpenBSD 3.9:
168
169 The pcb contains the register state at the context switch inside
170 cpu_switch(). */
171
172 /* The stack pointer shouldn't be zero. */
173 if (pcb->pcb_hw.apcb_ksp == 0)
174 return 0;
175
176 regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
177
178 for (regnum = ALPHA_S0_REGNUM; regnum < ALPHA_A0_REGNUM; regnum++)
179 regcache_raw_supply (regcache, regnum,
180 &pcb->pcb_context[regnum - ALPHA_S0_REGNUM]);
181 regcache_raw_supply (regcache, ALPHA_RA_REGNUM, &pcb->pcb_context[7]);
182
183 return 1;
184}
185\f
0d6e4ad7
MK
186
187/* Provide a prototype to silence -Wmissing-prototypes. */
188void _initialize_alphabsd_nat (void);
189
190void
191_initialize_alphabsd_nat (void)
192{
193 struct target_ops *t;
194
195 t = inf_ptrace_target ();
196 t->to_fetch_registers = alphabsd_fetch_inferior_registers;
197 t->to_store_registers = alphabsd_store_inferior_registers;
198 add_target (t);
4816ec69
MK
199
200 /* Support debugging kernel virtual memory images. */
201 bsd_kvm_add_target (alphabsd_supply_pcb);
0d6e4ad7 202}