Skip to content

Commit e6490b3

Browse files
haowqsjyao1
authored andcommitted
td-shim: Migration build ResetVector.bin
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Liu Jiang <gerry@linux.alibaba.com> Signed-off-by: haowei <WeiX.Hao@intel.com>
1 parent 20ad96a commit e6490b3

15 files changed

+1257
-0
lines changed

td-shim/ResetVector/CommonMacros.inc

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
;------------------------------------------------------------------------------
2+
; @file
3+
; Common macros used in the ResetVector VTF module.
4+
;
5+
; Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
6+
; SPDX-License-Identifier: BSD-2-Clause-Patent
7+
;
8+
;------------------------------------------------------------------------------
9+
10+
%macro tdcall 0
11+
%if (USE_TDX_EMULATION != 0)
12+
vmcall
13+
%else
14+
db 0x66,0x0f,0x01,0xcc
15+
%endif
16+
%endmacro
17+
18+
19+
%define ADDR16_OF(x) (0x10000 - fourGigabytes + x)
20+
%define ADDR_OF(x) (0x100000000 - fourGigabytes + x)
21+
22+
%macro OneTimeCall 1
23+
jmp %1
24+
%1 %+ OneTimerCallReturn:
25+
%endmacro
26+
27+
%macro OneTimeCallRet 1
28+
jmp %1 %+ OneTimerCallReturn
29+
%endmacro
30+
31+
32+
CommandOffset equ 00h
33+
ApicidOffset equ 04h
34+
WakeupVectorOffset equ 08h
35+
OSArgsOffset equ 10h
36+
FirmwareArgsOffset equ 800h
37+
WakeupArgsRelocatedMailBox equ 800h
38+
ApWorkingStackStart equ 800h
39+
CpuArrivalOffset equ 900h
40+
CpusExitingOffset equ 0a00h
41+
TalliesOffset equ 0a08h
42+
43+
MpProtectedModeWakeupCommandNoop equ 0
44+
MpProtectedModeWakeupCommandWakeup equ 1
45+
MpProtectedModeWakeupCommandSleep equ 2
46+
MpProtectedModeWakeupCommandAssignWork equ 3
47+
MpProtectedModeWakeupCommandCheck equ 4
48+
49+
MailboxApicIdInvalid equ 0xffffffff
50+
MailboxApicidBroadcast equ 0xfffffffe
51+
52+
%macro simple_spinlock 3
53+
mov edx, %1
54+
mov eax, 0
55+
mov ebx, 1
56+
%%testlock:
57+
lock cmpxchg [edx], ebx
58+
jnz %3
59+
mov eax, 0
60+
mov ebx, 1
61+
lock cmpxchg [edx+4], ebx
62+
jnz %2
63+
%%firstone:
64+
pause
65+
%endmacro
66+
67+
%macro simple_releaselock 3
68+
%2:
69+
mov eax, 1
70+
mov edx, %1
71+
jmp %%testlock
72+
%3:
73+
pause
74+
mov eax, 0
75+
%%testlock:
76+
mov ebx, 0
77+
lock cmpxchg [edx], ebx
78+
jnz %3
79+
%endmacro
80+
81+
82+
%define PAGE_PRESENT 0x01
83+
%define PAGE_READ_WRITE 0x02
84+
%define PAGE_USER_SUPERVISOR 0x04
85+
%define PAGE_WRITE_THROUGH 0x08
86+
%define PAGE_CACHE_DISABLE 0x010
87+
%define PAGE_ACCESSED 0x020
88+
%define PAGE_DIRTY 0x040
89+
%define PAGE_PAT 0x080
90+
%define PAGE_GLOBAL 0x0100
91+
%define PAGE_2M_MBO 0x080
92+
%define PAGE_2M_PAT 0x01000
93+
94+
%define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \
95+
PAGE_ACCESSED + \
96+
PAGE_DIRTY + \
97+
PAGE_READ_WRITE + \
98+
PAGE_PRESENT)
99+
100+
%define PAGE_PDP_ATTR (PAGE_ACCESSED + \
101+
PAGE_READ_WRITE + \
102+
PAGE_PRESENT)
103+
104+
%define PT_ADDR(Base,Offset) ((Base) + (Offset))
105+
106+
%macro clear_pagetables 1
107+
mov ecx, 6 * 0x1000 / 4
108+
xor eax, eax
109+
%%clearloop:
110+
mov dword[ecx * 4 + PT_ADDR (%1,0) - 4], eax
111+
loop %%clearloop
112+
%endmacro
113+
114+
%macro init_l4_l3_page_tables 2
115+
;
116+
; Top level Page Directory Pointers (1 * 512GB entry)
117+
;
118+
mov dword[PT_ADDR (%1,0)], PT_ADDR (%1,0x1000) + PAGE_PDP_ATTR
119+
mov dword[PT_ADDR (%1,4)], %2
120+
121+
;
122+
; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
123+
;
124+
mov dword[PT_ADDR (%1,0x1000)], PT_ADDR (%1,0x2000) + PAGE_PDP_ATTR
125+
mov dword[PT_ADDR (%1,0x1004)], %2
126+
mov dword[PT_ADDR (%1,0x1008)], PT_ADDR (%1,0x3000) + PAGE_PDP_ATTR
127+
mov dword[PT_ADDR (%1,0x100C)], %2
128+
mov dword[PT_ADDR (%1,0x1010)], PT_ADDR (%1,0x4000) + PAGE_PDP_ATTR
129+
mov dword[PT_ADDR (%1,0x1014)], %2
130+
mov dword[PT_ADDR (%1,0x1018)], PT_ADDR (%1,0x5000) + PAGE_PDP_ATTR
131+
mov dword[PT_ADDR (%1,0x101C)], %2
132+
%endmacro
133+
134+
%macro init_l2_page_tables 2
135+
;
136+
; Page Table Entries (2048 * 2MB entries => 4GB)
137+
;
138+
mov ecx, 0x800
139+
%%loop:
140+
mov eax, ecx
141+
dec eax
142+
shl eax, 21
143+
add eax, PAGE_2M_PDE_ATTR
144+
mov [ecx * 8 + PT_ADDR (%1,0x2000 - 8)], eax
145+
mov dword[(ecx * 8 + PT_ADDR (%1,0x2000 - 8)) + 4], %2
146+
loop %%loop
147+
%endmacro
148+
149+
%macro initialize_page_tables 2
150+
clear_pagetables %1
151+
init_l4_l3_page_tables %1,%2
152+
init_l2_page_tables %1,%2
153+
%endmacro
154+
155+
156+
%define EFI_HOB_TYPE_HANDOFF 0x0001
157+
%define EFI_HOB_TYPE_MEMORY_ALLOCATION 0x0002
158+
%define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR 0x0003
159+
%define EFI_HOB_TYPE_GUID_EXTENSION 0x0004
160+
%define EFI_HOB_TYPE_FV 0x0005
161+
%define EFI_HOB_TYPE_CPU 0x0006
162+
%define EFI_HOB_TYPE_MEMORY_POOL 0x0007
163+
%define EFI_HOB_TYPE_FV2 0x0009
164+
%define EFI_HOB_TYPE_LOAD_PEIM_UNUSED 0x000A
165+
%define EFI_HOB_TYPE_UEFI_CAPSULE 0x000B
166+
%define EFI_HOB_TYPE_FV3 0x000C
167+
%define EFI_HOB_TYPE_UNUSED 0xFFFE
168+
%define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF
169+
170+
%define EFI_RESOURCE_SYSTEM_MEMORY 0x00000000
171+
%define EFI_RESOURCE_MEMORY_MAPPED_IO 0x00000001
172+
%define EFI_RESOURCE_IO 0x00000002
173+
%define EFI_RESOURCE_FIRMWARE_DEVICE 0x00000003
174+
%define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT 0x00000004
175+
%define EFI_RESOURCE_MEMORY_RESERVED 0x00000005
176+
%define EFI_RESOURCE_IO_RESERVED 0x00000006
177+
%define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000007
178+
179+
%define EFI_RESOURCE_ATTRIBUTE_PRESENT 0x00000001
180+
%define EFI_RESOURCE_ATTRIBUTE_INITIALIZED 0x00000002
181+
%define EFI_RESOURCE_ATTRIBUTE_TESTED 0x00000004
182+
%define EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED 0x00000080
183+
184+
%define EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE 0x00000400
185+
%define EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE 0x00000800
186+
%define EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE 0x00001000
187+
%define EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE 0x00002000
188+
189+
190+
%define EFI_IO_ATTR (EFI_RESOURCE_ATTRIBUTE_PRESENT + \
191+
EFI_RESOURCE_ATTRIBUTE_INITIALIZED + \
192+
EFI_RESOURCE_ATTRIBUTE_TESTED + \
193+
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE)
194+
195+
%define EFI_LOW_MEM_ATTR (EFI_RESOURCE_ATTRIBUTE_PRESENT + \
196+
EFI_RESOURCE_ATTRIBUTE_INITIALIZED + \
197+
EFI_RESOURCE_ATTRIBUTE_TESTED + \
198+
EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE + \
199+
EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE + \
200+
EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE + \
201+
EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE)
202+
203+
%define TDCALL_TDINFO 0x1
204+
%define TDCALL_TDACCEPTPAGE 0x6

td-shim/ResetVector/DebugDisabled.asm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;------------------------------------------------------------------------------
2+
; @file
3+
; Debug disabled
4+
;
5+
; Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
6+
; SPDX-License-Identifier: BSD-2-Clause-Patent
7+
;
8+
;------------------------------------------------------------------------------
9+
10+
BITS 16
11+
12+
%macro debugInitialize 0
13+
;
14+
; No initialization is required
15+
;
16+
%endmacro
17+
18+
%macro debugShowPostCode 1
19+
%endmacro
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;------------------------------------------------------------------------------
2+
; @file
3+
; Transition from 32 bit flat protected mode into 64 bit flat protected mode
4+
;
5+
; Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
6+
; SPDX-License-Identifier: BSD-2-Clause-Patent
7+
;
8+
;------------------------------------------------------------------------------
9+
10+
BITS 32
11+
12+
;
13+
; Modified: EAX. ECX
14+
;
15+
Transition32FlatTo64Flat:
16+
17+
mov eax, cr4
18+
bts eax, 5 ; enable PAE
19+
20+
;
21+
; esp [6:0] holds gpaw, if it is at least 52 bits, need to set
22+
; LA57 and use 5-level paging
23+
;
24+
mov ecx, esp
25+
and ecx, 0x2f
26+
cmp ecx, 52
27+
jl .set_cr4
28+
bts eax, 12
29+
.set_cr4:
30+
mov cr4, eax
31+
32+
mov ecx, ADDR_OF(TopLevelPageDirectory)
33+
;
34+
; if we just set la57, we are ok, if using 4-level paging, adjust top-level page directory
35+
;
36+
bt eax, 12
37+
jc .set_cr3
38+
add ecx, 0x1000
39+
.set_cr3:
40+
mov cr3, ecx
41+
42+
mov eax, cr0
43+
bts eax, 31 ; set PG
44+
mov cr0, eax ; enable paging
45+
46+
jmp LINEAR_CODE64_SEL:ADDR_OF(jumpTo64BitAndLandHere)
47+
BITS 64
48+
jumpTo64BitAndLandHere:
49+
50+
debugShowPostCode POSTCODE_64BIT_MODE
51+
52+
OneTimeCallRet Transition32FlatTo64Flat

0 commit comments

Comments
 (0)