2 Public include file for Debug Port Library.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "DebugAgent.h"
18 Read the offset of FP / MMX / XMM registers by register index.
20 @param[in] Index Register index.
21 @param[out] Width Register width returned.
23 @return Offset in register address range.
27 ArchReadFxStatOffset (
32 if (Index
< SOFT_DEBUGGER_REGISTER_ST0
) {
34 case SOFT_DEBUGGER_REGISTER_FP_FCW
:
35 *Width
= (UINT8
) sizeof (UINT16
);
36 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Fcw
);
38 case SOFT_DEBUGGER_REGISTER_FP_FSW
:
39 *Width
= (UINT8
) sizeof (UINT16
);
40 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Fsw
);
42 case SOFT_DEBUGGER_REGISTER_FP_FTW
:
43 *Width
= (UINT8
) sizeof (UINT16
);
44 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Ftw
);
46 case SOFT_DEBUGGER_REGISTER_FP_OPCODE
:
47 *Width
= (UINT8
) sizeof (UINT16
);
48 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Opcode
);
50 case SOFT_DEBUGGER_REGISTER_FP_EIP
:
51 *Width
= (UINT8
) sizeof (UINTN
);
52 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Eip
);
54 case SOFT_DEBUGGER_REGISTER_FP_CS
:
55 *Width
= (UINT8
) sizeof (UINT16
);
56 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Cs
);
58 case SOFT_DEBUGGER_REGISTER_FP_DATAOFFSET
:
59 *Width
= (UINT8
) sizeof (UINTN
);
60 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, DataOffset
);
62 case SOFT_DEBUGGER_REGISTER_FP_DS
:
63 *Width
= (UINT8
) sizeof (UINT16
);
64 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Ds
);
66 case SOFT_DEBUGGER_REGISTER_FP_MXCSR
:
67 *Width
= (UINT8
) sizeof (UINTN
);
68 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Mxcsr
);
70 case SOFT_DEBUGGER_REGISTER_FP_MXCSR_MASK
:
71 *Width
= (UINT8
) sizeof (UINTN
);
72 return (UINT16
)OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, Mxcsr_Mask
);
76 if (Index
< SOFT_DEBUGGER_REGISTER_XMM0
) {
78 } else if (Index
< SOFT_DEBUGGER_REGISTER_MM0
) {
82 Index
-= SOFT_DEBUGGER_REGISTER_MM0
- SOFT_DEBUGGER_REGISTER_ST0
;
85 return (UINT16
)(OFFSET_OF(DEBUG_DATA_IA32_FX_SAVE_STATE
, St0Mm0
) + (Index
- SOFT_DEBUGGER_REGISTER_ST0
) * 16);
89 Write specified register into save CPU context.
91 @param[in] CpuContext Pointer to saved CPU context.
92 @param[in] Index Register index value.
93 @param[in] Offset Offset in register address range.
94 @param[in] Width Data width to read.
95 @param[in] RegisterBuffer Pointer to input buffer with data.
99 ArchWriteRegisterBuffer (
100 IN DEBUG_CPU_CONTEXT
*CpuContext
,
104 IN UINT8
*RegisterBuffer
108 if (Index
< SOFT_DEBUGGER_REGISTER_FP_BASE
) {
109 Buffer
= (UINT8
*) CpuContext
+ sizeof (DEBUG_DATA_IA32_FX_SAVE_STATE
) + Index
* 4;
112 // If it is MMX register, adjust its index position
114 if (Index
>= SOFT_DEBUGGER_REGISTER_MM0
) {
115 Index
-= SOFT_DEBUGGER_REGISTER_MM0
- SOFT_DEBUGGER_REGISTER_ST0
;
118 // FPU/MMX/XMM registers
120 Buffer
= (UINT8
*) CpuContext
+ ArchReadFxStatOffset (Index
, &Width
);
123 CopyMem (Buffer
+ Offset
, RegisterBuffer
, Width
);
127 Read register value from saved CPU context.
129 @param[in] CpuContext Pointer to saved CPU context.
130 @param[in] Index Register index value.
131 @param[in] Offset Offset in register address range
132 @param[in] Width Data width to read.
134 @return The address of register value.
138 ArchReadRegisterBuffer (
139 IN DEBUG_CPU_CONTEXT
*CpuContext
,
147 if (Index
< SOFT_DEBUGGER_REGISTER_FP_BASE
) {
148 Buffer
= (UINT8
*) CpuContext
+ sizeof (DEBUG_DATA_IA32_FX_SAVE_STATE
) + Index
* 4;
150 *Width
= (UINT8
) sizeof (UINTN
);
154 // FPU/MMX/XMM registers
156 Buffer
= (UINT8
*) CpuContext
+ ArchReadFxStatOffset (Index
, Width
);
163 Read group register of common registers.
165 @param[in] CpuContext Pointer to saved CPU context.
166 @param[in] RegisterGroup Pointer to Group registers.
171 IN DEBUG_CPU_CONTEXT
*CpuContext
,
172 IN DEBUG_DATA_REPONSE_READ_REGISTER_GROUP
*RegisterGroup
175 RegisterGroup
->Cs
= (UINT16
) CpuContext
->Cs
;
176 RegisterGroup
->Ds
= (UINT16
) CpuContext
->Ds
;
177 RegisterGroup
->Es
= (UINT16
) CpuContext
->Es
;
178 RegisterGroup
->Fs
= (UINT16
) CpuContext
->Fs
;
179 RegisterGroup
->Gs
= (UINT16
) CpuContext
->Gs
;
180 RegisterGroup
->Ss
= (UINT16
) CpuContext
->Ss
;
181 RegisterGroup
->Eflags
= CpuContext
->Eflags
;
182 RegisterGroup
->Ebp
= CpuContext
->Ebp
;
183 RegisterGroup
->Eip
= CpuContext
->Eip
;
184 RegisterGroup
->Esp
= CpuContext
->Esp
;
185 RegisterGroup
->Eax
= CpuContext
->Eax
;
186 RegisterGroup
->Ebx
= CpuContext
->Ebx
;
187 RegisterGroup
->Ecx
= CpuContext
->Ecx
;
188 RegisterGroup
->Edx
= CpuContext
->Edx
;
189 RegisterGroup
->Esi
= CpuContext
->Esi
;
190 RegisterGroup
->Edi
= CpuContext
->Edi
;
191 RegisterGroup
->Dr0
= CpuContext
->Dr0
;
192 RegisterGroup
->Dr1
= CpuContext
->Dr1
;
193 RegisterGroup
->Dr2
= CpuContext
->Dr2
;
194 RegisterGroup
->Dr3
= CpuContext
->Dr3
;
195 RegisterGroup
->Dr6
= CpuContext
->Dr6
;
196 RegisterGroup
->Dr7
= CpuContext
->Dr7
;
200 Initialize IDT entries to support source level debug.
208 IA32_IDT_GATE_DESCRIPTOR
*IdtEntry
;
209 UINTN InterruptHandler
;
210 IA32_DESCRIPTOR IdtDescriptor
;
214 AsmReadIdtr (&IdtDescriptor
);
217 // Use current CS as the segment selector of interrupt gate in IDT
219 CodeSegment
= AsmReadCs ();
221 IdtEntry
= (IA32_IDT_GATE_DESCRIPTOR
*) IdtDescriptor
.Base
;
223 for (Index
= 0; Index
< 20; Index
++) {
224 if ((PcdGet32 (PcdExceptionsIgnoredByDebugger
) & (1 << Index
)) != 0) {
226 // If the exception is masked to be reserved, skip it
230 InterruptHandler
= (UINTN
)&Exception0Handle
+ Index
* ExceptionStubHeaderSize
;
231 IdtEntry
[Index
].Bits
.OffsetLow
= (UINT16
)(UINTN
)InterruptHandler
;
232 IdtEntry
[Index
].Bits
.OffsetHigh
= (UINT16
)((UINTN
)InterruptHandler
>> 16);
233 IdtEntry
[Index
].Bits
.Selector
= CodeSegment
;
234 IdtEntry
[Index
].Bits
.GateType
= IA32_IDT_GATE_TYPE_INTERRUPT_32
;
237 InterruptHandler
= (UINTN
) &TimerInterruptHandle
;
238 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.OffsetLow
= (UINT16
)(UINTN
)InterruptHandler
;
239 IdtEntry
[DEBUG_TIMER_VECTOR
].Bits
.OffsetHigh
= (UINT16
)((UINTN
)InterruptHandler
>> 16);
240 IdtEntry
[Index
].Bits
.Selector
= CodeSegment
;
241 IdtEntry
[Index
].Bits
.GateType
= IA32_IDT_GATE_TYPE_INTERRUPT_32
;