One more time...
[deliverable/binutils-gdb.git] / gdb / arm-xdep.c
1 /* Acorn Risc Machine host machine support.
2 Copyright (C) 1988, 1989, 1991 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 #include "arm-opcode.h"
24
25 #include <sys/param.h>
26 #include <sys/dir.h>
27 #include <signal.h>
28 #include <sys/ioctl.h>
29 #include <sys/ptrace.h>
30 #include <machine/reg.h>
31
32 #define N_TXTADDR(hdr) 0x8000
33 #define N_DATADDR(hdr) (hdr.a_text + 0x8000)
34
35 #include "gdbcore.h"
36
37 #include <sys/user.h> /* After a.out.h */
38 #include <sys/file.h>
39 #include <sys/stat.h>
40
41 #include <errno.h>
42
43 void
44 fetch_inferior_registers (regno)
45 int regno; /* Original value discarded */
46 {
47 register unsigned int regaddr;
48 char buf[MAX_REGISTER_RAW_SIZE];
49 register int i;
50
51 struct user u;
52 unsigned int offset = (char *) &u.u_ar0 - (char *) &u;
53 offset = ptrace (PT_READ_U, inferior_pid, offset, 0) - KERNEL_U_ADDR;
54
55 registers_fetched ();
56
57 for (regno = 0; regno < 16; regno++)
58 {
59 regaddr = offset + regno * 4;
60 *(int *)&buf[0] = ptrace (PT_READ_U, inferior_pid, regaddr, 0);
61 if (regno == PC_REGNUM)
62 *(int *)&buf[0] = GET_PC_PART(*(int *)&buf[0]);
63 supply_register (regno, buf);
64 }
65 *(int *)&buf[0] = ptrace (PT_READ_U, inferior_pid, offset + PC*4);
66 supply_register (PS_REGNUM, buf); /* set virtual register ps same as pc */
67
68 /* read the floating point registers */
69 offset = (char *) &u.u_fp_regs - (char *)&u;
70 *(int *)buf = ptrace (PT_READ_U, inferior_pid, offset, 0);
71 supply_register (FPS_REGNUM, buf);
72 for (regno = 16; regno < 24; regno++) {
73 regaddr = offset + 4 + 12 * (regno - 16);
74 for (i = 0; i < 12; i += sizeof(int))
75 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid, regaddr + i, 0);
76 supply_register (regno, buf);
77 }
78 }
79
80 /* Store our register values back into the inferior.
81 If REGNO is -1, do this for all registers.
82 Otherwise, REGNO specifies which register (so we can save time). */
83
84 void
85 store_inferior_registers (regno)
86 int regno;
87 {
88 register unsigned int regaddr;
89 char buf[80];
90
91 struct user u;
92 unsigned long value;
93 unsigned int offset = (char *) &u.u_ar0 - (char *) &u;
94 offset = ptrace (PT_READ_U, inferior_pid, offset, 0) - KERNEL_U_ADDR;
95
96 if (regno >= 0) {
97 if (regno >= 16) return;
98 regaddr = offset + 4 * regno;
99 errno = 0;
100 value = read_register(regno);
101 if (regno == PC_REGNUM)
102 value = SET_PC_PART(read_register (PS_REGNUM), value);
103 ptrace (PT_WRITE_U, inferior_pid, regaddr, value);
104 if (errno != 0)
105 {
106 sprintf (buf, "writing register number %d", regno);
107 perror_with_name (buf);
108 }
109 }
110 else for (regno = 0; regno < 15; regno++)
111 {
112 regaddr = offset + regno * 4;
113 errno = 0;
114 value = read_register(regno);
115 if (regno == PC_REGNUM)
116 value = SET_PC_PART(read_register (PS_REGNUM), value);
117 ptrace (6, inferior_pid, regaddr, value);
118 if (errno != 0)
119 {
120 sprintf (buf, "writing all regs, number %d", regno);
121 perror_with_name (buf);
122 }
123 }
124 }
125 \f
126 /* Work with core dump and executable files, for GDB.
127 This code would be in core.c if it weren't machine-dependent. */
128
129 /* Structure to describe the chain of shared libraries used
130 by the execfile.
131 e.g. prog shares Xt which shares X11 which shares c. */
132
133 struct shared_library {
134 struct exec_header header;
135 char name[SHLIBLEN];
136 CORE_ADDR text_start; /* CORE_ADDR of 1st byte of text, this file */
137 long data_offset; /* offset of data section in file */
138 int chan; /* file descriptor for the file */
139 struct shared_library *shares; /* library this one shares */
140 };
141 static struct shared_library *shlib = 0;
142
143 /* Hook for `exec_file_command' command to call. */
144
145 extern void (*exec_file_display_hook) ();
146
147 static CORE_ADDR unshared_text_start;
148
149 /* extended header from exec file (for shared library info) */
150
151 static struct exec_header exec_header;
152 \f
153 void
154 core_file_command (filename, from_tty)
155 char *filename;
156 int from_tty;
157 {
158 int val;
159 extern char registers[];
160
161 /* Discard all vestiges of any previous core file
162 and mark data and stack spaces as empty. */
163
164 if (corefile)
165 free (corefile);
166 corefile = 0;
167
168 if (corechan >= 0)
169 close (corechan);
170 corechan = -1;
171
172 data_start = 0;
173 data_end = 0;
174 stack_start = STACK_END_ADDR;
175 stack_end = STACK_END_ADDR;
176
177 /* Now, if a new core file was specified, open it and digest it. */
178
179 if (filename)
180 {
181 filename = tilde_expand (filename);
182 make_cleanup (free, filename);
183
184 if (have_inferior_p ())
185 error ("To look at a core file, you must kill the inferior with \"kill\".");
186 corechan = open (filename, O_RDONLY, 0);
187 if (corechan < 0)
188 perror_with_name (filename);
189 /* 4.2-style (and perhaps also sysV-style) core dump file. */
190 {
191 struct user u;
192
193 unsigned int reg_offset, fp_reg_offset;
194
195 val = myread (corechan, &u, sizeof u);
196 if (val < 0)
197 perror_with_name ("Not a core file: reading upage");
198 if (val != sizeof u)
199 error ("Not a core file: could only read %d bytes", val);
200
201 /* We are depending on exec_file_command having been called
202 previously to set exec_data_start. Since the executable
203 and the core file share the same text segment, the address
204 of the data segment will be the same in both. */
205 data_start = exec_data_start;
206
207 data_end = data_start + NBPG * u.u_dsize;
208 stack_start = stack_end - NBPG * u.u_ssize;
209 data_offset = NBPG * UPAGES;
210 stack_offset = NBPG * (UPAGES + u.u_dsize);
211
212 /* Some machines put an absolute address in here and some put
213 the offset in the upage of the regs. */
214 reg_offset = (int) u.u_ar0;
215 if (reg_offset > NBPG * UPAGES)
216 reg_offset -= KERNEL_U_ADDR;
217 fp_reg_offset = (char *) &u.u_fp_regs - (char *)&u;
218
219 /* I don't know where to find this info.
220 So, for now, mark it as not available. */
221 N_SET_MAGIC (core_aouthdr, 0);
222
223 /* Read the register values out of the core file and store
224 them where `read_register' will find them. */
225
226 {
227 register int regno;
228
229 for (regno = 0; regno < NUM_REGS; regno++)
230 {
231 char buf[MAX_REGISTER_RAW_SIZE];
232
233 if (regno < 16)
234 val = lseek (corechan, reg_offset + 4 * regno, 0);
235 else if (regno < 24)
236 val = lseek (corechan, fp_reg_offset + 4 + 12*(regno - 24), 0);
237 else if (regno == 24)
238 val = lseek (corechan, fp_reg_offset, 0);
239 else if (regno == 25)
240 val = lseek (corechan, reg_offset + 4 * PC, 0);
241 if (val < 0
242 || (val = myread (corechan, buf, sizeof buf)) < 0)
243 {
244 char * buffer = (char *) alloca (strlen (reg_names[regno])
245 + 30);
246 strcpy (buffer, "Reading register ");
247 strcat (buffer, reg_names[regno]);
248
249 perror_with_name (buffer);
250 }
251
252 if (regno == PC_REGNUM)
253 *(int *)buf = GET_PC_PART(*(int *)buf);
254 supply_register (regno, buf);
255 }
256 }
257 }
258 if (filename[0] == '/')
259 corefile = savestring (filename, strlen (filename));
260 else
261 {
262 corefile = concat (current_directory, "/", filename, NULL);
263 }
264
265 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
266 read_pc ()));
267 select_frame (get_current_frame (), 0);
268 validate_files ();
269 }
270 else if (from_tty)
271 printf ("No core file now.\n");
272 }
This page took 0.03491 seconds and 4 git commands to generate.