Change the stream argument to _filtered to GDB_FILE *.
[deliverable/binutils-gdb.git] / gdb / i386mach-nat.c
CommitLineData
a113beac
RP
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
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 <sys/stat.h>
37#include <sys/core.h>
38
39
40
41void
42fetch_inferior_registers (regno)
43 int regno; /* Original value discarded */
44{
45 struct regs inferior_registers;
46 struct fp_state inferior_fp_registers;
47 extern char registers[];
48
49 registers_fetched ();
50
51 ptrace (PTRACE_GETREGS, inferior_pid,
52 (PTRACE_ARG3_TYPE) &inferior_registers);
53 ptrace (PTRACE_GETFPREGS, inferior_pid,
54 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
55
ade40d31 56 memcpy (registers, &inferior_registers, sizeof inferior_registers);
a113beac 57
ade40d31
RP
58 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
59 inferior_fp_registers.f_st,
a113beac 60 sizeof inferior_fp_registers.f_st);
ade40d31
RP
61 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
62 &inferior_fp_registers.f_ctrl,
a113beac
RP
63 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
64}
65
66/* Store our register values back into the inferior.
67 If REGNO is -1, do this for all registers.
68 Otherwise, REGNO specifies which register (so we can save time). */
69
70void
71store_inferior_registers (regno)
72 int regno;
73{
74 struct regs inferior_registers;
75 struct fp_state inferior_fp_registers;
76 extern char registers[];
77
ade40d31 78 memcpy (&inferior_registers, registers, 20 * 4);
a113beac 79
ade40d31 80 memcpy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
a113beac 81 sizeof inferior_fp_registers.f_st);
ade40d31
RP
82 memcpy (&inferior_fp_registers.f_ctrl,
83 &registers[REGISTER_BYTE (FPC_REGNUM)],
a113beac
RP
84 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
85
86#ifdef PTRACE_FP_BUG
87 if (regno == FP_REGNUM || regno == -1)
88 /* Storing the frame pointer requires a gross hack, in which an
89 instruction that moves eax into ebp gets single-stepped. */
90 {
91 int stack = inferior_registers.r_reg[SP_REGNUM];
92 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
93 (PTRACE_ARG3_TYPE) stack);
94 int reg = inferior_registers.r_reg[EAX];
95 inferior_registers.r_reg[EAX] =
96 inferior_registers.r_reg[FP_REGNUM];
97 ptrace (PTRACE_SETREGS, inferior_pid,
98 (PTRACE_ARG3_TYPE) &inferior_registers);
99 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0xc589);
100 ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0);
101 wait (0);
102 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, stuff);
103 inferior_registers.r_reg[EAX] = reg;
104 }
105#endif
106 ptrace (PTRACE_SETREGS, inferior_pid,
107 (PTRACE_ARG3_TYPE) &inferior_registers);
108 ptrace (PTRACE_SETFPREGS, inferior_pid,
109 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
110}
111
112
113
114/* Work with core files, for GDB. */
115
116void
117fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
118 char *core_reg_sect;
119 unsigned core_reg_size;
120 int which;
121 unsigned int reg_addr; /* Unused in this version */
122{
123 int val;
124 extern char registers[];
125
126 switch (which) {
127 case 0:
128 case 1:
ade40d31 129 memcpy (registers, core_reg_sect, core_reg_size);
a113beac
RP
130 break;
131
132 case 2:
133#ifdef FP0_REGNUM
ade40d31
RP
134 memcpy (&registers[REGISTER_BYTE (FP0_REGNUM)],
135 core_reg_sect,
a113beac
RP
136 core_reg_size); /* FIXME, probably bogus */
137#endif
138#ifdef FPC_REGNUM
ade40d31
RP
139 memcpy (&registers[REGISTER_BYTE (FPC_REGNUM)],
140 &corestr.c_fpu.f_fpstatus.f_ctrl,
a113beac
RP
141 sizeof corestr.c_fpu.f_fpstatus -
142 sizeof corestr.c_fpu.f_fpstatus.f_st);
143#endif
144 break;
145 }
146}
This page took 0.07972 seconds and 4 git commands to generate.