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 - 2008, 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 UINT8 St0Mm0
[10], Reserved3
[6];
80 UINT8 St1Mm1
[10], Reserved4
[6];
81 UINT8 St2Mm2
[10], Reserved5
[6];
82 UINT8 St3Mm3
[10], Reserved6
[6];
83 UINT8 St4Mm4
[10], Reserved7
[6];
84 UINT8 St5Mm5
[10], Reserved8
[6];
85 UINT8 St6Mm6
[10], Reserved9
[6];
86 UINT8 St7Mm7
[10], Reserved10
[6];
95 UINT8 Reserved11
[14 * 16];
96 } EFI_FX_SAVE_STATE_IA32
;
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
156 /// X64 processor context definition
159 /// FP / MMX / XMM registers (see fxrstor instruction definition)
169 UINT8 St0Mm0
[10], Reserved2
[6];
170 UINT8 St1Mm1
[10], Reserved3
[6];
171 UINT8 St2Mm2
[10], Reserved4
[6];
172 UINT8 St3Mm3
[10], Reserved5
[6];
173 UINT8 St4Mm4
[10], Reserved6
[6];
174 UINT8 St5Mm5
[10], Reserved7
[6];
175 UINT8 St6Mm6
[10], Reserved8
[6];
176 UINT8 St7Mm7
[10], Reserved9
[6];
186 // NOTE: UEFI 2.0 spec definition as follows.
188 UINT8 Reserved11
[14 * 16];
189 } EFI_FX_SAVE_STATE_X64
;
192 UINT64 ExceptionData
;
193 EFI_FX_SAVE_STATE_X64 FxSaveState
;
201 UINT64 Cr1
; /* Reserved */
234 } EFI_SYSTEM_CONTEXT_X64
;
237 // IPF processor exception types
239 #define EXCEPT_IPF_VHTP_TRANSLATION 0
240 #define EXCEPT_IPF_INSTRUCTION_TLB 1
241 #define EXCEPT_IPF_DATA_TLB 2
242 #define EXCEPT_IPF_ALT_INSTRUCTION_TLB 3
243 #define EXCEPT_IPF_ALT_DATA_TLB 4
244 #define EXCEPT_IPF_DATA_NESTED_TLB 5
245 #define EXCEPT_IPF_INSTRUCTION_KEY_MISSED 6
246 #define EXCEPT_IPF_DATA_KEY_MISSED 7
247 #define EXCEPT_IPF_DIRTY_BIT 8
248 #define EXCEPT_IPF_INSTRUCTION_ACCESS_BIT 9
249 #define EXCEPT_IPF_DATA_ACCESS_BIT 10
250 #define EXCEPT_IPF_BREAKPOINT 11
251 #define EXCEPT_IPF_EXTERNAL_INTERRUPT 12
255 #define EXCEPT_IPF_PAGE_NOT_PRESENT 20
256 #define EXCEPT_IPF_KEY_PERMISSION 21
257 #define EXCEPT_IPF_INSTRUCTION_ACCESS_RIGHTS 22
258 #define EXCEPT_IPF_DATA_ACCESS_RIGHTS 23
259 #define EXCEPT_IPF_GENERAL_EXCEPTION 24
260 #define EXCEPT_IPF_DISABLED_FP_REGISTER 25
261 #define EXCEPT_IPF_NAT_CONSUMPTION 26
262 #define EXCEPT_IPF_SPECULATION 27
266 #define EXCEPT_IPF_DEBUG 29
267 #define EXCEPT_IPF_UNALIGNED_REFERENCE 30
268 #define EXCEPT_IPF_UNSUPPORTED_DATA_REFERENCE 31
269 #define EXCEPT_IPF_FP_FAULT 32
270 #define EXCEPT_IPF_FP_TRAP 33
271 #define EXCEPT_IPF_LOWER_PRIVILEGE_TRANSFER_TRAP 34
272 #define EXCEPT_IPF_TAKEN_BRANCH 35
273 #define EXCEPT_IPF_SINGLE_STEP 36
277 #define EXCEPT_IPF_IA32_EXCEPTION 45
278 #define EXCEPT_IPF_IA32_INTERCEPT 46
279 #define EXCEPT_IPF_IA32_INTERRUPT 47
282 /// IPF processor context definition
286 // The first reserved field is necessary to preserve alignment for the correct
287 // bits in UNAT and to insure F2 is 16 byte aligned..
365 // application registers
431 // virtual registers - nat bits for R1-R31
435 } EFI_SYSTEM_CONTEXT_IPF
;
438 // EBC processor exception types
440 #define EXCEPT_EBC_UNDEFINED 0
441 #define EXCEPT_EBC_DIVIDE_ERROR 1
442 #define EXCEPT_EBC_DEBUG 2
443 #define EXCEPT_EBC_BREAKPOINT 3
444 #define EXCEPT_EBC_OVERFLOW 4
445 #define EXCEPT_EBC_INVALID_OPCODE 5 // opcode out of range
446 #define EXCEPT_EBC_STACK_FAULT 6
447 #define EXCEPT_EBC_ALIGNMENT_CHECK 7
448 #define EXCEPT_EBC_INSTRUCTION_ENCODING 8 // malformed instruction
449 #define EXCEPT_EBC_BAD_BREAK 9 // BREAK 0 or undefined BREAK
450 #define EXCEPT_EBC_STEP 10 // to support debug stepping
452 /// For coding convenience, define the maximum valid EBC exception.
454 #define MAX_EBC_EXCEPTION EXCEPT_EBC_STEP
457 /// EBC processor context definition
471 } EFI_SYSTEM_CONTEXT_EBC
;
474 /// Universal EFI_SYSTEM_CONTEXT definition
477 EFI_SYSTEM_CONTEXT_EBC
*SystemContextEbc
;
478 EFI_SYSTEM_CONTEXT_IA32
*SystemContextIa32
;
479 EFI_SYSTEM_CONTEXT_X64
*SystemContextX64
;
480 EFI_SYSTEM_CONTEXT_IPF
*SystemContextIpf
;
481 } EFI_SYSTEM_CONTEXT
;
484 // DebugSupport callback function prototypes
488 Registers and enables an exception callback function for the specified exception.
490 @param ExceptionType Exception types in EBC, IA-32, X64, or IPF
491 @param SystemContext Exception content.
496 (*EFI_EXCEPTION_CALLBACK
)(
497 IN EFI_EXCEPTION_TYPE ExceptionType
,
498 IN OUT EFI_SYSTEM_CONTEXT SystemContext
502 Registers and enables the on-target debug agent's periodic entry point.
504 @param SystemContext Exception content.
509 (*EFI_PERIODIC_CALLBACK
)(
510 IN OUT EFI_SYSTEM_CONTEXT SystemContext
514 /// Machine type definition
517 IsaIa32
= IMAGE_FILE_MACHINE_I386
, ///< 0x014C
518 IsaX64
= IMAGE_FILE_MACHINE_X64
, ///< 0x8664
519 IsaIpf
= IMAGE_FILE_MACHINE_IA64
, ///< 0x0200
520 IsaEbc
= IMAGE_FILE_MACHINE_EBC
///< 0x0EBC
521 } EFI_INSTRUCTION_SET_ARCHITECTURE
;
525 // DebugSupport member function definitions
529 Returns the maximum value that may be used for the ProcessorIndex parameter in
530 RegisterPeriodicCallback() and RegisterExceptionCallback().
532 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
533 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported
534 processor index is returned.
536 @retval EFI_SUCCESS The function completed successfully.
541 (EFIAPI
*EFI_GET_MAXIMUM_PROCESSOR_INDEX
)(
542 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
543 OUT UINTN
*MaxProcessorIndex
547 Registers a function to be called back periodically in interrupt context.
549 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
550 @param ProcessorIndex Specifies which processor the callback function applies to.
551 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main
552 periodic entry point of the debug agent.
554 @retval EFI_SUCCESS The function completed successfully.
555 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
556 function was previously registered.
557 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
563 (EFIAPI
*EFI_REGISTER_PERIODIC_CALLBACK
)(
564 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
565 IN UINTN ProcessorIndex
,
566 IN EFI_PERIODIC_CALLBACK PeriodicCallback
570 Registers a function to be called when a given processor exception occurs.
572 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
573 @param ProcessorIndex Specifies which processor the callback function applies to.
574 @param PeriodicCallback A pointer to a function of type EXCEPTION_CALLBACK that is called
575 when the processor exception specified by ExceptionType occurs.
576 @param ExceptionType Specifies which processor exception to hook.
578 @retval EFI_SUCCESS The function completed successfully.
579 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback
580 function was previously registered.
581 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback
587 (EFIAPI
*EFI_REGISTER_EXCEPTION_CALLBACK
)(
588 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
589 IN UINTN ProcessorIndex
,
590 IN EFI_EXCEPTION_CALLBACK ExceptionCallback
,
591 IN EFI_EXCEPTION_TYPE ExceptionType
595 Invalidates processor instruction cache for a memory range. Subsequent execution in this range
596 causes a fresh memory fetch to retrieve code to be executed.
598 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.
599 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.
600 @param Start Specifies the physical base of the memory range to be invalidated.
601 @param Length Specifies the minimum number of bytes in the processor's instruction
604 @retval EFI_SUCCESS The function completed successfully.
609 (EFIAPI
*EFI_INVALIDATE_INSTRUCTION_CACHE
)(
610 IN EFI_DEBUG_SUPPORT_PROTOCOL
*This
,
611 IN UINTN ProcessorIndex
,
617 /// This protocol provides the services to allow the debug agent to register
618 /// callback functions that are called either periodically or when specific
619 /// processor exceptions occur.
621 struct _EFI_DEBUG_SUPPORT_PROTOCOL
{
623 /// Declares the processor architecture for this instance of the EFI Debug Support protocol.
625 EFI_INSTRUCTION_SET_ARCHITECTURE Isa
;
626 EFI_GET_MAXIMUM_PROCESSOR_INDEX GetMaximumProcessorIndex
;
627 EFI_REGISTER_PERIODIC_CALLBACK RegisterPeriodicCallback
;
628 EFI_REGISTER_EXCEPTION_CALLBACK RegisterExceptionCallback
;
629 EFI_INVALIDATE_INSTRUCTION_CACHE InvalidateInstructionCache
;
632 extern EFI_GUID gEfiDebugSupportProtocolGuid
;