1 | ;------------------------------------------------------------------------------
|
---|
2 | ;*
|
---|
3 | ;* Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
---|
4 | ;* SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
5 | ;*
|
---|
6 | ;* CpuAsm.asm
|
---|
7 | ;*
|
---|
8 | ;* Abstract:
|
---|
9 | ;*
|
---|
10 | ;------------------------------------------------------------------------------
|
---|
11 |
|
---|
12 | #include <Base.h>
|
---|
13 |
|
---|
14 | DEFAULT REL
|
---|
15 | SECTION .text
|
---|
16 |
|
---|
17 | extern ASM_PFX(SecCoreStartupWithStack)
|
---|
18 |
|
---|
19 | %macro tdcall 0
|
---|
20 | db 0x66, 0x0f, 0x01, 0xcc
|
---|
21 | %endmacro
|
---|
22 |
|
---|
23 | ;
|
---|
24 | ; SecCore Entry Point
|
---|
25 | ;
|
---|
26 | ; Processor is in flat protected mode
|
---|
27 | ;
|
---|
28 | ; @param[in] RAX Initial value of the EAX register (BIST: Built-in Self Test)
|
---|
29 | ; @param[in] DI 'BP': boot-strap processor, or 'AP': application processor
|
---|
30 | ; @param[in] RBP Pointer to the start of the Boot Firmware Volume
|
---|
31 | ; @param[in] DS Selector allowing flat access to all addresses
|
---|
32 | ; @param[in] ES Selector allowing flat access to all addresses
|
---|
33 | ; @param[in] FS Selector allowing flat access to all addresses
|
---|
34 | ; @param[in] GS Selector allowing flat access to all addresses
|
---|
35 | ; @param[in] SS Selector allowing flat access to all addresses
|
---|
36 | ;
|
---|
37 | ; @return None This routine does not return
|
---|
38 | ;
|
---|
39 | global ASM_PFX(_ModuleEntryPoint)
|
---|
40 | ASM_PFX(_ModuleEntryPoint):
|
---|
41 |
|
---|
42 | ;
|
---|
43 | ; Guest type is stored in OVMF_WORK_AREA
|
---|
44 | ;
|
---|
45 | %define OVMF_WORK_AREA FixedPcdGet32 (PcdOvmfWorkAreaBase)
|
---|
46 | %define VM_GUEST_TYPE_TDX 2
|
---|
47 | mov eax, OVMF_WORK_AREA
|
---|
48 | cmp byte[eax], VM_GUEST_TYPE_TDX
|
---|
49 | jne InitStack
|
---|
50 |
|
---|
51 | %define TDCALL_TDINFO 1
|
---|
52 | mov rax, TDCALL_TDINFO
|
---|
53 | tdcall
|
---|
54 |
|
---|
55 | ;
|
---|
56 | ; R8 [31:0] NUM_VCPUS
|
---|
57 | ; [63:32] MAX_VCPUS
|
---|
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
|
---|
61 | ;
|
---|
62 | mov rax, r9
|
---|
63 | and rax, 0xffff
|
---|
64 | test rax, rax
|
---|
65 | jz InitStack
|
---|
66 | mov rsp, FixedPcdGet32 (PcdOvmfSecGhcbBackupBase)
|
---|
67 | jmp ParkAp
|
---|
68 |
|
---|
69 | InitStack:
|
---|
70 |
|
---|
71 | ;
|
---|
72 | ; Fill the temporary RAM with the initial stack value.
|
---|
73 | ; The loop below will seed the heap as well, but that's harmless.
|
---|
74 | ;
|
---|
75 | mov rax, (FixedPcdGet32 (PcdInitValueInTempStack) << 32) | FixedPcdGet32 (PcdInitValueInTempStack)
|
---|
76 | ; qword to store
|
---|
77 | mov rdi, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) ; base address,
|
---|
78 | ; relative to
|
---|
79 | ; ES
|
---|
80 | mov rcx, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) / 8 ; qword count
|
---|
81 | cld ; store from base
|
---|
82 | ; up
|
---|
83 | rep stosq
|
---|
84 |
|
---|
85 | ;
|
---|
86 | ; Load temporary RAM stack based on PCDs
|
---|
87 | ;
|
---|
88 | %define SEC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) + \
|
---|
89 | FixedPcdGet32 (PcdOvmfSecPeiTempRamSize))
|
---|
90 | mov rsp, SEC_TOP_OF_STACK
|
---|
91 | nop
|
---|
92 |
|
---|
93 | ;
|
---|
94 | ; Setup parameters and call SecCoreStartupWithStack
|
---|
95 | ; rcx: BootFirmwareVolumePtr
|
---|
96 | ; rdx: TopOfCurrentStack
|
---|
97 | ;
|
---|
98 | mov rcx, rbp
|
---|
99 | mov rdx, rsp
|
---|
100 | sub rsp, 0x20
|
---|
101 | call ASM_PFX(SecCoreStartupWithStack)
|
---|
102 |
|
---|
103 | %include "../../IntelTdx/Sec/X64/IntelTdxAPs.nasm"
|
---|