]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c
1. Merger generic functions into one file.
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / X64 / PlDebugSupportX64.c
CommitLineData
6e8a984e 1/** @file\r
2 X64 specific debug support functions\r
3\r
4Copyright (c) 2006 - 2007, Intel Corporation\r
5All rights reserved. This 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
12\r
13**/\r
14\r
15//\r
16// private header files\r
17//\r
18#include "DebugSupport.h"\r
19\r
20/**\r
21 Get Procedure Entry Point from IDT Gate Descriptor.\r
22\r
23 @param IdtGateDecriptor IDT Gate Descriptor.\r
24\r
25 @return Procedure Entry Point located in IDT Gate Descriptor.\r
26\r
27**/\r
28UINTN GetProcedureEntryPoint (\r
29 IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor\r
30 )\r
31{\r
32 UINTN ProcedureEntryPoint;\r
33 \r
34 ((UINT16 *) &ProcedureEntryPoint)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow;\r
35 ((UINT16 *) &ProcedureEntryPoint)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh;\r
36 ((UINT32 *) &ProcedureEntryPoint)[1] = (UINT32) IdtGateDecriptor->Bits.OffsetUpper;\r
37\r
38 return ProcedureEntryPoint;\r
39}\r
40\r
41/**\r
42 Allocate pool for a new IDT entry stub.\r
43\r
44 Copy the generic stub into the new buffer and fixup the vector number\r
45 and jump target address.\r
46\r
47 @param ExceptionType This is the exception type that the new stub will be created\r
48 for.\r
49 @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r
50\r
51 @retval EFI_SUCCESS Always.\r
52\r
53**/\r
54EFI_STATUS\r
55CreateEntryStub (\r
56 IN EFI_EXCEPTION_TYPE ExceptionType,\r
57 OUT VOID **Stub\r
58 )\r
59{\r
60 UINT8 *StubCopy;\r
61\r
62 StubCopy = *Stub;\r
63\r
64 //\r
65 // Fixup the stub code for this vector\r
66 //\r
67\r
68 // The stub code looks like this:\r
69 //\r
70 // 00000000 6A 00 push 0 ; push vector number - will be modified before installed\r
71 // 00000002 E9 db 0e9h ; jump rel32\r
72 // 00000003 00000000 dd 0 ; fixed up to relative address of CommonIdtEntry\r
73 //\r
74\r
75 //\r
76 // poke in the exception type so the second push pushes the exception type\r
77 //\r
78 StubCopy[0x1] = (UINT8) ExceptionType;\r
79\r
80 //\r
81 // fixup the jump target to point to the common entry\r
82 //\r
83 *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
84\r
85 return EFI_SUCCESS;\r
86}\r
87\r
88/**\r
89 This is the main worker function that manages the state of the interrupt\r
90 handlers. It both installs and uninstalls interrupt handlers based on the\r
91 value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r
92 If NewCallback is non-NULL, then install is indicated.\r
93\r
94 @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r
95 If NULL, specifies that the previously registered handler should\r
96 be uninstalled.\r
97 @param ExceptionType Indicates which entry to manage.\r
98\r
99 @retval EFI_SUCCESS Process is ok.\r
100 @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r
101 no handler registered for it\r
102 @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r
103 @retval others Possible return values are passed through from UnHookEntry and HookEntry.\r
104\r
105**/\r
106EFI_STATUS\r
107ManageIdtEntryTable (\r
108 VOID (*NewCallback)(),\r
109 EFI_EXCEPTION_TYPE ExceptionType\r
110 )\r
111{\r
112 EFI_STATUS Status;\r
113\r
114 Status = EFI_SUCCESS;\r
115\r
116 if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {\r
117 //\r
118 // we've already installed to this vector\r
119 //\r
120 if (NewCallback != NULL) {\r
121 //\r
122 // if the input handler is non-null, error\r
123 //\r
124 Status = EFI_ALREADY_STARTED;\r
125 } else {\r
126 Status = UnhookEntry (ExceptionType);\r
127 }\r
128 } else {\r
129 //\r
130 // no user handler installed on this vector\r
131 //\r
132 if (NewCallback == NULL) {\r
133 //\r
134 // if the input handler is null, error\r
135 //\r
136 Status = EFI_INVALID_PARAMETER;\r
137 } else {\r
138 Status = HookEntry (ExceptionType, NewCallback);\r
139 }\r
140 }\r
141 \r
142 return Status;\r
143}\r