@@ -15,12 +15,9 @@ limitations under the License.
1515*/
1616
1717use core:: arch:: global_asm;
18- use core:: mem:: size_of;
1918
20- use hyperlight_common:: mem:: RunMode ;
21-
22- use crate :: guest_error:: { set_invalid_runmode_error, set_stack_allocate_error} ;
23- use crate :: { MIN_STACK_ADDRESS , RUNNING_MODE } ;
19+ use crate :: guest_error:: set_stack_allocate_error;
20+ use crate :: MIN_STACK_ADDRESS ;
2421
2522extern "win64" {
2623 fn __chkstk ( ) ;
@@ -35,21 +32,6 @@ global_asm!(
3532 push r10
3633 push r11
3734
38- /* Load run_mode into r10 */
39- mov r10, qword ptr [rip+{run_mode}]
40-
41- cmp r10, 0
42- je handle_none
43- cmp r10, 1
44- je handle_hypervisor
45- cmp r10, 2
46- je handle_inproc_windows
47- cmp r10, 3
48- je handle_inproc_linux
49- /* run_mode > 3 (invalid), so treat like handle_none */
50- jmp handle_invalid
51-
52- handle_hypervisor:
5335 /* Load the minimum stack address from the PEB */
5436 mov r11, [rip+{min_stack_addr}]
5537
@@ -72,49 +54,11 @@ global_asm!(
7254 call {set_error}
7355 hlt
7456
75- handle_inproc_windows:
76- /* Get the current stack pointer */
77- lea r10, [rsp + 0x18]
78-
79- /* Calculate what the new stack pointer will be */
80- sub r10, rax
81- cmovb r10, r11
82- mov r11, qword ptr gs:[0x0000000000000010]
83- cmp r10, r11
84- jae cs_ret
85- and r10w, 0x0F000
86- csip_stackprobe:
87- lea r11, [r11 + 0x0FFFFFFFFFFFFF000]
88- mov byte ptr [r11], 0
89- cmp r10, r11
90- jne csip_stackprobe
9157 cs_ret:
9258 /* Restore RAX, R11 */
9359 pop r11
9460 pop r10
95- ret
96- handle_inproc_linux:
97- /* no-op */
98- jmp cs_ret
99- handle_none:
100- /* no-op. This can entrypoint has a large stack allocation
101- before RunMode variable is set */
102- jmp cs_ret
103- handle_invalid:
104- call {invalid_runmode}" ,
105- run_mode = sym RUNNING_MODE ,
61+ ret" ,
10662 min_stack_addr = sym MIN_STACK_ADDRESS ,
10763 set_error = sym set_stack_allocate_error,
108- invalid_runmode = sym set_invalid_runmode_error
10964) ;
110-
111- // Assumptions made in implementation above. If these are no longer true, compilation will fail
112- // and the developer will need to update the assembly code.
113- const _: ( ) = {
114- assert ! ( size_of:: <RunMode >( ) == size_of:: <u64 >( ) ) ;
115- assert ! ( RunMode :: None as u64 == 0 ) ;
116- assert ! ( RunMode :: Hypervisor as u64 == 1 ) ;
117- assert ! ( RunMode :: InProcessWindows as u64 == 2 ) ;
118- assert ! ( RunMode :: InProcessLinux as u64 == 3 ) ;
119- assert ! ( RunMode :: Invalid as u64 == 4 ) ;
120- } ;
0 commit comments