This commit was generated by cvs2svn to track changes on a CVS vendor
[platform/upstream/binutils.git] / gdb / i386nbsd-nat.c
1 /* Native-dependent code for NetBSD/i386, for GDB.
2    Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000
3    Free Software Foundation, Inc.
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() */
29
30 #define RF(dst, src) \
31         memcpy(&registers[REGISTER_BYTE(dst)], &src, sizeof(src))
32
33 #define RS(src, dst) \
34         memcpy(&dst, &registers[REGISTER_BYTE(src)], sizeof(dst))
35      
36 struct env387
37   {
38     unsigned short control;
39     unsigned short r0;
40     unsigned short status;
41     unsigned short r1;
42     unsigned short tag;  
43     unsigned short r2;
44     unsigned long eip;
45     unsigned short code_seg;
46     unsigned short opcode;
47     unsigned long operand; 
48     unsigned short operand_seg;
49     unsigned short r3;
50     unsigned char regs[8][10];
51   };
52
53 void
54 fetch_inferior_registers (regno)
55      int regno;
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
104 store_inferior_registers (regno)
105      int regno;
106 {
107   struct reg inferior_registers;
108   struct env387 inferior_fpregisters;
109
110   RS ( 0, inferior_registers.r_eax);
111   RS ( 1, inferior_registers.r_ecx);
112   RS ( 2, inferior_registers.r_edx);
113   RS ( 3, inferior_registers.r_ebx);
114   RS ( 4, inferior_registers.r_esp);
115   RS ( 5, inferior_registers.r_ebp);
116   RS ( 6, inferior_registers.r_esi);
117   RS ( 7, inferior_registers.r_edi);
118   RS ( 8, inferior_registers.r_eip);
119   RS ( 9, inferior_registers.r_eflags);
120   RS (10, inferior_registers.r_cs);
121   RS (11, inferior_registers.r_ss);
122   RS (12, inferior_registers.r_ds);
123   RS (13, inferior_registers.r_es);
124   RS (14, inferior_registers.r_fs);
125   RS (15, inferior_registers.r_gs);
126
127   
128   RS (FP0_REGNUM,     inferior_fpregisters.regs[0]);
129   RS (FP0_REGNUM + 1, inferior_fpregisters.regs[1]);
130   RS (FP0_REGNUM + 2, inferior_fpregisters.regs[2]);
131   RS (FP0_REGNUM + 3, inferior_fpregisters.regs[3]);
132   RS (FP0_REGNUM + 4, inferior_fpregisters.regs[4]);
133   RS (FP0_REGNUM + 5, inferior_fpregisters.regs[5]);
134   RS (FP0_REGNUM + 6, inferior_fpregisters.regs[6]);
135   RS (FP0_REGNUM + 7, inferior_fpregisters.regs[7]);
136
137   RS (FCTRL_REGNUM,   inferior_fpregisters.control);
138   RS (FSTAT_REGNUM,   inferior_fpregisters.status);
139   RS (FTAG_REGNUM,    inferior_fpregisters.tag);
140   RS (FCS_REGNUM,     inferior_fpregisters.code_seg);
141   RS (FCOFF_REGNUM,   inferior_fpregisters.eip);
142   RS (FDS_REGNUM,     inferior_fpregisters.operand_seg);
143   RS (FDOFF_REGNUM,   inferior_fpregisters.operand);
144   RS (FOP_REGNUM,     inferior_fpregisters.opcode);
145   
146   ptrace (PT_SETREGS, inferior_pid,
147           (PTRACE_ARG3_TYPE) &inferior_registers, 0);
148   ptrace (PT_SETFPREGS, inferior_pid,
149           (PTRACE_ARG3_TYPE) &inferior_fpregisters, 0);
150 }
151 \f
152 int
153 i386nbsd_use_struct_convention (int gcc_p, struct type *type)
154 {
155   return !(TYPE_LENGTH (type) == 1
156            || TYPE_LENGTH (type) == 2
157            || TYPE_LENGTH (type) == 4
158            || TYPE_LENGTH (type) == 8);
159 }
160 \f
161 struct md_core
162 {
163   struct reg intreg;
164   struct env387 freg;
165 };
166
167 static void
168 fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
169      char *core_reg_sect;
170      unsigned core_reg_size;
171      int which;
172      CORE_ADDR ignore;
173 {
174   struct md_core *core_reg = (struct md_core *) core_reg_sect;
175
176   /* integer registers */
177   memcpy (&registers[REGISTER_BYTE (0)], &core_reg->intreg,
178           sizeof (struct reg));
179
180   /* floating point registers */
181   RF (FP0_REGNUM,     core_reg->freg.regs[0]);
182   RF (FP0_REGNUM + 1, core_reg->freg.regs[1]);
183   RF (FP0_REGNUM + 2, core_reg->freg.regs[2]);
184   RF (FP0_REGNUM + 3, core_reg->freg.regs[3]);
185   RF (FP0_REGNUM + 4, core_reg->freg.regs[4]);
186   RF (FP0_REGNUM + 5, core_reg->freg.regs[5]);
187   RF (FP0_REGNUM + 6, core_reg->freg.regs[6]);
188   RF (FP0_REGNUM + 7, core_reg->freg.regs[7]);
189
190   RF (FCTRL_REGNUM,   core_reg->freg.control);
191   RF (FSTAT_REGNUM,   core_reg->freg.status);
192   RF (FTAG_REGNUM,    core_reg->freg.tag);
193   RF (FCS_REGNUM,     core_reg->freg.code_seg);
194   RF (FCOFF_REGNUM,   core_reg->freg.eip);
195   RF (FDS_REGNUM,     core_reg->freg.operand_seg);
196   RF (FDOFF_REGNUM,   core_reg->freg.operand);
197   RF (FOP_REGNUM,     core_reg->freg.opcode);
198
199   registers_fetched ();
200 }
201
202 /* Register that we are able to handle i386nbsd core file formats.
203    FIXME: is this really bfd_target_unknown_flavour? */
204
205 static struct core_fns i386nbsd_core_fns =
206 {
207   bfd_target_unknown_flavour,           /* core_flavour */
208   default_check_format,                 /* check_format */
209   default_core_sniffer,                 /* core_sniffer */
210   fetch_core_registers,                 /* core_read_registers */
211   NULL                                  /* next */
212 };
213
214 void
215 _initialize_i386nbsd_nat ()
216 {
217   add_core_fns (&i386nbsd_core_fns);
218 }