]>
Commit | Line | Data |
---|---|---|
ab7017fe | 1 | /** @file\r |
2 | The X64 entrypoint is used to process capsule in long mode.\r | |
3 | \r | |
1e172d6b | 4 | Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r |
ab7017fe | 5 | 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 | |
ab7017fe | 15 | #include <Library/DebugLib.h>\r |
1e172d6b | 16 | #include <Library/BaseMemoryLib.h>\r |
17 | #include <Library/CpuExceptionHandlerLib.h>\r | |
933d80a1 | 18 | #include <Library/DebugAgentLib.h>\r |
ab7017fe | 19 | #include "CommonHeader.h"\r |
20 | \r | |
933d80a1 | 21 | #define EXCEPTION_VECTOR_NUMBER 0x22\r |
1e172d6b | 22 | \r |
ab7017fe | 23 | /**\r |
24 | The X64 entrypoint is used to process capsule in long mode then\r | |
25 | return to 32-bit protected mode.\r | |
26 | \r | |
27 | @param EntrypointContext Pointer to the context of long mode.\r | |
28 | @param ReturnContext Pointer to the context of 32-bit protected mode.\r | |
29 | \r | |
30 | @retval This function should never return actually.\r | |
31 | \r | |
32 | **/\r | |
33 | EFI_STATUS\r | |
34 | EFIAPI\r | |
35 | _ModuleEntryPoint (\r | |
36 | SWITCH_32_TO_64_CONTEXT *EntrypointContext,\r | |
37 | SWITCH_64_TO_32_CONTEXT *ReturnContext\r | |
38 | )\r | |
39 | {\r | |
1e172d6b | 40 | EFI_STATUS Status;\r |
41 | IA32_DESCRIPTOR Ia32Idtr;\r | |
42 | IA32_DESCRIPTOR X64Idtr;\r | |
43 | IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER];\r | |
44 | \r | |
45 | //\r | |
46 | // Save the IA32 IDT Descriptor\r | |
47 | //\r | |
48 | AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); \r | |
49 | \r | |
50 | //\r | |
51 | // Setup X64 IDT table\r | |
52 | //\r | |
53 | ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER);\r | |
54 | X64Idtr.Base = (UINTN) IdtEntryTable;\r | |
55 | X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER - 1);\r | |
56 | AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr); \r | |
57 | \r | |
58 | //\r | |
59 | // Setup the default CPU exception handlers\r | |
60 | //\r | |
61 | SetupCpuExceptionHandlers (); \r | |
933d80a1 | 62 | \r |
63 | //\r | |
64 | // Initialize Debug Agent to support source level debug\r | |
65 | //\r | |
66 | InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *) &Ia32Idtr, NULL);\r | |
ab7017fe | 67 | \r |
68 | //\r | |
69 | // Call CapsuleDataCoalesce to process capsule.\r | |
70 | //\r | |
71 | Status = CapsuleDataCoalesce (\r | |
72 | NULL,\r | |
73 | (EFI_PHYSICAL_ADDRESS *) (UINTN) EntrypointContext->BlockListAddr,\r | |
74 | (VOID **) (UINTN) EntrypointContext->MemoryBase64Ptr,\r | |
75 | (UINTN *) (UINTN) EntrypointContext->MemorySize64Ptr\r | |
76 | );\r | |
77 | \r | |
78 | ReturnContext->ReturnStatus = Status;\r | |
79 | \r | |
933d80a1 | 80 | //\r |
81 | // Disable interrupt of Debug timer, since the new IDT table cannot work in long mode\r | |
82 | //\r | |
83 | SaveAndSetDebugTimerInterrupt (FALSE);\r | |
1e172d6b | 84 | //\r |
85 | // Restore IA32 IDT table\r | |
86 | //\r | |
87 | AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); \r | |
88 | \r | |
ab7017fe | 89 | //\r |
90 | // Finish to coalesce capsule, and return to 32-bit mode.\r | |
91 | //\r | |
92 | AsmDisablePaging64 (\r | |
93 | ReturnContext->ReturnCs,\r | |
94 | (UINT32) ReturnContext->ReturnEntryPoint,\r | |
95 | (UINT32) (UINTN) EntrypointContext,\r | |
96 | (UINT32) (UINTN) ReturnContext,\r | |
97 | (UINT32) (EntrypointContext->StackBufferBase + EntrypointContext->StackBufferLength)\r | |
98 | ); \r | |
99 | \r | |
100 | //\r | |
101 | // Should never be here.\r | |
102 | //\r | |
103 | ASSERT (FALSE);\r | |
104 | return EFI_SUCCESS;\r | |
105 | } |