* config/i386/nm-i386bsd.h (FLOAT_INFO): Remove redundant #undef.
[binutils-gdb.git] / gdb / i386b-nat.c
1 /* Native-dependent code for BSD Unix running on i386's, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000,
3 2001 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
24 #ifdef FETCH_INFERIOR_REGISTERS
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <machine/reg.h>
28 #include <machine/frame.h>
29 #include "inferior.h"
30 #include "gdbcore.h" /* for registers_fetched() */
31 #include "regcache.h"
32
33 void
34 fetch_inferior_registers (int regno)
35 {
36 struct reg inferior_registers;
37
38 ptrace (PT_GETREGS, PIDGET (inferior_ptid),
39 (PTRACE_ARG3_TYPE) & inferior_registers, 0);
40 memcpy (&registers[REGISTER_BYTE (0)], &inferior_registers, 4 * NUM_REGS);
41 registers_fetched ();
42 }
43
44 void
45 store_inferior_registers (int regno)
46 {
47 struct reg inferior_registers;
48
49 memcpy (&inferior_registers, &registers[REGISTER_BYTE (0)], 4 * NUM_REGS);
50 ptrace (PT_SETREGS, PIDGET (inferior_ptid),
51 (PTRACE_ARG3_TYPE) & inferior_registers, 0);
52 }
53
54 struct md_core
55 {
56 struct reg intreg;
57 struct fpreg freg;
58 };
59
60 void
61 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
62 CORE_ADDR ignore)
63 {
64 struct md_core *core_reg = (struct md_core *) core_reg_sect;
65
66 /* integer registers */
67 memcpy (&registers[REGISTER_BYTE (0)], &core_reg->intreg,
68 sizeof (struct reg));
69 /* floating point registers */
70 /* XXX */
71 }
72
73 #else
74
75 #include <machine/reg.h>
76
77 /* this table must line up with REGISTER_NAMES in tm-i386.h */
78 /* symbols like 'tEAX' come from <machine/reg.h> */
79 static int tregmap[] =
80 {
81 tEAX, tECX, tEDX, tEBX,
82 tESP, tEBP, tESI, tEDI,
83 tEIP, tEFLAGS, tCS, tSS
84 };
85
86 #ifdef sEAX
87 static int sregmap[] =
88 {
89 sEAX, sECX, sEDX, sEBX,
90 sESP, sEBP, sESI, sEDI,
91 sEIP, sEFLAGS, sCS, sSS
92 };
93 #else /* No sEAX */
94
95 /* FreeBSD has decided to collapse the s* and t* symbols. So if the s*
96 ones aren't around, use the t* ones for sregmap too. */
97
98 static int sregmap[] =
99 {
100 tEAX, tECX, tEDX, tEBX,
101 tESP, tEBP, tESI, tEDI,
102 tEIP, tEFLAGS, tCS, tSS
103 };
104 #endif /* No sEAX */
105
106 /* blockend is the value of u.u_ar0, and points to the
107 place where ES is stored. */
108
109 int
110 i386_register_u_addr (int blockend, int regnum)
111 {
112 /* The following condition is a kludge to get at the proper register map
113 depending upon the state of pcb_flag.
114 The proper condition would be
115 if (u.u_pcb.pcb_flag & FM_TRAP)
116 but that would require a ptrace call here and wouldn't work
117 for corefiles. */
118
119 if (blockend < 0x1fcc)
120 return (blockend + 4 * tregmap[regnum]);
121 else
122 return (blockend + 4 * sregmap[regnum]);
123 }
124
125 #endif /* !FETCH_INFERIOR_REGISTERS */