SVR4 names don't have underscores, according to the ABI.
[deliverable/binutils-gdb.git] / gdb / mach386-xdep.c
CommitLineData
6617b94e
JG
1/* Machine-dependent code for host Mach 386's for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
07427425 6This program is free software; you can redistribute it and/or modify
6617b94e 7it under the terms of the GNU General Public License as published by
07427425
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
6617b94e 10
07427425 11This program is distributed in the hope that it will be useful,
6617b94e
JG
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
07427425
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6617b94e 19
6617b94e 20#include "defs.h"
6617b94e
JG
21#include "frame.h"
22#include "inferior.h"
6617b94e
JG
23#include "gdbcore.h"
24
07427425
JG
25#if defined (GDB_TARGET_IS_MACH386)
26
6617b94e
JG
27#include <sys/param.h>
28#include <sys/dir.h>
29#include <sys/user.h>
30#include <signal.h>
31#include <sys/ioctl.h>
32#include <fcntl.h>
33
34#include <sys/ptrace.h>
35#include <machine/reg.h>
36
37#include <sys/file.h>
38#include <sys/stat.h>
39#include <sys/core.h>
1ab3bf1b 40
6617b94e
JG
41\f
42void
1ab3bf1b
JG
43fetch_inferior_registers (regno)
44 int regno; /* Original value discarded */
6617b94e
JG
45{
46 struct regs inferior_registers;
47 struct fp_state inferior_fp_registers;
48 extern char registers[];
49
50 registers_fetched ();
51
e676a15f
FF
52 ptrace (PTRACE_GETREGS, inferior_pid,
53 (PTRACE_ARG3_TYPE) &inferior_registers);
54 ptrace (PTRACE_GETFPREGS, inferior_pid,
55 (PTRACE_ARG3_TYPE) &inferior_fp_registers);
6617b94e
JG
56
57 bcopy (&inferior_registers, registers, sizeof inferior_registers);
58
59 bcopy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
60 sizeof inferior_fp_registers.f_st);
61 bcopy (&inferior_fp_registers.f_ctrl,
62 &registers[REGISTER_BYTE (FPC_REGNUM)],
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
1ab3bf1b 70void
6617b94e
JG
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
78 bcopy (registers, &inferior_registers, 20 * 4);
79
80 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
81 sizeof inferior_fp_registers.f_st);
82 bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
83 &inferior_fp_registers.f_ctrl,
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];
e676a15f
FF
92 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid,
93 (PTRACE_ARG3_TYPE) stack);
6617b94e
JG
94 int reg = inferior_registers.r_reg[EAX];
95 inferior_registers.r_reg[EAX] =
96 inferior_registers.r_reg[FP_REGNUM];
e676a15f
FF
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);
6617b94e 101 wait (0);
e676a15f 102 ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, stuff);
6617b94e
JG
103 inferior_registers.r_reg[EAX] = reg;
104 }
105#endif
e676a15f
FF
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);
6617b94e
JG
110}
111
07427425
JG
112#else /* Not mach386 target. */
113
114/* These functions shouldn't be called when we're cross-debugging. */
115
1ab3bf1b 116/* ARGSUSED */
07427425 117void
1ab3bf1b
JG
118fetch_inferior_registers (regno)
119 int regno;
07427425
JG
120{
121}
122
123/* ARGSUSED */
1ab3bf1b 124void
07427425
JG
125store_inferior_registers (regno)
126 int regno;
127{
128}
129
130#endif /* Not mach386 target. */
131
6617b94e
JG
132/* Work with core files, for GDB. */
133
6617b94e 134void
1ab3bf1b 135fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
6617b94e
JG
136 char *core_reg_sect;
137 unsigned core_reg_size;
138 int which;
1ab3bf1b 139 unsigned int reg_addr; /* Unused in this version */
6617b94e
JG
140{
141 int val;
142 extern char registers[];
143
144 switch (which) {
145 case 0:
146 case 1:
147 bcopy (core_reg_sect, registers, core_reg_size);
148 break;
149
150 case 2:
07427425 151#ifdef FP0_REGNUM
6617b94e
JG
152 bcopy (core_reg_sect,
153 &registers[REGISTER_BYTE (FP0_REGNUM)],
154 core_reg_size); /* FIXME, probably bogus */
07427425
JG
155#endif
156#ifdef FPC_REGNUM
6617b94e
JG
157 bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl,
158 &registers[REGISTER_BYTE (FPC_REGNUM)],
159 sizeof corestr.c_fpu.f_fpstatus -
160 sizeof corestr.c_fpu.f_fpstatus.f_st);
161#endif
162 break;
163 }
164}
This page took 0.064299 seconds and 4 git commands to generate.