]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
MdeModulePkg: Add DriverHealthManagerDxe driver.
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / X64 / X64Entry.c
1 /** @file
2 The X64 entrypoint is used to process capsule in long mode.
3
4 Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Library/DebugLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/CpuExceptionHandlerLib.h>
18 #include <Library/DebugAgentLib.h>
19 #include "CommonHeader.h"
20
21 #define EXCEPTION_VECTOR_NUMBER 0x22
22
23 /**
24 The X64 entrypoint is used to process capsule in long mode then
25 return to 32-bit protected mode.
26
27 @param EntrypointContext Pointer to the context of long mode.
28 @param ReturnContext Pointer to the context of 32-bit protected mode.
29
30 @retval This function should never return actually.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 _ModuleEntryPoint (
36 SWITCH_32_TO_64_CONTEXT *EntrypointContext,
37 SWITCH_64_TO_32_CONTEXT *ReturnContext
38 )
39 {
40 EFI_STATUS Status;
41 IA32_DESCRIPTOR Ia32Idtr;
42 IA32_DESCRIPTOR X64Idtr;
43 IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER];
44
45 //
46 // Save the IA32 IDT Descriptor
47 //
48 AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);
49
50 //
51 // Setup X64 IDT table
52 //
53 ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER);
54 X64Idtr.Base = (UINTN) IdtEntryTable;
55 X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER - 1);
56 AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr);
57
58 //
59 // Setup the default CPU exception handlers
60 //
61 Status = InitializeCpuExceptionHandlers (NULL);
62 ASSERT_EFI_ERROR (Status);
63
64 //
65 // Initialize Debug Agent to support source level debug
66 //
67 InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *) &Ia32Idtr, NULL);
68
69 //
70 // Call CapsuleDataCoalesce to process capsule.
71 //
72 Status = CapsuleDataCoalesce (
73 NULL,
74 (EFI_PHYSICAL_ADDRESS *) (UINTN) EntrypointContext->BlockListAddr,
75 (VOID **) (UINTN) EntrypointContext->MemoryBase64Ptr,
76 (UINTN *) (UINTN) EntrypointContext->MemorySize64Ptr
77 );
78
79 ReturnContext->ReturnStatus = Status;
80
81 //
82 // Disable interrupt of Debug timer, since the new IDT table cannot work in long mode
83 //
84 SaveAndSetDebugTimerInterrupt (FALSE);
85 //
86 // Restore IA32 IDT table
87 //
88 AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);
89
90 //
91 // Finish to coalesce capsule, and return to 32-bit mode.
92 //
93 AsmDisablePaging64 (
94 ReturnContext->ReturnCs,
95 (UINT32) ReturnContext->ReturnEntryPoint,
96 (UINT32) (UINTN) EntrypointContext,
97 (UINT32) (UINTN) ReturnContext,
98 (UINT32) (EntrypointContext->StackBufferBase + EntrypointContext->StackBufferLength)
99 );
100
101 //
102 // Should never be here.
103 //
104 ASSERT (FALSE);
105 return EFI_SUCCESS;
106 }