2 DebugSupport protocol and supporting definitions as defined in the UEFI2.4
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 - 2018, Intel Corporation. All rights reserved.<BR>
9 Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #ifndef __DEBUG_SUPPORT_H__
16 #define __DEBUG_SUPPORT_H__
18 #include <IndustryStandard/PeImage.h>
20 typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL
;
23 /// Debug Support protocol {2755590C-6F3C-42FA-9EA4-A3BA543CDA25}.
25 #define EFI_DEBUG_SUPPORT_PROTOCOL_GUID \
27 0x2755590C, 0x6F3C, 0x42FA, {0x9E, 0xA4, 0xA3, 0xBA, 0x54, 0x3C, 0xDA, 0x25 } \
31 /// Processor exception to be hooked.
32 /// All exception types for IA32, X64, Itanium and EBC processors are defined.
34 typedef INTN EFI_EXCEPTION_TYPE
;
37 /// IA-32 processor exception types.
39 #define EXCEPT_IA32_DIVIDE_ERROR 0
40 #define EXCEPT_IA32_DEBUG 1
41 #define EXCEPT_IA32_NMI 2
42 #define EXCEPT_IA32_BREAKPOINT 3
43 #define EXCEPT_IA32_OVERFLOW 4
44 #define EXCEPT_IA32_BOUND 5
45 #define EXCEPT_IA32_INVALID_OPCODE 6
46 #define EXCEPT_IA32_DOUBLE_FAULT 8
47 #define EXCEPT_IA32_INVALID_TSS 10
48 #define EXCEPT_IA32_SEG_NOT_PRESENT 11
49 #define EXCEPT_IA32_STACK_FAULT 12
50 #define EXCEPT_IA32_GP_FAULT 13
51 #define EXCEPT_IA32_PAGE_FAULT 14
52 #define EXCEPT_IA32_FP_ERROR 16
53 #define EXCEPT_IA32_ALIGNMENT_CHECK 17
54 #define EXCEPT_IA32_MACHINE_CHECK 18
55 #define EXCEPT_IA32_SIMD 19
59 /// FP / MMX / XMM registers (see fxrstor instruction definition).
72 UINT8 St0Mm0
[10], Reserved3
[6];
73 UINT8 St1Mm1
[10], Reserved4
[6];
74 UINT8 St2Mm2
[10], Reserved5
[6];
75 UINT8 St3Mm3
[10], Reserved6
[6];
76 UINT8 St4Mm4
[10], Reserved7
[6];
77 UINT8 St5Mm5
[10], Reserved8
[6];
78 UINT8 St6Mm6
[10], Reserved9
[6];
79 UINT8 St7Mm7
[10], Reserved10
[6];
88 UINT8 Reserved11
[14 * 16];
89 } EFI_FX_SAVE_STATE_IA32
;
92 /// IA-32 processor context definition.
96 EFI_FX_SAVE_STATE_IA32 FxSaveState
;
104 UINT32 Cr1
; /* Reserved */
128 } EFI_SYSTEM_CONTEXT_IA32
;
131 /// x64 processor exception types.
133 #define EXCEPT_X64_DIVIDE_ERROR 0
134 #define EXCEPT_X64_DEBUG 1
135 #define EXCEPT_X64_NMI 2
136 #define EXCEPT_X64_BREAKPOINT 3
137 #define EXCEPT_X64_OVERFLOW 4
138 #define EXCEPT_X64_BOUND 5
139 #define EXCEPT_X64_INVALID_OPCODE 6
140 #define EXCEPT_X64_DOUBLE_FAULT 8
141 #define EXCEPT_X64_INVALID_TSS 10
142 #define EXCEPT_X64_SEG_NOT_PRESENT 11
143 #define EXCEPT_X64_STACK_FAULT 12
144 #define EXCEPT_X64_GP_FAULT 13
145 #define EXCEPT_X64_PAGE_FAULT 14
146 #define EXCEPT_X64_FP_ERROR 16
147 #define EXCEPT_X64_ALIGNMENT_CHECK 17
148 #define EXCEPT_X64_MACHINE_CHECK 18
149 #define EXCEPT_X64_SIMD 19
153 /// FP / MMX / XMM registers (see fxrstor instruction definition).
163 UINT8 St0Mm0
[10], Reserved2
[6];
164 UINT8 St1Mm1
[10], Reserved3
[6];
165 UINT8 St2Mm2
[10], Reserved4
[6];
166 UINT8 St3Mm3
[10], Reserved5
[6];
167 UINT8 St4Mm4
[10], Reserved6
[6];
168 UINT8 St5Mm5
[10], Reserved7
[6];
169 UINT8 St6Mm6
[10], Reserved8
[6];
170 UINT8 St7Mm7
[10], Reserved9
[6];
180 // NOTE: UEFI 2.0 spec definition as follows.
182 UINT8 Reserved11
[14 * 16];
183 } EFI_FX_SAVE_STATE_X64
;
186 /// x64 processor context definition.
189 UINT64 ExceptionData
;
190 EFI_FX_SAVE_STATE_X64 FxSaveState
;
198 UINT64 Cr1
; /* Reserved */
231 } EFI_SYSTEM_CONTEXT_X64
;
234 /// Itanium Processor Family Exception types.
236 #define EXCEPT_IPF_VHTP_TRANSLATION 0
237 #define EXCEPT_IPF_INSTRUCTION_TLB 1
238 #define EXCEPT_IPF_DATA_TLB 2
239 #define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
240 #define EXCEPT_IPF_ALT_DATA_TLB 4
241 #define EXCEPT_IPF_DATA_NESTED_TLB 5
242 #define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
243 #define EXCEPT_IPF_DATA_KEY_MISSED 7
244 #define EXCEPT_IPF_DIRTY_BIT 8
245 #define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
246 #define EXCEPT_IPF_DATA_ACCESS_BIT 10
247 #define EXCEPT_IPF_BREAKPOINT 11
248 #define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
252 #define EXCEPT_IPF_PAGE_NOT_PRESENT 20
253 #define EXCEPT_IPF_KEY_PERMISSION 21
254 #define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
255 #define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
256 #define EXCEPT_IPF_GENERAL_EXCEPTION 24
257 #define EXCEPT_IPF_DISABLED_FP_REGISTER 25
258 #define EXCEPT_IPF_NAT_CONSUMPTION 26
259 #define EXCEPT_IPF_SPECULATION 27
263 #define EXCEPT_IPF_DEBUG 29
264 #define EXCEPT_IPF_UNALIGNED_REFERENCE 30
265 #define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
266 #define EXCEPT_IPF_FP_FAULT 32
267 #define EXCEPT_IPF_FP_TRAP 33
268 #define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
269 #define EXCEPT_IPF_TAKEN_BRANCH 35
270 #define EXCEPT_IPF_SINGLE_STEP 36
274 #define EXCEPT_IPF_IA32_EXCEPTION 45
275 #define EXCEPT_IPF_IA32_INTERCEPT 46
276 #define EXCEPT_IPF_IA32_INTERRUPT 47
279 /// IPF processor context definition.
283 // The first reserved field is necessary to preserve alignment for the correct
284 // bits in UNAT and to insure F2 is 16 byte aligned.
362 // application registers
428 // virtual registers - nat bits for R1-R31
432 } EFI_SYSTEM_CONTEXT_IPF
;
435 /// EBC processor exception types.
437 #define EXCEPT_EBC_UNDEFINED 0
438 #define EXCEPT_EBC_DIVIDE_ERROR 1
439 #define EXCEPT_EBC_DEBUG 2
440 #define EXCEPT_EBC_BREAKPOINT 3
441 #define EXCEPT_EBC_OVERFLOW 4
442 #define EXCEPT_EBC_INVALID_OPCODE 5 ///< Opcode out of range.
443 #define EXCEPT_EBC_STACK_FAULT 6
444 #define EXCEPT_EBC_ALIGNMENT_CHECK 7
445 #define EXCEPT_EBC_INSTRUCTION_ENCODING 8 ///< Malformed instruction.
446 #define EXCEPT_EBC_BAD_BREAK 9 ///< BREAK 0 or undefined BREAK.
447 #define EXCEPT_EBC_STEP 10 ///< To support debug stepping.
449 /// For coding convenience, define the maximum valid EBC exception.
451 #define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
454 /// EBC processor context definition.
468 } EFI_SYSTEM_CONTEXT_EBC
;
473 /// ARM processor exception types.
475 #define EXCEPT_ARM_RESET 0
476 #define EXCEPT_ARM_UNDEFINED_INSTRUCTION 1
477 #define EXCEPT_ARM_SOFTWARE_INTERRUPT 2
478 #define EXCEPT_ARM_PREFETCH_ABORT 3
479 #define EXCEPT_ARM_DATA_ABORT 4
480 #define EXCEPT_ARM_RESERVED 5
481 #define EXCEPT_ARM_IRQ 6
482 #define EXCEPT_ARM_FIQ 7
485 /// For coding convenience, define the maximum valid ARM exception.
487 #define MAX_ARM_EXCEPTION EXCEPT_ARM_FIQ
490 /// ARM processor context definition.
514 } EFI_SYSTEM_CONTEXT_ARM
;
518 /// AARCH64 processor exception types.
520 #define EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS 0
521 #define EXCEPT_AARCH64_IRQ 1
522 #define EXCEPT_AARCH64_FIQ 2
523 #define EXCEPT_AARCH64_SERROR 3
526 /// For coding convenience, define the maximum valid ARM exception.
528 #define MAX_AARCH64_EXCEPTION EXCEPT_AARCH64_SERROR
531 // General Purpose Registers
561 UINT64 FP
; // x29 - Frame pointer
562 UINT64 LR
; // x30 - Link Register
563 UINT64 SP
; // x31 - Stack pointer
599 UINT64 ELR
; // Exception Link Register
600 UINT64 SPSR
; // Saved Processor Status Register
601 UINT64 FPSR
; // Floating Point Status Register
602 UINT64 ESR
; // Exception syndrome register
603 UINT64 FAR
; // Fault Address Register
604 } EFI_SYSTEM_CONTEXT_AARCH64
;
608 /// Universal EFI_SYSTEM_CONTEXT definition.
611 EFI_SYSTEM_CONTEXT_EBC
*SystemContextEbc
;
612 EFI_SYSTEM_CONTEXT_IA32
*SystemContextIa32
;
613 EFI_SYSTEM_CONTEXT_X64
*SystemContextX64
;
614 EFI_SYSTEM_CONTEXT_IPF
*SystemContextIpf
;
615 EFI_SYSTEM_CONTEXT_ARM
*SystemContextArm
;
616 EFI_SYSTEM_CONTEXT_AARCH64
*SystemContextAArch64
;
617 } EFI_SYSTEM_CONTEXT
;
620 // DebugSupport callback function prototypes
624 Registers and enables an exception callback function for the specified exception.
626 @param ExceptionType Exception types in EBC, IA-32, x64, or IPF.
627 @param SystemContext Exception content.
632 (EFIAPI
*EFI_EXCEPTION_CALLBACK
)(
633 IN EFI_EXCEPTION_TYPE ExceptionType
,
634 IN OUT EFI_SYSTEM_CONTEXT SystemContext
638 Registers and enables the on-target debug agent's periodic entry point.
640 @param SystemContext Exception content.
645 (EFIAPI
*EFI_PERIODIC_CALLBACK
)(
646 IN OUT EFI_SYSTEM_CONTEXT SystemContext
650 /// Machine type definition
653 IsaIa32
= IMAGE_FILE_MACHINE_I386
, ///< 0x014C
654 IsaX64
= IMAGE_FILE_MACHINE_X64
, ///< 0x8664
655 IsaIpf
= IMAGE_FILE_MACHINE_IA64
, ///< 0x0200
656 IsaEbc
= IMAGE_FILE_MACHINE_EBC
, ///< 0x0EBC
657 IsaArm
= IMAGE_FILE_MACHINE_ARMTHUMB_MIXED
, ///< 0x01c2
658 IsaAArch64
= IMAGE_FILE_MACHINE_ARM64
///< 0xAA64
659 } EFI_INSTRUCTION_SET_ARCHITECTURE
;
663 // DebugSupport member function definitions
667 Returns the maximum value that may be used for the ProcessorIndex parameter in
668 RegisterPeriodicCallback() and RegisterExceptionCallback().
670 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
671 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported
672 processor index is returned.
674 @retval EFI_SUCCESS The function completed successfully.
679 (EFIAPI
*EFI_GET_MAXIMUM_PROCESSOR_INDEX
)(
680 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
681 OUT UINTN
*MaxProcessorIndex
685 Registers a function to be called back periodically in interrupt context.
687 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
688 @param ProcessorIndex Specifies which processor the callback function applies to.
689 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main
690 periodic entry point of the debug agent.
692 @retval EFI_SUCCESS The function completed successfully.
693 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
694 function was previously registered.
695 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
701 (EFIAPI
*EFI_REGISTER_PERIODIC_CALLBACK
)(
702 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
703 IN UINTN ProcessorIndex
,
704 IN EFI_PERIODIC_CALLBACK PeriodicCallback
708 Registers a function to be called when a given processor exception occurs.
710 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
711 @param ProcessorIndex Specifies which processor the callback function applies to.
712 @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called
713 when the processor exception specified by ExceptionType occurs.
714 @param ExceptionType Specifies which processor exception to hook.
716 @retval EFI_SUCCESS The function completed successfully.
717 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
718 function was previously registered.
719 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
725 (EFIAPI
*EFI_REGISTER_EXCEPTION_CALLBACK
)(
726 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
727 IN UINTN ProcessorIndex
,
728 IN EFI_EXCEPTION_CALLBACK ExceptionCallback
,
729 IN EFI_EXCEPTION_TYPE ExceptionType
733 Invalidates processor instruction cache for a memory range. Subsequent execution in this range
734 causes a fresh memory fetch to retrieve code to be executed.
736 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
737 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.
738 @param Start Specifies the physical base of the memory range to be invalidated.
739 @param Length Specifies the minimum number of bytes in the processor's instruction
742 @retval EFI_SUCCESS The function completed successfully.
747 (EFIAPI
*EFI_INVALIDATE_INSTRUCTION_CACHE
)(
748 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
749 IN UINTN ProcessorIndex
,
755 /// This protocol provides the services to allow the debug agent to register
756 /// callback functions that are called either periodically or when specific
757 /// processor exceptions occur.
759 struct _EFI_DEBUG_SUPPORT_PROTOCOL
{
761 /// Declares the processor architecture for this instance of the EFI Debug Support protocol.
763 EFI_INSTRUCTION_SET_ARCHITECTURE Isa
;
764 EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex
;
765 EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback
;
766 EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback
;
767 EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache
;
770 extern EFI_GUID gEfiDebugSupportProtocolGuid
;