1 /* Native-dependent code for NetBSD/i386, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
23 #include <sys/types.h>
24 #include <sys/ptrace.h>
25 #include <machine/reg.h>
26 #include <machine/frame.h>
28 #include "gdbcore.h" /* for registers_fetched() */
30 #define RF(dst, src) \
31 memcpy(®isters[REGISTER_BYTE(dst)], &src, sizeof(src))
33 #define RS(src, dst) \
34 memcpy(&dst, ®isters[REGISTER_BYTE(src)], sizeof(dst))
38 unsigned short control;
40 unsigned short status;
45 unsigned short code_seg;
46 unsigned short opcode;
47 unsigned long operand;
48 unsigned short operand_seg;
50 unsigned char regs[8][10];
54 fetch_inferior_registers (int regno)
56 struct reg inferior_registers;
57 struct env387 inferior_fpregisters;
59 ptrace (PT_GETREGS, inferior_pid,
60 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
61 ptrace (PT_GETFPREGS, inferior_pid,
62 (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0);
64 RF ( 0, inferior_registers.r_eax);
65 RF ( 1, inferior_registers.r_ecx);
66 RF ( 2, inferior_registers.r_edx);
67 RF ( 3, inferior_registers.r_ebx);
68 RF ( 4, inferior_registers.r_esp);
69 RF ( 5, inferior_registers.r_ebp);
70 RF ( 6, inferior_registers.r_esi);
71 RF ( 7, inferior_registers.r_edi);
72 RF ( 8, inferior_registers.r_eip);
73 RF ( 9, inferior_registers.r_eflags);
74 RF (10, inferior_registers.r_cs);
75 RF (11, inferior_registers.r_ss);
76 RF (12, inferior_registers.r_ds);
77 RF (13, inferior_registers.r_es);
78 RF (14, inferior_registers.r_fs);
79 RF (15, inferior_registers.r_gs);
81 RF (FP0_REGNUM, inferior_fpregisters.regs[0]);
82 RF (FP0_REGNUM + 1, inferior_fpregisters.regs[1]);
83 RF (FP0_REGNUM + 2, inferior_fpregisters.regs[2]);
84 RF (FP0_REGNUM + 3, inferior_fpregisters.regs[3]);
85 RF (FP0_REGNUM + 4, inferior_fpregisters.regs[4]);
86 RF (FP0_REGNUM + 5, inferior_fpregisters.regs[5]);
87 RF (FP0_REGNUM + 6, inferior_fpregisters.regs[6]);
88 RF (FP0_REGNUM + 7, inferior_fpregisters.regs[7]);
90 RF (FCTRL_REGNUM, inferior_fpregisters.control);
91 RF (FSTAT_REGNUM, inferior_fpregisters.status);
92 RF (FTAG_REGNUM, inferior_fpregisters.tag);
93 RF (FCS_REGNUM, inferior_fpregisters.code_seg);
94 RF (FCOFF_REGNUM, inferior_fpregisters.eip);
95 RF (FDS_REGNUM, inferior_fpregisters.operand_seg);
96 RF (FDOFF_REGNUM, inferior_fpregisters.operand);
97 RF (FOP_REGNUM, inferior_fpregisters.opcode);
103 store_inferior_registers (int regno)
105 struct reg inferior_registers;
106 struct env387 inferior_fpregisters;
108 RS ( 0, inferior_registers.r_eax);
109 RS ( 1, inferior_registers.r_ecx);
110 RS ( 2, inferior_registers.r_edx);
111 RS ( 3, inferior_registers.r_ebx);
112 RS ( 4, inferior_registers.r_esp);
113 RS ( 5, inferior_registers.r_ebp);
114 RS ( 6, inferior_registers.r_esi);
115 RS ( 7, inferior_registers.r_edi);
116 RS ( 8, inferior_registers.r_eip);
117 RS ( 9, inferior_registers.r_eflags);
118 RS (10, inferior_registers.r_cs);
119 RS (11, inferior_registers.r_ss);
120 RS (12, inferior_registers.r_ds);
121 RS (13, inferior_registers.r_es);
122 RS (14, inferior_registers.r_fs);
123 RS (15, inferior_registers.r_gs);
126 RS (FP0_REGNUM, inferior_fpregisters.regs[0]);
127 RS (FP0_REGNUM + 1, inferior_fpregisters.regs[1]);
128 RS (FP0_REGNUM + 2, inferior_fpregisters.regs[2]);
129 RS (FP0_REGNUM + 3, inferior_fpregisters.regs[3]);
130 RS (FP0_REGNUM + 4, inferior_fpregisters.regs[4]);
131 RS (FP0_REGNUM + 5, inferior_fpregisters.regs[5]);
132 RS (FP0_REGNUM + 6, inferior_fpregisters.regs[6]);
133 RS (FP0_REGNUM + 7, inferior_fpregisters.regs[7]);
135 RS (FCTRL_REGNUM, inferior_fpregisters.control);
136 RS (FSTAT_REGNUM, inferior_fpregisters.status);
137 RS (FTAG_REGNUM, inferior_fpregisters.tag);
138 RS (FCS_REGNUM, inferior_fpregisters.code_seg);
139 RS (FCOFF_REGNUM, inferior_fpregisters.eip);
140 RS (FDS_REGNUM, inferior_fpregisters.operand_seg);
141 RS (FDOFF_REGNUM, inferior_fpregisters.operand);
142 RS (FOP_REGNUM, inferior_fpregisters.opcode);
144 ptrace (PT_SETREGS, inferior_pid,
145 (PTRACE_ARG3_TYPE) &inferior_registers, 0);
146 ptrace (PT_SETFPREGS, inferior_pid,
147 (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0);
151 i386nbsd_use_struct_convention (int gcc_p, struct type *type)
153 return !(TYPE_LENGTH (type) == 1
154 || TYPE_LENGTH (type) == 2
155 || TYPE_LENGTH (type) == 4
156 || TYPE_LENGTH (type) == 8);
166 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
169 struct md_core *core_reg = (struct md_core *) core_reg_sect;
171 /* integer registers */
172 memcpy (®isters[REGISTER_BYTE (0)], &core_reg->intreg,
173 sizeof (struct reg));
175 /* floating point registers */
176 RF (FP0_REGNUM, core_reg->freg.regs[0]);
177 RF (FP0_REGNUM + 1, core_reg->freg.regs[1]);
178 RF (FP0_REGNUM + 2, core_reg->freg.regs[2]);
179 RF (FP0_REGNUM + 3, core_reg->freg.regs[3]);
180 RF (FP0_REGNUM + 4, core_reg->freg.regs[4]);
181 RF (FP0_REGNUM + 5, core_reg->freg.regs[5]);
182 RF (FP0_REGNUM + 6, core_reg->freg.regs[6]);
183 RF (FP0_REGNUM + 7, core_reg->freg.regs[7]);
185 RF (FCTRL_REGNUM, core_reg->freg.control);
186 RF (FSTAT_REGNUM, core_reg->freg.status);
187 RF (FTAG_REGNUM, core_reg->freg.tag);
188 RF (FCS_REGNUM, core_reg->freg.code_seg);
189 RF (FCOFF_REGNUM, core_reg->freg.eip);
190 RF (FDS_REGNUM, core_reg->freg.operand_seg);
191 RF (FDOFF_REGNUM, core_reg->freg.operand);
192 RF (FOP_REGNUM, core_reg->freg.opcode);
194 registers_fetched ();
197 /* Register that we are able to handle i386nbsd core file formats.
198 FIXME: is this really bfd_target_unknown_flavour? */
200 static struct core_fns i386nbsd_core_fns =
202 bfd_target_unknown_flavour, /* core_flavour */
203 default_check_format, /* check_format */
204 default_core_sniffer, /* core_sniffer */
205 fetch_core_registers, /* core_read_registers */
210 _initialize_i386nbsd_nat (void)
212 add_core_fns (&i386nbsd_core_fns);