1 ;------------------------------------------------------------------------------ ;
2 ; Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
3 ; SPDX-License-Identifier: BSD-2-Clause-Patent
11 ; This is the assembly code for run loop for APs in the guest TD
13 ;-------------------------------------------------------------------------------
15 %include "TdxCommondefs.inc"
23 %define TDVMCALL_EXPOSE_REGS_MASK 0xffec
25 %define EXIT_REASON_CPUID 0xa
28 db 0x66, 0x0f, 0x01, 0xcc
32 ; Relocated Ap Mailbox loop
34 ; @param[in] RBX: Relocated mailbox address
35 ; @param[in] RBP: vCpuId
37 ; @return None This routine does not return
39 global ASM_PFX(AsmRelocateApMailBoxLoop)
40 ASM_PFX(AsmRelocateApMailBoxLoop):
41 AsmRelocateApMailBoxLoopStart:
44 mov rcx, TDVMCALL_EXPOSE_REGS_MASK
45 mov r11, EXIT_REASON_CPUID
53 ; Spin until command set
54 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandNoop
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
61 MailBoxProcessCommand:
62 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandWakeup
64 cmp dword [rbx + CommandOffset], MpProtectedModeWakeupCommandSleep
66 ; Don't support this command, so ignore
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
79 AsmRelocateApMailBoxLoopEnd:
81 ;-------------------------------------------------------------------------------------
82 ; AsmGetRelocationMap (&RelocationMap);
83 ;-------------------------------------------------------------------------------------
84 global ASM_PFX(AsmGetRelocationMap)
85 ASM_PFX(AsmGetRelocationMap):
86 lea rax, [ASM_PFX(AsmRelocateApMailBoxLoopStart)]
88 mov qword [rcx + 8h], AsmRelocateApMailBoxLoopEnd - AsmRelocateApMailBoxLoopStart