Commit | Line | Data |
---|---|---|
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 | 24 | |
dc129d82 JT |
25 | #include "alpha-tdep.h" |
26 | ||
448628fe MK |
27 | #include <sys/types.h> |
28 | #include <sys/ptrace.h> | |
29 | #include <machine/reg.h> | |
30 | ||
31 | #ifdef HAVE_SYS_PROCFS_H | |
32 | #include <sys/procfs.h> | |
33 | #endif | |
34 | ||
35 | #ifndef HAVE_GREGSET_T | |
36 | typedef struct reg gregset_t; | |
37 | #endif | |
38 | ||
39 | #ifndef HAVE_FPREGSET_T | |
40 | typedef struct fpreg fpregset_t; | |
41 | #endif | |
42 | ||
43 | #include "gregset.h" | |
44 | ||
45 | /* Number of general-purpose registers. */ | |
46 | #define NUM_GREGS 32 | |
47 | ||
48 | /* Number of floating point registers. */ | |
49 | #define NUM_FPREGS 31 | |
50 | \f | |
51 | ||
52 | /* Transfering the registers between GDB, inferiors and core files. */ | |
53 | ||
ad2a4d09 | 54 | /* Fill GDB's register array with the general-purpose register values |
448628fe MK |
55 | in *GREGSETP. */ |
56 | ||
57 | void | |
58 | supply_gregset (gregset_t *gregsetp) | |
59 | { | |
60 | int i; | |
61 | ||
62 | for (i = 0; i < NUM_GREGS; i++) | |
63 | { | |
64 | if (CANNOT_FETCH_REGISTER (i)) | |
65 | supply_register (i, NULL); | |
66 | else | |
67 | supply_register (i, (char *) &gregsetp->r_regs[i]); | |
68 | } | |
69 | ||
70 | /* The PC travels in the R_ZERO slot. */ | |
71 | supply_register (PC_REGNUM, (char *) &gregsetp->r_regs[R_ZERO]); | |
72 | } | |
73 | ||
74 | /* Fill register REGNO (if it is a general-purpose register) in | |
75 | *GREGSETPS with the value in GDB's register array. If REGNO is -1, | |
76 | do this for all registers. */ | |
77 | ||
78 | void | |
79 | fill_gregset (gregset_t *gregsetp, int regno) | |
80 | { | |
81 | int i; | |
82 | ||
83 | for (i = 0; i < NUM_GREGS; i++) | |
84 | if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i)) | |
e771a871 | 85 | regcache_collect (i, (char *) &gregsetp->r_regs[i]); |
448628fe MK |
86 | |
87 | /* The PC travels in the R_ZERO slot. */ | |
88 | if (regno == -1 || regno == PC_REGNUM) | |
e771a871 | 89 | regcache_collect (PC_REGNUM, (char *) &gregsetp->r_regs[R_ZERO]); |
448628fe MK |
90 | } |
91 | ||
92 | /* Fill GDB's register array with the floating-point register values | |
93 | in *FPREGSETP. */ | |
94 | ||
95 | void | |
96 | supply_fpregset (fpregset_t *fpregsetp) | |
97 | { | |
98 | int i; | |
99 | ||
100 | for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++) | |
101 | { | |
102 | if (CANNOT_FETCH_REGISTER (i)) | |
103 | supply_register (i, NULL); | |
104 | else | |
66c9e0f2 | 105 | supply_register (i, (char *) &fpregsetp->fpr_regs[i - FP0_REGNUM]); |
448628fe MK |
106 | } |
107 | ||
dc129d82 | 108 | supply_register (ALPHA_FPCR_REGNUM, (char *) &fpregsetp->fpr_cr); |
448628fe MK |
109 | } |
110 | ||
111 | /* Fill register REGNO (if it is a floating-point register) in | |
112 | *FPREGSETP with the value in GDB's register array. If REGNO is -1, | |
113 | do this for all registers. */ | |
114 | ||
115 | void | |
116 | fill_fpregset (fpregset_t *fpregsetp, int regno) | |
117 | { | |
118 | int i; | |
119 | ||
120 | for (i = FP0_REGNUM; i < FP0_REGNUM + NUM_FPREGS; i++) | |
121 | if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i)) | |
e771a871 | 122 | regcache_collect (i, (char *) &fpregsetp->fpr_regs[i - FP0_REGNUM]); |
448628fe | 123 | |
dc129d82 JT |
124 | if (regno == -1 || regno == ALPHA_FPCR_REGNUM) |
125 | regcache_collect (ALPHA_FPCR_REGNUM, (char *) &fpregsetp->fpr_cr); | |
448628fe MK |
126 | } |
127 | ||
e771a871 JT |
128 | |
129 | /* Determine if PT_GETREGS fetches this register. */ | |
130 | ||
131 | static int | |
132 | getregs_supplies (int regno) | |
133 | { | |
134 | ||
dc129d82 | 135 | return ((regno >= ALPHA_V0_REGNUM && regno <= ALPHA_ZERO_REGNUM) |
e771a871 JT |
136 | || regno >= PC_REGNUM); |
137 | } | |
138 | ||
139 | ||
448628fe MK |
140 | /* Fetch register REGNO from the inferior. If REGNO is -1, do this |
141 | for all registers (including the floating point registers). */ | |
142 | ||
143 | void | |
144 | fetch_inferior_registers (int regno) | |
145 | { | |
448628fe | 146 | |
e771a871 JT |
147 | if (regno == -1 || getregs_supplies (regno)) |
148 | { | |
149 | gregset_t gregs; | |
150 | ||
151 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
152 | (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
153 | perror_with_name ("Couldn't get registers"); | |
448628fe | 154 | |
e771a871 JT |
155 | supply_gregset (&gregs); |
156 | if (regno != -1) | |
157 | return; | |
158 | } | |
448628fe MK |
159 | |
160 | if (regno == -1 || regno >= FP0_REGNUM) | |
161 | { | |
162 | fpregset_t fpregs; | |
163 | ||
39f77062 | 164 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), |
448628fe MK |
165 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) |
166 | perror_with_name ("Couldn't get floating point status"); | |
167 | ||
168 | supply_fpregset (&fpregs); | |
169 | } | |
170 | ||
171 | /* Reset virtual frame pointer. */ | |
172 | supply_register (FP_REGNUM, NULL); | |
173 | } | |
174 | ||
175 | /* Store register REGNO back into the inferior. If REGNO is -1, do | |
176 | this for all registers (including the floating point registers). */ | |
177 | ||
178 | void | |
179 | store_inferior_registers (int regno) | |
180 | { | |
448628fe | 181 | |
e771a871 JT |
182 | if (regno == -1 || getregs_supplies (regno)) |
183 | { | |
184 | gregset_t gregs; | |
185 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
186 | (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
187 | perror_with_name ("Couldn't get registers"); | |
188 | ||
189 | fill_gregset (&gregs, regno); | |
448628fe | 190 | |
e771a871 JT |
191 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), |
192 | (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
193 | perror_with_name ("Couldn't write registers"); | |
448628fe | 194 | |
e771a871 JT |
195 | if (regno != -1) |
196 | return; | |
197 | } | |
448628fe MK |
198 | |
199 | if (regno == -1 || regno >= FP0_REGNUM) | |
200 | { | |
201 | fpregset_t fpregs; | |
202 | ||
39f77062 | 203 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), |
448628fe MK |
204 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) |
205 | perror_with_name ("Couldn't get floating point status"); | |
206 | ||
207 | fill_fpregset (&fpregs, regno); | |
208 | ||
39f77062 | 209 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), |
448628fe MK |
210 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) |
211 | perror_with_name ("Couldn't write floating point status"); | |
212 | } | |
213 | } |