1 /* Acorn Risc Machine host machine support.
2 Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
23 #include "arm-opcode.h"
25 #include <sys/param.h>
28 #include <sys/ioctl.h>
29 #include <sys/ptrace.h>
30 #include <machine/reg.h>
32 #define N_TXTADDR(hdr) 0x8000
33 #define N_DATADDR(hdr) (hdr.a_text + 0x8000)
37 #include <sys/user.h> /* After a.out.h */
44 fetch_inferior_registers (regno)
45 int regno; /* Original value discarded */
47 register unsigned int regaddr;
48 char buf[MAX_REGISTER_RAW_SIZE];
52 unsigned int offset = (char *) &u.u_ar0 - (char *) &u;
53 offset = ptrace (PT_READ_U, inferior_pid, offset, 0) - KERNEL_U_ADDR;
57 for (regno = 0; regno < 16; regno++)
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);
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 */
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);
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). */
85 store_inferior_registers (regno)
88 register unsigned int regaddr;
93 unsigned int offset = (char *) &u.u_ar0 - (char *) &u;
94 offset = ptrace (PT_READ_U, inferior_pid, offset, 0) - KERNEL_U_ADDR;
97 if (regno >= 16) return;
98 regaddr = offset + 4 * regno;
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);
106 sprintf (buf, "writing register number %d", regno);
107 perror_with_name (buf);
110 else for (regno = 0; regno < 15; regno++)
112 regaddr = offset + regno * 4;
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);
120 sprintf (buf, "writing all regs, number %d", regno);
121 perror_with_name (buf);
126 /* Work with core dump and executable files, for GDB.
127 This code would be in core.c if it weren't machine-dependent. */
129 /* Structure to describe the chain of shared libraries used
131 e.g. prog shares Xt which shares X11 which shares c. */
133 struct shared_library {
134 struct exec_header header;
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 */
141 static struct shared_library *shlib = 0;
143 /* Hook for `exec_file_command' command to call. */
145 extern void (*exec_file_display_hook) ();
147 static CORE_ADDR unshared_text_start;
149 /* extended header from exec file (for shared library info) */
151 static struct exec_header exec_header;
154 core_file_command (filename, from_tty)
159 extern char registers[];
161 /* Discard all vestiges of any previous core file
162 and mark data and stack spaces as empty. */
174 stack_start = STACK_END_ADDR;
175 stack_end = STACK_END_ADDR;
177 /* Now, if a new core file was specified, open it and digest it. */
181 filename = tilde_expand (filename);
182 make_cleanup (free, filename);
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);
188 perror_with_name (filename);
189 /* 4.2-style (and perhaps also sysV-style) core dump file. */
193 unsigned int reg_offset, fp_reg_offset;
195 val = myread (corechan, &u, sizeof u);
197 perror_with_name ("Not a core file: reading upage");
199 error ("Not a core file: could only read %d bytes", val);
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;
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);
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;
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);
223 /* Read the register values out of the core file and store
224 them where `read_register' will find them. */
229 for (regno = 0; regno < NUM_REGS; regno++)
231 char buf[MAX_REGISTER_RAW_SIZE];
234 val = lseek (corechan, reg_offset + 4 * regno, 0);
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);
242 || (val = myread (corechan, buf, sizeof buf)) < 0)
244 char * buffer = (char *) alloca (strlen (reg_names[regno])
246 strcpy (buffer, "Reading register ");
247 strcat (buffer, reg_names[regno]);
249 perror_with_name (buffer);
252 if (regno == PC_REGNUM)
253 *(int *)buf = GET_PC_PART(*(int *)buf);
254 supply_register (regno, buf);
258 if (filename[0] == '/')
259 corefile = savestring (filename, strlen (filename));
262 corefile = concat (current_directory, "/", filename, NULL);
265 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
267 select_frame (get_current_frame (), 0);
271 printf ("No core file now.\n");