71264321341de0bdb2ebdb6399339fdf05529105
[external/binutils.git] / gdb / gdbserver / linux-i386-low.c
1 /* GNU/Linux/i386 specific low level interface, for the remote server for GDB.
2    Copyright 1995, 1996, 1998, 1999, 2000, 2001, 2002
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 "server.h"
23 #include "linux-low.h"
24 #include "i387-fp.h"
25
26 #ifdef HAVE_SYS_REG_H
27 #include <sys/reg.h>
28 #endif
29
30 /* This module only supports access to the general purpose registers.  */
31
32 #define i386_num_regs 16
33
34 /* This stuff comes from i386-linux-nat.c.  */
35
36 /* Mapping between the general-purpose registers in `struct user'
37    format and GDB's register array layout.  */
38 static int i386_regmap[] = 
39 {
40   EAX * 4, ECX * 4, EDX * 4, EBX * 4,
41   UESP * 4, EBP * 4, ESI * 4, EDI * 4,
42   EIP * 4, EFL * 4, CS * 4, SS * 4,
43   DS * 4, ES * 4, FS * 4, GS * 4
44 };
45
46 static int
47 i386_cannot_store_register (int regno)
48 {
49   return (regno >= i386_num_regs);
50 }
51
52 static int
53 i386_cannot_fetch_register (int regno)
54 {
55   return (regno >= i386_num_regs);
56 }
57
58
59 #ifdef HAVE_LINUX_REGSETS
60 #include <sys/procfs.h>
61 #include <sys/ptrace.h>
62
63 static void
64 i386_fill_gregset (void *buf)
65 {
66   int i;
67
68   for (i = 0; i < i386_num_regs; i++)
69     collect_register (i, ((char *) buf) + i386_regmap[i]);
70
71   collect_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
72 }
73
74 static void
75 i386_store_gregset (void *buf)
76 {
77   int i;
78
79   for (i = 0; i < i386_num_regs; i++)
80     supply_register (i, ((char *) buf) + i386_regmap[i]);
81
82   supply_register_by_name ("orig_eax", ((char *) buf) + ORIG_EAX * 4);
83 }
84
85 static void
86 i386_fill_fpregset (void *buf)
87 {
88   i387_cache_to_fsave (buf);
89 }
90
91 static void
92 i386_store_fpregset (void *buf)
93 {
94   i387_fsave_to_cache (buf);
95 }
96
97 static void
98 i386_fill_fpxregset (void *buf)
99 {
100   i387_cache_to_fxsave (buf);
101 }
102
103 static void
104 i386_store_fpxregset (void *buf)
105 {
106   i387_fxsave_to_cache (buf);
107 }
108
109
110 struct regset_info target_regsets[] = {
111   { PTRACE_GETREGS, PTRACE_SETREGS, sizeof (elf_gregset_t),
112     i386_fill_gregset, i386_store_gregset },
113 #ifdef HAVE_PTRACE_GETFPXREGS
114   { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, sizeof (elf_fpxregset_t),
115     i386_fill_fpxregset, i386_store_fpxregset },
116 #endif
117   { PTRACE_GETFPREGS, PTRACE_SETFPREGS, sizeof (elf_fpregset_t),
118     i386_fill_fpregset, i386_store_fpregset },
119   { 0, 0, -1, NULL, NULL }
120 };
121
122 #endif /* HAVE_LINUX_REGSETS */
123
124 static const char i386_breakpoint[] = { 0xCC };
125 #define i386_breakpoint_len 1
126
127 static CORE_ADDR
128 i386_stop_pc ()
129 {
130   unsigned long pc;
131
132   /* Overkill */
133   fetch_inferior_registers (0);
134
135   collect_register_by_name ("eip", &pc);
136   return pc - 1;
137 }
138
139 static void
140 i386_set_pc (CORE_ADDR newpc)
141 {
142   supply_register_by_name ("eip", &newpc);
143
144   /* Overkill */
145   store_inferior_registers (0);
146 }
147
148 struct linux_target_ops the_low_target = {
149   i386_num_regs,
150   i386_regmap,
151   i386_cannot_fetch_register,
152   i386_cannot_store_register,
153   i386_stop_pc,
154   i386_set_pc,
155   i386_breakpoint,
156   i386_breakpoint_len,
157 };