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 - 2009, Intel Corporation<BR>
9 Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #ifndef __DEBUG_SUPPORT_H__
21 #define __DEBUG_SUPPORT_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 /// Processor exception to be hooked.
37 /// All exception types for IA32, X64, Itanium and EBC processors are defined.
39 typedef INTN EFI_EXCEPTION_TYPE
;
42 /// IA-32 processor exception types
44 #define EXCEPT_IA32_DIVIDE_ERROR 0
45 #define EXCEPT_IA32_DEBUG 1
46 #define EXCEPT_IA32_NMI 2
47 #define EXCEPT_IA32_BREAKPOINT 3
48 #define EXCEPT_IA32_OVERFLOW 4
49 #define EXCEPT_IA32_BOUND 5
50 #define EXCEPT_IA32_INVALID_OPCODE 6
51 #define EXCEPT_IA32_DOUBLE_FAULT 8
52 #define EXCEPT_IA32_INVALID_TSS 10
53 #define EXCEPT_IA32_SEG_NOT_PRESENT 11
54 #define EXCEPT_IA32_STACK_FAULT 12
55 #define EXCEPT_IA32_GP_FAULT 13
56 #define EXCEPT_IA32_PAGE_FAULT 14
57 #define EXCEPT_IA32_FP_ERROR 16
58 #define EXCEPT_IA32_ALIGNMENT_CHECK 17
59 #define EXCEPT_IA32_MACHINE_CHECK 18
60 #define EXCEPT_IA32_SIMD 19
64 /// FP / MMX / XMM registers (see fxrstor instruction definition)
77 UINT8 St0Mm0
[10], Reserved3
[6];
78 UINT8 St1Mm1
[10], Reserved4
[6];
79 UINT8 St2Mm2
[10], Reserved5
[6];
80 UINT8 St3Mm3
[10], Reserved6
[6];
81 UINT8 St4Mm4
[10], Reserved7
[6];
82 UINT8 St5Mm5
[10], Reserved8
[6];
83 UINT8 St6Mm6
[10], Reserved9
[6];
84 UINT8 St7Mm7
[10], Reserved10
[6];
93 UINT8 Reserved11
[14 * 16];
94 } EFI_FX_SAVE_STATE_IA32
;
97 /// IA-32 processor context definition
100 UINT32 ExceptionData
;
101 EFI_FX_SAVE_STATE_IA32 FxSaveState
;
109 UINT32 Cr1
; /* Reserved */
133 } EFI_SYSTEM_CONTEXT_IA32
;
136 /// x64 processor exception types
138 #define EXCEPT_X64_DIVIDE_ERROR 0
139 #define EXCEPT_X64_DEBUG 1
140 #define EXCEPT_X64_NMI 2
141 #define EXCEPT_X64_BREAKPOINT 3
142 #define EXCEPT_X64_OVERFLOW 4
143 #define EXCEPT_X64_BOUND 5
144 #define EXCEPT_X64_INVALID_OPCODE 6
145 #define EXCEPT_X64_DOUBLE_FAULT 8
146 #define EXCEPT_X64_INVALID_TSS 10
147 #define EXCEPT_X64_SEG_NOT_PRESENT 11
148 #define EXCEPT_X64_STACK_FAULT 12
149 #define EXCEPT_X64_GP_FAULT 13
150 #define EXCEPT_X64_PAGE_FAULT 14
151 #define EXCEPT_X64_FP_ERROR 16
152 #define EXCEPT_X64_ALIGNMENT_CHECK 17
153 #define EXCEPT_X64_MACHINE_CHECK 18
154 #define EXCEPT_X64_SIMD 19
158 /// FP / MMX / XMM registers (see fxrstor instruction definition)
168 UINT8 St0Mm0
[10], Reserved2
[6];
169 UINT8 St1Mm1
[10], Reserved3
[6];
170 UINT8 St2Mm2
[10], Reserved4
[6];
171 UINT8 St3Mm3
[10], Reserved5
[6];
172 UINT8 St4Mm4
[10], Reserved6
[6];
173 UINT8 St5Mm5
[10], Reserved7
[6];
174 UINT8 St6Mm6
[10], Reserved8
[6];
175 UINT8 St7Mm7
[10], Reserved9
[6];
185 // NOTE: UEFI 2.0 spec definition as follows.
187 UINT8 Reserved11
[14 * 16];
188 } EFI_FX_SAVE_STATE_X64
;
191 /// x64 processor context definition
194 UINT64 ExceptionData
;
195 EFI_FX_SAVE_STATE_X64 FxSaveState
;
203 UINT64 Cr1
; /* Reserved */
236 } EFI_SYSTEM_CONTEXT_X64
;
239 /// Itanium Processor Family Exception types
241 #define EXCEPT_IPF_VHTP_TRANSLATION 0
242 #define EXCEPT_IPF_INSTRUCTION_TLB 1
243 #define EXCEPT_IPF_DATA_TLB 2
244 #define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
245 #define EXCEPT_IPF_ALT_DATA_TLB 4
246 #define EXCEPT_IPF_DATA_NESTED_TLB 5
247 #define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
248 #define EXCEPT_IPF_DATA_KEY_MISSED 7
249 #define EXCEPT_IPF_DIRTY_BIT 8
250 #define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
251 #define EXCEPT_IPF_DATA_ACCESS_BIT 10
252 #define EXCEPT_IPF_BREAKPOINT 11
253 #define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
257 #define EXCEPT_IPF_PAGE_NOT_PRESENT 20
258 #define EXCEPT_IPF_KEY_PERMISSION 21
259 #define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
260 #define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
261 #define EXCEPT_IPF_GENERAL_EXCEPTION 24
262 #define EXCEPT_IPF_DISABLED_FP_REGISTER 25
263 #define EXCEPT_IPF_NAT_CONSUMPTION 26
264 #define EXCEPT_IPF_SPECULATION 27
268 #define EXCEPT_IPF_DEBUG 29
269 #define EXCEPT_IPF_UNALIGNED_REFERENCE 30
270 #define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
271 #define EXCEPT_IPF_FP_FAULT 32
272 #define EXCEPT_IPF_FP_TRAP 33
273 #define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
274 #define EXCEPT_IPF_TAKEN_BRANCH 35
275 #define EXCEPT_IPF_SINGLE_STEP 36
279 #define EXCEPT_IPF_IA32_EXCEPTION 45
280 #define EXCEPT_IPF_IA32_INTERCEPT 46
281 #define EXCEPT_IPF_IA32_INTERRUPT 47
284 /// IPF processor context definition
288 // The first reserved field is necessary to preserve alignment for the correct
289 // bits in UNAT and to insure F2 is 16 byte aligned.
367 // application registers
433 // virtual registers - nat bits for R1-R31
437 } EFI_SYSTEM_CONTEXT_IPF
;
440 /// EBC processor exception types
442 #define EXCEPT_EBC_UNDEFINED 0
443 #define EXCEPT_EBC_DIVIDE_ERROR 1
444 #define EXCEPT_EBC_DEBUG 2
445 #define EXCEPT_EBC_BREAKPOINT 3
446 #define EXCEPT_EBC_OVERFLOW 4
447 #define EXCEPT_EBC_INVALID_OPCODE 5 ///< opcode out of range
448 #define EXCEPT_EBC_STACK_FAULT 6
449 #define EXCEPT_EBC_ALIGNMENT_CHECK 7
450 #define EXCEPT_EBC_INSTRUCTION_ENCODING 8 ///< malformed instruction
451 #define EXCEPT_EBC_BAD_BREAK 9 ///< BREAK 0 or undefined BREAK
452 #define EXCEPT_EBC_STEP 10 ///< to support debug stepping
454 /// For coding convenience, define the maximum valid EBC exception.
456 #define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
459 /// EBC processor context definition
473 } EFI_SYSTEM_CONTEXT_EBC
;
478 /// ARM processor exception types
480 #define EXCEPT_ARM_RESET 0
481 #define EXCEPT_ARM_UNDEFINED_INSTRUCTION 1
482 #define EXCEPT_ARM_SOFTWARE_INTERRUPT 2
483 #define EXCEPT_ARM_PREFETCH_ABORT 3
484 #define EXCEPT_ARM_DATA_ABORT 4
485 #define EXCEPT_ARM_RESERVED 5
486 #define EXCEPT_ARM_IRQ 6
487 #define EXCEPT_ARM_FIQ 7
490 /// For coding convenience, define the maximum valid ARM exception.
492 #define MAX_ARM_EXCEPTION EXCEPT_ARM_FIQ
495 /// ARM processor context definition
519 } EFI_SYSTEM_CONTEXT_ARM
;
522 /// Universal EFI_SYSTEM_CONTEXT definition
525 EFI_SYSTEM_CONTEXT_EBC
*SystemContextEbc
;
526 EFI_SYSTEM_CONTEXT_IA32
*SystemContextIa32
;
527 EFI_SYSTEM_CONTEXT_X64
*SystemContextX64
;
528 EFI_SYSTEM_CONTEXT_IPF
*SystemContextIpf
;
529 EFI_SYSTEM_CONTEXT_ARM
*SystemContextArm
;
530 } EFI_SYSTEM_CONTEXT
;
533 // DebugSupport callback function prototypes
537 Registers and enables an exception callback function for the specified exception.
539 @param ExceptionType Exception types in EBC, IA-32, x64, or IPF
540 @param SystemContext Exception content.
545 (EFIAPI
*EFI_EXCEPTION_CALLBACK
)(
546 IN EFI_EXCEPTION_TYPE ExceptionType
,
547 IN OUT EFI_SYSTEM_CONTEXT SystemContext
551 Registers and enables the on-target debug agent's periodic entry point.
553 @param SystemContext Exception content.
558 (EFIAPI
*EFI_PERIODIC_CALLBACK
)(
559 IN OUT EFI_SYSTEM_CONTEXT SystemContext
563 /// Machine type definition
566 IsaIa32
= IMAGE_FILE_MACHINE_I386
, ///< 0x014C
567 IsaX64
= IMAGE_FILE_MACHINE_X64
, ///< 0x8664
568 IsaIpf
= IMAGE_FILE_MACHINE_IA64
, ///< 0x0200
569 IsaEbc
= IMAGE_FILE_MACHINE_EBC
, ///< 0x0EBC
570 IsaArm
= IMAGE_FILE_MACHINE_ARMTHUMB_MIXED
///< 0x01c2
571 } EFI_INSTRUCTION_SET_ARCHITECTURE
;
575 // DebugSupport member function definitions
579 Returns the maximum value that may be used for the ProcessorIndex parameter in
580 RegisterPeriodicCallback() and RegisterExceptionCallback().
582 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
583 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported
584 processor index is returned.
586 @retval EFI_SUCCESS The function completed successfully.
591 (EFIAPI
*EFI_GET_MAXIMUM_PROCESSOR_INDEX
)(
592 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
593 OUT UINTN
*MaxProcessorIndex
597 Registers a function to be called back periodically in interrupt context.
599 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
600 @param ProcessorIndex Specifies which processor the callback function applies to.
601 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main
602 periodic entry point of the debug agent.
604 @retval EFI_SUCCESS The function completed successfully.
605 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
606 function was previously registered.
607 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
613 (EFIAPI
*EFI_REGISTER_PERIODIC_CALLBACK
)(
614 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
615 IN UINTN ProcessorIndex
,
616 IN EFI_PERIODIC_CALLBACK PeriodicCallback
620 Registers a function to be called when a given processor exception occurs.
622 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
623 @param ProcessorIndex Specifies which processor the callback function applies to.
624 @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called
625 when the processor exception specified by ExceptionType occurs.
626 @param ExceptionType Specifies which processor exception to hook.
628 @retval EFI_SUCCESS The function completed successfully.
629 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
630 function was previously registered.
631 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
637 (EFIAPI
*EFI_REGISTER_EXCEPTION_CALLBACK
)(
638 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
639 IN UINTN ProcessorIndex
,
640 IN EFI_EXCEPTION_CALLBACK ExceptionCallback
,
641 IN EFI_EXCEPTION_TYPE ExceptionType
645 Invalidates processor instruction cache for a memory range. Subsequent execution in this range
646 causes a fresh memory fetch to retrieve code to be executed.
648 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
649 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.
650 @param Start Specifies the physical base of the memory range to be invalidated.
651 @param Length Specifies the minimum number of bytes in the processor's instruction
654 @retval EFI_SUCCESS The function completed successfully.
659 (EFIAPI
*EFI_INVALIDATE_INSTRUCTION_CACHE
)(
660 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
661 IN UINTN ProcessorIndex
,
667 /// This protocol provides the services to allow the debug agent to register
668 /// callback functions that are called either periodically or when specific
669 /// processor exceptions occur.
671 struct _EFI_DEBUG_SUPPORT_PROTOCOL
{
673 /// Declares the processor architecture for this instance of the EFI Debug Support protocol.
675 EFI_INSTRUCTION_SET_ARCHITECTURE Isa
;
676 EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex
;
677 EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback
;
678 EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback
;
679 EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache
;
682 extern EFI_GUID gEfiDebugSupportProtocolGuid
;