2 DebugSupport protocol and supporting definitions as defined in the UEFI2.0
5 The DebugSupport protocol is used by source level debuggers to abstract the
6 processor and handle context save and restore operations.
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #ifndef __DEBUG_SUPPORT_H__
20 #define __DEBUG_SUPPORT_H__
22 #include <ProcessorBind.h>
23 #include <IndustryStandard/PeImage.h>
25 typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL
;
28 // Debug Support protocol {2755590C-6F3C-42FA-9EA4-A3BA543CDA25}
30 #define EFI_DEBUG_SUPPORT_PROTOCOL_GUID \
32 0x2755590C, 0x6F3C, 0x42FA, {0x9E, 0xA4, 0xA3, 0xBA, 0x54, 0x3C, 0xDA, 0x25 } \
36 // Debug Support definitions
38 typedef INTN EFI_EXCEPTION_TYPE
;
41 // IA-32 processor exception types
43 #define EXCEPT_IA32_DIVIDE_ERROR 0
44 #define EXCEPT_IA32_DEBUG 1
45 #define EXCEPT_IA32_NMI 2
46 #define EXCEPT_IA32_BREAKPOINT 3
47 #define EXCEPT_IA32_OVERFLOW 4
48 #define EXCEPT_IA32_BOUND 5
49 #define EXCEPT_IA32_INVALID_OPCODE 6
50 #define EXCEPT_IA32_DOUBLE_FAULT 8
51 #define EXCEPT_IA32_INVALID_TSS 10
52 #define EXCEPT_IA32_SEG_NOT_PRESENT 11
53 #define EXCEPT_IA32_STACK_FAULT 12
54 #define EXCEPT_IA32_GP_FAULT 13
55 #define EXCEPT_IA32_PAGE_FAULT 14
56 #define EXCEPT_IA32_FP_ERROR 16
57 #define EXCEPT_IA32_ALIGNMENT_CHECK 17
58 #define EXCEPT_IA32_MACHINE_CHECK 18
59 #define EXCEPT_IA32_SIMD 19
62 // IA-32 processor context definition
66 // FP / MMX / XMM registers (see fxrstor instruction definition)
79 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
80 UINT8 St0Mm0
[10], Reserved3
[6];
81 UINT8 St1Mm1
[10], Reserved4
[6];
82 UINT8 St2Mm2
[10], Reserved5
[6];
83 UINT8 St3Mm3
[10], Reserved6
[6];
84 UINT8 St4Mm4
[10], Reserved7
[6];
85 UINT8 St5Mm5
[10], Reserved8
[6];
86 UINT8 St6Mm6
[10], Reserved9
[6];
87 UINT8 St7Mm7
[10], Reserved10
[6];
96 UINT8 Reserved11
[14 * 16];
97 } EFI_FX_SAVE_STATE_IA32
;
99 UINT8 St0Mm0
[10], Reserved3
[6];
100 UINT8 St0Mm1
[10], Reserved4
[6];
101 UINT8 St0Mm2
[10], Reserved5
[6];
102 UINT8 St0Mm3
[10], Reserved6
[6];
103 UINT8 St0Mm4
[10], Reserved7
[6];
104 UINT8 St0Mm5
[10], Reserved8
[6];
105 UINT8 St0Mm6
[10], Reserved9
[6];
106 UINT8 St0Mm7
[10], Reserved10
[6];
107 UINT8 Reserved11
[22 * 16];
112 UINT32 ExceptionData
;
113 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
114 EFI_FX_SAVE_STATE_IA32 FxSaveState
;
116 EFI_FX_SAVE_STATE FxSaveState
;
125 UINT32 Cr1
; /* Reserved */
149 } EFI_SYSTEM_CONTEXT_IA32
;
152 // X64 processor exception types
154 #define EXCEPT_X64_DIVIDE_ERROR 0
155 #define EXCEPT_X64_DEBUG 1
156 #define EXCEPT_X64_NMI 2
157 #define EXCEPT_X64_BREAKPOINT 3
158 #define EXCEPT_X64_OVERFLOW 4
159 #define EXCEPT_X64_BOUND 5
160 #define EXCEPT_X64_INVALID_OPCODE 6
161 #define EXCEPT_X64_DOUBLE_FAULT 8
162 #define EXCEPT_X64_INVALID_TSS 10
163 #define EXCEPT_X64_SEG_NOT_PRESENT 11
164 #define EXCEPT_X64_STACK_FAULT 12
165 #define EXCEPT_X64_GP_FAULT 13
166 #define EXCEPT_X64_PAGE_FAULT 14
167 #define EXCEPT_X64_FP_ERROR 16
168 #define EXCEPT_X64_ALIGNMENT_CHECK 17
169 #define EXCEPT_X64_MACHINE_CHECK 18
170 #define EXCEPT_X64_SIMD 19
173 // X64 processor context definition
176 // FP / MMX / XMM registers (see fxrstor instruction definition)
186 UINT8 St0Mm0
[10], Reserved2
[6];
187 UINT8 St1Mm1
[10], Reserved3
[6];
188 UINT8 St2Mm2
[10], Reserved4
[6];
189 UINT8 St3Mm3
[10], Reserved5
[6];
190 UINT8 St4Mm4
[10], Reserved6
[6];
191 UINT8 St5Mm5
[10], Reserved7
[6];
192 UINT8 St6Mm6
[10], Reserved8
[6];
193 UINT8 St7Mm7
[10], Reserved9
[6];
202 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
204 // NOTE: UEFI 2.0 spec definition as follows. It should be updated
205 // after spec update.
207 UINT8 Reserved11
[14 * 16];
217 UINT8 Reserved10
[6 * 16];
219 } EFI_FX_SAVE_STATE_X64
;
222 UINT64 ExceptionData
;
223 EFI_FX_SAVE_STATE_X64 FxSaveState
;
231 UINT64 Cr1
; /* Reserved */
264 } EFI_SYSTEM_CONTEXT_X64
;
267 // IPF processor exception types
269 #define EXCEPT_IPF_VHTP_TRANSLATION 0
270 #define EXCEPT_IPF_INSTRUCTION_TLB 1
271 #define EXCEPT_IPF_DATA_TLB 2
272 #define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
273 #define EXCEPT_IPF_ALT_DATA_TLB 4
274 #define EXCEPT_IPF_DATA_NESTED_TLB 5
275 #define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
276 #define EXCEPT_IPF_DATA_KEY_MISSED 7
277 #define EXCEPT_IPF_DIRTY_BIT 8
278 #define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
279 #define EXCEPT_IPF_DATA_ACCESS_BIT 10
280 #define EXCEPT_IPF_BREAKPOINT 11
281 #define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
285 #define EXCEPT_IPF_PAGE_NOT_PRESENT 20
286 #define EXCEPT_IPF_KEY_PERMISSION 21
287 #define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
288 #define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
289 #define EXCEPT_IPF_GENERAL_EXCEPTION 24
290 #define EXCEPT_IPF_DISABLED_FP_REGISTER 25
291 #define EXCEPT_IPF_NAT_CONSUMPTION 26
292 #define EXCEPT_IPF_SPECULATION 27
296 #define EXCEPT_IPF_DEBUG 29
297 #define EXCEPT_IPF_UNALIGNED_REFERENCE 30
298 #define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
299 #define EXCEPT_IPF_FP_FAULT 32
300 #define EXCEPT_IPF_FP_TRAP 33
301 #define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
302 #define EXCEPT_IPF_TAKEN_BRANCH 35
303 #define EXCEPT_IPF_SINGLE_STEP 36
307 #define EXCEPT_IPF_IA32_EXCEPTION 45
308 #define EXCEPT_IPF_IA32_INTERCEPT 46
309 #define EXCEPT_IPF_IA32_INTERRUPT 47
312 // IPF processor context definition
316 // The first reserved field is necessary to preserve alignment for the correct
317 // bits in UNAT and to insure F2 is 16 byte aligned..
395 // application registers
461 // virtual registers - nat bits for R1-R31
465 } EFI_SYSTEM_CONTEXT_IPF
;
468 // EBC processor exception types
470 #define EXCEPT_EBC_UNDEFINED 0
471 #define EXCEPT_EBC_DIVIDE_ERROR 1
472 #define EXCEPT_EBC_DEBUG 2
473 #define EXCEPT_EBC_BREAKPOINT 3
474 #define EXCEPT_EBC_OVERFLOW 4
475 #define EXCEPT_EBC_INVALID_OPCODE 5 // opcode out of range
476 #define EXCEPT_EBC_STACK_FAULT 6
477 #define EXCEPT_EBC_ALIGNMENT_CHECK 7
478 #define EXCEPT_EBC_INSTRUCTION_ENCODING 8 // malformed instruction
479 #define EXCEPT_EBC_BAD_BREAK 9 // BREAK 0 or undefined BREAK
480 #define EXCEPT_EBC_STEP 10 // to support debug stepping
482 // For coding convenience, define the maximum valid EBC exception.
484 #define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
487 // EBC processor context definition
501 } EFI_SYSTEM_CONTEXT_EBC
;
504 // Universal EFI_SYSTEM_CONTEXT definition
507 EFI_SYSTEM_CONTEXT_EBC
*SystemContextEbc
;
508 EFI_SYSTEM_CONTEXT_IA32
*SystemContextIa32
;
509 EFI_SYSTEM_CONTEXT_X64
*SystemContextX64
;
510 EFI_SYSTEM_CONTEXT_IPF
*SystemContextIpf
;
511 } EFI_SYSTEM_CONTEXT
;
514 // DebugSupport callback function prototypes
518 Registers and enables an exception callback function for the specified exception.
520 @param ExceptionType Exception types in EBC, IA-32, X64, or IPF
521 @param SystemContext Exception content.
526 (*EFI_EXCEPTION_CALLBACK
) (
527 IN EFI_EXCEPTION_TYPE ExceptionType
,
528 IN OUT EFI_SYSTEM_CONTEXT SystemContext
532 Registers and enables the on-target debug agent's periodic entry point.
534 @param SystemContext Exception content.
539 (*EFI_PERIODIC_CALLBACK
) (
540 IN OUT EFI_SYSTEM_CONTEXT SystemContext
544 // Machine type definition
547 IsaIa32
= IMAGE_FILE_MACHINE_I386
, // 0x014C
548 IsaX64
= IMAGE_FILE_MACHINE_X64
, // 0x8664
549 IsaIpf
= IMAGE_FILE_MACHINE_IA64
, // 0x0200
550 IsaEbc
= IMAGE_FILE_MACHINE_EBC
// 0x0EBC
551 } EFI_INSTRUCTION_SET_ARCHITECTURE
;
555 // DebugSupport member function definitions
559 Returns the maximum value that may be used for the ProcessorIndex parameter in
560 RegisterPeriodicCallback() and RegisterExceptionCallback().
562 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
563 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported
564 processor index is returned.
566 @retval EFI_SUCCESS The function completed successfully.
571 (EFIAPI
*EFI_GET_MAXIMUM_PROCESSOR_INDEX
) (
572 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
573 OUT UINTN
*MaxProcessorIndex
577 Registers a function to be called back periodically in interrupt context.
579 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
580 @param ProcessorIndex Specifies which processor the callback function applies to.
581 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main
582 periodic entry point of the debug agent.
584 @retval EFI_SUCCESS The function completed successfully.
585 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
586 function was previously registered.
587 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
593 (EFIAPI
*EFI_REGISTER_PERIODIC_CALLBACK
) (
594 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
595 IN UINTN ProcessorIndex
,
596 IN EFI_PERIODIC_CALLBACK PeriodicCallback
600 Registers a function to be called when a given processor exception occurs.
602 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
603 @param ProcessorIndex Specifies which processor the callback function applies to.
604 @param PeriodicCallback A pointer to a function of type EXCEPTION_CALLBACK that is called
605 when the processor exception specified by ExceptionType occurs.
606 @param ExceptionType Specifies which processor exception to hook.
608 @retval EFI_SUCCESS The function completed successfully.
609 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
610 function was previously registered.
611 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
617 (EFIAPI
*EFI_REGISTER_EXCEPTION_CALLBACK
) (
618 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
619 IN UINTN ProcessorIndex
,
620 IN EFI_EXCEPTION_CALLBACK ExceptionCallback
,
621 IN EFI_EXCEPTION_TYPE ExceptionType
625 Invalidates processor instruction cache for a memory range. Subsequent execution in this range
626 causes a fresh memory fetch to retrieve code to be executed.
628 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
629 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.
630 @param Start Specifies the physical base of the memory range to be invalidated.
631 @param Length Specifies the minimum number of bytes in the processor's instruction
634 @retval EFI_SUCCESS The function completed successfully.
639 (EFIAPI
*EFI_INVALIDATE_INSTRUCTION_CACHE
) (
640 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
641 IN UINTN ProcessorIndex
,
647 // DebugSupport protocol definition
649 struct _EFI_DEBUG_SUPPORT_PROTOCOL
{
650 EFI_INSTRUCTION_SET_ARCHITECTURE Isa
;
651 EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex
;
652 EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback
;
653 EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback
;
654 EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache
;
657 extern EFI_GUID gEfiDebugSupportProtocolGuid
;