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, (PTRACE_ARG3_TYPE) offset, 0)
58 for (regno = 0; regno < 16; regno++)
60 regaddr = offset + regno * 4;
61 *(int *)&buf[0] = ptrace (PT_READ_U, inferior_pid,
62 (PTRACE_ARG3_TYPE) regaddr, 0);
63 if (regno == PC_REGNUM)
64 *(int *)&buf[0] = GET_PC_PART(*(int *)&buf[0]);
65 supply_register (regno, buf);
67 *(int *)&buf[0] = ptrace (PT_READ_U, inferior_pid,
68 (PTRACE_ARG3_TYPE) (offset + PC*4), 0);
69 supply_register (PS_REGNUM, buf); /* set virtual register ps same as pc */
71 /* read the floating point registers */
72 offset = (char *) &u.u_fp_regs - (char *)&u;
73 *(int *)buf = ptrace (PT_READ_U, inferior_pid, (PTRACE_ARG3_TYPE) offset, 0);
74 supply_register (FPS_REGNUM, buf);
75 for (regno = 16; regno < 24; regno++) {
76 regaddr = offset + 4 + 12 * (regno - 16);
77 for (i = 0; i < 12; i += sizeof(int))
78 *(int *) &buf[i] = ptrace (PT_READ_U, inferior_pid,
79 (PTRACE_ARG3_TYPE) (regaddr + i), 0);
80 supply_register (regno, buf);
84 /* Store our register values back into the inferior.
85 If REGNO is -1, do this for all registers.
86 Otherwise, REGNO specifies which register (so we can save time). */
89 store_inferior_registers (regno)
92 register unsigned int regaddr;
97 unsigned int offset = (char *) &u.u_ar0 - (char *) &u;
98 offset = ptrace (PT_READ_U, inferior_pid, (PTRACE_ARG3_TYPE) offset, 0)
102 if (regno >= 16) return;
103 regaddr = offset + 4 * regno;
105 value = read_register(regno);
106 if (regno == PC_REGNUM)
107 value = SET_PC_PART(read_register (PS_REGNUM), value);
108 ptrace (PT_WRITE_U, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, value);
111 sprintf (buf, "writing register number %d", regno);
112 perror_with_name (buf);
115 else for (regno = 0; regno < 15; regno++)
117 regaddr = offset + regno * 4;
119 value = read_register(regno);
120 if (regno == PC_REGNUM)
121 value = SET_PC_PART(read_register (PS_REGNUM), value);
122 ptrace (6, inferior_pid, (PTRACE_ARG3_TYPE) regaddr, value);
125 sprintf (buf, "writing all regs, number %d", regno);
126 perror_with_name (buf);
131 /* Work with core dump and executable files, for GDB.
132 This code would be in core.c if it weren't machine-dependent. */
134 /* Structure to describe the chain of shared libraries used
136 e.g. prog shares Xt which shares X11 which shares c. */
138 struct shared_library {
139 struct exec_header header;
141 CORE_ADDR text_start; /* CORE_ADDR of 1st byte of text, this file */
142 long data_offset; /* offset of data section in file */
143 int chan; /* file descriptor for the file */
144 struct shared_library *shares; /* library this one shares */
146 static struct shared_library *shlib = 0;
148 /* Hook for `exec_file_command' command to call. */
150 extern void (*exec_file_display_hook) ();
152 static CORE_ADDR unshared_text_start;
154 /* extended header from exec file (for shared library info) */
156 static struct exec_header exec_header;
159 core_file_command (filename, from_tty)
164 extern char registers[];
166 /* Discard all vestiges of any previous core file
167 and mark data and stack spaces as empty. */
179 stack_start = STACK_END_ADDR;
180 stack_end = STACK_END_ADDR;
182 /* Now, if a new core file was specified, open it and digest it. */
186 filename = tilde_expand (filename);
187 make_cleanup (free, filename);
189 if (have_inferior_p ())
190 error ("To look at a core file, you must kill the program with \"kill\".");
191 corechan = open (filename, O_RDONLY, 0);
193 perror_with_name (filename);
194 /* 4.2-style (and perhaps also sysV-style) core dump file. */
198 unsigned int reg_offset, fp_reg_offset;
200 val = myread (corechan, &u, sizeof u);
202 perror_with_name ("Not a core file: reading upage");
204 error ("Not a core file: could only read %d bytes", val);
206 /* We are depending on exec_file_command having been called
207 previously to set exec_data_start. Since the executable
208 and the core file share the same text segment, the address
209 of the data segment will be the same in both. */
210 data_start = exec_data_start;
212 data_end = data_start + NBPG * u.u_dsize;
213 stack_start = stack_end - NBPG * u.u_ssize;
214 data_offset = NBPG * UPAGES;
215 stack_offset = NBPG * (UPAGES + u.u_dsize);
217 /* Some machines put an absolute address in here and some put
218 the offset in the upage of the regs. */
219 reg_offset = (int) u.u_ar0;
220 if (reg_offset > NBPG * UPAGES)
221 reg_offset -= KERNEL_U_ADDR;
222 fp_reg_offset = (char *) &u.u_fp_regs - (char *)&u;
224 /* I don't know where to find this info.
225 So, for now, mark it as not available. */
226 N_SET_MAGIC (core_aouthdr, 0);
228 /* Read the register values out of the core file and store
229 them where `read_register' will find them. */
234 for (regno = 0; regno < NUM_REGS; regno++)
236 char buf[MAX_REGISTER_RAW_SIZE];
239 val = lseek (corechan, reg_offset + 4 * regno, 0);
241 val = lseek (corechan, fp_reg_offset + 4 + 12*(regno - 24), 0);
242 else if (regno == 24)
243 val = lseek (corechan, fp_reg_offset, 0);
244 else if (regno == 25)
245 val = lseek (corechan, reg_offset + 4 * PC, 0);
247 || (val = myread (corechan, buf, sizeof buf)) < 0)
249 char * buffer = (char *) alloca (strlen (reg_names[regno])
251 strcpy (buffer, "Reading register ");
252 strcat (buffer, reg_names[regno]);
254 perror_with_name (buffer);
257 if (regno == PC_REGNUM)
258 *(int *)buf = GET_PC_PART(*(int *)buf);
259 supply_register (regno, buf);
263 if (filename[0] == '/')
264 corefile = savestring (filename, strlen (filename));
267 corefile = concat (current_directory, "/", filename, NULL);
270 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
272 select_frame (get_current_frame (), 0);
276 printf ("No core file now.\n");