1 /* Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "win32-low.h"
24 #define FLAG_TRACE_BIT 0x100
26 /* Defined in auto-generated file reg-i386.c. */
27 void init_registers_i386 (void);
29 static unsigned dr
[8];
31 static int debug_registers_changed
= 0;
32 static int debug_registers_used
= 0;
35 i386_initial_stuff (void)
37 memset (&dr
, 0, sizeof (dr
));
38 debug_registers_changed
= 0;
39 debug_registers_used
= 0;
43 i386_get_thread_context (win32_thread_info
*th
, DEBUG_EVENT
* current_event
)
45 th
->context
.ContextFlags
= \
47 CONTEXT_FLOATING_POINT
| \
48 CONTEXT_EXTENDED_REGISTERS
| \
49 CONTEXT_DEBUG_REGISTERS
;
51 GetThreadContext (th
->h
, &th
->context
);
53 debug_registers_changed
= 0;
55 if (th
->tid
== current_event
->dwThreadId
)
57 /* Copy dr values from the current thread. */
58 dr
[0] = th
->context
.Dr0
;
59 dr
[1] = th
->context
.Dr1
;
60 dr
[2] = th
->context
.Dr2
;
61 dr
[3] = th
->context
.Dr3
;
62 dr
[6] = th
->context
.Dr6
;
63 dr
[7] = th
->context
.Dr7
;
68 i386_set_thread_context (win32_thread_info
*th
, DEBUG_EVENT
* current_event
)
70 if (debug_registers_changed
)
72 th
->context
.Dr0
= dr
[0];
73 th
->context
.Dr1
= dr
[1];
74 th
->context
.Dr2
= dr
[2];
75 th
->context
.Dr3
= dr
[3];
76 /* th->context.Dr6 = dr[6];
77 FIXME: should we set dr6 also ?? */
78 th
->context
.Dr7
= dr
[7];
81 SetThreadContext (th
->h
, &th
->context
);
85 i386_thread_added (win32_thread_info
*th
)
87 /* Set the debug registers for the new thread if they are used. */
88 if (debug_registers_used
)
90 th
->context
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
91 GetThreadContext (th
->h
, &th
->context
);
93 th
->context
.Dr0
= dr
[0];
94 th
->context
.Dr1
= dr
[1];
95 th
->context
.Dr2
= dr
[2];
96 th
->context
.Dr3
= dr
[3];
97 /* th->context.Dr6 = dr[6];
98 FIXME: should we set dr6 also ?? */
99 th
->context
.Dr7
= dr
[7];
101 SetThreadContext (th
->h
, &th
->context
);
102 th
->context
.ContextFlags
= 0;
107 i386_single_step (win32_thread_info
*th
)
109 th
->context
.EFlags
|= FLAG_TRACE_BIT
;
112 /* An array of offset mappings into a Win32 Context structure.
113 This is a one-to-one mapping which is indexed by gdb's register
114 numbers. It retrieves an offset into the context structure where
115 the 4 byte register is located.
116 An offset value of -1 indicates that Win32 does not provide this
117 register in it's CONTEXT structure. In this case regptr will return
118 a pointer into a dummy register. */
119 #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
120 static const int mappings
[] = {
121 context_offset (Eax
),
122 context_offset (Ecx
),
123 context_offset (Edx
),
124 context_offset (Ebx
),
125 context_offset (Esp
),
126 context_offset (Ebp
),
127 context_offset (Esi
),
128 context_offset (Edi
),
129 context_offset (Eip
),
130 context_offset (EFlags
),
131 context_offset (SegCs
),
132 context_offset (SegSs
),
133 context_offset (SegDs
),
134 context_offset (SegEs
),
135 context_offset (SegFs
),
136 context_offset (SegGs
),
137 context_offset (FloatSave
.RegisterArea
[0 * 10]),
138 context_offset (FloatSave
.RegisterArea
[1 * 10]),
139 context_offset (FloatSave
.RegisterArea
[2 * 10]),
140 context_offset (FloatSave
.RegisterArea
[3 * 10]),
141 context_offset (FloatSave
.RegisterArea
[4 * 10]),
142 context_offset (FloatSave
.RegisterArea
[5 * 10]),
143 context_offset (FloatSave
.RegisterArea
[6 * 10]),
144 context_offset (FloatSave
.RegisterArea
[7 * 10]),
145 context_offset (FloatSave
.ControlWord
),
146 context_offset (FloatSave
.StatusWord
),
147 context_offset (FloatSave
.TagWord
),
148 context_offset (FloatSave
.ErrorSelector
),
149 context_offset (FloatSave
.ErrorOffset
),
150 context_offset (FloatSave
.DataSelector
),
151 context_offset (FloatSave
.DataOffset
),
152 context_offset (FloatSave
.ErrorSelector
),
154 context_offset (ExtendedRegisters
[10 * 16]),
155 context_offset (ExtendedRegisters
[11 * 16]),
156 context_offset (ExtendedRegisters
[12 * 16]),
157 context_offset (ExtendedRegisters
[13 * 16]),
158 context_offset (ExtendedRegisters
[14 * 16]),
159 context_offset (ExtendedRegisters
[15 * 16]),
160 context_offset (ExtendedRegisters
[16 * 16]),
161 context_offset (ExtendedRegisters
[17 * 16]),
163 context_offset (ExtendedRegisters
[24])
165 #undef context_offset
167 /* Fetch register from gdbserver regcache data. */
169 i386_fetch_inferior_register (win32_thread_info
*th
, int r
)
171 char *context_offset
= (char *) &th
->context
+ mappings
[r
];
176 l
= *((long *) context_offset
) & 0xffff;
177 supply_register (r
, (char *) &l
);
179 else if (r
== FOP_REGNUM
)
181 l
= (*((long *) context_offset
) >> 16) & ((1 << 11) - 1);
182 supply_register (r
, (char *) &l
);
185 supply_register (r
, context_offset
);
188 /* Store a new register value into the thread context of TH. */
190 i386_store_inferior_register (win32_thread_info
*th
, int r
)
192 char *context_offset
= (char *) &th
->context
+ mappings
[r
];
193 collect_register (r
, context_offset
);
196 struct win32_target_ops the_low_target
= {
198 sizeof (mappings
) / sizeof (mappings
[0]),
200 i386_get_thread_context
,
201 i386_set_thread_context
,
203 i386_fetch_inferior_register
,
204 i386_store_inferior_register
,
206 NULL
, /* breakpoint */
207 0, /* breakpoint_len */
208 "i386" /* arch_string */