Commit | Line | Data |
---|---|---|
dd3b648e | 1 | /* Low level MIPS interface to ptrace, for GDB when running under Unix. |
b543979c | 2 | Copyright 1988, 1989, 1991, 1992 Free Software Foundation, Inc. |
dd3b648e RP |
3 | Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU |
4 | and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
99a7de40 | 8 | This program is free software; you can redistribute it and/or modify |
dd3b648e | 9 | it under the terms of the GNU General Public License as published by |
99a7de40 JG |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | |
dd3b648e | 12 | |
99a7de40 | 13 | This program is distributed in the hope that it will be useful, |
dd3b648e RP |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
99a7de40 JG |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
dd3b648e | 21 | |
d747e0af | 22 | #include "defs.h" |
625453dc SG |
23 | #ifdef sgi |
24 | #include <sys/inst.h> | |
25 | #else | |
dd3b648e | 26 | #include <mips/inst.h> |
625453dc | 27 | #endif |
dd3b648e RP |
28 | #include "frame.h" |
29 | #include "inferior.h" | |
30 | #include "symtab.h" | |
31 | #include "value.h" | |
32 | ||
33 | #ifdef USG | |
34 | #include <sys/types.h> | |
35 | #endif | |
36 | ||
37 | #include <sys/param.h> | |
38 | #include <sys/dir.h> | |
39 | #include <signal.h> | |
40 | #include <sys/ioctl.h> | |
41 | /* #include <fcntl.h> Can we live without this? */ | |
42 | ||
43 | #include "gdbcore.h" | |
44 | ||
45 | #include <sys/user.h> /* After a.out.h */ | |
46 | #include <sys/file.h> | |
47 | #include <sys/stat.h> | |
48 | ||
625453dc SG |
49 | /* For now we stub this out; sgi format is super-hairy (and completely |
50 | different in the new release) */ | |
51 | ||
52 | #ifdef sgi | |
53 | void | |
54 | fetch_core_registers () | |
55 | { | |
56 | return; | |
57 | } | |
58 | ||
1ab3bf1b | 59 | /* ARGSUSED */ |
625453dc | 60 | void |
1ab3bf1b JG |
61 | fetch_inferior_registers (regno) |
62 | int regno; | |
625453dc SG |
63 | { |
64 | return; | |
65 | } | |
66 | ||
1ab3bf1b JG |
67 | /* ARGSUSED */ |
68 | void | |
625453dc SG |
69 | store_inferior_registers (regno) |
70 | int regno; | |
71 | { | |
72 | return; | |
73 | } | |
74 | ||
75 | ||
76 | #else | |
77 | ||
abefb1f1 PB |
78 | /* Map gdb internal register number to ptrace address. */ |
79 | ||
80 | #define REGISTER_PTRACE_ADDR(regno) \ | |
81 | (regno < 32 ? regno \ | |
82 | : regno == PC_REGNUM ? 96 \ | |
83 | : regno == CAUSE_REGNUM ? 97 \ | |
84 | : regno == HI_REGNUM ? 98 \ | |
85 | : regno == LO_REGNUM ? 99 \ | |
86 | : regno == FCRCS_REGNUM ? 100 \ | |
87 | : regno == FCRIR_REGNUM ? 101 \ | |
88 | : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\ | |
89 | : 0) | |
90 | ||
dd3b648e RP |
91 | /* Get all registers from the inferior */ |
92 | ||
93 | void | |
1ab3bf1b JG |
94 | fetch_inferior_registers (regno) |
95 | int regno; | |
dd3b648e | 96 | { |
dd3b648e RP |
97 | register unsigned int regaddr; |
98 | char buf[MAX_REGISTER_RAW_SIZE]; | |
99 | register int i; | |
100 | ||
101 | registers_fetched (); | |
102 | ||
103 | for (regno = 1; regno < NUM_REGS; regno++) | |
104 | { | |
abefb1f1 | 105 | regaddr = REGISTER_PTRACE_ADDR (regno); |
dd3b648e RP |
106 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) |
107 | { | |
e676a15f FF |
108 | *(int *) &buf[i] = ptrace (3, inferior_pid, |
109 | (PTRACE_ARG3_TYPE) regaddr, 0); | |
dd3b648e RP |
110 | regaddr += sizeof (int); |
111 | } | |
112 | supply_register (regno, buf); | |
113 | } | |
114 | } | |
115 | ||
116 | /* Store our register values back into the inferior. | |
117 | If REGNO is -1, do this for all registers. | |
118 | Otherwise, REGNO specifies which register (so we can save time). */ | |
119 | ||
625453dc | 120 | void |
dd3b648e RP |
121 | store_inferior_registers (regno) |
122 | int regno; | |
625453dc | 123 | { |
dd3b648e RP |
124 | register unsigned int regaddr; |
125 | char buf[80]; | |
126 | ||
127 | if (regno == 0) | |
128 | return; | |
129 | ||
130 | if (regno > 0) | |
131 | { | |
abefb1f1 | 132 | regaddr = REGISTER_PTRACE_ADDR (regno); |
dd3b648e | 133 | errno = 0; |
e676a15f FF |
134 | ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
135 | read_register (regno)); | |
dd3b648e RP |
136 | if (errno != 0) |
137 | { | |
138 | sprintf (buf, "writing register number %d", regno); | |
139 | perror_with_name (buf); | |
140 | } | |
141 | } | |
142 | else | |
143 | { | |
abefb1f1 | 144 | for (regno = 0; regno < NUM_REGS; regno++) |
dd3b648e | 145 | { |
abefb1f1 PB |
146 | if (regno == ZERO_REGNUM || regno == PS_REGNUM |
147 | || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM | |
b543979c JG |
148 | || regno == FCRIR_REGNUM || regno == FP_REGNUM |
149 | || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM)) | |
dd3b648e RP |
150 | continue; |
151 | regaddr = register_addr (regno, 1); | |
152 | errno = 0; | |
e676a15f FF |
153 | ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, |
154 | read_register (regno)); | |
dd3b648e RP |
155 | if (errno != 0) |
156 | { | |
157 | sprintf (buf, "writing all regs, number %d", regno); | |
158 | perror_with_name (buf); | |
159 | } | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
625453dc SG |
164 | #endif /* sgi */ |
165 | ||
31ef19fc | 166 | #if 0 |
dd3b648e RP |
167 | void |
168 | fetch_core_registers () | |
169 | { | |
170 | register int regno; | |
171 | int val; | |
172 | ||
173 | for (regno = 1; regno < NUM_REGS; regno++) { | |
174 | char buf[MAX_REGISTER_RAW_SIZE]; | |
175 | ||
176 | val = bfd_seek (core_bfd, register_addr (regno, 0)); | |
177 | if (val < 0 || (val = bfd_read (core_bfd, buf, sizeof buf)) < 0) { | |
178 | char buffer[50]; | |
179 | strcpy (buffer, "Reading register "); | |
180 | strcat (buffer, reg_names[regno]); | |
181 | ||
182 | perror_with_name (buffer); | |
183 | } | |
184 | supply_register (regno, buf); | |
185 | } | |
186 | } | |
31ef19fc | 187 | #endif /* 0 */ |