hyperlight_guest/arch/amd64/layout.rs
1/*
2Copyright 2025 The Hyperlight Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15 */
16
17// The addresses in this file should be coordinated with
18// src/hyperlight_common/src/arch/amd64/layout.rs and
19// src/hyperlight_guest_bin/src/arch/amd64/layout.rs
20
21/// Note that the x86-64 ELF psABI requires that the stack be 16-byte
22/// aligned before a call instruction; we use the aligned version
23/// here, even though this requires adjusting the pointer by 8 bytes
24/// when entering the guest without a call instruction to push a
25/// return address.
26pub const MAIN_STACK_TOP_GVA: u64 = 0xffff_ff00_0000_0000;
27pub const MAIN_STACK_LIMIT_GVA: u64 = 0xffff_fe00_0000_0000;
28
29pub fn scratch_size() -> u64 {
30 let addr = crate::layout::scratch_size_gva();
31 let x: u64;
32 unsafe {
33 core::arch::asm!("mov {x}, [{addr}]", x = out(reg) x, addr = in(reg) addr);
34 }
35 x
36}
37
38pub fn scratch_base_gpa() -> u64 {
39 hyperlight_common::layout::scratch_base_gpa(scratch_size() as usize)
40}
41
42pub fn scratch_base_gva() -> u64 {
43 hyperlight_common::layout::scratch_base_gva(scratch_size() as usize)
44}