Skip to content

Commit 5594582

Browse files
committed
i686: add layout, vmem, etc stubs
As per the comments preexisting in src/hyperlight_common/src/layout.rs. This avoids some fairly cumbersome proliferation of #[cfg(feature = "init-paging")], and may be developed further in the future. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
1 parent 419ba3b commit 5594582

9 files changed

Lines changed: 127 additions & 11 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// This file is just dummy definitions at the moment, in order to
18+
// allow compiling the guest for real mode boot scenarios.
19+
20+
pub const MAX_GVA: usize = 0xffff_efff;
21+
pub const SNAPSHOT_PT_GVA: usize = 0xefff_efff;
22+
pub const MAX_GPA: usize = 0xffff_ffff;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// This file is just dummy definitions at the moment, in order to
18+
// allow compiling the guest for real mode boot scenarios.
19+
20+
use crate::vmem::{BasicMapping, Mapping, TableOps};
21+
22+
pub const PAGE_SIZE: usize = 4096;
23+
pub const PAGE_TABLE_SIZE: usize = 4096;
24+
pub type PageTableEntry = u32;
25+
pub type VirtAddr = u32;
26+
pub type PhysAddr = u32;
27+
28+
#[allow(clippy::missing_safety_doc)]
29+
pub unsafe fn map<Op: TableOps>(_op: &Op, _mapping: Mapping) {
30+
panic!("vmem::map: i686 guests do not support booting the full hyperlight guest kernel");
31+
}
32+
33+
#[allow(clippy::missing_safety_doc)]
34+
pub unsafe fn virt_to_phys<Op: TableOps>(_op: &Op, _address: u64) -> Option<(u64, BasicMapping)> {
35+
panic!(
36+
"vmem::virt_to_phys: i686 guests do not support booting the full hyperlight guest kernel"
37+
);
38+
}

src/hyperlight_common/src/layout.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,21 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// The constraint on the feature is temporary and will be removed when other arch i686 is added
1817
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/layout.rs")]
19-
#[cfg(feature = "init-paging")]
18+
#[cfg_attr(target_arch = "x86", path = "arch/i686/layout.rs")]
2019
mod arch;
2120

22-
// The constraint on the feature is temporary and will be removed when other arch i686 is added
23-
#[cfg(feature = "init-paging")]
24-
pub use arch::MAX_GPA;
25-
#[cfg(feature = "init-paging")]
26-
pub use arch::{MAX_GVA, SNAPSHOT_PT_GVA};
21+
pub use arch::{MAX_GPA, MAX_GVA, SNAPSHOT_PT_GVA};
2722

2823
// offsets down from the top of scratch memory for various things
2924
pub const SCRATCH_TOP_SIZE_OFFSET: u64 = 0x08;
3025
pub const SCRATCH_TOP_USED_OFFSET: u64 = 0x10;
3126
pub const SCRATCH_TOP_ALLOCATOR_OFFSET: u64 = 0x18;
3227
pub const SCRATCH_TOP_EXN_STACK_OFFSET: u64 = 0x20;
3328

34-
#[cfg(feature = "init-paging")]
3529
pub fn scratch_base_gpa(size: usize) -> u64 {
3630
(MAX_GPA - size + 1) as u64
3731
}
38-
#[cfg(feature = "init-paging")]
3932
pub fn scratch_base_gva(size: usize) -> u64 {
4033
(MAX_GVA - size + 1) as u64
4134
}

src/hyperlight_common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ pub mod resource;
4141

4242
/// cbindgen:ignore
4343
pub mod func;
44+
4445
// cbindgen:ignore
45-
#[cfg(feature = "init-paging")]
4646
pub mod vmem;

src/hyperlight_common/src/vmem.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ limitations under the License.
1515
*/
1616

1717
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/vmem.rs")]
18+
#[cfg_attr(target_arch = "x86", path = "arch/i686/vmem.rs")]
1819
pub mod arch;
1920

20-
pub use arch::{PAGE_SIZE, PAGE_TABLE_SIZE, PageTableEntry, PhysAddr, VirtAddr};
21+
/// This is always the page size that the /guest/ is being compiled
22+
/// for, which may or may not be the same as the host page size.
23+
pub use arch::PAGE_SIZE;
24+
pub use arch::{PAGE_TABLE_SIZE, PageTableEntry, PhysAddr, VirtAddr};
2125
pub const PAGE_TABLE_ENTRIES_PER_TABLE: usize =
2226
PAGE_TABLE_SIZE / core::mem::size_of::<PageTableEntry>();
2327

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// This file is just dummy definitions at the moment, in order to
18+
// allow compiling the guest for real mode boot scenarios.
19+
20+
pub const MAIN_STACK_TOP_GVA: usize = 0xdfff_efff;
21+
22+
pub fn scratch_size() -> u64 {
23+
hyperlight_common::vmem::PAGE_SIZE as u64
24+
}
25+
26+
pub fn scratch_base_gpa() -> u64 {
27+
hyperlight_common::layout::scratch_base_gpa(scratch_size() as usize)
28+
}
29+
30+
pub fn scratch_base_gva() -> u64 {
31+
hyperlight_common::layout::scratch_base_gva(scratch_size() as usize)
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2025 The Hyperlight Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// This file is just dummy definitions at the moment, in order to
18+
// allow compiling the guest for real mode boot scenarios.
19+
20+
#[allow(clippy::missing_safety_doc)]
21+
pub unsafe fn alloc_phys_pages(_n: u64) -> u64 {
22+
panic!(
23+
"prim_alloc::alloc_phys_pages: i686 guests do not support booting the full hyperlight guest kernel"
24+
);
25+
}

src/hyperlight_guest/src/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/layout.rs")]
18+
#[cfg_attr(target_arch = "x86", path = "arch/i686/layout.rs")]
1819
mod arch;
1920

2021
pub use arch::MAIN_STACK_TOP_GVA;

src/hyperlight_guest/src/prim_alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
#[cfg_attr(target_arch = "x86_64", path = "arch/amd64/prim_alloc.rs")]
18+
#[cfg_attr(target_arch = "x86", path = "arch/i686/prim_alloc.rs")]
1819
mod arch;
1920

2021
/// Allocate n contiguous physical pages and return the physical

0 commit comments

Comments
 (0)