]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/TdxDxe/X64/ApRunLoop.nasm
OvmfPkg: TdxDxe: Fix AsmRelocateApMailBoxLoop
[mirror_edk2.git] / OvmfPkg / TdxDxe / X64 / ApRunLoop.nasm
1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
3 ; SPDX-License-Identifier: BSD-2-Clause-Patent
4 ;
5 ; Module Name:
6 ;
7 ; ApRunLoop.nasm
8 ;
9 ; Abstract:
10 ;
11 ; This is the assembly code for run loop for APs in the guest TD
12 ;
13 ;-------------------------------------------------------------------------------
14
15 %include "TdxCommondefs.inc"
16
17 DEFAULT REL
18
19 SECTION .text
20
21 BITS 64
22
23 %define TDVMCALL_EXPOSE_REGS_MASK 0xffec
24 %define TDVMCALL 0x0
25 %define EXIT_REASON_CPUID 0xa
26
27 %macro tdcall 0
28 db 0x66, 0x0f, 0x01, 0xcc
29 %endmacro
30
31 ;
32 ; Relocated Ap Mailbox loop
33 ;
34 ; @param[in] RBX: Relocated mailbox address
35 ; @param[in] RBP: vCpuId
36 ;
37 ; @return None This routine does not return
38 ;
39 global ASM_PFX(AsmRelocateApMailBoxLoop)
40 ASM_PFX(AsmRelocateApMailBoxLoop):
41 AsmRelocateApMailBoxLoopStart:
42
43 mov rax, TDVMCALL
44 mov rcx, TDVMCALL_EXPOSE_REGS_MASK
45 mov r11, EXIT_REASON_CPUID
46 mov r12, 0xb
47 tdcall
48 test rax, rax
49 jnz Panic
50 mov r8, r15
51
52 MailBoxLoop:
53 ; Spin until command set
54 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandNoop
55 je MailBoxLoop
56 ; Determine if this is a broadcast or directly for my apic-id, if not, ignore
57 cmp dword [rbx + ApicidOffset], MailboxApicidBroadcast
58 je MailBoxProcessCommand
59 cmp dword [rbx + ApicidOffset], r8d
60 jne MailBoxLoop
61 MailBoxProcessCommand:
62 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandWakeup
63 je MailBoxWakeUp
64 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandSleep
65 je MailBoxSleep
66 ; Don't support this command, so ignore
67 jmp MailBoxLoop
68 MailBoxWakeUp:
69 mov rax, [rbx + WakeupVectorOffset]
70 ; OS sends a wakeup command for a given APIC ID, firmware is supposed to reset
71 ; the command field back to zero as acknowledgement.
72 mov qword [rbx + CommandOffset], 0
73 jmp rax
74 MailBoxSleep:
75 jmp $
76 Panic:
77 ud2
78 BITS 64
79 AsmRelocateApMailBoxLoopEnd:
80
81 ;-------------------------------------------------------------------------------------
82 ; AsmGetRelocationMap (&RelocationMap);
83 ;-------------------------------------------------------------------------------------
84 global ASM_PFX(AsmGetRelocationMap)
85 ASM_PFX(AsmGetRelocationMap):
86 lea rax, [ASM_PFX(AsmRelocateApMailBoxLoopStart)]
87 mov qword [rcx], rax
88 mov qword [rcx + 8h], AsmRelocateApMailBoxLoopEnd - AsmRelocateApMailBoxLoopStart
89 ret
90