1 /* Native dependent code for Mach 386's for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1995, 1996, 1999, 2000,
3 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include <sys/param.h>
32 #include <sys/ioctl.h>
35 #include <sys/ptrace.h>
36 #include <machine/reg.h>
42 static void fetch_core_registers (char *, unsigned, int, CORE_ADDR);
45 fetch_inferior_registers (int regno)
47 struct regs inferior_registers;
48 struct fp_state inferior_fp_registers;
52 ptrace (PTRACE_GETREGS, PIDGET (inferior_ptid),
53 (PTRACE_ARG3_TYPE) & inferior_registers);
54 ptrace (PTRACE_GETFPREGS, PIDGET (inferior_ptid),
55 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
57 memcpy (registers, &inferior_registers, sizeof inferior_registers);
59 memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)],
60 inferior_fp_registers.f_st,
61 sizeof inferior_fp_registers.f_st);
62 memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
63 &inferior_fp_registers.f_ctrl,
64 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
67 /* Store our register values back into the inferior.
68 If REGNO is -1, do this for all registers.
69 Otherwise, REGNO specifies which register (so we can save time). */
72 store_inferior_registers (int regno)
74 struct regs inferior_registers;
75 struct fp_state inferior_fp_registers;
77 memcpy (&inferior_registers, registers, 20 * 4);
79 memcpy (inferior_fp_registers.f_st, ®isters[REGISTER_BYTE (FP0_REGNUM)],
80 sizeof inferior_fp_registers.f_st);
81 memcpy (&inferior_fp_registers.f_ctrl,
82 ®isters[REGISTER_BYTE (FPC_REGNUM)],
83 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
86 if (regno == FP_REGNUM || regno == -1)
87 /* Storing the frame pointer requires a gross hack, in which an
88 instruction that moves eax into ebp gets single-stepped. */
90 int stack = inferior_registers.r_reg[SP_REGNUM];
91 int stuff = ptrace (PTRACE_PEEKDATA, PIDGET (inferior_ptid),
92 (PTRACE_ARG3_TYPE) stack);
93 int reg = inferior_registers.r_reg[EAX];
94 inferior_registers.r_reg[EAX] =
95 inferior_registers.r_reg[FP_REGNUM];
96 ptrace (PTRACE_SETREGS, PIDGET (inferior_ptid),
97 (PTRACE_ARG3_TYPE) & inferior_registers);
98 ptrace (PTRACE_POKEDATA, PIDGET (inferior_ptid),
99 (PTRACE_ARG3_TYPE) stack, 0xc589);
100 ptrace (PTRACE_SINGLESTEP, PIDGET (inferior_ptid),
101 (PTRACE_ARG3_TYPE) stack, 0);
103 ptrace (PTRACE_POKEDATA, PIDGET (inferior_ptid),
104 (PTRACE_ARG3_TYPE) stack, stuff);
105 inferior_registers.r_reg[EAX] = reg;
108 ptrace (PTRACE_SETREGS, PIDGET (inferior_ptid),
109 (PTRACE_ARG3_TYPE) & inferior_registers);
110 ptrace (PTRACE_SETFPREGS, PIDGET (inferior_ptid),
111 (PTRACE_ARG3_TYPE) & inferior_fp_registers);
116 /* Provide registers to GDB from a core file.
118 CORE_REG_SECT points to an array of bytes, which were obtained from
119 a core file which BFD thinks might contain register contents.
120 CORE_REG_SIZE is its size.
122 WHICH says which register set corelow suspects this is:
123 0 --- the general-purpose register set
124 2 --- the floating-point register set
126 REG_ADDR isn't used. */
129 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
130 int which, CORE_ADDR reg_addr)
138 memcpy (registers, core_reg_sect, core_reg_size);
142 memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)],
144 core_reg_size); /* FIXME, probably bogus */
146 memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)],
147 &corestr.c_fpu.f_fpstatus.f_ctrl,
148 sizeof corestr.c_fpu.f_fpstatus -
149 sizeof corestr.c_fpu.f_fpstatus.f_st);
156 /* Register that we are able to handle i386mach core file formats.
157 FIXME: is this really bfd_target_unknown_flavour? */
159 static struct core_fns i386mach_core_fns =
161 bfd_target_unknown_flavour, /* core_flavour */
162 default_check_format, /* check_format */
163 default_core_sniffer, /* core_sniffer */
164 fetch_core_registers, /* core_read_registers */
169 _initialize_core_i386mach (void)
171 add_core_fns (&i386mach_core_fns);