Commit | Line | Data |
---|---|---|
c906108c SS |
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 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
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. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "frame.h" | |
23 | #include "inferior.h" | |
24 | #include "gdbcore.h" | |
25 | ||
26 | #include <sys/param.h> | |
27 | #include <sys/dir.h> | |
28 | #include <sys/user.h> | |
29 | #include <signal.h> | |
30 | #include <sys/ioctl.h> | |
31 | #include <fcntl.h> | |
32 | ||
33 | #include <sys/ptrace.h> | |
34 | #include <machine/reg.h> | |
35 | ||
36 | #include <sys/file.h> | |
37 | #include "gdb_stat.h" | |
38 | #include <sys/core.h> | |
39 | ||
a14ed312 | 40 | static void fetch_core_registers (char *, unsigned, int, CORE_ADDR); |
c906108c SS |
41 | |
42 | void | |
43 | fetch_inferior_registers (regno) | |
c5aa993b | 44 | int regno; /* Original value discarded */ |
c906108c SS |
45 | { |
46 | struct regs inferior_registers; | |
47 | struct fp_state inferior_fp_registers; | |
c906108c SS |
48 | |
49 | registers_fetched (); | |
50 | ||
51 | ptrace (PTRACE_GETREGS, inferior_pid, | |
c5aa993b | 52 | (PTRACE_ARG3_TYPE) & inferior_registers); |
c906108c | 53 | ptrace (PTRACE_GETFPREGS, inferior_pid, |
c5aa993b | 54 | (PTRACE_ARG3_TYPE) & inferior_fp_registers); |
c906108c SS |
55 | |
56 | memcpy (registers, &inferior_registers, sizeof inferior_registers); | |
57 | ||
58 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], | |
c5aa993b JM |
59 | inferior_fp_registers.f_st, |
60 | sizeof inferior_fp_registers.f_st); | |
c906108c | 61 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], |
c5aa993b JM |
62 | &inferior_fp_registers.f_ctrl, |
63 | sizeof inferior_fp_registers - sizeof inferior_fp_registers.f_st); | |
c906108c SS |
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 | ||
70 | void | |
71 | store_inferior_registers (regno) | |
72 | int regno; | |
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 | ||
113 | /* Work with core files, for GDB. */ | |
114 | ||
115 | static void | |
116 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) | |
117 | char *core_reg_sect; | |
118 | unsigned core_reg_size; | |
119 | int which; | |
120 | CORE_ADDR reg_addr; /* Unused in this version */ | |
121 | { | |
122 | int val; | |
c906108c | 123 | |
c5aa993b JM |
124 | switch (which) |
125 | { | |
126 | case 0: | |
127 | case 1: | |
128 | memcpy (registers, core_reg_sect, core_reg_size); | |
129 | break; | |
c906108c | 130 | |
c5aa993b | 131 | case 2: |
c5aa993b JM |
132 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], |
133 | core_reg_sect, | |
134 | core_reg_size); /* FIXME, probably bogus */ | |
c906108c | 135 | #ifdef FPC_REGNUM |
c5aa993b JM |
136 | memcpy (®isters[REGISTER_BYTE (FPC_REGNUM)], |
137 | &corestr.c_fpu.f_fpstatus.f_ctrl, | |
138 | sizeof corestr.c_fpu.f_fpstatus - | |
139 | sizeof corestr.c_fpu.f_fpstatus.f_st); | |
c906108c | 140 | #endif |
c5aa993b JM |
141 | break; |
142 | } | |
c906108c | 143 | } |
c906108c | 144 | \f |
c5aa993b | 145 | |
c906108c SS |
146 | /* Register that we are able to handle i386mach core file formats. |
147 | FIXME: is this really bfd_target_unknown_flavour? */ | |
148 | ||
149 | static struct core_fns i386mach_core_fns = | |
150 | { | |
2acceee2 JM |
151 | bfd_target_unknown_flavour, /* core_flavour */ |
152 | default_check_format, /* check_format */ | |
153 | default_core_sniffer, /* core_sniffer */ | |
154 | fetch_core_registers, /* core_read_registers */ | |
155 | NULL /* next */ | |
c906108c SS |
156 | }; |
157 | ||
158 | void | |
159 | _initialize_core_i386mach () | |
160 | { | |
161 | add_core_fns (&i386mach_core_fns); | |
162 | } |