1 /* Copyright (C) 2007 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 2 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, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. */
21 #include "win32-low.h"
26 #define FLAG_TRACE_BIT 0x100
28 static unsigned dr
[8];
30 static int debug_registers_changed
= 0;
31 static int debug_registers_used
= 0;
34 i386_initial_stuff (void)
36 memset (&dr
, 0, sizeof (dr
));
37 debug_registers_changed
= 0;
38 debug_registers_used
= 0;
42 i386_get_thread_context (win32_thread_info
*th
, DEBUG_EVENT
* current_event
)
44 th
->context
.ContextFlags
= \
46 CONTEXT_FLOATING_POINT
| \
47 CONTEXT_EXTENDED_REGISTERS
| \
48 CONTEXT_DEBUG_REGISTERS
;
50 GetThreadContext (th
->h
, &th
->context
);
52 debug_registers_changed
= 0;
54 if (th
->tid
== current_event
->dwThreadId
)
56 /* Copy dr values from the current thread. */
57 dr
[0] = th
->context
.Dr0
;
58 dr
[1] = th
->context
.Dr1
;
59 dr
[2] = th
->context
.Dr2
;
60 dr
[3] = th
->context
.Dr3
;
61 dr
[6] = th
->context
.Dr6
;
62 dr
[7] = th
->context
.Dr7
;
67 i386_set_thread_context (win32_thread_info
*th
, DEBUG_EVENT
* current_event
)
69 if (debug_registers_changed
)
71 th
->context
.Dr0
= dr
[0];
72 th
->context
.Dr1
= dr
[1];
73 th
->context
.Dr2
= dr
[2];
74 th
->context
.Dr3
= dr
[3];
75 /* th->context.Dr6 = dr[6];
76 FIXME: should we set dr6 also ?? */
77 th
->context
.Dr7
= dr
[7];
80 SetThreadContext (th
->h
, &th
->context
);
84 i386_thread_added (win32_thread_info
*th
)
86 /* Set the debug registers for the new thread if they are used. */
87 if (debug_registers_used
)
89 th
->context
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
90 GetThreadContext (th
->h
, &th
->context
);
92 th
->context
.Dr0
= dr
[0];
93 th
->context
.Dr1
= dr
[1];
94 th
->context
.Dr2
= dr
[2];
95 th
->context
.Dr3
= dr
[3];
96 /* th->context.Dr6 = dr[6];
97 FIXME: should we set dr6 also ?? */
98 th
->context
.Dr7
= dr
[7];
100 SetThreadContext (th
->h
, &th
->context
);
101 th
->context
.ContextFlags
= 0;
106 i386_single_step (win32_thread_info
*th
)
108 th
->context
.EFlags
|= FLAG_TRACE_BIT
;
111 /* An array of offset mappings into a Win32 Context structure.
112 This is a one-to-one mapping which is indexed by gdb's register
113 numbers. It retrieves an offset into the context structure where
114 the 4 byte register is located.
115 An offset value of -1 indicates that Win32 does not provide this
116 register in it's CONTEXT structure. In this case regptr will return
117 a pointer into a dummy register. */
118 #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x))
119 static const int mappings
[] = {
120 context_offset (Eax
),
121 context_offset (Ecx
),
122 context_offset (Edx
),
123 context_offset (Ebx
),
124 context_offset (Esp
),
125 context_offset (Ebp
),
126 context_offset (Esi
),
127 context_offset (Edi
),
128 context_offset (Eip
),
129 context_offset (EFlags
),
130 context_offset (SegCs
),
131 context_offset (SegSs
),
132 context_offset (SegDs
),
133 context_offset (SegEs
),
134 context_offset (SegFs
),
135 context_offset (SegGs
),
136 context_offset (FloatSave
.RegisterArea
[0 * 10]),
137 context_offset (FloatSave
.RegisterArea
[1 * 10]),
138 context_offset (FloatSave
.RegisterArea
[2 * 10]),
139 context_offset (FloatSave
.RegisterArea
[3 * 10]),
140 context_offset (FloatSave
.RegisterArea
[4 * 10]),
141 context_offset (FloatSave
.RegisterArea
[5 * 10]),
142 context_offset (FloatSave
.RegisterArea
[6 * 10]),
143 context_offset (FloatSave
.RegisterArea
[7 * 10]),
144 context_offset (FloatSave
.ControlWord
),
145 context_offset (FloatSave
.StatusWord
),
146 context_offset (FloatSave
.TagWord
),
147 context_offset (FloatSave
.ErrorSelector
),
148 context_offset (FloatSave
.ErrorOffset
),
149 context_offset (FloatSave
.DataSelector
),
150 context_offset (FloatSave
.DataOffset
),
151 context_offset (FloatSave
.ErrorSelector
),
153 context_offset (ExtendedRegisters
[10 * 16]),
154 context_offset (ExtendedRegisters
[11 * 16]),
155 context_offset (ExtendedRegisters
[12 * 16]),
156 context_offset (ExtendedRegisters
[13 * 16]),
157 context_offset (ExtendedRegisters
[14 * 16]),
158 context_offset (ExtendedRegisters
[15 * 16]),
159 context_offset (ExtendedRegisters
[16 * 16]),
160 context_offset (ExtendedRegisters
[17 * 16]),
162 context_offset (ExtendedRegisters
[24])
164 #undef context_offset
166 /* Fetch register from gdbserver regcache data. */
168 i386_fetch_inferior_register (win32_thread_info
*th
, int r
)
170 char *context_offset
= (char *) &th
->context
+ mappings
[r
];
175 l
= *((long *) context_offset
) & 0xffff;
176 supply_register (r
, (char *) &l
);
178 else if (r
== FOP_REGNUM
)
180 l
= (*((long *) context_offset
) >> 16) & ((1 << 11) - 1);
181 supply_register (r
, (char *) &l
);
184 supply_register (r
, context_offset
);
187 /* Store a new register value into the thread context of TH. */
189 i386_store_inferior_register (win32_thread_info
*th
, int r
)
191 char *context_offset
= (char *) &th
->context
+ mappings
[r
];
192 collect_register (r
, context_offset
);
195 struct win32_target_ops the_low_target
= {
196 sizeof (mappings
) / sizeof (mappings
[0]),
198 i386_get_thread_context
,
199 i386_set_thread_context
,
201 i386_fetch_inferior_register
,
202 i386_store_inferior_register
,
204 NULL
, /* breakpoint */
205 0, /* breakpoint_len */
206 "i386" /* arch_string */