43cdb7509087ead9631a69642a6e218e8c4b9d2f
[deliverable/binutils-gdb.git] / gdb / alphabsd-nat.c
1 /* Native-dependent code for Alpha BSD's.
2 Copyright (C) 2000 Free Software Foundation, Inc.
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"
23
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27
28 #ifdef HAVE_SYS_PROCFS_H
29 #include <sys/procfs.h>
30 #endif
31
32 #ifndef HAVE_GREGSET_T
33 typedef struct reg gregset_t;
34 #endif
35
36 #ifndef HAVE_FPREGSET_T
37 typedef struct fpreg fpregset_t;
38 #endif
39
40 #include "gregset.h"
41
42 /* Number of general-purpose registers. */
43 #define NUM_GREGS 32
44
45 /* Number of floating point registers. */
46 #define NUM_FPREGS 31
47 \f
48
49 /* Transfering the registers between GDB, inferiors and core files. */
50
51 /* Fill GDB's register array with the general-purpose register values
52 in *GREGSETP. */
53
54 void
55 supply_gregset (gregset_t *gregsetp)
56 {
57 int i;
58
59 for (i = 0; i < NUM_GREGS; i++)
60 {
61 if (CANNOT_FETCH_REGISTER (i))
62 supply_register (i, NULL);
63 else
64 supply_register (i, (char *) &gregsetp->r_regs[i]);
65 }
66
67 /* The PC travels in the R_ZERO slot. */
68 supply_register (PC_REGNUM, (char *) &gregsetp->r_regs[R_ZERO]);
69 }
70
71 /* Fill register REGNO (if it is a general-purpose register) in
72 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
73 do this for all registers. */
74
75 void
76 fill_gregset (gregset_t *gregsetp, int regno)
77 {
78 int i;
79
80 for (i = 0; i < NUM_GREGS; i++)
81 if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i))
82 memcpy (&gregsetp->r_regs[i], &registers[REGISTER_BYTE (i)],
83 REGISTER_RAW_SIZE (i));
84
85 /* The PC travels in the R_ZERO slot. */
86 if (regno == -1 || regno == PC_REGNUM)
87 memcpy (&gregsetp->r_regs[R_ZERO], &registers[REGISTER_BYTE (PC_REGNUM)],
88 REGISTER_RAW_SIZE (PC_REGNUM));
89 }
90
91 /* Fill GDB's register array with the floating-point register values
92 in *FPREGSETP. */
93
94 void
95 supply_fpregset (fpregset_t *fpregsetp)
96 {
97 int i;
98
99 for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++)
100 {
101 if (CANNOT_FETCH_REGISTER (i))
102 supply_register (i, NULL);
103 else
104 supply_register (i, (char *) &fpregsetp->fpr_regs[i - FP0_REGNUM]);
105 }
106
107 supply_register (FPCR_REGNUM, (char *) &fpregsetp->fpr_cr);
108 }
109
110 /* Fill register REGNO (if it is a floating-point register) in
111 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
112 do this for all registers. */
113
114 void
115 fill_fpregset (fpregset_t *fpregsetp, int regno)
116 {
117 int i;
118
119 for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++)
120 if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i))
121 memcpy (&fpregsetp->fpr_regs[i - FP0_REGNUM],
122 &registers[REGISTER_BYTE (i)], REGISTER_RAW_SIZE (i));
123
124 if (regno == -1 || regno == FPCR_REGNUM)
125 memcpy (&fpregsetp->fpr_cr, &registers[REGISTER_BYTE (FPCR_REGNUM)],
126 REGISTER_RAW_SIZE (FPCR_REGNUM));
127 }
128
129 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
130 for all registers (including the floating point registers). */
131
132 void
133 fetch_inferior_registers (int regno)
134 {
135 gregset_t gregs;
136
137 if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
138 perror_with_name ("Couldn't get registers");
139
140 supply_gregset (&gregs);
141
142 if (regno == -1 || regno >= FP0_REGNUM)
143 {
144 fpregset_t fpregs;
145
146 if (ptrace (PT_GETFPREGS, inferior_pid,
147 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
148 perror_with_name ("Couldn't get floating point status");
149
150 supply_fpregset (&fpregs);
151 }
152
153 /* Reset virtual frame pointer. */
154 supply_register (FP_REGNUM, NULL);
155 }
156
157 /* Store register REGNO back into the inferior. If REGNO is -1, do
158 this for all registers (including the floating point registers). */
159
160 void
161 store_inferior_registers (int regno)
162 {
163 gregset_t gregs;
164
165 if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
166 perror_with_name ("Couldn't get registers");
167
168 fill_gregset (&gregs, regno);
169
170 if (ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
171 perror_with_name ("Couldn't write registers");
172
173 if (regno == -1 || regno >= FP0_REGNUM)
174 {
175 fpregset_t fpregs;
176
177 if (ptrace (PT_GETFPREGS, inferior_pid,
178 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
179 perror_with_name ("Couldn't get floating point status");
180
181 fill_fpregset (&fpregs, regno);
182
183 if (ptrace (PT_SETFPREGS, inferior_pid,
184 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
185 perror_with_name ("Couldn't write floating point status");
186 }
187 }
This page took 0.043494 seconds and 3 git commands to generate.