| 1 |
/* Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
This file is part of GDB. |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 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/>. */ |
| 17 |
|
| 18 |
#include "win32-low.h" |
| 19 |
#include "x86-low.h" |
| 20 |
#include "gdbsupport/x86-xstate.h" |
| 21 |
#ifdef __x86_64__ |
| 22 |
#include "arch/amd64.h" |
| 23 |
#endif |
| 24 |
#include "arch/i386.h" |
| 25 |
#include "tdesc.h" |
| 26 |
#include "x86-tdesc.h" |
| 27 |
|
| 28 |
using namespace windows_nat; |
| 29 |
|
| 30 |
#ifndef CONTEXT_EXTENDED_REGISTERS |
| 31 |
#define CONTEXT_EXTENDED_REGISTERS 0 |
| 32 |
#endif |
| 33 |
|
| 34 |
#define I386_FISEG_REGNUM 27 |
| 35 |
#define I386_FOP_REGNUM 31 |
| 36 |
|
| 37 |
#define I386_CS_REGNUM 10 |
| 38 |
#define I386_GS_REGNUM 15 |
| 39 |
|
| 40 |
#define AMD64_FISEG_REGNUM 35 |
| 41 |
#define AMD64_FOP_REGNUM 39 |
| 42 |
|
| 43 |
#define AMD64_CS_REGNUM 18 |
| 44 |
#define AMD64_GS_REGNUM 23 |
| 45 |
|
| 46 |
#define FLAG_TRACE_BIT 0x100 |
| 47 |
|
| 48 |
static struct x86_debug_reg_state debug_reg_state; |
| 49 |
|
| 50 |
static void |
| 51 |
update_debug_registers (thread_info *thread) |
| 52 |
{ |
| 53 |
auto th = static_cast<windows_thread_info *> (thread->target_data ()); |
| 54 |
|
| 55 |
/* The actual update is done later just before resuming the lwp, |
| 56 |
we just mark that the registers need updating. */ |
| 57 |
th->debug_registers_changed = true; |
| 58 |
} |
| 59 |
|
| 60 |
/* Update the inferior's debug register REGNUM from STATE. */ |
| 61 |
|
| 62 |
static void |
| 63 |
x86_dr_low_set_addr (int regnum, CORE_ADDR addr) |
| 64 |
{ |
| 65 |
gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR); |
| 66 |
|
| 67 |
/* Only update the threads of this process. */ |
| 68 |
current_process ()->for_each_thread (update_debug_registers); |
| 69 |
} |
| 70 |
|
| 71 |
/* Update the inferior's DR7 debug control register from STATE. */ |
| 72 |
|
| 73 |
static void |
| 74 |
x86_dr_low_set_control (unsigned long control) |
| 75 |
{ |
| 76 |
/* Only update the threads of this process. */ |
| 77 |
current_process ()->for_each_thread (update_debug_registers); |
| 78 |
} |
| 79 |
|
| 80 |
/* Return the current value of a DR register of the current thread's |
| 81 |
context. */ |
| 82 |
|
| 83 |
static DWORD64 |
| 84 |
win32_get_current_dr (int dr) |
| 85 |
{ |
| 86 |
auto th |
| 87 |
= static_cast<windows_thread_info *> (current_thread->target_data ()); |
| 88 |
|
| 89 |
win32_require_context (th); |
| 90 |
|
| 91 |
return windows_process.with_context (th, [&] (auto *context) -> DWORD64 |
| 92 |
{ |
| 93 |
#define RET_DR(DR) \ |
| 94 |
case DR: \ |
| 95 |
return context->Dr ## DR |
| 96 |
|
| 97 |
switch (dr) |
| 98 |
{ |
| 99 |
RET_DR (0); |
| 100 |
RET_DR (1); |
| 101 |
RET_DR (2); |
| 102 |
RET_DR (3); |
| 103 |
RET_DR (6); |
| 104 |
RET_DR (7); |
| 105 |
} |
| 106 |
#undef RET_DR |
| 107 |
|
| 108 |
gdb_assert_not_reached ("unhandled dr"); |
| 109 |
}); |
| 110 |
} |
| 111 |
|
| 112 |
static CORE_ADDR |
| 113 |
x86_dr_low_get_addr (int regnum) |
| 114 |
{ |
| 115 |
gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR); |
| 116 |
|
| 117 |
return win32_get_current_dr (regnum - DR_FIRSTADDR); |
| 118 |
} |
| 119 |
|
| 120 |
static unsigned long |
| 121 |
x86_dr_low_get_control (void) |
| 122 |
{ |
| 123 |
return win32_get_current_dr (7); |
| 124 |
} |
| 125 |
|
| 126 |
/* Get the value of the DR6 debug status register from the inferior |
| 127 |
and record it in STATE. */ |
| 128 |
|
| 129 |
static unsigned long |
| 130 |
x86_dr_low_get_status (void) |
| 131 |
{ |
| 132 |
return win32_get_current_dr (6); |
| 133 |
} |
| 134 |
|
| 135 |
/* Low-level function vector. */ |
| 136 |
struct x86_dr_low_type x86_dr_low = |
| 137 |
{ |
| 138 |
x86_dr_low_set_control, |
| 139 |
x86_dr_low_set_addr, |
| 140 |
x86_dr_low_get_addr, |
| 141 |
x86_dr_low_get_status, |
| 142 |
x86_dr_low_get_control, |
| 143 |
sizeof (void *), |
| 144 |
}; |
| 145 |
|
| 146 |
/* Breakpoint/watchpoint support. */ |
| 147 |
|
| 148 |
static int |
| 149 |
i386_supports_z_point_type (char z_type) |
| 150 |
{ |
| 151 |
switch (z_type) |
| 152 |
{ |
| 153 |
case Z_PACKET_HW_BP: |
| 154 |
case Z_PACKET_WRITE_WP: |
| 155 |
case Z_PACKET_ACCESS_WP: |
| 156 |
return 1; |
| 157 |
default: |
| 158 |
return 0; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
static int |
| 163 |
i386_insert_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 164 |
int size, struct raw_breakpoint *bp) |
| 165 |
{ |
| 166 |
switch (type) |
| 167 |
{ |
| 168 |
case raw_bkpt_type_hw: |
| 169 |
case raw_bkpt_type_write_wp: |
| 170 |
case raw_bkpt_type_access_wp: |
| 171 |
{ |
| 172 |
enum target_hw_bp_type hw_type |
| 173 |
= raw_bkpt_type_to_target_hw_bp_type (type); |
| 174 |
|
| 175 |
return x86_dr_insert_watchpoint (&debug_reg_state, |
| 176 |
hw_type, addr, size); |
| 177 |
} |
| 178 |
default: |
| 179 |
/* Unsupported. */ |
| 180 |
return 1; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
static int |
| 185 |
i386_remove_point (enum raw_bkpt_type type, CORE_ADDR addr, |
| 186 |
int size, struct raw_breakpoint *bp) |
| 187 |
{ |
| 188 |
switch (type) |
| 189 |
{ |
| 190 |
case raw_bkpt_type_hw: |
| 191 |
case raw_bkpt_type_write_wp: |
| 192 |
case raw_bkpt_type_access_wp: |
| 193 |
{ |
| 194 |
enum target_hw_bp_type hw_type |
| 195 |
= raw_bkpt_type_to_target_hw_bp_type (type); |
| 196 |
|
| 197 |
return x86_dr_remove_watchpoint (&debug_reg_state, |
| 198 |
hw_type, addr, size); |
| 199 |
} |
| 200 |
default: |
| 201 |
/* Unsupported. */ |
| 202 |
return 1; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
static int |
| 207 |
x86_stopped_by_watchpoint (void) |
| 208 |
{ |
| 209 |
return x86_dr_stopped_by_watchpoint (&debug_reg_state); |
| 210 |
} |
| 211 |
|
| 212 |
static CORE_ADDR |
| 213 |
x86_stopped_data_address (void) |
| 214 |
{ |
| 215 |
CORE_ADDR addr; |
| 216 |
if (x86_dr_stopped_data_address (&debug_reg_state, &addr)) |
| 217 |
return addr; |
| 218 |
return 0; |
| 219 |
} |
| 220 |
|
| 221 |
static void |
| 222 |
i386_initial_stuff (void) |
| 223 |
{ |
| 224 |
x86_low_init_dregs (&debug_reg_state); |
| 225 |
} |
| 226 |
|
| 227 |
static void |
| 228 |
i386_get_thread_context (windows_thread_info *th) |
| 229 |
{ |
| 230 |
windows_process.with_context (th, [&] (auto *context) |
| 231 |
{ |
| 232 |
/* Requesting the CONTEXT_EXTENDED_REGISTERS register set fails if |
| 233 |
the system doesn't support extended registers. */ |
| 234 |
static DWORD extended_registers |
| 235 |
= WindowsContext<decltype(context)>::extended; |
| 236 |
|
| 237 |
again: |
| 238 |
context->ContextFlags = (WindowsContext<decltype(context)>::full |
| 239 |
| WindowsContext<decltype(context)>::floating |
| 240 |
| WindowsContext<decltype(context)>::debug |
| 241 |
| extended_registers); |
| 242 |
|
| 243 |
BOOL ret = get_thread_context (th->h, context); |
| 244 |
if (!ret) |
| 245 |
{ |
| 246 |
DWORD e = GetLastError (); |
| 247 |
|
| 248 |
if (extended_registers && e == ERROR_INVALID_PARAMETER) |
| 249 |
{ |
| 250 |
extended_registers = 0; |
| 251 |
goto again; |
| 252 |
} |
| 253 |
|
| 254 |
error ("GetThreadContext failure %ld\n", (long) e); |
| 255 |
} |
| 256 |
}); |
| 257 |
} |
| 258 |
|
| 259 |
static void |
| 260 |
i386_prepare_to_resume (windows_thread_info *th) |
| 261 |
{ |
| 262 |
if (th->debug_registers_changed) |
| 263 |
{ |
| 264 |
struct x86_debug_reg_state *dr = &debug_reg_state; |
| 265 |
|
| 266 |
win32_require_context (th); |
| 267 |
|
| 268 |
windows_process.with_context (th, [&] (auto *context) |
| 269 |
{ |
| 270 |
context->Dr0 = dr->dr_mirror[0]; |
| 271 |
context->Dr1 = dr->dr_mirror[1]; |
| 272 |
context->Dr2 = dr->dr_mirror[2]; |
| 273 |
context->Dr3 = dr->dr_mirror[3]; |
| 274 |
/* context->Dr6 = dr->dr_status_mirror; |
| 275 |
FIXME: should we set dr6 also ?? */ |
| 276 |
context->Dr7 = dr->dr_control_mirror; |
| 277 |
}); |
| 278 |
|
| 279 |
th->debug_registers_changed = false; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
static void |
| 284 |
i386_thread_added (windows_thread_info *th) |
| 285 |
{ |
| 286 |
th->debug_registers_changed = true; |
| 287 |
} |
| 288 |
|
| 289 |
static void |
| 290 |
i386_single_step (windows_thread_info *th) |
| 291 |
{ |
| 292 |
windows_process.with_context (th, [] (auto *context) |
| 293 |
{ |
| 294 |
context->EFlags |= FLAG_TRACE_BIT; |
| 295 |
}); |
| 296 |
} |
| 297 |
|
| 298 |
/* An array of offset mappings into a Win32 Context structure. |
| 299 |
This is a one-to-one mapping which is indexed by gdb's register |
| 300 |
numbers. It retrieves an offset into the context structure where |
| 301 |
the 4 byte register is located. |
| 302 |
An offset value of -1 indicates that Win32 does not provide this |
| 303 |
register in it's CONTEXT structure. In this case regptr will return |
| 304 |
a pointer into a dummy register. */ |
| 305 |
#ifdef __x86_64__ |
| 306 |
#define context_offset(x) (offsetof (WOW64_CONTEXT, x)) |
| 307 |
#else |
| 308 |
#define context_offset(x) ((int)&(((CONTEXT *)NULL)->x)) |
| 309 |
#endif |
| 310 |
static const int i386_mappings[] = { |
| 311 |
context_offset (Eax), |
| 312 |
context_offset (Ecx), |
| 313 |
context_offset (Edx), |
| 314 |
context_offset (Ebx), |
| 315 |
context_offset (Esp), |
| 316 |
context_offset (Ebp), |
| 317 |
context_offset (Esi), |
| 318 |
context_offset (Edi), |
| 319 |
context_offset (Eip), |
| 320 |
context_offset (EFlags), |
| 321 |
context_offset (SegCs), |
| 322 |
context_offset (SegSs), |
| 323 |
context_offset (SegDs), |
| 324 |
context_offset (SegEs), |
| 325 |
context_offset (SegFs), |
| 326 |
context_offset (SegGs), |
| 327 |
context_offset (FloatSave.RegisterArea[0 * 10]), |
| 328 |
context_offset (FloatSave.RegisterArea[1 * 10]), |
| 329 |
context_offset (FloatSave.RegisterArea[2 * 10]), |
| 330 |
context_offset (FloatSave.RegisterArea[3 * 10]), |
| 331 |
context_offset (FloatSave.RegisterArea[4 * 10]), |
| 332 |
context_offset (FloatSave.RegisterArea[5 * 10]), |
| 333 |
context_offset (FloatSave.RegisterArea[6 * 10]), |
| 334 |
context_offset (FloatSave.RegisterArea[7 * 10]), |
| 335 |
context_offset (FloatSave.ControlWord), |
| 336 |
context_offset (FloatSave.StatusWord), |
| 337 |
context_offset (FloatSave.TagWord), |
| 338 |
context_offset (FloatSave.ErrorSelector), |
| 339 |
context_offset (FloatSave.ErrorOffset), |
| 340 |
context_offset (FloatSave.DataSelector), |
| 341 |
context_offset (FloatSave.DataOffset), |
| 342 |
context_offset (FloatSave.ErrorSelector), |
| 343 |
/* XMM0-7 */ |
| 344 |
context_offset (ExtendedRegisters[10 * 16]), |
| 345 |
context_offset (ExtendedRegisters[11 * 16]), |
| 346 |
context_offset (ExtendedRegisters[12 * 16]), |
| 347 |
context_offset (ExtendedRegisters[13 * 16]), |
| 348 |
context_offset (ExtendedRegisters[14 * 16]), |
| 349 |
context_offset (ExtendedRegisters[15 * 16]), |
| 350 |
context_offset (ExtendedRegisters[16 * 16]), |
| 351 |
context_offset (ExtendedRegisters[17 * 16]), |
| 352 |
/* MXCSR */ |
| 353 |
context_offset (ExtendedRegisters[24]) |
| 354 |
}; |
| 355 |
#undef context_offset |
| 356 |
|
| 357 |
#ifdef __x86_64__ |
| 358 |
|
| 359 |
#define context_offset(x) (offsetof (CONTEXT, x)) |
| 360 |
static const int amd64_mappings[] = |
| 361 |
{ |
| 362 |
context_offset (Rax), |
| 363 |
context_offset (Rbx), |
| 364 |
context_offset (Rcx), |
| 365 |
context_offset (Rdx), |
| 366 |
context_offset (Rsi), |
| 367 |
context_offset (Rdi), |
| 368 |
context_offset (Rbp), |
| 369 |
context_offset (Rsp), |
| 370 |
context_offset (R8), |
| 371 |
context_offset (R9), |
| 372 |
context_offset (R10), |
| 373 |
context_offset (R11), |
| 374 |
context_offset (R12), |
| 375 |
context_offset (R13), |
| 376 |
context_offset (R14), |
| 377 |
context_offset (R15), |
| 378 |
context_offset (Rip), |
| 379 |
context_offset (EFlags), |
| 380 |
context_offset (SegCs), |
| 381 |
context_offset (SegSs), |
| 382 |
context_offset (SegDs), |
| 383 |
context_offset (SegEs), |
| 384 |
context_offset (SegFs), |
| 385 |
context_offset (SegGs), |
| 386 |
context_offset (FloatSave.FloatRegisters[0]), |
| 387 |
context_offset (FloatSave.FloatRegisters[1]), |
| 388 |
context_offset (FloatSave.FloatRegisters[2]), |
| 389 |
context_offset (FloatSave.FloatRegisters[3]), |
| 390 |
context_offset (FloatSave.FloatRegisters[4]), |
| 391 |
context_offset (FloatSave.FloatRegisters[5]), |
| 392 |
context_offset (FloatSave.FloatRegisters[6]), |
| 393 |
context_offset (FloatSave.FloatRegisters[7]), |
| 394 |
context_offset (FloatSave.ControlWord), |
| 395 |
context_offset (FloatSave.StatusWord), |
| 396 |
context_offset (FloatSave.TagWord), |
| 397 |
context_offset (FloatSave.ErrorSelector), |
| 398 |
context_offset (FloatSave.ErrorOffset), |
| 399 |
context_offset (FloatSave.DataSelector), |
| 400 |
context_offset (FloatSave.DataOffset), |
| 401 |
context_offset (FloatSave.ErrorSelector) |
| 402 |
/* XMM0-7 */ , |
| 403 |
context_offset (Xmm0), |
| 404 |
context_offset (Xmm1), |
| 405 |
context_offset (Xmm2), |
| 406 |
context_offset (Xmm3), |
| 407 |
context_offset (Xmm4), |
| 408 |
context_offset (Xmm5), |
| 409 |
context_offset (Xmm6), |
| 410 |
context_offset (Xmm7), |
| 411 |
context_offset (Xmm8), |
| 412 |
context_offset (Xmm9), |
| 413 |
context_offset (Xmm10), |
| 414 |
context_offset (Xmm11), |
| 415 |
context_offset (Xmm12), |
| 416 |
context_offset (Xmm13), |
| 417 |
context_offset (Xmm14), |
| 418 |
context_offset (Xmm15), |
| 419 |
/* MXCSR */ |
| 420 |
context_offset (FloatSave.MxCsr) |
| 421 |
}; |
| 422 |
#undef context_offset |
| 423 |
|
| 424 |
#endif /* __x86_64__ */ |
| 425 |
|
| 426 |
/* Return true if R is the FISEG register. */ |
| 427 |
static bool |
| 428 |
is_fiseg_register (int r) |
| 429 |
{ |
| 430 |
#ifdef __x86_64__ |
| 431 |
if (!windows_process.wow64_process) |
| 432 |
return r == AMD64_FISEG_REGNUM; |
| 433 |
else |
| 434 |
#endif |
| 435 |
return r == I386_FISEG_REGNUM; |
| 436 |
} |
| 437 |
|
| 438 |
/* Return true if R is the FOP register. */ |
| 439 |
static bool |
| 440 |
is_fop_register (int r) |
| 441 |
{ |
| 442 |
#ifdef __x86_64__ |
| 443 |
if (!windows_process.wow64_process) |
| 444 |
return r == AMD64_FOP_REGNUM; |
| 445 |
else |
| 446 |
#endif |
| 447 |
return r == I386_FOP_REGNUM; |
| 448 |
} |
| 449 |
|
| 450 |
/* Return true if R is a segment register. */ |
| 451 |
static bool |
| 452 |
is_segment_register (int r) |
| 453 |
{ |
| 454 |
#ifdef __x86_64__ |
| 455 |
if (!windows_process.wow64_process) |
| 456 |
return r >= AMD64_CS_REGNUM && r <= AMD64_GS_REGNUM; |
| 457 |
else |
| 458 |
#endif |
| 459 |
return r >= I386_CS_REGNUM && r <= I386_GS_REGNUM; |
| 460 |
} |
| 461 |
|
| 462 |
/* Fetch register from gdbserver regcache data. */ |
| 463 |
static void |
| 464 |
i386_fetch_inferior_register (struct regcache *regcache, |
| 465 |
windows_thread_info *th, int r) |
| 466 |
{ |
| 467 |
const int *mappings; |
| 468 |
#ifdef __x86_64__ |
| 469 |
if (!windows_process.wow64_process) |
| 470 |
mappings = amd64_mappings; |
| 471 |
else |
| 472 |
#endif |
| 473 |
mappings = i386_mappings; |
| 474 |
|
| 475 |
char *context_offset = windows_process.with_context (th, [&] (auto *context) |
| 476 |
{ |
| 477 |
return (char *) context + mappings[r]; |
| 478 |
}); |
| 479 |
|
| 480 |
/* GDB treats some registers as 32-bit, where they are in fact only |
| 481 |
16 bits long. These cases must be handled specially to avoid |
| 482 |
reading extraneous bits from the context. */ |
| 483 |
if (is_fiseg_register (r) || is_segment_register (r)) |
| 484 |
{ |
| 485 |
gdb_byte bytes[4] = {}; |
| 486 |
memcpy (bytes, context_offset, 2); |
| 487 |
supply_register (regcache, r, bytes); |
| 488 |
} |
| 489 |
else if (is_fop_register (r)) |
| 490 |
{ |
| 491 |
long l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1); |
| 492 |
supply_register (regcache, r, (char *) &l); |
| 493 |
} |
| 494 |
else |
| 495 |
supply_register (regcache, r, context_offset); |
| 496 |
} |
| 497 |
|
| 498 |
/* Store a new register value into the thread context of TH. */ |
| 499 |
static void |
| 500 |
i386_store_inferior_register (struct regcache *regcache, |
| 501 |
windows_thread_info *th, int r) |
| 502 |
{ |
| 503 |
const int *mappings; |
| 504 |
#ifdef __x86_64__ |
| 505 |
if (!windows_process.wow64_process) |
| 506 |
mappings = amd64_mappings; |
| 507 |
else |
| 508 |
#endif |
| 509 |
mappings = i386_mappings; |
| 510 |
|
| 511 |
char *context_offset = windows_process.with_context (th, [&] (auto *context) |
| 512 |
{ |
| 513 |
return (char *) context + mappings[r]; |
| 514 |
}); |
| 515 |
|
| 516 |
/* GDB treats some registers as 32-bit, where they are in fact only |
| 517 |
16 bits long. These cases must be handled specially to avoid |
| 518 |
overwriting other registers in the context. */ |
| 519 |
if (is_fiseg_register (r) || is_segment_register (r)) |
| 520 |
{ |
| 521 |
gdb_byte bytes[4]; |
| 522 |
collect_register (regcache, r, bytes); |
| 523 |
memcpy (context_offset, bytes, 2); |
| 524 |
} |
| 525 |
else if (is_fop_register (r)) |
| 526 |
{ |
| 527 |
gdb_byte bytes[4]; |
| 528 |
collect_register (regcache, r, bytes); |
| 529 |
/* The value of FOP occupies the top two bytes in the context, |
| 530 |
so write the two low-order bytes from the cache into the |
| 531 |
appropriate spot. */ |
| 532 |
memcpy (context_offset + 2, bytes, 2); |
| 533 |
} |
| 534 |
else |
| 535 |
collect_register (regcache, r, context_offset); |
| 536 |
} |
| 537 |
|
| 538 |
static const unsigned char i386_win32_breakpoint = 0xcc; |
| 539 |
#define i386_win32_breakpoint_len 1 |
| 540 |
|
| 541 |
static void |
| 542 |
i386_arch_setup (void) |
| 543 |
{ |
| 544 |
struct target_desc *tdesc; |
| 545 |
|
| 546 |
#ifdef __x86_64__ |
| 547 |
tdesc = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, |
| 548 |
false, false); |
| 549 |
init_target_desc (tdesc, amd64_expedite_regs, WINDOWS_OSABI); |
| 550 |
win32_tdesc = tdesc; |
| 551 |
#endif |
| 552 |
|
| 553 |
tdesc = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); |
| 554 |
init_target_desc (tdesc, i386_expedite_regs, WINDOWS_OSABI); |
| 555 |
#ifdef __x86_64__ |
| 556 |
wow64_win32_tdesc = tdesc; |
| 557 |
#else |
| 558 |
win32_tdesc = tdesc; |
| 559 |
#endif |
| 560 |
} |
| 561 |
|
| 562 |
/* Implement win32_target_ops "num_regs" method. */ |
| 563 |
|
| 564 |
static int |
| 565 |
i386_win32_num_regs (void) |
| 566 |
{ |
| 567 |
int num_regs; |
| 568 |
#ifdef __x86_64__ |
| 569 |
if (!windows_process.wow64_process) |
| 570 |
num_regs = sizeof (amd64_mappings) / sizeof (amd64_mappings[0]); |
| 571 |
else |
| 572 |
#endif |
| 573 |
num_regs = sizeof (i386_mappings) / sizeof (i386_mappings[0]); |
| 574 |
return num_regs; |
| 575 |
} |
| 576 |
|
| 577 |
/* Implement win32_target_ops "get_pc" method. */ |
| 578 |
|
| 579 |
static CORE_ADDR |
| 580 |
i386_win32_get_pc (struct regcache *regcache) |
| 581 |
{ |
| 582 |
bool use_64bit = register_size (regcache->tdesc, 0) == 8; |
| 583 |
|
| 584 |
if (use_64bit) |
| 585 |
{ |
| 586 |
uint64_t pc; |
| 587 |
|
| 588 |
collect_register_by_name (regcache, "rip", &pc); |
| 589 |
return (CORE_ADDR) pc; |
| 590 |
} |
| 591 |
else |
| 592 |
{ |
| 593 |
uint32_t pc; |
| 594 |
|
| 595 |
collect_register_by_name (regcache, "eip", &pc); |
| 596 |
return (CORE_ADDR) pc; |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
/* Implement win32_target_ops "set_pc" method. */ |
| 601 |
|
| 602 |
static void |
| 603 |
i386_win32_set_pc (struct regcache *regcache, CORE_ADDR pc) |
| 604 |
{ |
| 605 |
bool use_64bit = register_size (regcache->tdesc, 0) == 8; |
| 606 |
|
| 607 |
if (use_64bit) |
| 608 |
{ |
| 609 |
uint64_t newpc = pc; |
| 610 |
|
| 611 |
supply_register_by_name (regcache, "rip", &newpc); |
| 612 |
} |
| 613 |
else |
| 614 |
{ |
| 615 |
uint32_t newpc = pc; |
| 616 |
|
| 617 |
supply_register_by_name (regcache, "eip", &newpc); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
struct win32_target_ops the_low_target = { |
| 622 |
i386_arch_setup, |
| 623 |
i386_win32_num_regs, |
| 624 |
i386_initial_stuff, |
| 625 |
i386_get_thread_context, |
| 626 |
i386_prepare_to_resume, |
| 627 |
i386_thread_added, |
| 628 |
i386_fetch_inferior_register, |
| 629 |
i386_store_inferior_register, |
| 630 |
i386_single_step, |
| 631 |
&i386_win32_breakpoint, |
| 632 |
i386_win32_breakpoint_len, |
| 633 |
1, |
| 634 |
i386_win32_get_pc, |
| 635 |
i386_win32_set_pc, |
| 636 |
i386_supports_z_point_type, |
| 637 |
i386_insert_point, |
| 638 |
i386_remove_point, |
| 639 |
x86_stopped_by_watchpoint, |
| 640 |
x86_stopped_data_address |
| 641 |
}; |