]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Native-dependent Motorola 88xxx support for GDB, the GNU Debugger. |
2 | Copyright 1988, 1990, 1991, 1992 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | ||
25 | #include <sys/types.h> | |
26 | #include <sys/param.h> | |
27 | #include <sys/dir.h> | |
28 | #include <signal.h> | |
29 | #include "gdbcore.h" | |
30 | #include <sys/user.h> | |
31 | ||
32 | #ifndef USER /* added to support BCS ptrace_user */ | |
33 | #define USER ptrace_user | |
34 | #endif | |
35 | #include <sys/ioctl.h> | |
36 | #include <fcntl.h> | |
37 | #include <sys/file.h> | |
38 | #include "gdb_stat.h" | |
39 | ||
40 | #include "symtab.h" | |
41 | #include "setjmp.h" | |
42 | #include "value.h" | |
43 | ||
44 | #ifdef DELTA88 | |
45 | #include <sys/ptrace.h> | |
46 | ||
47 | /* define offsets to the pc instruction offsets in ptrace_user struct */ | |
48 | #define SXIP_OFFSET ((char *)&u.pt_sigframe.sig_sxip - (char *)&u) | |
49 | #define SNIP_OFFSET ((char *)&u.pt_sigframe.sig_snip - (char *)&u) | |
50 | #define SFIP_OFFSET ((char *)&u.pt_sigframe.sig_sfip - (char *)&u) | |
51 | #else | |
52 | /* define offsets to the pc instruction offsets in ptrace_user struct */ | |
53 | #define SXIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_sxip - (char *)&u) | |
54 | #define SNIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_snip - (char *)&u) | |
55 | #define SFIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u) | |
56 | #endif | |
57 | ||
c5aa993b | 58 | extern int have_symbol_file_p (); |
c906108c SS |
59 | |
60 | extern jmp_buf stack_jmp; | |
61 | ||
62 | extern int errno; | |
c906108c SS |
63 | |
64 | void | |
afd64b4e | 65 | fetch_inferior_registers (int regno) |
c906108c SS |
66 | { |
67 | register unsigned int regaddr; | |
68 | char buf[MAX_REGISTER_RAW_SIZE]; | |
69 | register int i; | |
70 | ||
71 | struct USER u; | |
72 | unsigned int offset; | |
73 | ||
c5aa993b JM |
74 | offset = (char *) &u.pt_r0 - (char *) &u; |
75 | regaddr = offset; /* byte offset to r0; */ | |
c906108c SS |
76 | |
77 | /* offset = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) offset, 0) - KERNEL_U_ADDR; */ | |
78 | for (regno = 0; regno < NUM_REGS; regno++) | |
79 | { | |
c5aa993b JM |
80 | /*regaddr = register_addr (regno, offset); */ |
81 | /* 88k enhancement */ | |
82 | ||
c906108c | 83 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) |
c5aa993b JM |
84 | { |
85 | *(int *) &buf[i] = ptrace (3, inferior_pid, | |
c906108c | 86 | (PTRACE_ARG3_TYPE) regaddr, 0); |
c5aa993b JM |
87 | regaddr += sizeof (int); |
88 | } | |
c906108c SS |
89 | supply_register (regno, buf); |
90 | } | |
c5aa993b JM |
91 | /* now load up registers 36 - 38; special pc registers */ |
92 | *(int *) &buf[0] = ptrace (3, inferior_pid, | |
93 | (PTRACE_ARG3_TYPE) SXIP_OFFSET, 0); | |
94 | supply_register (SXIP_REGNUM, buf); | |
95 | *(int *) &buf[0] = ptrace (3, inferior_pid, | |
96 | (PTRACE_ARG3_TYPE) SNIP_OFFSET, 0); | |
97 | supply_register (SNIP_REGNUM, buf); | |
98 | *(int *) &buf[0] = ptrace (3, inferior_pid, | |
99 | (PTRACE_ARG3_TYPE) SFIP_OFFSET, 0); | |
100 | supply_register (SFIP_REGNUM, buf); | |
c906108c SS |
101 | } |
102 | ||
103 | /* Store our register values back into the inferior. | |
104 | If REGNO is -1, do this for all registers. | |
105 | Otherwise, REGNO specifies which register (so we can save time). */ | |
106 | ||
107 | void | |
fba45db2 | 108 | store_inferior_registers (int regno) |
c906108c SS |
109 | { |
110 | register unsigned int regaddr; | |
111 | char buf[80]; | |
112 | ||
113 | struct USER u; | |
114 | ||
115 | unsigned int offset = (char *) &u.pt_r0 - (char *) &u; | |
116 | ||
117 | regaddr = offset; | |
118 | ||
119 | /* Don't try to deal with EXIP_REGNUM or ENIP_REGNUM, because I think either | |
120 | svr3 doesn't run on an 88110, or the kernel isolates the different (not | |
121 | completely sure this is true, but seems to be. */ | |
122 | if (regno >= 0) | |
123 | { | |
124 | /* regaddr = register_addr (regno, offset); */ | |
125 | if (regno < PC_REGNUM) | |
c5aa993b | 126 | { |
c906108c SS |
127 | regaddr = offset + regno * sizeof (int); |
128 | errno = 0; | |
129 | ptrace (6, inferior_pid, | |
130 | (PTRACE_ARG3_TYPE) regaddr, read_register (regno)); | |
131 | if (errno != 0) | |
132 | { | |
133 | sprintf (buf, "writing register number %d", regno); | |
134 | perror_with_name (buf); | |
135 | } | |
136 | } | |
137 | else if (regno == SXIP_REGNUM) | |
138 | ptrace (6, inferior_pid, | |
c5aa993b | 139 | (PTRACE_ARG3_TYPE) SXIP_OFFSET, read_register (regno)); |
c906108c SS |
140 | else if (regno == SNIP_REGNUM) |
141 | ptrace (6, inferior_pid, | |
c5aa993b | 142 | (PTRACE_ARG3_TYPE) SNIP_OFFSET, read_register (regno)); |
c906108c SS |
143 | else if (regno == SFIP_REGNUM) |
144 | ptrace (6, inferior_pid, | |
c5aa993b | 145 | (PTRACE_ARG3_TYPE) SFIP_OFFSET, read_register (regno)); |
c906108c SS |
146 | else |
147 | printf_unfiltered ("Bad register number for store_inferior routine\n"); | |
148 | } | |
149 | else | |
c5aa993b | 150 | { |
c906108c SS |
151 | for (regno = 0; regno < PC_REGNUM; regno++) |
152 | { | |
153 | /* regaddr = register_addr (regno, offset); */ | |
154 | errno = 0; | |
155 | regaddr = offset + regno * sizeof (int); | |
156 | ptrace (6, inferior_pid, | |
157 | (PTRACE_ARG3_TYPE) regaddr, read_register (regno)); | |
158 | if (errno != 0) | |
159 | { | |
160 | sprintf (buf, "writing register number %d", regno); | |
161 | perror_with_name (buf); | |
162 | } | |
163 | } | |
c5aa993b JM |
164 | ptrace (6, inferior_pid, |
165 | (PTRACE_ARG3_TYPE) SXIP_OFFSET, read_register (SXIP_REGNUM)); | |
166 | ptrace (6, inferior_pid, | |
167 | (PTRACE_ARG3_TYPE) SNIP_OFFSET, read_register (SNIP_REGNUM)); | |
168 | ptrace (6, inferior_pid, | |
169 | (PTRACE_ARG3_TYPE) SFIP_OFFSET, read_register (SFIP_REGNUM)); | |
c906108c SS |
170 | } |
171 | } | |
172 | ||
173 | ||
174 | /* blockend is the address of the end of the user structure */ | |
fba45db2 | 175 | m88k_register_u_addr (int blockend, int regnum) |
c906108c SS |
176 | { |
177 | struct USER u; | |
178 | int ustart = blockend - sizeof (struct USER); | |
179 | switch (regnum) | |
180 | { | |
181 | case 0: | |
182 | case 1: | |
183 | case 2: | |
184 | case 3: | |
185 | case 4: | |
186 | case 5: | |
187 | case 6: | |
188 | case 7: | |
189 | case 8: | |
190 | case 9: | |
191 | case 10: | |
192 | case 11: | |
193 | case 12: | |
194 | case 13: | |
195 | case 14: | |
196 | case 15: | |
197 | case 16: | |
198 | case 17: | |
199 | case 18: | |
200 | case 19: | |
201 | case 20: | |
202 | case 21: | |
203 | case 22: | |
204 | case 23: | |
205 | case 24: | |
206 | case 25: | |
207 | case 26: | |
208 | case 27: | |
209 | case 28: | |
210 | case 29: | |
211 | case 30: | |
212 | case 31: | |
213 | return (ustart + ((int) &u.pt_r0 - (int) &u) + REGISTER_SIZE * regnum); | |
c5aa993b JM |
214 | case PSR_REGNUM: |
215 | return (ustart + ((int) &u.pt_psr - (int) &u)); | |
216 | case FPSR_REGNUM: | |
217 | return (ustart + ((int) &u.pt_fpsr - (int) &u)); | |
218 | case FPCR_REGNUM: | |
219 | return (ustart + ((int) &u.pt_fpcr - (int) &u)); | |
220 | case SXIP_REGNUM: | |
221 | return (ustart + SXIP_OFFSET); | |
222 | case SNIP_REGNUM: | |
223 | return (ustart + SNIP_OFFSET); | |
224 | case SFIP_REGNUM: | |
225 | return (ustart + SFIP_OFFSET); | |
226 | default: | |
227 | if (regnum < NUM_REGS) | |
228 | /* The register is one of those which is not defined... | |
229 | give it zero */ | |
230 | return (ustart + ((int) &u.pt_r0 - (int) &u)); | |
231 | else | |
232 | return (blockend + REGISTER_SIZE * regnum); | |
c906108c SS |
233 | } |
234 | } | |
235 | ||
236 | #ifdef USE_PROC_FS | |
237 | ||
238 | #include <sys/procfs.h> | |
239 | ||
c60c0f5f MS |
240 | /* Prototypes for supply_gregset etc. */ |
241 | #include "gregset.h" | |
242 | ||
c906108c | 243 | /* Given a pointer to a general register set in /proc format (gregset_t *), |
c5aa993b JM |
244 | unpack the register contents and supply them as gdb's idea of the current |
245 | register values. */ | |
c906108c SS |
246 | |
247 | void | |
fba45db2 | 248 | supply_gregset (gregset_t *gregsetp) |
c906108c | 249 | { |
c5aa993b JM |
250 | register int regi; |
251 | register greg_t *regp = (greg_t *) gregsetp; | |
252 | ||
253 | for (regi = 0; regi <= SP_REGNUM; regi++) | |
254 | supply_register (regi, (char *) (regp + regi)); | |
255 | ||
256 | supply_register (SXIP_REGNUM, (char *) (regp + R_XIP)); | |
257 | supply_register (SNIP_REGNUM, (char *) (regp + R_NIP)); | |
258 | supply_register (SFIP_REGNUM, (char *) (regp + R_FIP)); | |
259 | supply_register (PSR_REGNUM, (char *) (regp + R_PSR)); | |
260 | supply_register (FPSR_REGNUM, (char *) (regp + R_FPSR)); | |
261 | supply_register (FPCR_REGNUM, (char *) (regp + R_FPCR)); | |
c906108c SS |
262 | } |
263 | ||
264 | void | |
fba45db2 | 265 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c | 266 | { |
c5aa993b JM |
267 | int regi; |
268 | register greg_t *regp = (greg_t *) gregsetp; | |
269 | ||
270 | for (regi = 0; regi <= R_R31; regi++) | |
271 | if ((regno == -1) || (regno == regi)) | |
272 | *(regp + regi) = *(int *) ®isters[REGISTER_BYTE (regi)]; | |
273 | ||
274 | if ((regno == -1) || (regno == SXIP_REGNUM)) | |
275 | *(regp + R_XIP) = *(int *) ®isters[REGISTER_BYTE (SXIP_REGNUM)]; | |
276 | if ((regno == -1) || (regno == SNIP_REGNUM)) | |
277 | *(regp + R_NIP) = *(int *) ®isters[REGISTER_BYTE (SNIP_REGNUM)]; | |
278 | if ((regno == -1) || (regno == SFIP_REGNUM)) | |
279 | *(regp + R_FIP) = *(int *) ®isters[REGISTER_BYTE (SFIP_REGNUM)]; | |
280 | if ((regno == -1) || (regno == PSR_REGNUM)) | |
281 | *(regp + R_PSR) = *(int *) ®isters[REGISTER_BYTE (PSR_REGNUM)]; | |
282 | if ((regno == -1) || (regno == FPSR_REGNUM)) | |
283 | *(regp + R_FPSR) = *(int *) ®isters[REGISTER_BYTE (FPSR_REGNUM)]; | |
284 | if ((regno == -1) || (regno == FPCR_REGNUM)) | |
285 | *(regp + R_FPCR) = *(int *) ®isters[REGISTER_BYTE (FPCR_REGNUM)]; | |
c906108c SS |
286 | } |
287 | ||
288 | #endif /* USE_PROC_FS */ |