]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
1. Introduced CPU Exception Handler Library to provide the CPU exception handlers...
[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 - 2012, 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 "CommonHeader.h"
19
20 #define EXCEPTION_VECTOR_NUMBER 0x20
21
22 /**
23 The X64 entrypoint is used to process capsule in long mode then
24 return to 32-bit protected mode.
25
26 @param EntrypointContext Pointer to the context of long mode.
27 @param ReturnContext Pointer to the context of 32-bit protected mode.
28
29 @retval This function should never return actually.
30
31 **/
32 EFI_STATUS
33 EFIAPI
34 _ModuleEntryPoint (
35 SWITCH_32_TO_64_CONTEXT *EntrypointContext,
36 SWITCH_64_TO_32_CONTEXT *ReturnContext
37 )
38 {
39 EFI_STATUS Status;
40 IA32_DESCRIPTOR Ia32Idtr;
41 IA32_DESCRIPTOR X64Idtr;
42 IA32_IDT_GATE_DESCRIPTOR IdtEntryTable[EXCEPTION_VECTOR_NUMBER];
43
44 //
45 // Save the IA32 IDT Descriptor
46 //
47 AsmReadIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);
48
49 //
50 // Setup X64 IDT table
51 //
52 ZeroMem (IdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER);
53 X64Idtr.Base = (UINTN) IdtEntryTable;
54 X64Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * EXCEPTION_VECTOR_NUMBER - 1);
55 AsmWriteIdtr ((IA32_DESCRIPTOR *) &X64Idtr);
56
57 //
58 // Setup the default CPU exception handlers
59 //
60 SetupCpuExceptionHandlers ();
61
62 //
63 // Call CapsuleDataCoalesce to process capsule.
64 //
65 Status = CapsuleDataCoalesce (
66 NULL,
67 (EFI_PHYSICAL_ADDRESS *) (UINTN) EntrypointContext->BlockListAddr,
68 (VOID **) (UINTN) EntrypointContext->MemoryBase64Ptr,
69 (UINTN *) (UINTN) EntrypointContext->MemorySize64Ptr
70 );
71
72 ReturnContext->ReturnStatus = Status;
73
74 //
75 // Restore IA32 IDT table
76 //
77 AsmWriteIdtr ((IA32_DESCRIPTOR *) &Ia32Idtr);
78
79 //
80 // Finish to coalesce capsule, and return to 32-bit mode.
81 //
82 AsmDisablePaging64 (
83 ReturnContext->ReturnCs,
84 (UINT32) ReturnContext->ReturnEntryPoint,
85 (UINT32) (UINTN) EntrypointContext,
86 (UINT32) (UINTN) ReturnContext,
87 (UINT32) (EntrypointContext->StackBufferBase + EntrypointContext->StackBufferLength)
88 );
89
90 //
91 // Should never be here.
92 //
93 ASSERT (FALSE);
94 return EFI_SUCCESS;
95 }