]>
Commit | Line | Data |
---|---|---|
448628fe | 1 | /* Native-dependent code for Alpha BSD's. |
4e052eda | 2 | Copyright 2000, 2001 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 | |
34 | typedef struct reg gregset_t; | |
35 | #endif | |
36 | ||
37 | #ifndef HAVE_FPREGSET_T | |
38 | typedef 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 | ||
55 | void | |
56 | supply_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 | ||
76 | void | |
77 | fill_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)) | |
83 | memcpy (&gregsetp->r_regs[i], ®isters[REGISTER_BYTE (i)], | |
84 | REGISTER_RAW_SIZE (i)); | |
85 | ||
86 | /* The PC travels in the R_ZERO slot. */ | |
87 | if (regno == -1 || regno == PC_REGNUM) | |
88 | memcpy (&gregsetp->r_regs[R_ZERO], ®isters[REGISTER_BYTE (PC_REGNUM)], | |
89 | REGISTER_RAW_SIZE (PC_REGNUM)); | |
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 | ||
108 | supply_register (FPCR_REGNUM, (char *) &fpregsetp->fpr_cr); | |
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)) | |
122 | memcpy (&fpregsetp->fpr_regs[i - FP0_REGNUM], | |
123 | ®isters[REGISTER_BYTE (i)], REGISTER_RAW_SIZE (i)); | |
124 | ||
125 | if (regno == -1 || regno == FPCR_REGNUM) | |
126 | memcpy (&fpregsetp->fpr_cr, ®isters[REGISTER_BYTE (FPCR_REGNUM)], | |
127 | REGISTER_RAW_SIZE (FPCR_REGNUM)); | |
128 | } | |
129 | ||
130 | /* Fetch register REGNO from the inferior. If REGNO is -1, do this | |
131 | for all registers (including the floating point registers). */ | |
132 | ||
133 | void | |
134 | fetch_inferior_registers (int regno) | |
135 | { | |
136 | gregset_t gregs; | |
137 | ||
138 | if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
139 | perror_with_name ("Couldn't get registers"); | |
140 | ||
141 | supply_gregset (&gregs); | |
142 | ||
143 | if (regno == -1 || regno >= FP0_REGNUM) | |
144 | { | |
145 | fpregset_t fpregs; | |
146 | ||
147 | if (ptrace (PT_GETFPREGS, inferior_pid, | |
148 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
149 | perror_with_name ("Couldn't get floating point status"); | |
150 | ||
151 | supply_fpregset (&fpregs); | |
152 | } | |
153 | ||
154 | /* Reset virtual frame pointer. */ | |
155 | supply_register (FP_REGNUM, NULL); | |
156 | } | |
157 | ||
158 | /* Store register REGNO back into the inferior. If REGNO is -1, do | |
159 | this for all registers (including the floating point registers). */ | |
160 | ||
161 | void | |
162 | store_inferior_registers (int regno) | |
163 | { | |
164 | gregset_t gregs; | |
165 | ||
166 | if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
167 | perror_with_name ("Couldn't get registers"); | |
168 | ||
169 | fill_gregset (&gregs, regno); | |
170 | ||
171 | if (ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
172 | perror_with_name ("Couldn't write registers"); | |
173 | ||
174 | if (regno == -1 || regno >= FP0_REGNUM) | |
175 | { | |
176 | fpregset_t fpregs; | |
177 | ||
178 | if (ptrace (PT_GETFPREGS, inferior_pid, | |
179 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
180 | perror_with_name ("Couldn't get floating point status"); | |
181 | ||
182 | fill_fpregset (&fpregs, regno); | |
183 | ||
184 | if (ptrace (PT_SETFPREGS, inferior_pid, | |
185 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
186 | perror_with_name ("Couldn't write floating point status"); | |
187 | } | |
188 | } |