* gdbarch.sh (make_corefile_notes): New architecture callback.
[deliverable/binutils-gdb.git] / gdb / alphabsd-nat.c
... / ...
CommitLineData
1/* Native-dependent code for Alpha BSD's.
2
3 Copyright (C) 2000-2002, 2004-2012 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "inferior.h"
22#include "regcache.h"
23
24#include "alpha-tdep.h"
25#include "alphabsd-tdep.h"
26#include "inf-ptrace.h"
27
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
40#ifndef HAVE_FPREGSET_T
41typedef struct fpreg fpregset_t;
42#endif
43
44#include "gregset.h"
45
46/* Provide *regset() wrappers around the generic Alpha BSD register
47 supply/fill routines. */
48
49void
50supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
51{
52 alphabsd_supply_reg (regcache, (const char *) gregsetp, -1);
53}
54
55void
56fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
57{
58 alphabsd_fill_reg (regcache, (char *) gregsetp, regno);
59}
60
61void
62supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
63{
64 alphabsd_supply_fpreg (regcache, (const char *) fpregsetp, -1);
65}
66
67void
68fill_fpregset (const struct regcache *regcache,
69 fpregset_t *fpregsetp, int regno)
70{
71 alphabsd_fill_fpreg (regcache, (char *) fpregsetp, regno);
72}
73\f
74/* Determine if PT_GETREGS fetches this register. */
75
76static int
77getregs_supplies (int regno)
78{
79 return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM)
80 || regno >= ALPHA_PC_REGNUM);
81}
82
83/* Fetch register REGNO from the inferior. If REGNO is -1, do this
84 for all registers (including the floating point registers). */
85
86static void
87alphabsd_fetch_inferior_registers (struct target_ops *ops,
88 struct regcache *regcache, int regno)
89{
90 if (regno == -1 || getregs_supplies (regno))
91 {
92 struct reg gregs;
93
94 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
95 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
96 perror_with_name (_("Couldn't get registers"));
97
98 alphabsd_supply_reg (regcache, (char *) &gregs, regno);
99 if (regno != -1)
100 return;
101 }
102
103 if (regno == -1
104 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
105 {
106 struct fpreg fpregs;
107
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"));
111
112 alphabsd_supply_fpreg (regcache, (char *) &fpregs, regno);
113 }
114}
115
116/* Store register REGNO back into the inferior. If REGNO is -1, do
117 this for all registers (including the floating point registers). */
118
119static void
120alphabsd_store_inferior_registers (struct target_ops *ops,
121 struct regcache *regcache, int regno)
122{
123 if (regno == -1 || getregs_supplies (regno))
124 {
125 struct reg gregs;
126 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
127 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
128 perror_with_name (_("Couldn't get registers"));
129
130 alphabsd_fill_reg (regcache, (char *) &gregs, regno);
131
132 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
133 (PTRACE_TYPE_ARG3) &gregs, 0) == -1)
134 perror_with_name (_("Couldn't write registers"));
135
136 if (regno != -1)
137 return;
138 }
139
140 if (regno == -1
141 || regno >= gdbarch_fp0_regnum (get_regcache_arch (regcache)))
142 {
143 struct fpreg fpregs;
144
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"));
148
149 alphabsd_fill_fpreg (regcache, (char *) &fpregs, regno);
150
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"));
154 }
155}
156\f
157
158/* Support for debugging kernel virtual memory images. */
159
160#include <sys/types.h>
161#include <sys/signal.h>
162#include <machine/pcb.h>
163
164#include "bsd-kvm.h"
165
166static int
167alphabsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
168{
169 int regnum;
170
171 /* The following is true for OpenBSD 3.9:
172
173 The pcb contains the register state at the context switch inside
174 cpu_switch(). */
175
176 /* The stack pointer shouldn't be zero. */
177 if (pcb->pcb_hw.apcb_ksp == 0)
178 return 0;
179
180 regcache_raw_supply (regcache, ALPHA_SP_REGNUM, &pcb->pcb_hw.apcb_ksp);
181
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]);
186
187 return 1;
188}
189\f
190
191/* Provide a prototype to silence -Wmissing-prototypes. */
192void _initialize_alphabsd_nat (void);
193
194void
195_initialize_alphabsd_nat (void)
196{
197 struct target_ops *t;
198
199 t = inf_ptrace_target ();
200 t->to_fetch_registers = alphabsd_fetch_inferior_registers;
201 t->to_store_registers = alphabsd_store_inferior_registers;
202 add_target (t);
203
204 /* Support debugging kernel virtual memory images. */
205 bsd_kvm_add_target (alphabsd_supply_pcb);
206}
This page took 0.02348 seconds and 4 git commands to generate.