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