]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupport.h
eb04f1a88c4ecabc2f131540ab262785c6f8e399
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / X64 / PlDebugSupport.h
1 /** @file
2 X64 specific debug support macros, typedefs and prototypes.
3
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _PLDEBUG_SUPPORT_H_
16 #define _PLDEBUG_SUPPORT_H_
17
18
19 #include <Uefi.h>
20
21 #include <Protocol/DebugSupport.h>
22 #include <Protocol/LoadedImage.h>
23
24 #include <Library/DebugLib.h>
25 #include <Library/UefiDriverEntryPoint.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/BaseLib.h>
30
31 #include <Library/PcdLib.h>
32 #define NUM_IDT_ENTRIES 0x78
33 #define SYSTEM_TIMER_VECTOR 0x68
34 #define VECTOR_ENTRY_PAGES 1
35 #define COPY_DESCRIPTOR(Dest, Src) CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))
36 #define READ_IDT(Vector, Dest) COPY_DESCRIPTOR ((Dest), &((GetIdtr ())[(Vector)]))
37 #define WRITE_IDT(Vector, Src) COPY_DESCRIPTOR (&((GetIdtr ())[(Vector)]), (Src))
38 #define COMPARE_DESCRIPTOR(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))
39 #define EFI_ISA IsaX64
40 #define FF_FXSR (1 << 24)
41
42 typedef struct {
43 UINT64 Low;
44 UINT64 High;
45 } DESCRIPTOR;
46
47 typedef
48 VOID
49 (*DEBUG_PROC) (
50 VOID
51 );
52
53 typedef struct {
54 DESCRIPTOR OrigDesc;
55 DEBUG_PROC OrigVector;
56 DESCRIPTOR NewDesc;
57 DEBUG_PROC StubEntry;
58 VOID (*RegisteredCallback) ();
59 } IDT_ENTRY;
60
61 extern EFI_SYSTEM_CONTEXT SystemContext;
62 extern UINT8 InterruptEntryStub[];
63 extern UINT32 StubSize;
64 extern VOID (*OrigVector) (VOID);
65
66 /**
67 Generic IDT entry.
68
69 **/
70 VOID
71 CommonIdtEntry (
72 VOID
73 );
74
75 /**
76 Check whether FXSTOR is supported
77
78 @retval TRUE FXSTOR is supported.
79 @retval FALSE FXSTOR is not supported.
80
81 **/
82 BOOLEAN
83 FxStorSupport (
84 VOID
85 );
86
87 /**
88 Return the physical address of IDTR.
89
90 @return The physical address of IDTR.
91
92 **/
93 DESCRIPTOR *
94 GetIdtr (
95 VOID
96 );
97
98 /**
99 Encodes an IDT descriptor with the given physical address.
100
101 @param DestDesc The IDT descriptor address.
102 @param Vecotr The interrupt vector entry.
103
104 **/
105 VOID
106 Vect2Desc (
107 DESCRIPTOR * DestDesc,
108 VOID (*Vector) (VOID)
109 );
110
111 /**
112 Programs interrupt flag to the requested state and returns previous
113 state.
114
115 @param NewState New interrupt status.
116
117 @retval TRUE Old interrupt status is TRUE.
118 @retval FALSE Old interrupt status is FALSE
119
120 **/
121 BOOLEAN
122 WriteInterruptFlag (
123 BOOLEAN NewState
124 );
125
126 /**
127 Initializes driver's handler registration databas.
128
129 This code executes in boot services context
130 Must be public because it's referenced from DebugSupport.c
131
132 @retval EFI_UNSUPPORTED If x64 processor does not support FXSTOR/FXRSTOR instructions,
133 the context save will fail, so these processor's are not supported.
134 @retval EFI_OUT_OF_RESOURCES Fails to allocate memory.
135 @retval EFI_SUCCESS Initializes successfully.
136
137 **/
138 EFI_STATUS
139 PlInitializeDebugSupportDriver (
140 VOID
141 );
142
143 /**
144 This is the callback that is written to the LoadedImage protocol instance
145 on the image handle. It uninstalls all registered handlers and frees all entry
146 stub memory.
147
148 @param ImageHandle The firmware allocated handle for the EFI image.
149
150 @retval EFI_SUCCESS Always.
151
152 **/
153 EFI_STATUS
154 EFIAPI
155 PlUnloadDebugSupportDriver (
156 IN EFI_HANDLE ImageHandle
157 );
158
159 /**
160 This is a DebugSupport protocol member function, hard
161 coded to support only 1 processor for now.
162
163 @param This The DebugSupport instance
164 @param MaxProcessorIndex The maximuim supported processor index
165
166 @retval EFI_SUCCESS Always returned with **MaxProcessorIndex set to 0.
167
168 **/
169 EFI_STATUS
170 EFIAPI
171 GetMaximumProcessorIndex (
172 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
173 OUT UINTN *MaxProcessorIndex
174 );
175
176 /**
177 DebugSupport protocol member function.
178
179 @param This The DebugSupport instance
180 @param ProcessorIndex Which processor the callback applies to.
181 @param PeriodicCallback Callback function
182
183 @retval EFI_SUCCESS Indicates the callback was registered.
184 @retval others Callback was not registered.
185
186 **/
187 EFI_STATUS
188 EFIAPI
189 RegisterPeriodicCallback (
190 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
191 IN UINTN ProcessorIndex,
192 IN EFI_PERIODIC_CALLBACK PeriodicCallback
193 );
194
195 /**
196 DebugSupport protocol member function.
197
198 This code executes in boot services context.
199
200 @param This The DebugSupport instance
201 @param ProcessorIndex Which processor the callback applies to.
202 @param NewCallback Callback function
203 @param ExceptionType Which exception to hook
204
205 @retval EFI_SUCCESS Indicates the callback was registered.
206 @retval others Callback was not registered.
207
208 **/
209 EFI_STATUS
210 EFIAPI
211 RegisterExceptionCallback (
212 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
213 IN UINTN ProcessorIndex,
214 IN EFI_EXCEPTION_CALLBACK NewCallback,
215 IN EFI_EXCEPTION_TYPE ExceptionType
216 );
217
218 /**
219 DebugSupport protocol member function. Calls assembly routine to flush cache.
220
221 @param This The DebugSupport instance
222 @param ProcessorIndex Which processor the callback applies to.
223 @param Start Physical base of the memory range to be invalidated
224 @param Length mininum number of bytes in instruction cache to invalidate
225
226 @retval EFI_SUCCESS Always returned.
227
228 **/
229 EFI_STATUS
230 EFIAPI
231 InvalidateInstructionCache (
232 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
233 IN UINTN ProcessorIndex,
234 IN VOID *Start,
235 IN UINT64 Length
236 );
237
238 #endif