1 /* Functions specific to running gdb native on an ns32k running NetBSD
2 Copyright 1989, 1992, 1993, 1994, 1996 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <sys/types.h>
22 #include <sys/ptrace.h>
23 #include <machine/reg.h>
24 #include <machine/frame.h>
25 #include <machine/pcb.h>
32 #define RF(dst, src) \
33 memcpy(®isters[REGISTER_BYTE(dst)], &src, sizeof(src))
35 #define RS(src, dst) \
36 memcpy(&dst, ®isters[REGISTER_BYTE(src)], sizeof(dst))
39 fetch_inferior_registers (int regno
)
41 struct reg inferior_registers
;
42 struct fpreg inferior_fpregisters
;
44 ptrace (PT_GETREGS
, inferior_pid
,
45 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
46 ptrace (PT_GETFPREGS
, inferior_pid
,
47 (PTRACE_ARG3_TYPE
) & inferior_fpregisters
, 0);
49 RF (R0_REGNUM
+ 0, inferior_registers
.r_r0
);
50 RF (R0_REGNUM
+ 1, inferior_registers
.r_r1
);
51 RF (R0_REGNUM
+ 2, inferior_registers
.r_r2
);
52 RF (R0_REGNUM
+ 3, inferior_registers
.r_r3
);
53 RF (R0_REGNUM
+ 4, inferior_registers
.r_r4
);
54 RF (R0_REGNUM
+ 5, inferior_registers
.r_r5
);
55 RF (R0_REGNUM
+ 6, inferior_registers
.r_r6
);
56 RF (R0_REGNUM
+ 7, inferior_registers
.r_r7
);
58 RF (SP_REGNUM
, inferior_registers
.r_sp
);
59 RF (FP_REGNUM
, inferior_registers
.r_fp
);
60 RF (PC_REGNUM
, inferior_registers
.r_pc
);
61 RF (PS_REGNUM
, inferior_registers
.r_psr
);
63 RF (FPS_REGNUM
, inferior_fpregisters
.r_fsr
);
64 RF (FP0_REGNUM
+ 0, inferior_fpregisters
.r_freg
[0]);
65 RF (FP0_REGNUM
+ 2, inferior_fpregisters
.r_freg
[2]);
66 RF (FP0_REGNUM
+ 4, inferior_fpregisters
.r_freg
[4]);
67 RF (FP0_REGNUM
+ 6, inferior_fpregisters
.r_freg
[6]);
68 RF (LP0_REGNUM
+ 1, inferior_fpregisters
.r_freg
[1]);
69 RF (LP0_REGNUM
+ 3, inferior_fpregisters
.r_freg
[3]);
70 RF (LP0_REGNUM
+ 5, inferior_fpregisters
.r_freg
[5]);
71 RF (LP0_REGNUM
+ 7, inferior_fpregisters
.r_freg
[7]);
76 store_inferior_registers (int regno
)
78 struct reg inferior_registers
;
79 struct fpreg inferior_fpregisters
;
81 RS (R0_REGNUM
+ 0, inferior_registers
.r_r0
);
82 RS (R0_REGNUM
+ 1, inferior_registers
.r_r1
);
83 RS (R0_REGNUM
+ 2, inferior_registers
.r_r2
);
84 RS (R0_REGNUM
+ 3, inferior_registers
.r_r3
);
85 RS (R0_REGNUM
+ 4, inferior_registers
.r_r4
);
86 RS (R0_REGNUM
+ 5, inferior_registers
.r_r5
);
87 RS (R0_REGNUM
+ 6, inferior_registers
.r_r6
);
88 RS (R0_REGNUM
+ 7, inferior_registers
.r_r7
);
90 RS (SP_REGNUM
, inferior_registers
.r_sp
);
91 RS (FP_REGNUM
, inferior_registers
.r_fp
);
92 RS (PC_REGNUM
, inferior_registers
.r_pc
);
93 RS (PS_REGNUM
, inferior_registers
.r_psr
);
95 RS (FPS_REGNUM
, inferior_fpregisters
.r_fsr
);
96 RS (FP0_REGNUM
+ 0, inferior_fpregisters
.r_freg
[0]);
97 RS (FP0_REGNUM
+ 2, inferior_fpregisters
.r_freg
[2]);
98 RS (FP0_REGNUM
+ 4, inferior_fpregisters
.r_freg
[4]);
99 RS (FP0_REGNUM
+ 6, inferior_fpregisters
.r_freg
[6]);
100 RS (LP0_REGNUM
+ 1, inferior_fpregisters
.r_freg
[1]);
101 RS (LP0_REGNUM
+ 3, inferior_fpregisters
.r_freg
[3]);
102 RS (LP0_REGNUM
+ 5, inferior_fpregisters
.r_freg
[5]);
103 RS (LP0_REGNUM
+ 7, inferior_fpregisters
.r_freg
[7]);
105 ptrace (PT_SETREGS
, inferior_pid
,
106 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
107 ptrace (PT_SETFPREGS
, inferior_pid
,
108 (PTRACE_ARG3_TYPE
) & inferior_fpregisters
, 0);
112 /* XXX - Add this to machine/regs.h instead? */
119 /* Get registers from a core file. REG_ADDR is unused. */
121 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
122 unsigned int reg_addr
)
124 struct coreregs
*core_reg
;
126 core_reg
= (struct coreregs
*) core_reg_sect
;
129 * We have *all* registers
130 * in the first core section.
134 if (core_reg_size
< sizeof (*core_reg
))
136 fprintf_unfiltered (gdb_stderr
, "Couldn't read regs from core file\n");
140 /* Integer registers */
141 RF (R0_REGNUM
+ 0, core_reg
->intreg
.r_r0
);
142 RF (R0_REGNUM
+ 1, core_reg
->intreg
.r_r1
);
143 RF (R0_REGNUM
+ 2, core_reg
->intreg
.r_r2
);
144 RF (R0_REGNUM
+ 3, core_reg
->intreg
.r_r3
);
145 RF (R0_REGNUM
+ 4, core_reg
->intreg
.r_r4
);
146 RF (R0_REGNUM
+ 5, core_reg
->intreg
.r_r5
);
147 RF (R0_REGNUM
+ 6, core_reg
->intreg
.r_r6
);
148 RF (R0_REGNUM
+ 7, core_reg
->intreg
.r_r7
);
150 RF (SP_REGNUM
, core_reg
->intreg
.r_sp
);
151 RF (FP_REGNUM
, core_reg
->intreg
.r_fp
);
152 RF (PC_REGNUM
, core_reg
->intreg
.r_pc
);
153 RF (PS_REGNUM
, core_reg
->intreg
.r_psr
);
155 /* Floating point registers */
156 RF (FPS_REGNUM
, core_reg
->freg
.r_fsr
);
157 RF (FP0_REGNUM
+ 0, core_reg
->freg
.r_freg
[0]);
158 RF (FP0_REGNUM
+ 2, core_reg
->freg
.r_freg
[2]);
159 RF (FP0_REGNUM
+ 4, core_reg
->freg
.r_freg
[4]);
160 RF (FP0_REGNUM
+ 6, core_reg
->freg
.r_freg
[6]);
161 RF (LP0_REGNUM
+ 1, core_reg
->freg
.r_freg
[1]);
162 RF (LP0_REGNUM
+ 3, core_reg
->freg
.r_freg
[3]);
163 RF (LP0_REGNUM
+ 5, core_reg
->freg
.r_freg
[5]);
164 RF (LP0_REGNUM
+ 7, core_reg
->freg
.r_freg
[7]);
165 registers_fetched ();
168 /* Register that we are able to handle ns32knbsd core file formats.
169 FIXME: is this really bfd_target_unknown_flavour? */
171 static struct core_fns nat_core_fns
=
173 bfd_target_unknown_flavour
, /* core_flavour */
174 default_check_format
, /* check_format */
175 default_core_sniffer
, /* core_sniffer */
176 fetch_core_registers
, /* core_read_registers */
181 _initialize_ns32knbsd_nat (void)
183 add_core_fns (&nat_core_fns
);
188 * kernel_u_size() is not helpful on NetBSD because
189 * the "u" struct is NOT in the core dump file.
192 #ifdef FETCH_KCORE_REGISTERS
194 * Get registers from a kernel crash dump or live kernel.
195 * Called by kcore-nbsd.c:get_kcore_registers().
198 fetch_kcore_registers (struct pcb
*pcb
)
200 struct switchframe sf
;
204 /* Integer registers */
205 if (target_read_memory ((CORE_ADDR
) pcb
->pcb_ksp
, (char *) &sf
, sizeof sf
))
206 error ("Cannot read integer registers.");
208 /* We use the psr at kernel entry */
209 if (target_read_memory ((CORE_ADDR
) pcb
->pcb_onstack
, (char *) &intreg
, sizeof intreg
))
210 error ("Cannot read processor status register.");
213 RF (R0_REGNUM
+ 0, dummy
);
214 RF (R0_REGNUM
+ 1, dummy
);
215 RF (R0_REGNUM
+ 2, dummy
);
216 RF (R0_REGNUM
+ 3, sf
.sf_r3
);
217 RF (R0_REGNUM
+ 4, sf
.sf_r4
);
218 RF (R0_REGNUM
+ 5, sf
.sf_r5
);
219 RF (R0_REGNUM
+ 6, sf
.sf_r6
);
220 RF (R0_REGNUM
+ 7, sf
.sf_r7
);
222 dummy
= pcb
->pcb_kfp
+ 8;
223 RF (SP_REGNUM
, dummy
);
224 RF (FP_REGNUM
, sf
.sf_fp
);
225 RF (PC_REGNUM
, sf
.sf_pc
);
226 RF (PS_REGNUM
, intreg
.r_psr
);
228 /* Floating point registers */
229 RF (FPS_REGNUM
, pcb
->pcb_fsr
);
230 RF (FP0_REGNUM
+ 0, pcb
->pcb_freg
[0]);
231 RF (FP0_REGNUM
+ 2, pcb
->pcb_freg
[2]);
232 RF (FP0_REGNUM
+ 4, pcb
->pcb_freg
[4]);
233 RF (FP0_REGNUM
+ 6, pcb
->pcb_freg
[6]);
234 RF (LP0_REGNUM
+ 1, pcb
->pcb_freg
[1]);
235 RF (LP0_REGNUM
+ 3, pcb
->pcb_freg
[3]);
236 RF (LP0_REGNUM
+ 5, pcb
->pcb_freg
[5]);
237 RF (LP0_REGNUM
+ 7, pcb
->pcb_freg
[7]);
238 registers_fetched ();
240 #endif /* FETCH_KCORE_REGISTERS */
248 /* Integer registers */
249 RF (R0_REGNUM
+ 0, null
);
250 RF (R0_REGNUM
+ 1, null
);
251 RF (R0_REGNUM
+ 2, null
);
252 RF (R0_REGNUM
+ 3, null
);
253 RF (R0_REGNUM
+ 4, null
);
254 RF (R0_REGNUM
+ 5, null
);
255 RF (R0_REGNUM
+ 6, null
);
256 RF (R0_REGNUM
+ 7, null
);
258 RF (SP_REGNUM
, null
);
259 RF (FP_REGNUM
, null
);
260 RF (PC_REGNUM
, null
);
261 RF (PS_REGNUM
, null
);
263 /* Floating point registers */
264 RF (FPS_REGNUM
, zero
);
265 RF (FP0_REGNUM
+ 0, zero
);
266 RF (FP0_REGNUM
+ 2, zero
);
267 RF (FP0_REGNUM
+ 4, zero
);
268 RF (FP0_REGNUM
+ 6, zero
);
269 RF (LP0_REGNUM
+ 0, zero
);
270 RF (LP0_REGNUM
+ 1, zero
);
271 RF (LP0_REGNUM
+ 2, zero
);
272 RF (LP0_REGNUM
+ 3, zero
);
276 /* Return number of args passed to a frame.
277 Can return -1, meaning no way to tell. */
280 frame_num_args (struct frame_info
*fi
)
282 CORE_ADDR enter_addr
;
288 if (read_memory_integer (fi
->frame
, 4) == 0 && fi
->pc
< 0x10000)
290 /* main is always called with three args */
293 enter_addr
= ns32k_get_enter_addr (fi
->pc
);
296 argp
= enter_addr
== 1 ? SAVED_PC_AFTER_CALL (fi
) : FRAME_SAVED_PC (fi
);
297 for (i
= 0; i
< 16; i
++)
300 * After a bsr gcc may emit the following instructions
301 * to remove the arguments from the stack:
302 * cmpqd 0,tos - to remove 4 bytes from the stack
303 * cmpd tos,tos - to remove 8 bytes from the stack
304 * adjsp[bwd] -n - to remove n bytes from the stack
305 * Gcc sometimes delays emitting these instructions and
306 * may even throw a branch between our feet.
308 inst
= read_memory_integer (argp
, 4);
309 args
= read_memory_integer (argp
+ 2, 4);
310 if ((inst
& 0xff) == 0xea)
312 args
= ((inst
>> 8) & 0xffffff) | (args
<< 24);
321 args
= ntohs (args
& 0xffff);
335 if ((inst
& 0xffff) == 0xb81f) /* cmpqd 0,tos */
337 else if ((inst
& 0xffff) == 0xbdc7) /* cmpd tos,tos */
339 else if ((inst
& 0xfffc) == 0xa57c)
344 args
= ((args
& 0xff) + 0x80);
347 args
= ((ntohs (args
) & 0xffff) + 0x8000);
350 args
= -ntohl (args
);
355 if (args
/ 4 > 10 || (args
& 3) != 0)