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