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 (regno
)
42 struct reg inferior_registers
;
43 struct fpreg inferior_fpregisters
;
45 ptrace (PT_GETREGS
, inferior_pid
,
46 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
47 ptrace (PT_GETFPREGS
, inferior_pid
,
48 (PTRACE_ARG3_TYPE
) & inferior_fpregisters
, 0);
50 RF (R0_REGNUM
+ 0, inferior_registers
.r_r0
);
51 RF (R0_REGNUM
+ 1, inferior_registers
.r_r1
);
52 RF (R0_REGNUM
+ 2, inferior_registers
.r_r2
);
53 RF (R0_REGNUM
+ 3, inferior_registers
.r_r3
);
54 RF (R0_REGNUM
+ 4, inferior_registers
.r_r4
);
55 RF (R0_REGNUM
+ 5, inferior_registers
.r_r5
);
56 RF (R0_REGNUM
+ 6, inferior_registers
.r_r6
);
57 RF (R0_REGNUM
+ 7, inferior_registers
.r_r7
);
59 RF (SP_REGNUM
, inferior_registers
.r_sp
);
60 RF (FP_REGNUM
, inferior_registers
.r_fp
);
61 RF (PC_REGNUM
, inferior_registers
.r_pc
);
62 RF (PS_REGNUM
, inferior_registers
.r_psr
);
64 RF (FPS_REGNUM
, inferior_fpregisters
.r_fsr
);
65 RF (FP0_REGNUM
+ 0, inferior_fpregisters
.r_freg
[0]);
66 RF (FP0_REGNUM
+ 2, inferior_fpregisters
.r_freg
[2]);
67 RF (FP0_REGNUM
+ 4, inferior_fpregisters
.r_freg
[4]);
68 RF (FP0_REGNUM
+ 6, inferior_fpregisters
.r_freg
[6]);
69 RF (LP0_REGNUM
+ 1, inferior_fpregisters
.r_freg
[1]);
70 RF (LP0_REGNUM
+ 3, inferior_fpregisters
.r_freg
[3]);
71 RF (LP0_REGNUM
+ 5, inferior_fpregisters
.r_freg
[5]);
72 RF (LP0_REGNUM
+ 7, inferior_fpregisters
.r_freg
[7]);
77 store_inferior_registers (regno
)
80 struct reg inferior_registers
;
81 struct fpreg inferior_fpregisters
;
83 RS (R0_REGNUM
+ 0, inferior_registers
.r_r0
);
84 RS (R0_REGNUM
+ 1, inferior_registers
.r_r1
);
85 RS (R0_REGNUM
+ 2, inferior_registers
.r_r2
);
86 RS (R0_REGNUM
+ 3, inferior_registers
.r_r3
);
87 RS (R0_REGNUM
+ 4, inferior_registers
.r_r4
);
88 RS (R0_REGNUM
+ 5, inferior_registers
.r_r5
);
89 RS (R0_REGNUM
+ 6, inferior_registers
.r_r6
);
90 RS (R0_REGNUM
+ 7, inferior_registers
.r_r7
);
92 RS (SP_REGNUM
, inferior_registers
.r_sp
);
93 RS (FP_REGNUM
, inferior_registers
.r_fp
);
94 RS (PC_REGNUM
, inferior_registers
.r_pc
);
95 RS (PS_REGNUM
, inferior_registers
.r_psr
);
97 RS (FPS_REGNUM
, inferior_fpregisters
.r_fsr
);
98 RS (FP0_REGNUM
+ 0, inferior_fpregisters
.r_freg
[0]);
99 RS (FP0_REGNUM
+ 2, inferior_fpregisters
.r_freg
[2]);
100 RS (FP0_REGNUM
+ 4, inferior_fpregisters
.r_freg
[4]);
101 RS (FP0_REGNUM
+ 6, inferior_fpregisters
.r_freg
[6]);
102 RS (LP0_REGNUM
+ 1, inferior_fpregisters
.r_freg
[1]);
103 RS (LP0_REGNUM
+ 3, inferior_fpregisters
.r_freg
[3]);
104 RS (LP0_REGNUM
+ 5, inferior_fpregisters
.r_freg
[5]);
105 RS (LP0_REGNUM
+ 7, inferior_fpregisters
.r_freg
[7]);
107 ptrace (PT_SETREGS
, inferior_pid
,
108 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0);
109 ptrace (PT_SETFPREGS
, inferior_pid
,
110 (PTRACE_ARG3_TYPE
) & inferior_fpregisters
, 0);
114 /* XXX - Add this to machine/regs.h instead? */
121 /* Get registers from a core file. */
123 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
125 unsigned core_reg_size
;
127 unsigned int reg_addr
; /* Unused in this version */
129 struct coreregs
*core_reg
;
131 core_reg
= (struct coreregs
*) core_reg_sect
;
134 * We have *all* registers
135 * in the first core section.
139 if (core_reg_size
< sizeof (*core_reg
))
141 fprintf_unfiltered (gdb_stderr
, "Couldn't read regs from core file\n");
145 /* Integer registers */
146 RF (R0_REGNUM
+ 0, core_reg
->intreg
.r_r0
);
147 RF (R0_REGNUM
+ 1, core_reg
->intreg
.r_r1
);
148 RF (R0_REGNUM
+ 2, core_reg
->intreg
.r_r2
);
149 RF (R0_REGNUM
+ 3, core_reg
->intreg
.r_r3
);
150 RF (R0_REGNUM
+ 4, core_reg
->intreg
.r_r4
);
151 RF (R0_REGNUM
+ 5, core_reg
->intreg
.r_r5
);
152 RF (R0_REGNUM
+ 6, core_reg
->intreg
.r_r6
);
153 RF (R0_REGNUM
+ 7, core_reg
->intreg
.r_r7
);
155 RF (SP_REGNUM
, core_reg
->intreg
.r_sp
);
156 RF (FP_REGNUM
, core_reg
->intreg
.r_fp
);
157 RF (PC_REGNUM
, core_reg
->intreg
.r_pc
);
158 RF (PS_REGNUM
, core_reg
->intreg
.r_psr
);
160 /* Floating point registers */
161 RF (FPS_REGNUM
, core_reg
->freg
.r_fsr
);
162 RF (FP0_REGNUM
+ 0, core_reg
->freg
.r_freg
[0]);
163 RF (FP0_REGNUM
+ 2, core_reg
->freg
.r_freg
[2]);
164 RF (FP0_REGNUM
+ 4, core_reg
->freg
.r_freg
[4]);
165 RF (FP0_REGNUM
+ 6, core_reg
->freg
.r_freg
[6]);
166 RF (LP0_REGNUM
+ 1, core_reg
->freg
.r_freg
[1]);
167 RF (LP0_REGNUM
+ 3, core_reg
->freg
.r_freg
[3]);
168 RF (LP0_REGNUM
+ 5, core_reg
->freg
.r_freg
[5]);
169 RF (LP0_REGNUM
+ 7, core_reg
->freg
.r_freg
[7]);
170 registers_fetched ();
173 /* Register that we are able to handle ns32knbsd core file formats.
174 FIXME: is this really bfd_target_unknown_flavour? */
176 static struct core_fns nat_core_fns
=
178 bfd_target_unknown_flavour
, /* core_flavour */
179 default_check_format
, /* check_format */
180 default_core_sniffer
, /* core_sniffer */
181 fetch_core_registers
, /* core_read_registers */
186 _initialize_ns32knbsd_nat ()
188 add_core_fns (&nat_core_fns
);
193 * kernel_u_size() is not helpful on NetBSD because
194 * the "u" struct is NOT in the core dump file.
197 #ifdef FETCH_KCORE_REGISTERS
199 * Get registers from a kernel crash dump or live kernel.
200 * Called by kcore-nbsd.c:get_kcore_registers().
203 fetch_kcore_registers (pcb
)
206 struct switchframe sf
;
210 /* Integer registers */
211 if (target_read_memory ((CORE_ADDR
) pcb
->pcb_ksp
, (char *) &sf
, sizeof sf
))
212 error ("Cannot read integer registers.");
214 /* We use the psr at kernel entry */
215 if (target_read_memory ((CORE_ADDR
) pcb
->pcb_onstack
, (char *) &intreg
, sizeof intreg
))
216 error ("Cannot read processor status register.");
219 RF (R0_REGNUM
+ 0, dummy
);
220 RF (R0_REGNUM
+ 1, dummy
);
221 RF (R0_REGNUM
+ 2, dummy
);
222 RF (R0_REGNUM
+ 3, sf
.sf_r3
);
223 RF (R0_REGNUM
+ 4, sf
.sf_r4
);
224 RF (R0_REGNUM
+ 5, sf
.sf_r5
);
225 RF (R0_REGNUM
+ 6, sf
.sf_r6
);
226 RF (R0_REGNUM
+ 7, sf
.sf_r7
);
228 dummy
= pcb
->pcb_kfp
+ 8;
229 RF (SP_REGNUM
, dummy
);
230 RF (FP_REGNUM
, sf
.sf_fp
);
231 RF (PC_REGNUM
, sf
.sf_pc
);
232 RF (PS_REGNUM
, intreg
.r_psr
);
234 /* Floating point registers */
235 RF (FPS_REGNUM
, pcb
->pcb_fsr
);
236 RF (FP0_REGNUM
+ 0, pcb
->pcb_freg
[0]);
237 RF (FP0_REGNUM
+ 2, pcb
->pcb_freg
[2]);
238 RF (FP0_REGNUM
+ 4, pcb
->pcb_freg
[4]);
239 RF (FP0_REGNUM
+ 6, pcb
->pcb_freg
[6]);
240 RF (LP0_REGNUM
+ 1, pcb
->pcb_freg
[1]);
241 RF (LP0_REGNUM
+ 3, pcb
->pcb_freg
[3]);
242 RF (LP0_REGNUM
+ 5, pcb
->pcb_freg
[5]);
243 RF (LP0_REGNUM
+ 7, pcb
->pcb_freg
[7]);
244 registers_fetched ();
246 #endif /* FETCH_KCORE_REGISTERS */
254 /* Integer registers */
255 RF (R0_REGNUM
+ 0, null
);
256 RF (R0_REGNUM
+ 1, null
);
257 RF (R0_REGNUM
+ 2, null
);
258 RF (R0_REGNUM
+ 3, null
);
259 RF (R0_REGNUM
+ 4, null
);
260 RF (R0_REGNUM
+ 5, null
);
261 RF (R0_REGNUM
+ 6, null
);
262 RF (R0_REGNUM
+ 7, null
);
264 RF (SP_REGNUM
, null
);
265 RF (FP_REGNUM
, null
);
266 RF (PC_REGNUM
, null
);
267 RF (PS_REGNUM
, null
);
269 /* Floating point registers */
270 RF (FPS_REGNUM
, zero
);
271 RF (FP0_REGNUM
+ 0, zero
);
272 RF (FP0_REGNUM
+ 2, zero
);
273 RF (FP0_REGNUM
+ 4, zero
);
274 RF (FP0_REGNUM
+ 6, zero
);
275 RF (LP0_REGNUM
+ 0, zero
);
276 RF (LP0_REGNUM
+ 1, zero
);
277 RF (LP0_REGNUM
+ 2, zero
);
278 RF (LP0_REGNUM
+ 3, zero
);
282 /* Return number of args passed to a frame.
283 Can return -1, meaning no way to tell. */
287 struct frame_info
*fi
;
289 CORE_ADDR enter_addr
;
295 if (read_memory_integer (fi
->frame
, 4) == 0 && fi
->pc
< 0x10000)
297 /* main is always called with three args */
300 enter_addr
= ns32k_get_enter_addr (fi
->pc
);
303 argp
= enter_addr
== 1 ? SAVED_PC_AFTER_CALL (fi
) : FRAME_SAVED_PC (fi
);
304 for (i
= 0; i
< 16; i
++)
307 * After a bsr gcc may emit the following instructions
308 * to remove the arguments from the stack:
309 * cmpqd 0,tos - to remove 4 bytes from the stack
310 * cmpd tos,tos - to remove 8 bytes from the stack
311 * adjsp[bwd] -n - to remove n bytes from the stack
312 * Gcc sometimes delays emitting these instructions and
313 * may even throw a branch between our feet.
315 inst
= read_memory_integer (argp
, 4);
316 args
= read_memory_integer (argp
+ 2, 4);
317 if ((inst
& 0xff) == 0xea)
319 args
= ((inst
>> 8) & 0xffffff) | (args
<< 24);
328 args
= ntohs (args
& 0xffff);
342 if ((inst
& 0xffff) == 0xb81f) /* cmpqd 0,tos */
344 else if ((inst
& 0xffff) == 0xbdc7) /* cmpd tos,tos */
346 else if ((inst
& 0xfffc) == 0xa57c)
351 args
= ((args
& 0xff) + 0x80);
354 args
= ((ntohs (args
) & 0xffff) + 0x8000);
357 args
= -ntohl (args
);
362 if (args
/ 4 > 10 || (args
& 3) != 0)