2 The X64 entrypoint is used to process capsule in long mode.
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
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.
15 #include <Library/DebugLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/CpuExceptionHandlerLib.h>
18 #include "CommonHeader.h"
20 #define EXCEPTION_VECTOR_NUMBER 0x20
23 The X64 entrypoint is used to process capsule in long mode then
24 return to 32-bit protected mode.
26 @param EntrypointContext Pointer to the context of long mode.
27 @param ReturnContext Pointer to the context of 32-bit protected mode.
29 @retval This function should never return actually.
35 SWITCH_32_TO_64_CONTEXT
*EntrypointContext
,
36 SWITCH_64_TO_32_CONTEXT
*ReturnContext
40 IA32_DESCRIPTOR Ia32Idtr
;
41 IA32_DESCRIPTOR X64Idtr
;
42 IA32_IDT_GATE_DESCRIPTOR IdtEntryTable
[EXCEPTION_VECTOR_NUMBER
];
45 // Save the IA32 IDT Descriptor
47 AsmReadIdtr ((IA32_DESCRIPTOR
*) &Ia32Idtr
);
50 // Setup X64 IDT table
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
);
58 // Setup the default CPU exception handlers
60 SetupCpuExceptionHandlers ();
63 // Call CapsuleDataCoalesce to process capsule.
65 Status
= CapsuleDataCoalesce (
67 (EFI_PHYSICAL_ADDRESS
*) (UINTN
) EntrypointContext
->BlockListAddr
,
68 (VOID
**) (UINTN
) EntrypointContext
->MemoryBase64Ptr
,
69 (UINTN
*) (UINTN
) EntrypointContext
->MemorySize64Ptr
72 ReturnContext
->ReturnStatus
= Status
;
75 // Restore IA32 IDT table
77 AsmWriteIdtr ((IA32_DESCRIPTOR
*) &Ia32Idtr
);
80 // Finish to coalesce capsule, and return to 32-bit mode.
83 ReturnContext
->ReturnCs
,
84 (UINT32
) ReturnContext
->ReturnEntryPoint
,
85 (UINT32
) (UINTN
) EntrypointContext
,
86 (UINT32
) (UINTN
) ReturnContext
,
87 (UINT32
) (EntrypointContext
->StackBufferBase
+ EntrypointContext
->StackBufferLength
)
91 // Should never be here.