One more time...
[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"
23#include "signame.h"
24#include "gdbcore.h"
25
07427425
JG
26#if defined (GDB_TARGET_IS_MACH386)
27
6617b94e
JG
28#include <sys/param.h>
29#include <sys/dir.h>
30#include <sys/user.h>
31#include <signal.h>
32#include <sys/ioctl.h>
33#include <fcntl.h>
34
35#include <sys/ptrace.h>
36#include <machine/reg.h>
37
38#include <sys/file.h>
39#include <sys/stat.h>
40#include <sys/core.h>
1ab3bf1b 41
6617b94e
JG
42\f
43void
1ab3bf1b
JG
44fetch_inferior_registers (regno)
45 int regno; /* Original value discarded */
6617b94e
JG
46{
47 struct regs inferior_registers;
48 struct fp_state inferior_fp_registers;
49 extern char registers[];
50
51 registers_fetched ();
52
53 ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers);
54 ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers);
55
56 bcopy (&inferior_registers, registers, sizeof inferior_registers);
57
58 bcopy (inferior_fp_registers.f_st,&registers[REGISTER_BYTE (FP0_REGNUM)],
59 sizeof inferior_fp_registers.f_st);
60 bcopy (&inferior_fp_registers.f_ctrl,
61 &registers[REGISTER_BYTE (FPC_REGNUM)],
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
1ab3bf1b 69void
6617b94e
JG
70store_inferior_registers (regno)
71 int regno;
72{
73 struct regs inferior_registers;
74 struct fp_state inferior_fp_registers;
75 extern char registers[];
76
77 bcopy (registers, &inferior_registers, 20 * 4);
78
79 bcopy (&registers[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st,
80 sizeof inferior_fp_registers.f_st);
81 bcopy (&registers[REGISTER_BYTE (FPC_REGNUM)],
82 &inferior_fp_registers.f_ctrl,
83 sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st);
84
85#ifdef PTRACE_FP_BUG
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. */
89 {
90 int stack = inferior_registers.r_reg[SP_REGNUM];
91 int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid, 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, &inferior_registers);
96 ptrace (PTRACE_POKEDATA, inferior_pid, stack, 0xc589);
97 ptrace (PTRACE_SINGLESTEP, inferior_pid, stack, 0);
98 wait (0);
99 ptrace (PTRACE_POKEDATA, inferior_pid, stack, stuff);
100 inferior_registers.r_reg[EAX] = reg;
101 }
102#endif
103 ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers);
104 ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers);
105}
106
07427425
JG
107#else /* Not mach386 target. */
108
109/* These functions shouldn't be called when we're cross-debugging. */
110
1ab3bf1b 111/* ARGSUSED */
07427425 112void
1ab3bf1b
JG
113fetch_inferior_registers (regno)
114 int regno;
07427425
JG
115{
116}
117
118/* ARGSUSED */
1ab3bf1b 119void
07427425
JG
120store_inferior_registers (regno)
121 int regno;
122{
123}
124
125#endif /* Not mach386 target. */
126
6617b94e
JG
127/* Work with core files, for GDB. */
128
6617b94e 129void
1ab3bf1b 130fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
6617b94e
JG
131 char *core_reg_sect;
132 unsigned core_reg_size;
133 int which;
1ab3bf1b 134 unsigned int reg_addr; /* Unused in this version */
6617b94e
JG
135{
136 int val;
137 extern char registers[];
138
139 switch (which) {
140 case 0:
141 case 1:
142 bcopy (core_reg_sect, registers, core_reg_size);
143 break;
144
145 case 2:
07427425 146#ifdef FP0_REGNUM
6617b94e
JG
147 bcopy (core_reg_sect,
148 &registers[REGISTER_BYTE (FP0_REGNUM)],
149 core_reg_size); /* FIXME, probably bogus */
07427425
JG
150#endif
151#ifdef FPC_REGNUM
6617b94e
JG
152 bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl,
153 &registers[REGISTER_BYTE (FPC_REGNUM)],
154 sizeof corestr.c_fpu.f_fpstatus -
155 sizeof corestr.c_fpu.f_fpstatus.f_st);
156#endif
157 break;
158 }
159}
This page took 0.047117 seconds and 4 git commands to generate.