]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/DebugSupportDxe/Ia32/DebugSupport.h
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / Ia32 / DebugSupport.h
CommitLineData
6e8a984e 1/** @file\r
2 Generic debug support macros, typedefs and prototypes for IA32/x64.\r
3\r
d1102dba
LG
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6e8a984e 12\r
13**/\r
14\r
15#ifndef _DEBUG_SUPPORT_H_\r
16#define _DEBUG_SUPPORT_H_\r
17\r
6e8a984e 18#include <Uefi.h>\r
19\r
20#include <Protocol/DebugSupport.h>\r
21#include <Protocol/LoadedImage.h>\r
22\r
23#include <Library/DebugLib.h>\r
24#include <Library/UefiDriverEntryPoint.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/BaseLib.h>\r
6e8a984e 29\r
30#define NUM_IDT_ENTRIES 0x78\r
31#define SYSTEM_TIMER_VECTOR 0x68\r
6e8a984e 32\r
33typedef\r
34VOID\r
35(*DEBUG_PROC) (\r
36 VOID\r
37 );\r
38\r
1ccdbf2a 39typedef\r
40VOID\r
41(EFIAPI *CALLBACK_FUNC) (\r
42 );\r
43\r
6e8a984e 44typedef struct {\r
45 IA32_IDT_GATE_DESCRIPTOR OrigDesc;\r
46 DEBUG_PROC OrigVector;\r
47 IA32_IDT_GATE_DESCRIPTOR NewDesc;\r
48 DEBUG_PROC StubEntry;\r
1ccdbf2a 49 CALLBACK_FUNC RegisteredCallback;\r
6e8a984e 50} IDT_ENTRY;\r
51\r
c84507ab 52extern UINT8 InterruptEntryStub[];\r
53extern UINT32 StubSize;\r
54extern VOID (*OrigVector) (VOID);\r
55extern IDT_ENTRY *IdtEntryTable;\r
6e8a984e 56extern IA32_IDT_GATE_DESCRIPTOR NullDesc;\r
57\r
58/**\r
59 Generic IDT entry.\r
60\r
61**/\r
62VOID\r
63CommonIdtEntry (\r
64 VOID\r
65 );\r
66\r
67/**\r
68 Check whether FXSTOR is supported\r
69\r
70 @retval TRUE FXSTOR is supported.\r
71 @retval FALSE FXSTOR is not supported.\r
72\r
73**/\r
74BOOLEAN\r
75FxStorSupport (\r
76 VOID\r
77 );\r
78\r
79/**\r
80 Encodes an IDT descriptor with the given physical address.\r
81\r
82 @param DestDesc The IDT descriptor address.\r
83 @param Vecotr The interrupt vector entry.\r
84\r
85**/\r
86VOID\r
87Vect2Desc (\r
88 IA32_IDT_GATE_DESCRIPTOR * DestDesc,\r
89 VOID (*Vector) (VOID)\r
90 );\r
91\r
6e8a984e 92/**\r
d1102dba
LG
93 Initializes driver's handler registration database.\r
94\r
6e8a984e 95 This code executes in boot services context\r
96 Must be public because it's referenced from DebugSupport.c\r
97\r
98 @retval EFI_UNSUPPORTED If IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
99 the context save will fail, so these processor's are not supported.\r
100 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
101 @retval EFI_SUCCESS Initializes successfully.\r
102\r
103**/\r
104EFI_STATUS\r
105PlInitializeDebugSupportDriver (\r
106 VOID\r
107 );\r
108\r
109/**\r
110 This is the callback that is written to the LoadedImage protocol instance\r
111 on the image handle. It uninstalls all registered handlers and frees all entry\r
112 stub memory.\r
113\r
114 @param ImageHandle The firmware allocated handle for the EFI image.\r
115\r
116 @retval EFI_SUCCESS Always.\r
117\r
118**/\r
119EFI_STATUS\r
120EFIAPI\r
121PlUnloadDebugSupportDriver (\r
122 IN EFI_HANDLE ImageHandle\r
123 );\r
124\r
125/**\r
c84507ab 126 Returns the maximum value that may be used for the ProcessorIndex parameter in\r
d1102dba
LG
127 RegisterPeriodicCallback() and RegisterExceptionCallback().\r
128\r
c84507ab 129 Hard coded to support only 1 processor for now.\r
6e8a984e 130\r
c84507ab 131 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
132 @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported\r
d1102dba
LG
133 processor index is returned. Always 0 returned.\r
134\r
c84507ab 135 @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.\r
6e8a984e 136\r
137**/\r
138EFI_STATUS\r
139EFIAPI\r
140GetMaximumProcessorIndex (\r
141 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
142 OUT UINTN *MaxProcessorIndex\r
143 );\r
144\r
145/**\r
c84507ab 146 Registers a function to be called back periodically in interrupt context.\r
d1102dba 147\r
c84507ab 148 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
149 @param ProcessorIndex Specifies which processor the callback function applies to.\r
150 @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main\r
151 periodic entry point of the debug agent.\r
d1102dba
LG
152\r
153 @retval EFI_SUCCESS The function completed successfully.\r
c84507ab 154 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
d1102dba
LG
155 function was previously registered.\r
156 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
157 function.\r
6e8a984e 158**/\r
159EFI_STATUS\r
160EFIAPI\r
161RegisterPeriodicCallback (\r
162 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
163 IN UINTN ProcessorIndex,\r
164 IN EFI_PERIODIC_CALLBACK PeriodicCallback\r
165 );\r
166\r
167/**\r
c84507ab 168 Registers a function to be called when a given processor exception occurs.\r
6e8a984e 169\r
170 This code executes in boot services context.\r
d1102dba 171\r
c84507ab 172 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
173 @param ProcessorIndex Specifies which processor the callback function applies to.\r
174 @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called\r
d1102dba
LG
175 when the processor exception specified by ExceptionType occurs.\r
176 @param ExceptionType Specifies which processor exception to hook.\r
177\r
178 @retval EFI_SUCCESS The function completed successfully.\r
c84507ab 179 @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
d1102dba
LG
180 function was previously registered.\r
181 @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
c84507ab 182 function.\r
6e8a984e 183**/\r
184EFI_STATUS\r
185EFIAPI\r
186RegisterExceptionCallback (\r
187 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
188 IN UINTN ProcessorIndex,\r
c84507ab 189 IN EFI_EXCEPTION_CALLBACK ExceptionCallback,\r
6e8a984e 190 IN EFI_EXCEPTION_TYPE ExceptionType\r
191 );\r
192\r
193/**\r
c84507ab 194 Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
d1102dba
LG
195 causes a fresh memory fetch to retrieve code to be executed.\r
196\r
c84507ab 197 @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
198 @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.\r
d1102dba 199 @param Start Specifies the physical base of the memory range to be invalidated.\r
c84507ab 200 @param Length Specifies the minimum number of bytes in the processor's instruction\r
d1102dba
LG
201 cache to invalidate.\r
202\r
c84507ab 203 @retval EFI_SUCCESS Always returned.\r
6e8a984e 204\r
205**/\r
206EFI_STATUS\r
207EFIAPI\r
208InvalidateInstructionCache (\r
209 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
210 IN UINTN ProcessorIndex,\r
211 IN VOID *Start,\r
212 IN UINT64 Length\r
213 );\r
214\r
215/**\r
216 Allocate pool for a new IDT entry stub.\r
217\r
218 Copy the generic stub into the new buffer and fixup the vector number\r
219 and jump target address.\r
220\r
221 @param ExceptionType This is the exception type that the new stub will be created\r
222 for.\r
223 @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r
224\r
6e8a984e 225**/\r
c84507ab 226VOID\r
6e8a984e 227CreateEntryStub (\r
228 IN EFI_EXCEPTION_TYPE ExceptionType,\r
229 OUT VOID **Stub\r
230 );\r
231\r
232/**\r
c84507ab 233 Get Interrupt Handle from IDT Gate Descriptor.\r
6e8a984e 234\r
235 @param IdtGateDecriptor IDT Gate Descriptor.\r
236\r
c84507ab 237 @return Interrupt Handle stored in IDT Gate Descriptor.\r
6e8a984e 238\r
239**/\r
c84507ab 240UINTN\r
241GetInterruptHandleFromIdt (\r
6e8a984e 242 IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor\r
243 );\r
244\r
245/**\r
246 This is the main worker function that manages the state of the interrupt\r
247 handlers. It both installs and uninstalls interrupt handlers based on the\r
248 value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r
249 If NewCallback is non-NULL, then install is indicated.\r
250\r
251 @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r
252 If NULL, specifies that the previously registered handler should\r
253 be uninstalled.\r
254 @param ExceptionType Indicates which entry to manage.\r
255\r
256 @retval EFI_SUCCESS Process is ok.\r
257 @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r
258 no handler registered for it\r
259 @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r
260 @retval others Possible return values are passed through from UnHookEntry and HookEntry.\r
261\r
262**/\r
263EFI_STATUS\r
264ManageIdtEntryTable (\r
1ccdbf2a 265 CALLBACK_FUNC NewCallback,\r
6e8a984e 266 EFI_EXCEPTION_TYPE ExceptionType\r
267 );\r
268\r
269/**\r
270 Creates a nes entry stub. Then saves the current IDT entry and replaces it\r
271 with an interrupt gate for the new entry point. The IdtEntryTable is updated\r
272 with the new registered function.\r
273\r
274 This code executes in boot services context. The stub entry executes in interrupt\r
275 context.\r
276\r
277 @param ExceptionType Specifies which vector to hook.\r
278 @param NewCallback A pointer to the new function to be registered.\r
279\r
6e8a984e 280**/\r
c84507ab 281VOID\r
6e8a984e 282HookEntry (\r
283 IN EFI_EXCEPTION_TYPE ExceptionType,\r
1ccdbf2a 284 IN CALLBACK_FUNC NewCallback\r
6e8a984e 285 );\r
286\r
287/**\r
288 Undoes HookEntry. This code executes in boot services context.\r
289\r
290 @param ExceptionType Specifies which entry to unhook\r
291\r
6e8a984e 292**/\r
c84507ab 293VOID\r
6e8a984e 294UnhookEntry (\r
295 IN EFI_EXCEPTION_TYPE ExceptionType\r
296 );\r
297\r
298#endif\r