]>
Commit | Line | Data |
---|---|---|
5f04ac3d | 1 | /* Native-dependent code for NetBSD/i386, for GDB. |
b6ba6518 KB |
2 | Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001 |
3 | Free Software Foundation, Inc. | |
5f04ac3d C |
4 | |
5 | This file is part of GDB. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include <sys/types.h> | |
24 | #include <sys/ptrace.h> | |
25 | #include <machine/reg.h> | |
26 | #include <machine/frame.h> | |
27 | #include "inferior.h" | |
28 | #include "gdbcore.h" /* for registers_fetched() */ | |
4e052eda | 29 | #include "regcache.h" |
5f04ac3d C |
30 | |
31 | #define RF(dst, src) \ | |
32 | memcpy(®isters[REGISTER_BYTE(dst)], &src, sizeof(src)) | |
33 | ||
34 | #define RS(src, dst) \ | |
35 | memcpy(&dst, ®isters[REGISTER_BYTE(src)], sizeof(dst)) | |
36 | ||
37 | struct env387 | |
38 | { | |
39 | unsigned short control; | |
40 | unsigned short r0; | |
41 | unsigned short status; | |
42 | unsigned short r1; | |
43 | unsigned short tag; | |
44 | unsigned short r2; | |
45 | unsigned long eip; | |
46 | unsigned short code_seg; | |
47 | unsigned short opcode; | |
48 | unsigned long operand; | |
49 | unsigned short operand_seg; | |
50 | unsigned short r3; | |
51 | unsigned char regs[8][10]; | |
52 | }; | |
53 | ||
54 | void | |
fba45db2 | 55 | fetch_inferior_registers (int regno) |
5f04ac3d C |
56 | { |
57 | struct reg inferior_registers; | |
58 | struct env387 inferior_fpregisters; | |
59 | ||
60 | ptrace (PT_GETREGS, inferior_pid, | |
61 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); | |
62 | ptrace (PT_GETFPREGS, inferior_pid, | |
63 | (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0); | |
64 | ||
65 | RF ( 0, inferior_registers.r_eax); | |
66 | RF ( 1, inferior_registers.r_ecx); | |
67 | RF ( 2, inferior_registers.r_edx); | |
68 | RF ( 3, inferior_registers.r_ebx); | |
69 | RF ( 4, inferior_registers.r_esp); | |
70 | RF ( 5, inferior_registers.r_ebp); | |
71 | RF ( 6, inferior_registers.r_esi); | |
72 | RF ( 7, inferior_registers.r_edi); | |
73 | RF ( 8, inferior_registers.r_eip); | |
74 | RF ( 9, inferior_registers.r_eflags); | |
75 | RF (10, inferior_registers.r_cs); | |
76 | RF (11, inferior_registers.r_ss); | |
77 | RF (12, inferior_registers.r_ds); | |
78 | RF (13, inferior_registers.r_es); | |
79 | RF (14, inferior_registers.r_fs); | |
80 | RF (15, inferior_registers.r_gs); | |
81 | ||
82 | RF (FP0_REGNUM, inferior_fpregisters.regs[0]); | |
83 | RF (FP0_REGNUM + 1, inferior_fpregisters.regs[1]); | |
84 | RF (FP0_REGNUM + 2, inferior_fpregisters.regs[2]); | |
85 | RF (FP0_REGNUM + 3, inferior_fpregisters.regs[3]); | |
86 | RF (FP0_REGNUM + 4, inferior_fpregisters.regs[4]); | |
87 | RF (FP0_REGNUM + 5, inferior_fpregisters.regs[5]); | |
88 | RF (FP0_REGNUM + 6, inferior_fpregisters.regs[6]); | |
89 | RF (FP0_REGNUM + 7, inferior_fpregisters.regs[7]); | |
90 | ||
91 | RF (FCTRL_REGNUM, inferior_fpregisters.control); | |
92 | RF (FSTAT_REGNUM, inferior_fpregisters.status); | |
93 | RF (FTAG_REGNUM, inferior_fpregisters.tag); | |
94 | RF (FCS_REGNUM, inferior_fpregisters.code_seg); | |
95 | RF (FCOFF_REGNUM, inferior_fpregisters.eip); | |
96 | RF (FDS_REGNUM, inferior_fpregisters.operand_seg); | |
97 | RF (FDOFF_REGNUM, inferior_fpregisters.operand); | |
98 | RF (FOP_REGNUM, inferior_fpregisters.opcode); | |
99 | ||
100 | registers_fetched (); | |
101 | } | |
102 | ||
103 | void | |
fba45db2 | 104 | store_inferior_registers (int regno) |
5f04ac3d C |
105 | { |
106 | struct reg inferior_registers; | |
107 | struct env387 inferior_fpregisters; | |
108 | ||
109 | RS ( 0, inferior_registers.r_eax); | |
110 | RS ( 1, inferior_registers.r_ecx); | |
111 | RS ( 2, inferior_registers.r_edx); | |
112 | RS ( 3, inferior_registers.r_ebx); | |
113 | RS ( 4, inferior_registers.r_esp); | |
114 | RS ( 5, inferior_registers.r_ebp); | |
115 | RS ( 6, inferior_registers.r_esi); | |
116 | RS ( 7, inferior_registers.r_edi); | |
117 | RS ( 8, inferior_registers.r_eip); | |
118 | RS ( 9, inferior_registers.r_eflags); | |
119 | RS (10, inferior_registers.r_cs); | |
120 | RS (11, inferior_registers.r_ss); | |
121 | RS (12, inferior_registers.r_ds); | |
122 | RS (13, inferior_registers.r_es); | |
123 | RS (14, inferior_registers.r_fs); | |
124 | RS (15, inferior_registers.r_gs); | |
125 | ||
126 | ||
127 | RS (FP0_REGNUM, inferior_fpregisters.regs[0]); | |
128 | RS (FP0_REGNUM + 1, inferior_fpregisters.regs[1]); | |
129 | RS (FP0_REGNUM + 2, inferior_fpregisters.regs[2]); | |
130 | RS (FP0_REGNUM + 3, inferior_fpregisters.regs[3]); | |
131 | RS (FP0_REGNUM + 4, inferior_fpregisters.regs[4]); | |
132 | RS (FP0_REGNUM + 5, inferior_fpregisters.regs[5]); | |
133 | RS (FP0_REGNUM + 6, inferior_fpregisters.regs[6]); | |
134 | RS (FP0_REGNUM + 7, inferior_fpregisters.regs[7]); | |
135 | ||
136 | RS (FCTRL_REGNUM, inferior_fpregisters.control); | |
137 | RS (FSTAT_REGNUM, inferior_fpregisters.status); | |
138 | RS (FTAG_REGNUM, inferior_fpregisters.tag); | |
139 | RS (FCS_REGNUM, inferior_fpregisters.code_seg); | |
140 | RS (FCOFF_REGNUM, inferior_fpregisters.eip); | |
141 | RS (FDS_REGNUM, inferior_fpregisters.operand_seg); | |
142 | RS (FDOFF_REGNUM, inferior_fpregisters.operand); | |
143 | RS (FOP_REGNUM, inferior_fpregisters.opcode); | |
144 | ||
145 | ptrace (PT_SETREGS, inferior_pid, | |
146 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); | |
147 | ptrace (PT_SETFPREGS, inferior_pid, | |
148 | (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0); | |
149 | } | |
76a22209 | 150 | \f |
5f04ac3d C |
151 | struct md_core |
152 | { | |
153 | struct reg intreg; | |
76a22209 | 154 | struct env387 freg; |
5f04ac3d C |
155 | }; |
156 | ||
eafd4536 | 157 | static void |
fba45db2 KB |
158 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which, |
159 | CORE_ADDR ignore) | |
5f04ac3d C |
160 | { |
161 | struct md_core *core_reg = (struct md_core *) core_reg_sect; | |
162 | ||
163 | /* integer registers */ | |
164 | memcpy (®isters[REGISTER_BYTE (0)], &core_reg->intreg, | |
165 | sizeof (struct reg)); | |
76a22209 | 166 | |
5f04ac3d | 167 | /* floating point registers */ |
76a22209 C |
168 | RF (FP0_REGNUM, core_reg->freg.regs[0]); |
169 | RF (FP0_REGNUM + 1, core_reg->freg.regs[1]); | |
170 | RF (FP0_REGNUM + 2, core_reg->freg.regs[2]); | |
171 | RF (FP0_REGNUM + 3, core_reg->freg.regs[3]); | |
172 | RF (FP0_REGNUM + 4, core_reg->freg.regs[4]); | |
173 | RF (FP0_REGNUM + 5, core_reg->freg.regs[5]); | |
174 | RF (FP0_REGNUM + 6, core_reg->freg.regs[6]); | |
175 | RF (FP0_REGNUM + 7, core_reg->freg.regs[7]); | |
176 | ||
177 | RF (FCTRL_REGNUM, core_reg->freg.control); | |
178 | RF (FSTAT_REGNUM, core_reg->freg.status); | |
179 | RF (FTAG_REGNUM, core_reg->freg.tag); | |
180 | RF (FCS_REGNUM, core_reg->freg.code_seg); | |
181 | RF (FCOFF_REGNUM, core_reg->freg.eip); | |
182 | RF (FDS_REGNUM, core_reg->freg.operand_seg); | |
183 | RF (FDOFF_REGNUM, core_reg->freg.operand); | |
184 | RF (FOP_REGNUM, core_reg->freg.opcode); | |
185 | ||
186 | registers_fetched (); | |
187 | } | |
188 | ||
189 | /* Register that we are able to handle i386nbsd core file formats. | |
190 | FIXME: is this really bfd_target_unknown_flavour? */ | |
191 | ||
192 | static struct core_fns i386nbsd_core_fns = | |
193 | { | |
194 | bfd_target_unknown_flavour, /* core_flavour */ | |
195 | default_check_format, /* check_format */ | |
196 | default_core_sniffer, /* core_sniffer */ | |
197 | fetch_core_registers, /* core_read_registers */ | |
198 | NULL /* next */ | |
199 | }; | |
200 | ||
201 | void | |
fba45db2 | 202 | _initialize_i386nbsd_nat (void) |
76a22209 C |
203 | { |
204 | add_core_fns (&i386nbsd_core_fns); | |
5f04ac3d | 205 | } |