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"
26 #include <sys/param.h>
29 #include <sys/ioctl.h>
30 #include <sys/ptrace.h>
31 #include <machine/reg.h>
33 #define N_TXTADDR(hdr) 0x8000
34 #define N_DATADDR(hdr) (hdr.a_text + 0x8000)
38 #include <sys/user.h> /* After a.out.h */
45 fetch_inferior_registers (regno
)
49 register unsigned int regaddr
;
50 char buf
[MAX_REGISTER_RAW_SIZE
];
54 unsigned int offset
= (char *) &u
.u_ar0
- (char *) &u
;
55 offset
= ptrace (PT_READ_U
, inferior_pid
, offset
, 0) - KERNEL_U_ADDR
;
59 for (regno
= 0; regno
< 16; regno
++)
61 regaddr
= offset
+ regno
* 4;
62 *(int *)&buf
[0] = ptrace (PT_READ_U
, inferior_pid
, 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
, offset
+ PC
*4);
68 supply_register (PS_REGNUM
, buf
); /* set virtual register ps same as pc */
70 /* read the floating point registers */
71 offset
= (char *) &u
.u_fp_regs
- (char *)&u
;
72 *(int *)buf
= ptrace (PT_READ_U
, inferior_pid
, offset
, 0);
73 supply_register (FPS_REGNUM
, buf
);
74 for (regno
= 16; regno
< 24; regno
++) {
75 regaddr
= offset
+ 4 + 12 * (regno
- 16);
76 for (i
= 0; i
< 12; i
+= sizeof(int))
77 *(int *) &buf
[i
] = ptrace (PT_READ_U
, inferior_pid
, regaddr
+ i
, 0);
78 supply_register (regno
, buf
);
82 /* Store our register values back into the inferior.
83 If REGNO is -1, do this for all registers.
84 Otherwise, REGNO specifies which register (so we can save time). */
86 store_inferior_registers (regno
)
89 register unsigned int regaddr
;
94 unsigned int offset
= (char *) &u
.u_ar0
- (char *) &u
;
95 offset
= ptrace (PT_READ_U
, inferior_pid
, offset
, 0) - KERNEL_U_ADDR
;
98 if (regno
>= 16) return;
99 regaddr
= offset
+ 4 * regno
;
101 value
= read_register(regno
);
102 if (regno
== PC_REGNUM
)
103 value
= SET_PC_PART(read_register (PS_REGNUM
), value
);
104 ptrace (PT_WRITE_U
, inferior_pid
, regaddr
, value
);
107 sprintf (buf
, "writing register number %d", regno
);
108 perror_with_name (buf
);
111 else for (regno
= 0; regno
< 15; regno
++)
113 regaddr
= offset
+ regno
* 4;
115 value
= read_register(regno
);
116 if (regno
== PC_REGNUM
)
117 value
= SET_PC_PART(read_register (PS_REGNUM
), value
);
118 ptrace (6, inferior_pid
, regaddr
, value
);
121 sprintf (buf
, "writing all regs, number %d", regno
);
122 perror_with_name (buf
);
127 /* Work with core dump and executable files, for GDB.
128 This code would be in core.c if it weren't machine-dependent. */
130 /* Structure to describe the chain of shared libraries used
132 e.g. prog shares Xt which shares X11 which shares c. */
134 struct shared_library
{
135 struct exec_header header
;
137 CORE_ADDR text_start
; /* CORE_ADDR of 1st byte of text, this file */
138 long data_offset
; /* offset of data section in file */
139 int chan
; /* file descriptor for the file */
140 struct shared_library
*shares
; /* library this one shares */
142 static struct shared_library
*shlib
= 0;
144 /* Hook for `exec_file_command' command to call. */
146 extern void (*exec_file_display_hook
) ();
148 static CORE_ADDR unshared_text_start
;
150 /* extended header from exec file (for shared library info) */
152 static struct exec_header exec_header
;
155 core_file_command (filename
, from_tty
)
160 extern char registers
[];
162 /* Discard all vestiges of any previous core file
163 and mark data and stack spaces as empty. */
175 stack_start
= STACK_END_ADDR
;
176 stack_end
= STACK_END_ADDR
;
178 /* Now, if a new core file was specified, open it and digest it. */
182 filename
= tilde_expand (filename
);
183 make_cleanup (free
, filename
);
185 if (have_inferior_p ())
186 error ("To look at a core file, you must kill the inferior with \"kill\".");
187 corechan
= open (filename
, O_RDONLY
, 0);
189 perror_with_name (filename
);
190 /* 4.2-style (and perhaps also sysV-style) core dump file. */
194 unsigned int reg_offset
, fp_reg_offset
;
196 val
= myread (corechan
, &u
, sizeof u
);
198 perror_with_name ("Not a core file: reading upage");
200 error ("Not a core file: could only read %d bytes", val
);
202 /* We are depending on exec_file_command having been called
203 previously to set exec_data_start. Since the executable
204 and the core file share the same text segment, the address
205 of the data segment will be the same in both. */
206 data_start
= exec_data_start
;
208 data_end
= data_start
+ NBPG
* u
.u_dsize
;
209 stack_start
= stack_end
- NBPG
* u
.u_ssize
;
210 data_offset
= NBPG
* UPAGES
;
211 stack_offset
= NBPG
* (UPAGES
+ u
.u_dsize
);
213 /* Some machines put an absolute address in here and some put
214 the offset in the upage of the regs. */
215 reg_offset
= (int) u
.u_ar0
;
216 if (reg_offset
> NBPG
* UPAGES
)
217 reg_offset
-= KERNEL_U_ADDR
;
218 fp_reg_offset
= (char *) &u
.u_fp_regs
- (char *)&u
;
220 /* I don't know where to find this info.
221 So, for now, mark it as not available. */
222 N_SET_MAGIC (core_aouthdr
, 0);
224 /* Read the register values out of the core file and store
225 them where `read_register' will find them. */
230 for (regno
= 0; regno
< NUM_REGS
; regno
++)
232 char buf
[MAX_REGISTER_RAW_SIZE
];
235 val
= lseek (corechan
, reg_offset
+ 4 * regno
, 0);
237 val
= lseek (corechan
, fp_reg_offset
+ 4 + 12*(regno
- 24), 0);
238 else if (regno
== 24)
239 val
= lseek (corechan
, fp_reg_offset
, 0);
240 else if (regno
== 25)
241 val
= lseek (corechan
, reg_offset
+ 4 * PC
, 0);
243 || (val
= myread (corechan
, buf
, sizeof buf
)) < 0)
245 char * buffer
= (char *) alloca (strlen (reg_names
[regno
])
247 strcpy (buffer
, "Reading register ");
248 strcat (buffer
, reg_names
[regno
]);
250 perror_with_name (buffer
);
253 if (regno
== PC_REGNUM
)
254 *(int *)buf
= GET_PC_PART(*(int *)buf
);
255 supply_register (regno
, buf
);
259 if (filename
[0] == '/')
260 corefile
= savestring (filename
, strlen (filename
));
263 corefile
= concat (current_directory
, "/", filename
, NULL
);
266 set_current_frame ( create_new_frame (read_register (FP_REGNUM
),
268 select_frame (get_current_frame (), 0);
272 printf ("No core file now.\n");