import gdb-19990422 snapshot
[deliverable/binutils-gdb.git] / gdb / i386mach-nat.c
1 /* Native dependent code for Mach 386's for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "gdbcore.h"
24
25 #include <sys/param.h>
26 #include <sys/dir.h>
27 #include <sys/user.h>
28 #include <signal.h>
29 #include <sys/ioctl.h>
30 #include <fcntl.h>
31
32 #include <sys/ptrace.h>
33 #include <machine/reg.h>
34
35 #include <sys/file.h>
36 #include "gdb_stat.h"
37 #include <sys/core.h>
38
39 static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
40
41 void
42 fetch_inferior_registers (regno)
43 int regno; /* Original value discarded */
44 {
45 struct regs inferior_registers;
46 struct fp_state inferior_fp_registers;
47
48 registers_fetched ();
49
50 ptrace (PTRACE_GETREGS, inferior_pid,
51 (PTRACE_ARG3_TYPE) &inferior_registers);
52 ptrace (PTRACE_GETFPREGS, inferior_pid,
53 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
54
55 memcpy (registers, &inferior_registers, sizeof inferior_registers);
56
57 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
58 inferior_fp_registers.f_st,
59 sizeof inferior_fp_registers.f_st);
60 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
61 &inferior_fp_registers.f_ctrl,
62 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
63 }
64
65 /* Store our register values back into the inferior.
66 If REGNO is -1, do this for all registers.
67 Otherwise, REGNO specifies which register (so we can save time). */
68
69 void
70 store_inferior_registers (regno)
71 int regno;
72 {
73 struct regs inferior_registers;
74 struct fp_state inferior_fp_registers;
75
76 memcpy (&inferior_registers, registers, 20 * 4);
77
78 memcpy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
79 sizeof inferior_fp_registers.f_st);
80 memcpy (&inferior_fp_registers.f_ctrl,
81 &registers[REGISTER_BYTE (FPC_REGNUM)],
82 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
83
84 #ifdef PTRACE_FP_BUG
85 if (regno == FP_REGNUM || regno == -1)
86 /* Storing the frame pointer requires a gross hack, in which an
87 instruction that moves eax into ebp gets single-stepped. */
88 {
89 int stack = inferior_registers.r_reg[SP_REGNUM];
90 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
91 (PTRACE_ARG3_TYPE) stack);
92 int reg = inferior_registers.r_reg[EAX];
93 inferior_registers.r_reg[EAX] =
94 inferior_registers.r_reg[FP_REGNUM];
95 ptrace (PTRACE_SETREGS, inferior_pid,
96 (PTRACE_ARG3_TYPE) &inferior_registers);
97 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0xc589);
98 ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0);
99 wait (0);
100 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, stuff);
101 inferior_registers.r_reg[EAX] = reg;
102 }
103 #endif
104 ptrace (PTRACE_SETREGS, inferior_pid,
105 (PTRACE_ARG3_TYPE) &inferior_registers);
106 ptrace (PTRACE_SETFPREGS, inferior_pid,
107 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
108 }
109
110
111
112 /* Work with core files, for GDB. */
113
114 static void
115 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
116 char *core_reg_sect;
117 unsigned core_reg_size;
118 int which;
119 CORE_ADDR reg_addr; /* Unused in this version */
120 {
121 int val;
122
123 switch (which) {
124 case 0:
125 case 1:
126 memcpy (registers, core_reg_sect, core_reg_size);
127 break;
128
129 case 2:
130 #ifdef FP0_REGNUM
131 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
132 core_reg_sect,
133 core_reg_size); /* FIXME, probably bogus */
134 #endif
135 #ifdef FPC_REGNUM
136 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
137 &corestr.c_fpu.f_fpstatus.f_ctrl,
138 sizeof corestr.c_fpu.f_fpstatus -
139 sizeof corestr.c_fpu.f_fpstatus.f_st);
140 #endif
141 break;
142 }
143 }
144
145 \f
146 /* Register that we are able to handle i386mach core file formats.
147 FIXME: is this really bfd_target_unknown_flavour? */
148
149 static struct core_fns i386mach_core_fns =
150 {
151 bfd_target_unknown_flavour,
152 fetch_core_registers,
153 NULL
154 };
155
156 void
157 _initialize_core_i386mach ()
158 {
159 add_core_fns (&i386mach_core_fns);
160 }
This page took 0.03424 seconds and 4 git commands to generate.