1 ;------------------------------------------------------------------------------
3 ;* Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
4 ;* SPDX-License-Identifier: BSD-2-Clause-Patent
10 ;------------------------------------------------------------------------------
13 %include "TdxCommondefs.inc"
18 extern ASM_PFX(SecCoreStartupWithStack)
21 db 0x66, 0x0f, 0x01, 0xcc
27 ; Processor is in flat protected mode
29 ; @param[in] RAX Initial value of the EAX register (BIST: Built-in Self Test)
30 ; @param[in] DI 'BP': boot-strap processor, or 'AP': application processor
31 ; @param[in] RBP Pointer to the start of the Boot Firmware Volume
32 ; @param[in] DS Selector allowing flat access to all addresses
33 ; @param[in] ES Selector allowing flat access to all addresses
34 ; @param[in] FS Selector allowing flat access to all addresses
35 ; @param[in] GS Selector allowing flat access to all addresses
36 ; @param[in] SS Selector allowing flat access to all addresses
38 ; @return None This routine does not return
40 global ASM_PFX(_ModuleEntryPoint)
41 ASM_PFX(_ModuleEntryPoint):
44 ; Guest type is stored in OVMF_WORK_AREA
46 %define OVMF_WORK_AREA FixedPcdGet32 (PcdOvmfWorkAreaBase)
47 %define VM_GUEST_TYPE_TDX 2
48 mov eax, OVMF_WORK_AREA
49 cmp byte[eax], VM_GUEST_TYPE_TDX
52 mov rax, TDCALL_TDINFO
58 ; R9 [31:0] VCPU_INDEX
59 ; Td Guest set the VCPU0 as the BSP, others are the APs
60 ; APs jump to spinloop and get released by DXE's MpInitLib
70 ; Fill the temporary RAM with the initial stack value.
71 ; The loop below will seed the heap as well, but that's harmless.
73 mov rax, (FixedPcdGet32 (PcdInitValueInTempStack) << 32) | FixedPcdGet32 (PcdInitValueInTempStack)
75 mov rdi, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) ; base address,
78 mov rcx, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) / 8 ; qword count
84 ; Load temporary RAM stack based on PCDs
86 %define SEC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + \
87 FixedPcdGet32 (PcdOvmfSecPeiTempRamSize))
88 mov rsp, SEC_TOP_OF_STACK
92 ; Setup parameters and call SecCoreStartupWithStack
93 ; rcx: BootFirmwareVolumePtr
94 ; rdx: TopOfCurrentStack
99 call ASM_PFX(SecCoreStartupWithStack)
102 ; Note: BSP never gets here. APs will be unblocked by DXE
104 ; R8 [31:0] NUM_VCPUS
106 ; R9 [31:0] VCPU_INDEX
113 mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase)
116 ; register itself in [rsp + CpuArrivalOffset]
119 lock xadd dword [rsp + CpuArrivalOffset], eax
125 mov eax, dword[rsp + CpuArrivalOffset]
126 jmp .check_arrival_cnt
129 mov eax, dword[rsp + CommandOffset]
130 cmp eax, MpProtectedModeWakeupCommandNoop
133 cmp eax, MpProtectedModeWakeupCommandWakeup
136 ; Don't support this command, so ignore
141 ; BSP sets these variables before unblocking APs
142 ; RAX: WakeupVectorOffset
143 ; RBX: Relocated mailbox address
147 mov eax, dword[rsp + WakeupVectorOffset]
148 mov rbx, [rsp + WakeupArgsRelocatedMailBox]