2002-04-09 Daniel Jacobowitz <drow@mvista.com>
[deliverable/binutils-gdb.git] / gdb / alphabsd-nat.c
CommitLineData
448628fe 1/* Native-dependent code for Alpha BSD's.
e771a871 2 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
448628fe
MK
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "inferior.h"
4e052eda 23#include "regcache.h"
448628fe
MK
24
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <machine/reg.h>
28
29#ifdef HAVE_SYS_PROCFS_H
30#include <sys/procfs.h>
31#endif
32
33#ifndef HAVE_GREGSET_T
34typedef struct reg gregset_t;
35#endif
36
37#ifndef HAVE_FPREGSET_T
38typedef struct fpreg fpregset_t;
39#endif
40
41#include "gregset.h"
42
43/* Number of general-purpose registers. */
44#define NUM_GREGS 32
45
46/* Number of floating point registers. */
47#define NUM_FPREGS 31
48\f
49
50/* Transfering the registers between GDB, inferiors and core files. */
51
ad2a4d09 52/* Fill GDB's register array with the general-purpose register values
448628fe
MK
53 in *GREGSETP. */
54
55void
56supply_gregset (gregset_t *gregsetp)
57{
58 int i;
59
60 for (i = 0; i < NUM_GREGS; i++)
61 {
62 if (CANNOT_FETCH_REGISTER (i))
63 supply_register (i, NULL);
64 else
65 supply_register (i, (char *) &gregsetp->r_regs[i]);
66 }
67
68 /* The PC travels in the R_ZERO slot. */
69 supply_register (PC_REGNUM, (char *) &gregsetp->r_regs[R_ZERO]);
70}
71
72/* Fill register REGNO (if it is a general-purpose register) in
73 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
74 do this for all registers. */
75
76void
77fill_gregset (gregset_t *gregsetp, int regno)
78{
79 int i;
80
81 for (i = 0; i < NUM_GREGS; i++)
82 if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i))
e771a871 83 regcache_collect (i, (char *) &gregsetp->r_regs[i]);
448628fe
MK
84
85 /* The PC travels in the R_ZERO slot. */
86 if (regno == -1 || regno == PC_REGNUM)
e771a871 87 regcache_collect (PC_REGNUM, (char *) &gregsetp->r_regs[R_ZERO]);
448628fe
MK
88}
89
90/* Fill GDB's register array with the floating-point register values
91 in *FPREGSETP. */
92
93void
94supply_fpregset (fpregset_t *fpregsetp)
95{
96 int i;
97
98 for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++)
99 {
100 if (CANNOT_FETCH_REGISTER (i))
101 supply_register (i, NULL);
102 else
66c9e0f2 103 supply_register (i, (char *) &fpregsetp->fpr_regs[i - FP0_REGNUM]);
448628fe
MK
104 }
105
106 supply_register (FPCR_REGNUM, (char *) &fpregsetp->fpr_cr);
107}
108
109/* Fill register REGNO (if it is a floating-point register) in
110 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
111 do this for all registers. */
112
113void
114fill_fpregset (fpregset_t *fpregsetp, int regno)
115{
116 int i;
117
118 for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++)
119 if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i))
e771a871 120 regcache_collect (i, (char *) &fpregsetp->fpr_regs[i - FP0_REGNUM]);
448628fe
MK
121
122 if (regno == -1 || regno == FPCR_REGNUM)
e771a871 123 regcache_collect (FPCR_REGNUM, (char *) &fpregsetp->fpr_cr);
448628fe
MK
124}
125
e771a871
JT
126
127/* Determine if PT_GETREGS fetches this register. */
128
129static int
130getregs_supplies (int regno)
131{
132
133 return ((regno >= V0_REGNUM && regno <= ZERO_REGNUM)
134 || regno >= PC_REGNUM);
135}
136
137
448628fe
MK
138/* Fetch register REGNO from the inferior. If REGNO is -1, do this
139 for all registers (including the floating point registers). */
140
141void
142fetch_inferior_registers (int regno)
143{
448628fe 144
e771a871
JT
145 if (regno == -1 || getregs_supplies (regno))
146 {
147 gregset_t gregs;
148
149 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
150 (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
151 perror_with_name ("Couldn't get registers");
448628fe 152
e771a871
JT
153 supply_gregset (&gregs);
154 if (regno != -1)
155 return;
156 }
448628fe
MK
157
158 if (regno == -1 || regno >= FP0_REGNUM)
159 {
160 fpregset_t fpregs;
161
39f77062 162 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
448628fe
MK
163 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
164 perror_with_name ("Couldn't get floating point status");
165
166 supply_fpregset (&fpregs);
167 }
168
169 /* Reset virtual frame pointer. */
170 supply_register (FP_REGNUM, NULL);
171}
172
173/* Store register REGNO back into the inferior. If REGNO is -1, do
174 this for all registers (including the floating point registers). */
175
176void
177store_inferior_registers (int regno)
178{
448628fe 179
e771a871
JT
180 if (regno == -1 || getregs_supplies (regno))
181 {
182 gregset_t gregs;
183 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
184 (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
185 perror_with_name ("Couldn't get registers");
186
187 fill_gregset (&gregs, regno);
448628fe 188
e771a871
JT
189 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
190 (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
191 perror_with_name ("Couldn't write registers");
448628fe 192
e771a871
JT
193 if (regno != -1)
194 return;
195 }
448628fe
MK
196
197 if (regno == -1 || regno >= FP0_REGNUM)
198 {
199 fpregset_t fpregs;
200
39f77062 201 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
448628fe
MK
202 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
203 perror_with_name ("Couldn't get floating point status");
204
205 fill_fpregset (&fpregs, regno);
206
39f77062 207 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
448628fe
MK
208 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
209 perror_with_name ("Couldn't write floating point status");
210 }
211}
This page took 0.128123 seconds and 4 git commands to generate.