Add X64 support for DebugSupport driver.
[mirror_edk2.git] / EdkModulePkg / Universal / DebugSupport / Dxe / x64 / plDebugSupport.h
1 /**@file
2 X64 specific debug support macros, typedefs and prototypes.
3
4 Copyright (c) 2006, 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 #define NUM_IDT_ENTRIES 0x78
19 #define SYSTEM_TIMER_VECTOR 0x68
20 #define VECTOR_ENTRY_PAGES 1
21 #define CopyDescriptor(Dest, Src) CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))
22 #define ZeroDescriptor(Dest) CopyDescriptor ((Dest), &NullDesc)
23 #define ReadIdt(Vector, Dest) CopyDescriptor ((Dest), &((GetIdtr ())[(Vector)]))
24 #define WriteIdt(Vector, Src) CopyDescriptor (&((GetIdtr ())[(Vector)]), (Src))
25 #define CompareDescriptor(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))
26 #define EFI_ISA IsaX64
27 #define FF_FXSR (1 << 24)
28
29 typedef struct {
30 UINT64 Low;
31 UINT64 High;
32 } DESCRIPTOR;
33
34 typedef struct {
35 DESCRIPTOR OrigDesc;
36 VOID (*OrigVector) (VOID);
37 DESCRIPTOR NewDesc;
38 VOID (*StubEntry) (VOID);
39 VOID (*RegisteredCallback) ();
40 } IDT_ENTRY;
41
42 extern EFI_SYSTEM_CONTEXT SystemContext;
43 extern UINT8 InterruptEntryStub[];
44 extern UINT32 StubSize;
45 extern VOID (*OrigVector) (VOID);
46
47 VOID
48 CommonIdtEntry (
49 VOID
50 )
51 /*++
52
53 Routine Description:
54
55 Generic IDT entry
56
57 Arguments:
58
59 None
60
61 Returns:
62
63 None
64
65 --*/
66 ;
67
68
69 BOOLEAN
70 FxStorSupport (
71 VOID
72 )
73 /*++
74
75 Routine Description:
76
77 Check whether FXSTOR is supported
78
79 Arguments:
80
81 None
82
83 Returns:
84
85 TRUE - supported
86 FALSE - not supported
87
88 --*/
89 ;
90
91 DESCRIPTOR *
92 GetIdtr (
93 VOID
94 )
95 /*++
96
97 Routine Description:
98
99 Return the physical address of IDTR
100
101 Arguments:
102
103 None
104
105 Returns:
106
107 The physical address of IDTR
108
109 --*/
110 ;
111
112 VOID
113 Vect2Desc (
114 DESCRIPTOR * DestDesc,
115 VOID (*Vector) (VOID)
116 )
117 /*++
118
119 Routine Description:
120
121 Encodes an IDT descriptor with the given physical address
122
123 Arguments:
124
125 DestDesc - The IDT descriptor address
126 Vector - The interrupt vector entry
127
128 Returns:
129
130 None
131
132 --*/
133 ;
134
135 BOOLEAN
136 WriteInterruptFlag (
137 BOOLEAN NewState
138 )
139 /*++
140
141 Routine Description:
142
143 Programs interrupt flag to the requested state and returns previous
144 state.
145
146 Arguments:
147
148 NewState - New interrupt status
149
150 Returns:
151
152 Old interrupt status
153
154 --*/
155 ;
156
157 EFI_STATUS
158 plInitializeDebugSupportDriver (
159 VOID
160 )
161 /*++
162
163 Routine Description:
164 Initializes driver's handler registration database.
165
166 This code executes in boot services context.
167
168 Arguments:
169 None
170
171 Returns:
172 EFI_SUCCESS
173 EFI_UNSUPPORTED - if X64 processor does not support FXSTOR/FXRSTOR instructions,
174 the context save will fail, so these processor's are not supported.
175 EFI_OUT_OF_RESOURCES - not resource to finish initialization
176
177 --*/
178 ;
179
180 EFI_STATUS
181 EFIAPI
182 plUnloadDebugSupportDriver (
183 IN EFI_HANDLE ImageHandle
184 )
185 /*++
186
187 Routine Description:
188 This is the callback that is written to the LoadedImage protocol instance
189 on the image handle. It uninstalls all registered handlers and frees all entry
190 stub memory.
191
192 This code executes in boot services context.
193
194 Arguments:
195 ImageHandle - The image handle of the unload handler
196
197 Returns:
198
199 EFI_SUCCESS - always return success
200
201 --*/
202 ;
203
204 //
205 // DebugSupport protocol member functions
206 //
207 EFI_STATUS
208 EFIAPI
209 GetMaximumProcessorIndex (
210 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
211 OUT UINTN *MaxProcessorIndex
212 )
213 /*++
214
215 Routine Description: This is a DebugSupport protocol member function.
216
217 Arguments:
218 This - The DebugSupport instance
219 MaxProcessorIndex - The maximuim supported processor index
220
221 Returns:
222 Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0
223
224 --*/
225 ;
226
227 EFI_STATUS
228 EFIAPI
229 RegisterPeriodicCallback (
230 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
231 IN UINTN ProcessorIndex,
232 IN EFI_PERIODIC_CALLBACK PeriodicCallback
233 )
234 /*++
235
236 Routine Description: This is a DebugSupport protocol member function.
237
238 Arguments:
239 This - The DebugSupport instance
240 ProcessorIndex - Which processor the callback applies to.
241 PeriodicCallback - Callback function
242
243 Returns:
244
245 EFI_SUCCESS
246 EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has
247 no handler registered for it
248 EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.
249
250 Other possible return values are passed through from UnHookEntry and HookEntry.
251
252 --*/
253 ;
254
255 EFI_STATUS
256 EFIAPI
257 RegisterExceptionCallback (
258 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
259 IN UINTN ProcessorIndex,
260 IN EFI_EXCEPTION_CALLBACK NewCallback,
261 IN EFI_EXCEPTION_TYPE ExceptionType
262 )
263 /*++
264
265 Routine Description:
266 This is a DebugSupport protocol member function.
267
268 This code executes in boot services context.
269
270 Arguments:
271 This - The DebugSupport instance
272 ProcessorIndex - Which processor the callback applies to.
273 NewCallback - Callback function
274 ExceptionType - Which exception to hook
275
276 Returns:
277
278 EFI_SUCCESS
279 EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has
280 no handler registered for it
281 EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.
282
283 Other possible return values are passed through from UnHookEntry and HookEntry.
284
285 --*/
286 ;
287
288 EFI_STATUS
289 EFIAPI
290 InvalidateInstructionCache (
291 IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
292 IN UINTN ProcessorIndex,
293 IN VOID *Start,
294 IN UINT64 Length
295 )
296 /*++
297
298 Routine Description:
299 This is a DebugSupport protocol member function.
300 Calls assembly routine to flush cache.
301
302 Arguments:
303 This - The DebugSupport instance
304 ProcessorIndex - Which processor the callback applies to.
305 Start - Physical base of the memory range to be invalidated
306 Length - mininum number of bytes in instruction cache to invalidate
307
308 Returns:
309
310 EFI_SUCCESS - always return success
311
312 --*/
313 ;
314
315 #endif