| 1 | /* Copyright (C) 2007 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 2 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, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. */ |
| 19 | |
| 20 | #include "server.h" |
| 21 | #include "win32-low.h" |
| 22 | |
| 23 | #define FCS_REGNUM 27 |
| 24 | #define FOP_REGNUM 31 |
| 25 | |
| 26 | #define FLAG_TRACE_BIT 0x100 |
| 27 | |
| 28 | static unsigned dr[8]; |
| 29 | |
| 30 | static void |
| 31 | initial_stuff (void) |
| 32 | { |
| 33 | memset (&dr, 0, sizeof (dr)); |
| 34 | } |
| 35 | |
| 36 | static void |
| 37 | store_debug_registers (win32_thread_info *th) |
| 38 | { |
| 39 | dr[0] = th->context.Dr0; |
| 40 | dr[1] = th->context.Dr1; |
| 41 | dr[2] = th->context.Dr2; |
| 42 | dr[3] = th->context.Dr3; |
| 43 | dr[6] = th->context.Dr6; |
| 44 | dr[7] = th->context.Dr7; |
| 45 | } |
| 46 | |
| 47 | static void |
| 48 | load_debug_registers (win32_thread_info *th) |
| 49 | { |
| 50 | th->context.Dr0 = dr[0]; |
| 51 | th->context.Dr1 = dr[1]; |
| 52 | th->context.Dr2 = dr[2]; |
| 53 | th->context.Dr3 = dr[3]; |
| 54 | /* th->context.Dr6 = dr[6]; |
| 55 | FIXME: should we set dr6 also ?? */ |
| 56 | th->context.Dr7 = dr[7]; |
| 57 | } |
| 58 | |
| 59 | /* Fetch register(s) from gdbserver regcache data. */ |
| 60 | static void |
| 61 | do_fetch_inferior_registers (win32_thread_info *th, int r) |
| 62 | { |
| 63 | char *context_offset = regptr (&th->context, r); |
| 64 | |
| 65 | long l; |
| 66 | if (r == FCS_REGNUM) |
| 67 | { |
| 68 | l = *((long *) context_offset) & 0xffff; |
| 69 | supply_register (r, (char *) &l); |
| 70 | } |
| 71 | else if (r == FOP_REGNUM) |
| 72 | { |
| 73 | l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1); |
| 74 | supply_register (r, (char *) &l); |
| 75 | } |
| 76 | else |
| 77 | supply_register (r, context_offset); |
| 78 | } |
| 79 | |
| 80 | static void |
| 81 | single_step (win32_thread_info *th) |
| 82 | { |
| 83 | th->context.EFlags |= FLAG_TRACE_BIT; |
| 84 | } |
| 85 | |
| 86 | /* An array of offset mappings into a Win32 Context structure. |
| 87 | This is a one-to-one mapping which is indexed by gdb's register |
| 88 | numbers. It retrieves an offset into the context structure where |
| 89 | the 4 byte register is located. |
| 90 | An offset value of -1 indicates that Win32 does not provide this |
| 91 | register in it's CONTEXT structure. In this case regptr will return |
| 92 | a pointer into a dummy register. */ |
| 93 | #define context_offset(x) ((int)&(((CONTEXT *)NULL)->x)) |
| 94 | static const int mappings[] = { |
| 95 | context_offset (Eax), |
| 96 | context_offset (Ecx), |
| 97 | context_offset (Edx), |
| 98 | context_offset (Ebx), |
| 99 | context_offset (Esp), |
| 100 | context_offset (Ebp), |
| 101 | context_offset (Esi), |
| 102 | context_offset (Edi), |
| 103 | context_offset (Eip), |
| 104 | context_offset (EFlags), |
| 105 | context_offset (SegCs), |
| 106 | context_offset (SegSs), |
| 107 | context_offset (SegDs), |
| 108 | context_offset (SegEs), |
| 109 | context_offset (SegFs), |
| 110 | context_offset (SegGs), |
| 111 | context_offset (FloatSave.RegisterArea[0 * 10]), |
| 112 | context_offset (FloatSave.RegisterArea[1 * 10]), |
| 113 | context_offset (FloatSave.RegisterArea[2 * 10]), |
| 114 | context_offset (FloatSave.RegisterArea[3 * 10]), |
| 115 | context_offset (FloatSave.RegisterArea[4 * 10]), |
| 116 | context_offset (FloatSave.RegisterArea[5 * 10]), |
| 117 | context_offset (FloatSave.RegisterArea[6 * 10]), |
| 118 | context_offset (FloatSave.RegisterArea[7 * 10]), |
| 119 | context_offset (FloatSave.ControlWord), |
| 120 | context_offset (FloatSave.StatusWord), |
| 121 | context_offset (FloatSave.TagWord), |
| 122 | context_offset (FloatSave.ErrorSelector), |
| 123 | context_offset (FloatSave.ErrorOffset), |
| 124 | context_offset (FloatSave.DataSelector), |
| 125 | context_offset (FloatSave.DataOffset), |
| 126 | context_offset (FloatSave.ErrorSelector), |
| 127 | /* XMM0-7 */ |
| 128 | context_offset (ExtendedRegisters[10 * 16]), |
| 129 | context_offset (ExtendedRegisters[11 * 16]), |
| 130 | context_offset (ExtendedRegisters[12 * 16]), |
| 131 | context_offset (ExtendedRegisters[13 * 16]), |
| 132 | context_offset (ExtendedRegisters[14 * 16]), |
| 133 | context_offset (ExtendedRegisters[15 * 16]), |
| 134 | context_offset (ExtendedRegisters[16 * 16]), |
| 135 | context_offset (ExtendedRegisters[17 * 16]), |
| 136 | /* MXCSR */ |
| 137 | context_offset (ExtendedRegisters[24]) |
| 138 | }; |
| 139 | #undef context_offset |
| 140 | |
| 141 | struct win32_target_ops the_low_target = { |
| 142 | mappings, |
| 143 | sizeof (mappings) / sizeof (mappings[0]), |
| 144 | initial_stuff, |
| 145 | store_debug_registers, |
| 146 | load_debug_registers, |
| 147 | do_fetch_inferior_registers, |
| 148 | single_step, |
| 149 | (const char*)NULL, /* breakpoint */ |
| 150 | 0, /* breakpoint_len */ |
| 151 | "i386" /* arch_string */ |
| 152 | }; |