]>
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([email protected]) at CMU |
4 | and by Per Bothner([email protected]) 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 RP |
21 | |
22 | #include <stdio.h> | |
625453dc SG |
23 | #ifdef sgi |
24 | #include <sys/inst.h> | |
25 | #else | |
dd3b648e | 26 | #include <mips/inst.h> |
625453dc | 27 | #endif |
dd3b648e | 28 | #include "defs.h" |
dd3b648e RP |
29 | #include "frame.h" |
30 | #include "inferior.h" | |
31 | #include "symtab.h" | |
32 | #include "value.h" | |
33 | ||
34 | #ifdef USG | |
35 | #include <sys/types.h> | |
36 | #endif | |
37 | ||
38 | #include <sys/param.h> | |
39 | #include <sys/dir.h> | |
40 | #include <signal.h> | |
41 | #include <sys/ioctl.h> | |
42 | /* #include <fcntl.h> Can we live without this? */ | |
43 | ||
44 | #include "gdbcore.h" | |
45 | ||
46 | #include <sys/user.h> /* After a.out.h */ | |
47 | #include <sys/file.h> | |
48 | #include <sys/stat.h> | |
49 | ||
625453dc SG |
50 | /* For now we stub this out; sgi format is super-hairy (and completely |
51 | different in the new release) */ | |
52 | ||
53 | #ifdef sgi | |
54 | void | |
55 | fetch_core_registers () | |
56 | { | |
57 | return; | |
58 | } | |
59 | ||
1ab3bf1b | 60 | /* ARGSUSED */ |
625453dc | 61 | void |
1ab3bf1b JG |
62 | fetch_inferior_registers (regno) |
63 | int regno; | |
625453dc SG |
64 | { |
65 | return; | |
66 | } | |
67 | ||
1ab3bf1b JG |
68 | /* ARGSUSED */ |
69 | void | |
625453dc SG |
70 | store_inferior_registers (regno) |
71 | int regno; | |
72 | { | |
73 | return; | |
74 | } | |
75 | ||
76 | ||
77 | #else | |
78 | ||
abefb1f1 PB |
79 | /* Map gdb internal register number to ptrace address. */ |
80 | ||
81 | #define REGISTER_PTRACE_ADDR(regno) \ | |
82 | (regno < 32 ? regno \ | |
83 | : regno == PC_REGNUM ? 96 \ | |
84 | : regno == CAUSE_REGNUM ? 97 \ | |
85 | : regno == HI_REGNUM ? 98 \ | |
86 | : regno == LO_REGNUM ? 99 \ | |
87 | : regno == FCRCS_REGNUM ? 100 \ | |
88 | : regno == FCRIR_REGNUM ? 101 \ | |
89 | : regno >= FP0_REGNUM ? regno - (FP0_REGNUM-32)\ | |
90 | : 0) | |
91 | ||
dd3b648e RP |
92 | /* Get all registers from the inferior */ |
93 | ||
94 | void | |
1ab3bf1b JG |
95 | fetch_inferior_registers (regno) |
96 | int regno; | |
dd3b648e | 97 | { |
dd3b648e RP |
98 | register unsigned int regaddr; |
99 | char buf[MAX_REGISTER_RAW_SIZE]; | |
100 | register int i; | |
101 | ||
102 | registers_fetched (); | |
103 | ||
104 | for (regno = 1; regno < NUM_REGS; regno++) | |
105 | { | |
abefb1f1 | 106 | regaddr = REGISTER_PTRACE_ADDR (regno); |
dd3b648e RP |
107 | for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) |
108 | { | |
109 | *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0); | |
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 RP |
133 | errno = 0; |
134 | ptrace (6, inferior_pid, regaddr, read_register (regno)); | |
135 | if (errno != 0) | |
136 | { | |
137 | sprintf (buf, "writing register number %d", regno); | |
138 | perror_with_name (buf); | |
139 | } | |
140 | } | |
141 | else | |
142 | { | |
abefb1f1 | 143 | for (regno = 0; regno < NUM_REGS; regno++) |
dd3b648e | 144 | { |
abefb1f1 PB |
145 | if (regno == ZERO_REGNUM || regno == PS_REGNUM |
146 | || regno == BADVADDR_REGNUM || regno == CAUSE_REGNUM | |
b543979c JG |
147 | || regno == FCRIR_REGNUM || regno == FP_REGNUM |
148 | || (regno >= FIRST_EMBED_REGNUM && regno <= LAST_EMBED_REGNUM)) | |
dd3b648e RP |
149 | continue; |
150 | regaddr = register_addr (regno, 1); | |
151 | errno = 0; | |
152 | ptrace (6, inferior_pid, regaddr, read_register (regno)); | |
153 | if (errno != 0) | |
154 | { | |
155 | sprintf (buf, "writing all regs, number %d", regno); | |
156 | perror_with_name (buf); | |
157 | } | |
158 | } | |
159 | } | |
160 | } | |
161 | ||
625453dc SG |
162 | #endif /* sgi */ |
163 | ||
31ef19fc | 164 | #if 0 |
dd3b648e RP |
165 | void |
166 | fetch_core_registers () | |
167 | { | |
168 | register int regno; | |
169 | int val; | |
170 | ||
171 | for (regno = 1; regno < NUM_REGS; regno++) { | |
172 | char buf[MAX_REGISTER_RAW_SIZE]; | |
173 | ||
174 | val = bfd_seek (core_bfd, register_addr (regno, 0)); | |
175 | if (val < 0 || (val = bfd_read (core_bfd, buf, sizeof buf)) < 0) { | |
176 | char buffer[50]; | |
177 | strcpy (buffer, "Reading register "); | |
178 | strcat (buffer, reg_names[regno]); | |
179 | ||
180 | perror_with_name (buffer); | |
181 | } | |
182 | supply_register (regno, buf); | |
183 | } | |
184 | } | |
31ef19fc | 185 | #endif /* 0 */ |