Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native dependent code for Mach 386's for GDB, the GNU debugger. |
b6ba6518 KB |
2 | Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1995, 1996, 1999, 2000, |
3 | 2001 Free Software Foundation, Inc. | |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "inferior.h" | |
25 | #include "gdbcore.h" | |
4e052eda | 26 | #include "regcache.h" |
c906108c SS |
27 | |
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 "gdb_stat.h" | |
40 | #include <sys/core.h> | |
41 | ||
a14ed312 | 42 | static void fetch_core_registers (char *, unsigned, int, CORE_ADDR); |
c906108c SS |
43 | |
44 | void | |
5c678a12 | 45 | fetch_inferior_registers (int regno) |
c906108c SS |
46 | { |
47 | struct regs inferior_registers; | |
48 | struct fp_state inferior_fp_registers; | |
c906108c SS |
49 | |
50 | registers_fetched (); | |
51 | ||
52 | ptrace (PTRACE_GETREGS, inferior_pid, | |
c5aa993b | 53 | (PTRACE_ARG3_TYPE) & inferior_registers); |
c906108c | 54 | ptrace (PTRACE_GETFPREGS, inferior_pid, |
c5aa993b | 55 | (PTRACE_ARG3_TYPE) & inferior_fp_registers); |
c906108c SS |
56 | |
57 | memcpy (registers, &inferior_registers, sizeof inferior_registers); | |
58 | ||
59 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], | |
c5aa993b JM |
60 | inferior_fp_registers.f_st, |
61 | sizeof inferior_fp_registers.f_st); | |
c906108c | 62 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], |
c5aa993b JM |
63 | &inferior_fp_registers.f_ctrl, |
64 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st); | |
c906108c SS |
65 | } |
66 | ||
67 | /* Store our register values back into the inferior. | |
68 | If REGNO is -1, do this for all registers. | |
69 | Otherwise, REGNO specifies which register (so we can save time). */ | |
70 | ||
71 | void | |
fba45db2 | 72 | store_inferior_registers (int regno) |
c906108c SS |
73 | { |
74 | struct regs inferior_registers; | |
75 | struct fp_state inferior_fp_registers; | |
c906108c SS |
76 | |
77 | memcpy (&inferior_registers, registers, 20 * 4); | |
78 | ||
c5aa993b JM |
79 | memcpy (inferior_fp_registers.f_st, ®isters[REGISTER_BYTE (FP0_REGNUM)], |
80 | sizeof inferior_fp_registers.f_st); | |
c906108c | 81 | memcpy (&inferior_fp_registers.f_ctrl, |
c5aa993b JM |
82 | ®isters[REGISTER_BYTE (FPC_REGNUM)], |
83 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st); | |
84 | ||
c906108c SS |
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, | |
92 | (PTRACE_ARG3_TYPE) stack); | |
93 | int reg = inferior_registers.r_reg[EAX]; | |
94 | inferior_registers.r_reg[EAX] = | |
95 | inferior_registers.r_reg[FP_REGNUM]; | |
96 | ptrace (PTRACE_SETREGS, inferior_pid, | |
c5aa993b | 97 | (PTRACE_ARG3_TYPE) & inferior_registers); |
c906108c SS |
98 | ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0xc589); |
99 | ptrace (PTRACE_SINGLESTEP, inferior_pid, (PTRACE_ARG3_TYPE) stack, 0); | |
100 | wait (0); | |
101 | ptrace (PTRACE_POKEDATA, inferior_pid, (PTRACE_ARG3_TYPE) stack, stuff); | |
102 | inferior_registers.r_reg[EAX] = reg; | |
103 | } | |
104 | #endif | |
105 | ptrace (PTRACE_SETREGS, inferior_pid, | |
c5aa993b | 106 | (PTRACE_ARG3_TYPE) & inferior_registers); |
c906108c | 107 | ptrace (PTRACE_SETFPREGS, inferior_pid, |
c5aa993b | 108 | (PTRACE_ARG3_TYPE) & inferior_fp_registers); |
c906108c SS |
109 | } |
110 | ||
111 | ||
112 | ||
5c678a12 KB |
113 | /* Provide registers to GDB from a core file. |
114 | ||
115 | CORE_REG_SECT points to an array of bytes, which were obtained from | |
116 | a core file which BFD thinks might contain register contents. | |
117 | CORE_REG_SIZE is its size. | |
118 | ||
119 | WHICH says which register set corelow suspects this is: | |
120 | 0 --- the general-purpose register set | |
121 | 2 --- the floating-point register set | |
122 | ||
123 | REG_ADDR isn't used. */ | |
c906108c SS |
124 | |
125 | static void | |
5c678a12 KB |
126 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
127 | int which, CORE_ADDR reg_addr) | |
c906108c SS |
128 | { |
129 | int val; | |
c906108c | 130 | |
c5aa993b JM |
131 | switch (which) |
132 | { | |
133 | case 0: | |
134 | case 1: | |
135 | memcpy (registers, core_reg_sect, core_reg_size); | |
136 | break; | |
c906108c | 137 | |
c5aa993b | 138 | case 2: |
c5aa993b JM |
139 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], |
140 | core_reg_sect, | |
141 | core_reg_size); /* FIXME, probably bogus */ | |
c906108c | 142 | #ifdef FPC_REGNUM |
c5aa993b JM |
143 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], |
144 | &corestr.c_fpu.f_fpstatus.f_ctrl, | |
145 | sizeof corestr.c_fpu.f_fpstatus - | |
146 | sizeof corestr.c_fpu.f_fpstatus.f_st); | |
c906108c | 147 | #endif |
c5aa993b JM |
148 | break; |
149 | } | |
c906108c | 150 | } |
c906108c | 151 | \f |
c5aa993b | 152 | |
c906108c SS |
153 | /* Register that we are able to handle i386mach core file formats. |
154 | FIXME: is this really bfd_target_unknown_flavour? */ | |
155 | ||
156 | static struct core_fns i386mach_core_fns = | |
157 | { | |
2acceee2 JM |
158 | bfd_target_unknown_flavour, /* core_flavour */ |
159 | default_check_format, /* check_format */ | |
160 | default_core_sniffer, /* core_sniffer */ | |
161 | fetch_core_registers, /* core_read_registers */ | |
162 | NULL /* next */ | |
c906108c SS |
163 | }; |
164 | ||
165 | void | |
fba45db2 | 166 | _initialize_core_i386mach (void) |
c906108c SS |
167 | { |
168 | add_core_fns (&i386mach_core_fns); | |
169 | } |