Commit | Line | Data |
---|---|---|
173a4f1b RP |
1 | /* Native-dependent Motorola 88xxx support for GDB, the GNU Debugger. |
2 | Copyright 1988, 1990, 1991, 1992 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "inferior.h" | |
23 | ||
173a4f1b | 24 | #include <sys/types.h> |
173a4f1b RP |
25 | #include <sys/param.h> |
26 | #include <sys/dir.h> | |
27 | #include <signal.h> | |
28 | #include "gdbcore.h" | |
29 | #include <sys/user.h> | |
30 | ||
31 | #ifndef USER /* added to support BCS ptrace_user */ | |
32 | #define USER ptrace_user | |
33 | #endif | |
34 | #include <sys/ioctl.h> | |
35 | #include <fcntl.h> | |
36 | #include <sys/file.h> | |
37 | #include <sys/stat.h> | |
38 | ||
39 | #include "symtab.h" | |
40 | #include "setjmp.h" | |
41 | #include "value.h" | |
42 | ||
43 | #ifdef DELTA88 | |
fc61e9ee | 44 | #include <sys/ptrace.h> |
173a4f1b RP |
45 | |
46 | /* define offsets to the pc instruction offsets in ptrace_user struct */ | |
e5bb7e61 FF |
47 | #define SXIP_OFFSET ((char *)&u.pt_sigframe.sig_sxip - (char *)&u) |
48 | #define SNIP_OFFSET ((char *)&u.pt_sigframe.sig_snip - (char *)&u) | |
49 | #define SFIP_OFFSET ((char *)&u.pt_sigframe.sig_sfip - (char *)&u) | |
173a4f1b RP |
50 | #else |
51 | /* define offsets to the pc instruction offsets in ptrace_user struct */ | |
e5bb7e61 FF |
52 | #define SXIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_sxip - (char *)&u) |
53 | #define SNIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_snip - (char *)&u) | |
54 | #define SFIP_OFFSET ((char *)&u.pt_sigframe.dg_sigframe.sc_sfip - (char *)&u) | |
173a4f1b RP |
55 | #endif |
56 | ||
57 | extern int have_symbol_file_p(); | |
58 | ||
59 | extern jmp_buf stack_jmp; | |
60 | ||
61 | extern int errno; | |
62 | extern char registers[REGISTER_BYTES]; | |
63 | ||
64 | void | |
65 | fetch_inferior_registers (regno) | |
66 | int regno; /* Original value discarded */ | |
67 | { | |
68 | register unsigned int regaddr; | |
69 | char buf[MAX_REGISTER_RAW_SIZE]; | |
70 | register int i; | |
71 | ||
72 | struct USER u; | |
73 | unsigned int offset; | |
74 | ||
75 | offset = (char *) &u.pt_r0 - (char *) &u; | |
76 | regaddr = offset; /* byte offset to r0;*/ | |
77 | ||
78 | /* offset = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) offset, 0) - KERNEL_U_ADDR; */ | |
79 | for (regno = 0; regno < NUM_REGS; regno++) | |
80 | { | |
81 | /*regaddr = register_addr (regno, offset);*/ | |
82 | /* 88k enhancement */ | |
83 | ||
84 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) | |
85 | { | |
86 | *(int *) &buf[i] = ptrace (3, inferior_pid, | |
87 | (PTRACE_ARG3_TYPE) regaddr, 0); | |
88 | regaddr += sizeof (int); | |
89 | } | |
90 | supply_register (regno, buf); | |
91 | } | |
92 | /* now load up registers 36 - 38; special pc registers */ | |
93 | *(int *) &buf[0] = ptrace (3,inferior_pid, | |
94 | (PTRACE_ARG3_TYPE) SXIP_OFFSET ,0); | |
95 | supply_register (SXIP_REGNUM, buf); | |
96 | *(int *) &buf[0] = ptrace (3, inferior_pid, | |
97 | (PTRACE_ARG3_TYPE) SNIP_OFFSET,0); | |
98 | supply_register (SNIP_REGNUM, buf); | |
99 | *(int *) &buf[0] = ptrace (3, inferior_pid, | |
100 | (PTRACE_ARG3_TYPE) SFIP_OFFSET,0); | |
101 | supply_register (SFIP_REGNUM, buf); | |
102 | } | |
103 | ||
104 | /* Store our register values back into the inferior. | |
105 | If REGNO is -1, do this for all registers. | |
106 | Otherwise, REGNO specifies which register (so we can save time). */ | |
107 | ||
108 | void | |
109 | store_inferior_registers (regno) | |
110 | int regno; | |
111 | { | |
112 | register unsigned int regaddr; | |
113 | char buf[80]; | |
114 | ||
115 | struct USER u; | |
116 | ||
117 | ||
118 | unsigned int offset = (char *) &u.pt_r0 - (char *) &u; | |
119 | ||
120 | regaddr = offset; | |
121 | ||
122 | if (regno >= 0) | |
123 | { | |
124 | /* regaddr = register_addr (regno, offset); */ | |
125 | if (regno < PC_REGNUM) | |
126 | { | |
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, | |
139 | (PTRACE_ARG3_TYPE) SXIP_OFFSET, read_register(regno)); | |
140 | else if (regno == SNIP_REGNUM) | |
141 | ptrace (6, inferior_pid, | |
142 | (PTRACE_ARG3_TYPE) SNIP_OFFSET, read_register(regno)); | |
143 | else if (regno == SFIP_REGNUM) | |
144 | ptrace (6, inferior_pid, | |
145 | (PTRACE_ARG3_TYPE) SFIP_OFFSET, read_register(regno)); | |
146 | else printf ("Bad register number for store_inferior routine\n"); | |
147 | } | |
148 | else { | |
149 | for (regno = 0; regno < NUM_REGS - 3; regno++) | |
150 | { | |
151 | /* regaddr = register_addr (regno, offset); */ | |
152 | errno = 0; | |
153 | regaddr = offset + regno * sizeof (int); | |
154 | ptrace (6, inferior_pid, | |
155 | (PTRACE_ARG3_TYPE) regaddr, read_register (regno)); | |
156 | if (errno != 0) | |
157 | { | |
158 | sprintf (buf, "writing register number %d", regno); | |
159 | perror_with_name (buf); | |
160 | } | |
161 | } | |
162 | ptrace (6,inferior_pid, | |
163 | (PTRACE_ARG3_TYPE) SXIP_OFFSET,read_register(SXIP_REGNUM)); | |
164 | ptrace (6,inferior_pid, | |
165 | (PTRACE_ARG3_TYPE) SNIP_OFFSET,read_register(SNIP_REGNUM)); | |
166 | ptrace (6,inferior_pid, | |
167 | (PTRACE_ARG3_TYPE) SFIP_OFFSET,read_register(SFIP_REGNUM)); | |
168 | } | |
169 | ||
170 | ||
171 | } | |
172 | ||
173 | ||
174 | /* blockend is the address of the end of the user structure */ | |
175 | m88k_register_u_addr (blockend, regnum) | |
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: return (ustart + ((int) &u.pt_r0 - (int) &u) + sizeof(REGISTER_TYPE) * regnum); | |
213 | case PSR_REGNUM: return (ustart + ((int) &u.pt_psr - (int) &u)); | |
214 | case FPSR_REGNUM: return (ustart + ((int) &u.pt_fpsr - (int) &u)); | |
215 | case FPCR_REGNUM: return (ustart + ((int) &u.pt_fpcr - (int) &u)); | |
216 | case SXIP_REGNUM: return (ustart + SXIP_OFFSET); | |
217 | case SNIP_REGNUM: return (ustart + SNIP_OFFSET); | |
218 | case SFIP_REGNUM: return (ustart + SFIP_OFFSET); | |
219 | default: return (blockend + sizeof (REGISTER_TYPE) * regnum); | |
220 | } | |
221 | } | |
222 | ||
304977ab JK |
223 | #ifdef USE_PROC_FS |
224 | ||
225 | #include <sys/procfs.h> | |
226 | ||
227 | /* Given a pointer to a general register set in /proc format (gregset_t *), | |
228 | unpack the register contents and supply them as gdb's idea of the current | |
229 | register values. */ | |
230 | ||
231 | void | |
232 | supply_gregset (gregsetp) | |
233 | gregset_t *gregsetp; | |
234 | { | |
235 | register int regi; | |
236 | register greg_t *regp = (greg_t *) gregsetp; | |
237 | ||
238 | for (regi=0; regi <= SP_REGNUM; regi++) | |
239 | supply_register (regi, (char *) (regp + regi)); | |
240 | ||
241 | supply_register (SXIP_REGNUM, (char *) (regp + R_XIP)); | |
242 | supply_register (SNIP_REGNUM, (char *) (regp + R_NIP)); | |
243 | supply_register (SFIP_REGNUM, (char *) (regp + R_FIP)); | |
244 | supply_register (PSR_REGNUM, (char *) (regp + R_PSR)); | |
245 | supply_register (FPSR_REGNUM, (char *) (regp + R_FPSR)); | |
246 | supply_register (FPCR_REGNUM, (char *) (regp + R_FPCR)); | |
247 | } | |
248 | ||
249 | void | |
250 | fill_gregset (gregsetp, regno) | |
251 | gregset_t *gregsetp; | |
252 | int regno; | |
253 | { | |
254 | int regi; | |
255 | register greg_t *regp = (greg_t *) gregsetp; | |
256 | extern char registers[]; | |
257 | ||
00dff753 | 258 | for (regi = 0 ; regi <= R_R31 ; regi++) |
304977ab JK |
259 | if ((regno == -1) || (regno == regi)) |
260 | *(regp + regi) = *(int *) ®isters[REGISTER_BYTE(regi)]; | |
261 | ||
262 | if ((regno == -1) || (regno == SXIP_REGNUM)) | |
263 | *(regp + R_XIP) = *(int *) ®isters[REGISTER_BYTE(SXIP_REGNUM)]; | |
264 | if ((regno == -1) || (regno == SNIP_REGNUM)) | |
265 | *(regp + R_NIP) = *(int *) ®isters[REGISTER_BYTE(SNIP_REGNUM)]; | |
266 | if ((regno == -1) || (regno == SFIP_REGNUM)) | |
3d8536f3 | 267 | *(regp + R_FIP) = *(int *) ®isters[REGISTER_BYTE(SFIP_REGNUM)]; |
304977ab JK |
268 | if ((regno == -1) || (regno == PSR_REGNUM)) |
269 | *(regp + R_PSR) = *(int *) ®isters[REGISTER_BYTE(PSR_REGNUM)]; | |
270 | if ((regno == -1) || (regno == FPSR_REGNUM)) | |
271 | *(regp + R_FPSR) = *(int *) ®isters[REGISTER_BYTE(FPSR_REGNUM)]; | |
272 | if ((regno == -1) || (regno == FPCR_REGNUM)) | |
273 | *(regp + R_FPCR) = *(int *) ®isters[REGISTER_BYTE(FPCR_REGNUM)]; | |
274 | } | |
275 | ||
276 | #endif /* USE_PROC_FS */ |