]>
Commit | Line | Data |
---|---|---|
6e8a984e | 1 | /** @file\r |
509bc208 | 2 | IA32 specific functions to support Debug Support protocol.\r |
6e8a984e | 3 | \r |
e5eed7d3 | 4 | Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
6e8a984e | 6 | \r |
7 | **/\r | |
8 | \r | |
cfcbb8bc | 9 | #include "PlDebugSupport.h"\r |
6e8a984e | 10 | \r |
43a99f08 | 11 | IA32_IDT_GATE_DESCRIPTOR NullDesc = {{0}};\r |
12 | \r | |
6e8a984e | 13 | /**\r |
c84507ab | 14 | Get Interrupt Handle from IDT Gate Descriptor.\r |
6e8a984e | 15 | \r |
c84507ab | 16 | @param IdtGateDescriptor IDT Gate Descriptor.\r |
6e8a984e | 17 | \r |
c84507ab | 18 | @return Interrupt Handle stored in IDT Gate Descriptor.\r |
6e8a984e | 19 | \r |
20 | **/\r | |
c84507ab | 21 | UINTN\r |
22 | GetInterruptHandleFromIdt (\r | |
23 | IN IA32_IDT_GATE_DESCRIPTOR *IdtGateDescriptor\r | |
6e8a984e | 24 | )\r |
25 | {\r | |
c84507ab | 26 | UINTN InterruptHandle;\r |
cfcbb8bc | 27 | \r |
28 | //\r | |
29 | // InterruptHandle 0-15 : OffsetLow\r | |
30 | // InterruptHandle 16-31 : OffsetHigh\r | |
31 | //\r | |
c84507ab | 32 | ((UINT16 *) &InterruptHandle)[0] = (UINT16) IdtGateDescriptor->Bits.OffsetLow;\r |
33 | ((UINT16 *) &InterruptHandle)[1] = (UINT16) IdtGateDescriptor->Bits.OffsetHigh;\r | |
6e8a984e | 34 | \r |
c84507ab | 35 | return InterruptHandle;\r |
6e8a984e | 36 | }\r |
37 | \r | |
38 | /**\r | |
39 | Allocate pool for a new IDT entry stub.\r | |
40 | \r | |
41 | Copy the generic stub into the new buffer and fixup the vector number\r | |
42 | and jump target address.\r | |
43 | \r | |
44 | @param ExceptionType This is the exception type that the new stub will be created\r | |
45 | for.\r | |
46 | @param Stub On successful exit, *Stub contains the newly allocated entry stub.\r | |
47 | \r | |
6e8a984e | 48 | **/\r |
c84507ab | 49 | VOID\r |
6e8a984e | 50 | CreateEntryStub (\r |
51 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
52 | OUT VOID **Stub\r | |
53 | )\r | |
54 | {\r | |
55 | UINT8 *StubCopy;\r | |
56 | \r | |
57 | StubCopy = *Stub;\r | |
58 | \r | |
59 | //\r | |
60 | // Fixup the stub code for this vector\r | |
61 | //\r | |
62 | \r | |
63 | // The stub code looks like this:\r | |
64 | //\r | |
65 | // 00000000 89 25 00000004 R mov AppEsp, esp ; save stack top\r | |
66 | // 00000006 BC 00008014 R mov esp, offset DbgStkBot ; switch to debugger stack\r | |
67 | // 0000000B 6A 00 push 0 ; push vector number - will be modified before installed\r | |
68 | // 0000000D E9 db 0e9h ; jump rel32\r | |
69 | // 0000000E 00000000 dd 0 ; fixed up to relative address of CommonIdtEntry\r | |
70 | //\r | |
71 | \r | |
72 | //\r | |
73 | // poke in the exception type so the second push pushes the exception type\r | |
74 | //\r | |
75 | StubCopy[0x0c] = (UINT8) ExceptionType;\r | |
76 | \r | |
77 | //\r | |
78 | // fixup the jump target to point to the common entry\r | |
79 | //\r | |
80 | *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];\r | |
81 | \r | |
c84507ab | 82 | return ;\r |
6e8a984e | 83 | }\r |
84 | \r | |
85 | /**\r | |
86 | This is the main worker function that manages the state of the interrupt\r | |
87 | handlers. It both installs and uninstalls interrupt handlers based on the\r | |
88 | value of NewCallback. If NewCallback is NULL, then uninstall is indicated.\r | |
89 | If NewCallback is non-NULL, then install is indicated.\r | |
90 | \r | |
91 | @param NewCallback If non-NULL, NewCallback specifies the new handler to register.\r | |
92 | If NULL, specifies that the previously registered handler should\r | |
93 | be uninstalled.\r | |
94 | @param ExceptionType Indicates which entry to manage.\r | |
95 | \r | |
c84507ab | 96 | @retval EFI_SUCCESS Installing or Uninstalling operation is ok.\r |
6e8a984e | 97 | @retval EFI_INVALID_PARAMETER Requested uninstalling a handler from a vector that has\r |
98 | no handler registered for it\r | |
99 | @retval EFI_ALREADY_STARTED Requested install to a vector that already has a handler registered.\r | |
6e8a984e | 100 | \r |
101 | **/\r | |
102 | EFI_STATUS\r | |
103 | ManageIdtEntryTable (\r | |
1ccdbf2a | 104 | CALLBACK_FUNC NewCallback,\r |
6e8a984e | 105 | EFI_EXCEPTION_TYPE ExceptionType\r |
106 | )\r | |
107 | {\r | |
108 | EFI_STATUS Status;\r | |
109 | \r | |
110 | Status = EFI_SUCCESS;\r | |
111 | \r | |
ea2d9086 | 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 | |
6e8a984e | 117 | //\r |
ea2d9086 | 118 | // if the input handler is non-null, error\r |
6e8a984e | 119 | //\r |
ea2d9086 | 120 | Status = EFI_ALREADY_STARTED;\r |
6e8a984e | 121 | } else {\r |
ea2d9086 | 122 | UnhookEntry (ExceptionType);\r |
123 | }\r | |
124 | } else {\r | |
125 | //\r | |
126 | // no user handler installed on this vector\r | |
127 | //\r | |
128 | if (NewCallback == NULL) {\r | |
6e8a984e | 129 | //\r |
ea2d9086 | 130 | // if the input handler is null, error\r |
6e8a984e | 131 | //\r |
ea2d9086 | 132 | Status = EFI_INVALID_PARAMETER;\r |
133 | } else {\r | |
134 | HookEntry (ExceptionType, NewCallback);\r | |
6e8a984e | 135 | }\r |
136 | }\r | |
137 | \r | |
138 | return Status;\r | |
139 | }\r |