Skip to content

Commit

Permalink
stage1: support TDX in trampoline-only mode
Browse files Browse the repository at this point in the history
Since TDP is the only platform right now that uses stage1-trampoline,
only allow platform type TDP when in trampoline-only mode. All TD vCPUs
start execution in 32-bit mode concurrently and therefore only TD BSP is
allowed to use the stage2 stack. Program an invalid address (0x7ffff000)
into a TD AP's ESP register. This address is chosen because a) it is
usually not an MMIO address and b) it is an unaccepted page if it's
backed by memory.

Signed-off-by: Peter Fang <[email protected]>
  • Loading branch information
peterfang committed Jun 28, 2024
1 parent 4bdafc9 commit 465bce0
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions stage1/stage1.S
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ startup_32:
2: popl %ebp
leal 2b, %eax
subl %eax, %ebp
#endif

#ifdef LOAD_STAGE2
leal stage2_bin(%ebp), %esi
movl $STAGE2_START, %edi
movl stage2_size(%ebp), %ecx
Expand Down Expand Up @@ -75,14 +73,35 @@ startup_32:
/* Reserve space for VTOM */
pushl %eax
pushl %eax

#else
/* Setup stack for stage 2 */
/*
* Stage 2 launch info has been prepared
* Make sure platform type is TDP
*/
movl $(STAGE2_START - 24), %eax
movl (%eax), %eax
cmpl $2, %eax
je .Lsetup_td
ud2

.Lsetup_td:
/* %esi is initialized with TD CPU index */
test %esi, %esi
jz .Lsetup_bsp_stack

/* Set up invalid stack for APs since they must run stacklessly */
movl $0x7ffff000, %esp
jmp .Lenter_stage2
.Lsetup_bsp_stack:
/* Set up BSP stack for stage 2 */
movl $(STAGE2_START - 32), %esp
.Lenter_stage2:
#endif

/* Jump to stage 2 */
movl $STAGE2_START, %eax
jmp *%eax

.data

#ifdef LOAD_STAGE2
Expand Down

0 comments on commit 465bce0

Please sign in to comment.