]>
Commit | Line | Data |
---|---|---|
6e8a984e | 1 | /** @file\r |
509bc208 | 2 | X64 specific functions to support Debug Support protocol.\r |
6e8a984e | 3 | \r |
509bc208 | 4 | Copyright (c) 2008, Intel Corporation\r |
6e8a984e | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
cfcbb8bc | 15 | #include "PlDebugSupport.h"\r |
6e8a984e | 16 | \r |
43a99f08 | 17 | IA32_IDT_GATE_DESCRIPTOR NullDesc = {{0,0}};\r |
18 | \r | |
6e8a984e | 19 | /**\r |
c84507ab | 20 | Get Interrupt Handle from IDT Gate Descriptor.\r |
6e8a984e | 21 | \r |
22 | @param IdtGateDecriptor IDT Gate Descriptor.\r | |
23 | \r | |
c84507ab | 24 | @return Interrupt Handle stored in IDT Gate Descriptor.\r |
6e8a984e | 25 | \r |
26 | **/\r | |
c84507ab | 27 | UINTN\r |
28 | GetInterruptHandleFromIdt (\r | |
6e8a984e | 29 | IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDecriptor\r |
30 | )\r | |
31 | {\r | |
c84507ab | 32 | UINTN InterruptHandle;\r |
cfcbb8bc | 33 | \r |
34 | //\r | |
35 | // InterruptHandle 0-15 : OffsetLow\r | |
36 | // InterruptHandle 16-31 : OffsetHigh\r | |
37 | // InterruptHandle 32-63 : OffsetUpper\r | |
38 | //\r | |
c84507ab | 39 | ((UINT16 *) &InterruptHandle)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow;\r |
40 | ((UINT16 *) &InterruptHandle)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh;\r | |
41 | ((UINT32 *) &InterruptHandle)[1] = (UINT32) IdtGateDecriptor->Bits.OffsetUpper;\r | |
6e8a984e | 42 | \r |
c84507ab | 43 | return InterruptHandle;\r |
6e8a984e | 44 | }\r |
45 | \r | |
46 | /**\r | |
47 | Allocate pool for a new IDT entry stub.\r | |
48 | \r | |
49 | Copy the generic stub into the new buffer and fixup the vector number\r | |
50 | and jump target address.\r | |
51 | \r | |
52 | @param ExceptionType This is the exception type that the new stub will be created\r | |
53 | for.\r | |
54 | @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r | |
55 | \r | |
6e8a984e | 56 | **/\r |
c84507ab | 57 | VOID\r |
6e8a984e | 58 | CreateEntryStub (\r |
59 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
60 | OUT VOID **Stub\r | |
61 | )\r | |
62 | {\r | |
63 | UINT8 *StubCopy;\r | |
64 | \r | |
65 | StubCopy = *Stub;\r | |
66 | \r | |
67 | //\r | |
68 | // Fixup the stub code for this vector\r | |
69 | //\r | |
70 | \r | |
71 | // The stub code looks like this:\r | |
72 | //\r | |
73 | // 00000000 6A 00 push 0 ; push vector number - will be modified before installed\r | |
74 | // 00000002 E9 db 0e9h ; jump rel32\r | |
75 | // 00000003 00000000 dd 0 ; fixed up to relative address of CommonIdtEntry\r | |
76 | //\r | |
77 | \r | |
78 | //\r | |
79 | // poke in the exception type so the second push pushes the exception type\r | |
80 | //\r | |
81 | StubCopy[0x1] = (UINT8) ExceptionType;\r | |
82 | \r | |
83 | //\r | |
84 | // fixup the jump target to point to the common entry\r | |
85 | //\r | |
86 | *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r | |
87 | \r | |
c84507ab | 88 | return;\r |
6e8a984e | 89 | }\r |
90 | \r | |
91 | /**\r | |
92 | This is the main worker function that manages the state of the interrupt\r | |
93 | handlers. It both installs and uninstalls interrupt handlers based on the\r | |
94 | value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r | |
95 | If NewCallback is non-NULL, then install is indicated.\r | |
96 | \r | |
97 | @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r | |
98 | If NULL, specifies that the previously registered handler should\r | |
99 | be uninstalled.\r | |
100 | @param ExceptionType Indicates which entry to manage.\r | |
101 | \r | |
102 | @retval EFI_SUCCESS Process is ok.\r | |
103 | @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r | |
104 | no handler registered for it\r | |
105 | @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r | |
106 | @retval others Possible return values are passed through from UnHookEntry and HookEntry.\r | |
107 | \r | |
108 | **/\r | |
109 | EFI_STATUS\r | |
110 | ManageIdtEntryTable (\r | |
509bc208 | 111 | VOID (*NewCallback)(),\r |
6e8a984e | 112 | EFI_EXCEPTION_TYPE ExceptionType\r |
113 | )\r | |
114 | {\r | |
115 | EFI_STATUS Status;\r | |
116 | \r | |
117 | Status = EFI_SUCCESS;\r | |
118 | \r | |
119 | if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {\r | |
120 | //\r | |
121 | // we've already installed to this vector\r | |
122 | //\r | |
123 | if (NewCallback != NULL) {\r | |
124 | //\r | |
125 | // if the input handler is non-null, error\r | |
126 | //\r | |
127 | Status = EFI_ALREADY_STARTED;\r | |
128 | } else {\r | |
c84507ab | 129 | UnhookEntry (ExceptionType);\r |
6e8a984e | 130 | }\r |
131 | } else {\r | |
132 | //\r | |
133 | // no user handler installed on this vector\r | |
134 | //\r | |
135 | if (NewCallback == NULL) {\r | |
136 | //\r | |
137 | // if the input handler is null, error\r | |
138 | //\r | |
139 | Status = EFI_INVALID_PARAMETER;\r | |
140 | } else {\r | |
c84507ab | 141 | HookEntry (ExceptionType, NewCallback);\r |
6e8a984e | 142 | }\r |
143 | }\r | |
cfcbb8bc | 144 | \r |
6e8a984e | 145 | return Status;\r |
146 | }\r |