1 /* Native-dependent code for BSD Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 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, Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
23 #include <sys/ptrace.h>
24 #include <machine/reg.h>
25 #include <machine/frame.h>
26 #include <sys/param.h>
33 #if defined(HAVE_GREGSET_T)
34 #include <sys/procfs.h>
37 int kernel_debugging = 0;
39 /* Size of elements in jmpbuf */
41 #define JB_ELEMENT_SIZE 8
43 /* The definition for JB_PC in machine/reg.h is wrong.
44 And we can't get at the correct definition in setjmp.h as it is
45 not always available (eg. if _POSIX_SOURCE is defined which is the
46 default). As the defintion is unlikely to change (see comment
47 in <setjmp.h>, define the correct value here. */
52 /* Figure out where the longjmp will land.
53 We expect the first arg to be a pointer to the jmp_buf structure from which
54 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
55 This routine returns true on success. */
58 get_longjmp_target (pc)
62 char raw_buffer[MAX_REGISTER_RAW_SIZE];
64 jb_addr = read_register(A0_REGNUM);
66 if (target_read_memory(jb_addr + JB_PC * JB_ELEMENT_SIZE, raw_buffer,
70 *pc = extract_address (raw_buffer, sizeof(CORE_ADDR));
75 fetch_inferior_registers (regno)
78 struct reg regs; /* ptrace order, not gcc/gdb order */
82 ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) ®s, 0);
83 ptrace (PT_GETFPREGS, inferior_pid, (PTRACE_ARG3_TYPE) &fpregs, 0);
85 for (r = 0; r < 31; r++)
86 memcpy (®isters[REGISTER_BYTE (r)],
87 ®s.r_regs[r], sizeof(u_int64_t));
88 for (r = 0; r < 32; r++)
89 memcpy (®isters[REGISTER_BYTE (r + FP0_REGNUM)],
90 &fpregs.fpr_regs[r], sizeof(u_int64_t));
91 memcpy (®isters[REGISTER_BYTE (PC_REGNUM)],
92 ®s.r_regs[31], sizeof(u_int64_t));
94 memset (®isters[REGISTER_BYTE (ZERO_REGNUM)], 0, sizeof(u_int64_t));
95 memset (®isters[REGISTER_BYTE (FP_REGNUM)], 0, sizeof(u_int64_t));
101 store_inferior_registers (regno)
104 struct reg regs; /* ptrace order, not gcc/gdb order */
108 for (r = 0; r < 31; r++)
109 memcpy (®s.r_regs[r],
110 ®isters[REGISTER_BYTE (r)], sizeof(u_int64_t));
111 for (r = 0; r < 32; r++)
112 memcpy (&fpregs.fpr_regs[r],
113 ®isters[REGISTER_BYTE (r + FP0_REGNUM)], sizeof(u_int64_t));
114 memcpy (®s.r_regs[31],
115 ®isters[REGISTER_BYTE (PC_REGNUM)], sizeof(u_int64_t));
117 ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) ®s, 0);
118 ptrace (PT_SETFPREGS, inferior_pid, (PTRACE_ARG3_TYPE) &fpregs, 0);
121 #ifdef HAVE_GREGSET_T
128 /* These must be ordered the same as REGISTER_NAMES in
129 config/alpha/tm-alpha.h. */
130 for (regno = 0; regno < 31; regno++)
131 supply_register (regno, (char *)&gp->r_regs[regno]);
132 supply_register (PC_REGNUM, (char *)&gp->r_regs[regno]);
134 #endif /* HAVE_GREGSET_T */
136 #ifdef HAVE_FPREGSET_T
143 for (regno = 0; regno < 32; regno++)
144 supply_register (regno + 32, (char *)&fp->fpr_regs[regno]);
146 #endif /* HAVE_FPREGSET_T */
149 * Get registers from a kernel crash dump or live kernel.
150 * Called by kvm-fbsd.c:get_kcore_registers().
152 fetch_kcore_registers (pcbp)
156 /* First clear out any garbage. */
157 memset(registers, '\0', REGISTER_BYTES);
160 *(long *) ®isters[REGISTER_BYTE (SP_REGNUM)] =
161 pcbp->pcb_hw.apcb_ksp;
164 memcpy (®isters[REGISTER_BYTE (S0_REGNUM)],
165 &pcbp->pcb_context[0], 7 * sizeof(long));
168 *(long *) ®isters[REGISTER_BYTE (PC_REGNUM)] =
169 pcbp->pcb_context[7];
171 registers_fetched ();