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
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 <IndustryStandard/PeImage.h>
24 typedef struct _EFI_DEBUG_SUPPORT_PROTOCOL EFI_DEBUG_SUPPORT_PROTOCOL
;
27 /// Debug Support protocol {2755590C-6F3C-42FA-9EA4-A3BA543CDA25}
29 #define EFI_DEBUG_SUPPORT_PROTOCOL_GUID \
31 0x2755590C, 0x6F3C, 0x42FA, {0x9E, 0xA4, 0xA3, 0xBA, 0x54, 0x3C, 0xDA, 0x25 } \
35 /// Processor exception to be hooked.
36 /// All exception types for IA32, X64, Itanium and EBC processors are defined.
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
63 /// FP / MMX / XMM registers (see fxrstor instruction definition)
76 UINT8 St0Mm0
[10], Reserved3
[6];
77 UINT8 St1Mm1
[10], Reserved4
[6];
78 UINT8 St2Mm2
[10], Reserved5
[6];
79 UINT8 St3Mm3
[10], Reserved6
[6];
80 UINT8 St4Mm4
[10], Reserved7
[6];
81 UINT8 St5Mm5
[10], Reserved8
[6];
82 UINT8 St6Mm6
[10], Reserved9
[6];
83 UINT8 St7Mm7
[10], Reserved10
[6];
92 UINT8 Reserved11
[14 * 16];
93 } EFI_FX_SAVE_STATE_IA32
;
96 /// IA-32 processor context definition
100 EFI_FX_SAVE_STATE_IA32 FxSaveState
;
108 UINT32 Cr1
; /* Reserved */
132 } EFI_SYSTEM_CONTEXT_IA32
;
135 /// x64 processor exception types
137 #define EXCEPT_X64_DIVIDE_ERROR 0
138 #define EXCEPT_X64_DEBUG 1
139 #define EXCEPT_X64_NMI 2
140 #define EXCEPT_X64_BREAKPOINT 3
141 #define EXCEPT_X64_OVERFLOW 4
142 #define EXCEPT_X64_BOUND 5
143 #define EXCEPT_X64_INVALID_OPCODE 6
144 #define EXCEPT_X64_DOUBLE_FAULT 8
145 #define EXCEPT_X64_INVALID_TSS 10
146 #define EXCEPT_X64_SEG_NOT_PRESENT 11
147 #define EXCEPT_X64_STACK_FAULT 12
148 #define EXCEPT_X64_GP_FAULT 13
149 #define EXCEPT_X64_PAGE_FAULT 14
150 #define EXCEPT_X64_FP_ERROR 16
151 #define EXCEPT_X64_ALIGNMENT_CHECK 17
152 #define EXCEPT_X64_MACHINE_CHECK 18
153 #define EXCEPT_X64_SIMD 19
157 /// FP / MMX / XMM registers (see fxrstor instruction definition)
167 UINT8 St0Mm0
[10], Reserved2
[6];
168 UINT8 St1Mm1
[10], Reserved3
[6];
169 UINT8 St2Mm2
[10], Reserved4
[6];
170 UINT8 St3Mm3
[10], Reserved5
[6];
171 UINT8 St4Mm4
[10], Reserved6
[6];
172 UINT8 St5Mm5
[10], Reserved7
[6];
173 UINT8 St6Mm6
[10], Reserved8
[6];
174 UINT8 St7Mm7
[10], Reserved9
[6];
184 // NOTE: UEFI 2.0 spec definition as follows.
186 UINT8 Reserved11
[14 * 16];
187 } EFI_FX_SAVE_STATE_X64
;
190 /// x64 processor context definition
193 UINT64 ExceptionData
;
194 EFI_FX_SAVE_STATE_X64 FxSaveState
;
202 UINT64 Cr1
; /* Reserved */
235 } EFI_SYSTEM_CONTEXT_X64
;
238 /// Itanium Processor Family Exception types
240 #define EXCEPT_IPF_VHTP_TRANSLATION 0
241 #define EXCEPT_IPF_INSTRUCTION_TLB 1
242 #define EXCEPT_IPF_DATA_TLB 2
243 #define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
244 #define EXCEPT_IPF_ALT_DATA_TLB 4
245 #define EXCEPT_IPF_DATA_NESTED_TLB 5
246 #define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
247 #define EXCEPT_IPF_DATA_KEY_MISSED 7
248 #define EXCEPT_IPF_DIRTY_BIT 8
249 #define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
250 #define EXCEPT_IPF_DATA_ACCESS_BIT 10
251 #define EXCEPT_IPF_BREAKPOINT 11
252 #define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
256 #define EXCEPT_IPF_PAGE_NOT_PRESENT 20
257 #define EXCEPT_IPF_KEY_PERMISSION 21
258 #define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
259 #define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
260 #define EXCEPT_IPF_GENERAL_EXCEPTION 24
261 #define EXCEPT_IPF_DISABLED_FP_REGISTER 25
262 #define EXCEPT_IPF_NAT_CONSUMPTION 26
263 #define EXCEPT_IPF_SPECULATION 27
267 #define EXCEPT_IPF_DEBUG 29
268 #define EXCEPT_IPF_UNALIGNED_REFERENCE 30
269 #define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
270 #define EXCEPT_IPF_FP_FAULT 32
271 #define EXCEPT_IPF_FP_TRAP 33
272 #define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
273 #define EXCEPT_IPF_TAKEN_BRANCH 35
274 #define EXCEPT_IPF_SINGLE_STEP 36
278 #define EXCEPT_IPF_IA32_EXCEPTION 45
279 #define EXCEPT_IPF_IA32_INTERCEPT 46
280 #define EXCEPT_IPF_IA32_INTERRUPT 47
283 /// IPF processor context definition
287 // The first reserved field is necessary to preserve alignment for the correct
288 // bits in UNAT and to insure F2 is 16 byte aligned..
366 // application registers
432 // virtual registers - nat bits for R1-R31
436 } EFI_SYSTEM_CONTEXT_IPF
;
439 /// EBC processor exception types
441 #define EXCEPT_EBC_UNDEFINED 0
442 #define EXCEPT_EBC_DIVIDE_ERROR 1
443 #define EXCEPT_EBC_DEBUG 2
444 #define EXCEPT_EBC_BREAKPOINT 3
445 #define EXCEPT_EBC_OVERFLOW 4
446 #define EXCEPT_EBC_INVALID_OPCODE 5 ///< opcode out of range
447 #define EXCEPT_EBC_STACK_FAULT 6
448 #define EXCEPT_EBC_ALIGNMENT_CHECK 7
449 #define EXCEPT_EBC_INSTRUCTION_ENCODING 8 ///< malformed instruction
450 #define EXCEPT_EBC_BAD_BREAK 9 ///< BREAK 0 or undefined BREAK
451 #define EXCEPT_EBC_STEP 10 ///< to support debug stepping
453 /// For coding convenience, define the maximum valid EBC exception.
455 #define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
458 /// EBC processor context definition
472 } EFI_SYSTEM_CONTEXT_EBC
;
475 /// Universal EFI_SYSTEM_CONTEXT definition
478 EFI_SYSTEM_CONTEXT_EBC
*SystemContextEbc
;
479 EFI_SYSTEM_CONTEXT_IA32
*SystemContextIa32
;
480 EFI_SYSTEM_CONTEXT_X64
*SystemContextX64
;
481 EFI_SYSTEM_CONTEXT_IPF
*SystemContextIpf
;
482 } EFI_SYSTEM_CONTEXT
;
485 // DebugSupport callback function prototypes
489 Registers and enables an exception callback function for the specified exception.
491 @param ExceptionType Exception types in EBC, IA-32, x64, or IPF
492 @param SystemContext Exception content.
497 (EFIAPI
*EFI_EXCEPTION_CALLBACK
)(
498 IN EFI_EXCEPTION_TYPE ExceptionType
,
499 IN OUT EFI_SYSTEM_CONTEXT SystemContext
503 Registers and enables the on-target debug agent's periodic entry point.
505 @param SystemContext Exception content.
510 (EFIAPI
*EFI_PERIODIC_CALLBACK
)(
511 IN OUT EFI_SYSTEM_CONTEXT SystemContext
515 /// Machine type definition
518 IsaIa32
= IMAGE_FILE_MACHINE_I386
, ///< 0x014C
519 IsaX64
= IMAGE_FILE_MACHINE_X64
, ///< 0x8664
520 IsaIpf
= IMAGE_FILE_MACHINE_IA64
, ///< 0x0200
521 IsaEbc
= IMAGE_FILE_MACHINE_EBC
///< 0x0EBC
522 } EFI_INSTRUCTION_SET_ARCHITECTURE
;
526 // DebugSupport member function definitions
530 Returns the maximum value that may be used for the ProcessorIndex parameter in
531 RegisterPeriodicCallback() and RegisterExceptionCallback().
533 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
534 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported
535 processor index is returned.
537 @retval EFI_SUCCESS The function completed successfully.
542 (EFIAPI
*EFI_GET_MAXIMUM_PROCESSOR_INDEX
)(
543 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
544 OUT UINTN
*MaxProcessorIndex
548 Registers a function to be called back periodically in interrupt context.
550 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
551 @param ProcessorIndex Specifies which processor the callback function applies to.
552 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main
553 periodic entry point of the debug agent.
555 @retval EFI_SUCCESS The function completed successfully.
556 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
557 function was previously registered.
558 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
564 (EFIAPI
*EFI_REGISTER_PERIODIC_CALLBACK
)(
565 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
566 IN UINTN ProcessorIndex
,
567 IN EFI_PERIODIC_CALLBACK PeriodicCallback
571 Registers a function to be called when a given processor exception occurs.
573 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
574 @param ProcessorIndex Specifies which processor the callback function applies to.
575 @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called
576 when the processor exception specified by ExceptionType occurs.
577 @param ExceptionType Specifies which processor exception to hook.
579 @retval EFI_SUCCESS The function completed successfully.
580 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
581 function was previously registered.
582 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
588 (EFIAPI
*EFI_REGISTER_EXCEPTION_CALLBACK
)(
589 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
590 IN UINTN ProcessorIndex
,
591 IN EFI_EXCEPTION_CALLBACK ExceptionCallback
,
592 IN EFI_EXCEPTION_TYPE ExceptionType
596 Invalidates processor instruction cache for a memory range. Subsequent execution in this range
597 causes a fresh memory fetch to retrieve code to be executed.
599 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
600 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.
601 @param Start Specifies the physical base of the memory range to be invalidated.
602 @param Length Specifies the minimum number of bytes in the processor's instruction
605 @retval EFI_SUCCESS The function completed successfully.
610 (EFIAPI
*EFI_INVALIDATE_INSTRUCTION_CACHE
)(
611 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
612 IN UINTN ProcessorIndex
,
618 /// This protocol provides the services to allow the debug agent to register
619 /// callback functions that are called either periodically or when specific
620 /// processor exceptions occur.
622 struct _EFI_DEBUG_SUPPORT_PROTOCOL
{
624 /// Declares the processor architecture for this instance of the EFI Debug Support protocol.
626 EFI_INSTRUCTION_SET_ARCHITECTURE Isa
;
627 EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex
;
628 EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback
;
629 EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback
;
630 EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache
;
633 extern EFI_GUID gEfiDebugSupportProtocolGuid
;