]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
1. DxeIplPeim will locate Vector Handoff Table PPI and build GUIDed HOB if it has.
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / X64 / X64Entry.c
CommitLineData
ab7017fe 1/** @file\r
2 The X64 entrypoint is used to process capsule in long mode.\r
3\r
57f360f2 4Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
ab7017fe 5This 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
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
33EFI_STATUS\r
34EFIAPI\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
57f360f2
JF
61 Status = InitializeCpuExceptionHandlers (NULL);\r
62 ASSERT_EFI_ERROR (Status);\r
933d80a1 63 \r
64 //\r
65 // Initialize Debug Agent to support source level debug\r
66 //\r
67 InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *) &Ia32Idtr, NULL);\r
ab7017fe 68\r
69 //\r
70 // Call CapsuleDataCoalesce to process capsule.\r
71 //\r
72 Status = CapsuleDataCoalesce (\r
73 NULL,\r
74 (EFI_PHYSICAL_ADDRESS *) (UINTN) EntrypointContext->BlockListAddr,\r
75 (VOID **) (UINTN) EntrypointContext->MemoryBase64Ptr,\r
76 (UINTN *) (UINTN) EntrypointContext->MemorySize64Ptr\r
77 );\r
78 \r
79 ReturnContext->ReturnStatus = Status;\r
80\r
933d80a1 81 //\r
82 // Disable interrupt of Debug timer, since the new IDT table cannot work in long mode\r
83 //\r
84 SaveAndSetDebugTimerInterrupt (FALSE);\r
1e172d6b 85 //\r
86 // Restore IA32 IDT table\r
87 //\r
88 AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr); \r
89 \r
ab7017fe 90 //\r
91 // Finish to coalesce capsule, and return to 32-bit mode.\r
92 //\r
93 AsmDisablePaging64 (\r
94 ReturnContext->ReturnCs,\r
95 (UINT32) ReturnContext->ReturnEntryPoint,\r
96 (UINT32) (UINTN) EntrypointContext,\r
97 (UINT32) (UINTN) ReturnContext,\r
98 (UINT32) (EntrypointContext->StackBufferBase + EntrypointContext->StackBufferLength)\r
99 ); \r
100 \r
101 //\r
102 // Should never be here.\r
103 //\r
104 ASSERT (FALSE);\r
105 return EFI_SUCCESS;\r
106}