]>
Commit | Line | Data |
---|---|---|
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 | ||
4 | This file is part of GDB. | |
5 | ||
07427425 | 6 | This program is free software; you can redistribute it and/or modify |
6617b94e | 7 | it under the terms of the GNU General Public License as published by |
07427425 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
6617b94e | 10 | |
07427425 | 11 | This program is distributed in the hope that it will be useful, |
6617b94e JG |
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 | |
07427425 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
6617b94e JG |
19 | |
20 | #include <stdio.h> | |
21 | #include "defs.h" | |
6617b94e JG |
22 | #include "frame.h" |
23 | #include "inferior.h" | |
24 | #include "signame.h" | |
25 | #include "gdbcore.h" | |
26 | ||
07427425 JG |
27 | #if defined (GDB_TARGET_IS_MACH386) |
28 | ||
6617b94e JG |
29 | #include <sys/param.h> |
30 | #include <sys/dir.h> | |
31 | #include <sys/user.h> | |
32 | #include <signal.h> | |
33 | #include <sys/ioctl.h> | |
34 | #include <fcntl.h> | |
35 | ||
36 | #include <sys/ptrace.h> | |
37 | #include <machine/reg.h> | |
38 | ||
39 | #include <sys/file.h> | |
40 | #include <sys/stat.h> | |
41 | #include <sys/core.h> | |
42 | \f | |
43 | void | |
44 | fetch_inferior_registers () | |
45 | { | |
46 | struct regs inferior_registers; | |
47 | struct fp_state inferior_fp_registers; | |
48 | extern char registers[]; | |
49 | ||
50 | registers_fetched (); | |
51 | ||
52 | ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers); | |
53 | ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers); | |
54 | ||
55 | bcopy (&inferior_registers, registers, sizeof inferior_registers); | |
56 | ||
57 | bcopy (inferior_fp_registers.f_st,®isters[REGISTER_BYTE (FP0_REGNUM)], | |
58 | sizeof inferior_fp_registers.f_st); | |
59 | bcopy (&inferior_fp_registers.f_ctrl, | |
60 | ®isters[REGISTER_BYTE (FPC_REGNUM)], | |
61 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st); | |
62 | } | |
63 | ||
64 | /* Store our register values back into the inferior. | |
65 | If REGNO is -1, do this for all registers. | |
66 | Otherwise, REGNO specifies which register (so we can save time). */ | |
67 | ||
68 | store_inferior_registers (regno) | |
69 | int regno; | |
70 | { | |
71 | struct regs inferior_registers; | |
72 | struct fp_state inferior_fp_registers; | |
73 | extern char registers[]; | |
74 | ||
75 | bcopy (registers, &inferior_registers, 20 * 4); | |
76 | ||
77 | bcopy (®isters[REGISTER_BYTE (FP0_REGNUM)],inferior_fp_registers.f_st, | |
78 | sizeof inferior_fp_registers.f_st); | |
79 | bcopy (®isters[REGISTER_BYTE (FPC_REGNUM)], | |
80 | &inferior_fp_registers.f_ctrl, | |
81 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st); | |
82 | ||
83 | #ifdef PTRACE_FP_BUG | |
84 | if (regno == FP_REGNUM || regno == -1) | |
85 | /* Storing the frame pointer requires a gross hack, in which an | |
86 | instruction that moves eax into ebp gets single-stepped. */ | |
87 | { | |
88 | int stack = inferior_registers.r_reg[SP_REGNUM]; | |
89 | int stuff = ptrace (PTRACE_PEEKDATA, inferior_pid, stack); | |
90 | int reg = inferior_registers.r_reg[EAX]; | |
91 | inferior_registers.r_reg[EAX] = | |
92 | inferior_registers.r_reg[FP_REGNUM]; | |
93 | ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers); | |
94 | ptrace (PTRACE_POKEDATA, inferior_pid, stack, 0xc589); | |
95 | ptrace (PTRACE_SINGLESTEP, inferior_pid, stack, 0); | |
96 | wait (0); | |
97 | ptrace (PTRACE_POKEDATA, inferior_pid, stack, stuff); | |
98 | inferior_registers.r_reg[EAX] = reg; | |
99 | } | |
100 | #endif | |
101 | ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers); | |
102 | ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers); | |
103 | } | |
104 | ||
07427425 JG |
105 | #else /* Not mach386 target. */ |
106 | ||
107 | /* These functions shouldn't be called when we're cross-debugging. */ | |
108 | ||
109 | void | |
110 | fetch_inferior_registers () | |
111 | { | |
112 | } | |
113 | ||
114 | /* ARGSUSED */ | |
115 | store_inferior_registers (regno) | |
116 | int regno; | |
117 | { | |
118 | } | |
119 | ||
120 | #endif /* Not mach386 target. */ | |
121 | ||
6617b94e JG |
122 | /* Work with core files, for GDB. */ |
123 | ||
6617b94e JG |
124 | void |
125 | fetch_core_registers (core_reg_sect, core_reg_size, which) | |
126 | char *core_reg_sect; | |
127 | unsigned core_reg_size; | |
128 | int which; | |
129 | { | |
130 | int val; | |
131 | extern char registers[]; | |
132 | ||
133 | switch (which) { | |
134 | case 0: | |
135 | case 1: | |
136 | bcopy (core_reg_sect, registers, core_reg_size); | |
137 | break; | |
138 | ||
139 | case 2: | |
07427425 | 140 | #ifdef FP0_REGNUM |
6617b94e JG |
141 | bcopy (core_reg_sect, |
142 | ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
143 | core_reg_size); /* FIXME, probably bogus */ | |
07427425 JG |
144 | #endif |
145 | #ifdef FPC_REGNUM | |
6617b94e JG |
146 | bcopy (&corestr.c_fpu.f_fpstatus.f_ctrl, |
147 | ®isters[REGISTER_BYTE (FPC_REGNUM)], | |
148 | sizeof corestr.c_fpu.f_fpstatus - | |
149 | sizeof corestr.c_fpu.f_fpstatus.f_st); | |
150 | #endif | |
151 | break; | |
152 | } | |
153 | } |