Skip to content

Commit 6d32033

Browse files
feat: opentmk init
feat: opentmk init feat: opentmk init feat: opentmk init feat: opentmk init feat: opentmk init feat: opentmk init feat: init 1 feat: init 2 feat: init 1 feat: opentmk feat: opentmk init 3 feat: opentmk init 4 feat: opentmk init 4
1 parent e97db3d commit 6d32033

28 files changed

+3493
-1
lines changed

Cargo.lock

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,9 @@ name = "lazy_static"
35473547
version = "1.4.0"
35483548
source = "registry+https://github.com/rust-lang/crates.io-index"
35493549
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
3550+
dependencies = [
3551+
"spin 0.5.2",
3552+
]
35503553

35513554
[[package]]
35523555
name = "libc"
@@ -3609,6 +3612,15 @@ dependencies = [
36093612
"escape8259",
36103613
]
36113614

3615+
[[package]]
3616+
name = "linked_list_allocator"
3617+
version = "0.10.5"
3618+
source = "registry+https://github.com/rust-lang/crates.io-index"
3619+
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
3620+
dependencies = [
3621+
"spinning_top",
3622+
]
3623+
36123624
[[package]]
36133625
name = "linkme"
36143626
version = "0.3.31"
@@ -4769,6 +4781,27 @@ dependencies = [
47694781
"thiserror 2.0.0",
47704782
]
47714783

4784+
[[package]]
4785+
name = "opentmk"
4786+
version = "0.0.0"
4787+
dependencies = [
4788+
"arrayvec",
4789+
"bitfield-struct",
4790+
"cfg-if",
4791+
"hvdef",
4792+
"lazy_static",
4793+
"linked_list_allocator",
4794+
"memory_range",
4795+
"minimal_rt",
4796+
"minimal_rt_build",
4797+
"serde",
4798+
"serde_json",
4799+
"spin 0.10.0",
4800+
"uefi",
4801+
"x86_64",
4802+
"zerocopy 0.8.14",
4803+
]
4804+
47724805
[[package]]
47734806
name = "openvmm"
47744807
version = "0.0.0"
@@ -6360,6 +6393,30 @@ dependencies = [
63606393
"zerocopy 0.8.14",
63616394
]
63626395

6396+
[[package]]
6397+
name = "spin"
6398+
version = "0.5.2"
6399+
source = "registry+https://github.com/rust-lang/crates.io-index"
6400+
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
6401+
6402+
[[package]]
6403+
name = "spin"
6404+
version = "0.10.0"
6405+
source = "registry+https://github.com/rust-lang/crates.io-index"
6406+
checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591"
6407+
dependencies = [
6408+
"lock_api",
6409+
]
6410+
6411+
[[package]]
6412+
name = "spinning_top"
6413+
version = "0.2.5"
6414+
source = "registry+https://github.com/rust-lang/crates.io-index"
6415+
checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
6416+
dependencies = [
6417+
"lock_api",
6418+
]
6419+
63636420
[[package]]
63646421
name = "stackfuture"
63656422
version = "0.3.0"
@@ -8736,6 +8793,12 @@ dependencies = [
87368793
"vmsocket",
87378794
]
87388795

8796+
[[package]]
8797+
name = "volatile"
8798+
version = "0.4.6"
8799+
source = "registry+https://github.com/rust-lang/crates.io-index"
8800+
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
8801+
87398802
[[package]]
87408803
name = "vpci"
87418804
version = "0.0.0"
@@ -9313,6 +9376,18 @@ dependencies = [
93139376
"tap",
93149377
]
93159378

9379+
[[package]]
9380+
name = "x86_64"
9381+
version = "0.15.2"
9382+
source = "registry+https://github.com/rust-lang/crates.io-index"
9383+
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
9384+
dependencies = [
9385+
"bit_field",
9386+
"bitflags 2.6.0",
9387+
"rustversion",
9388+
"volatile",
9389+
]
9390+
93169391
[[package]]
93179392
name = "x86defs"
93189393
version = "0.0.0"

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ members = [
4242
"vm/loader/igvmfilegen",
4343
"vm/vmgs/vmgs_lib",
4444
"vm/vmgs/vmgstool",
45+
"opentmk"
4546
]
4647
exclude = [
4748
"xsync",
@@ -525,6 +526,7 @@ xshell-macros = "0.2"
525526
# We add the derive feature here since the vast majority of our crates use it.
526527
#zerocopy = { version = "0.7.32", features = ["derive"]}
527528
zerocopy = { version = "0.8.14", features = ["derive"]}
529+
linked_list_allocator = "0.10.5"
528530

529531
[workspace.metadata.xtask.unused-deps]
530532
# Pulled in through "tracing", but we need to pin the version

opentmk/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
[package]
5+
name = "opentmk"
6+
edition.workspace = true
7+
rust-version.workspace = true
8+
9+
[dependencies]
10+
uefi = { workspace = true, features = ["alloc"] }
11+
minimal_rt.workspace = true
12+
linked_list_allocator = { workspace = true }
13+
hvdef = {workspace = true}
14+
zerocopy = {workspace = true}
15+
memory_range = { workspace = true }
16+
arrayvec = {workspace = true}
17+
cfg-if.workspace = true
18+
bitfield-struct.workspace = true
19+
x86_64 = "0.15.2"
20+
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
21+
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
22+
spin = "0.10.0"
23+
serde = {version = "1.0", default-features = false}
24+
[lints]
25+
workspace = true
26+
27+
[build-dependencies]
28+
minimal_rt_build.workspace = true
29+
30+
[profile.release]
31+
debug = false
32+
strip = "debuginfo"

opentmk/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `guest_test_uefi`
2+
3+
See the guide for more info on how to build/run the code in this crate.

opentmk/build_deploy.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RUST_BACKTRACE=1 cargo build -p opentmk --target x86_64-unknown-uefi
2+
cargo xtask guest-test uefi --bootx64 ./target/x86_64-unknown-uefi/debug/opentmk.efi
3+
qemu-img convert -f raw -O vhdx ./target/x86_64-unknown-uefi/debug/opentmk.img ~/projects/opentmk.vhdx

opentmk/src/arch/aarch64/hypercall.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/// Writes a synthehtic register to tell the hypervisor the OS ID for the boot shim.
5+
fn report_os_id(guest_os_id: u64) {
6+
// On ARM64, to be able to make hypercalls, one needs first to set the Guest OS ID
7+
// synthetic register using a hypercall. Can't use `Hvcall::set_register` at that will
8+
// lead to the infinite recursion as that function will first try initializing hypercalls
9+
// with setting a register.
10+
//
11+
// Only one very specific HvSetVpRegisters hypercall is allowed to set the Guest OS ID
12+
// (this is TLFS section 17.4.4.1.1 and 5.3), and that must be the fast hypercall.
13+
let _ = minimal_rt::arch::hypercall::set_register_fast(
14+
hvdef::HvArm64RegisterName::GuestOsId.into(),
15+
guest_os_id.into(),
16+
);
17+
}
18+
19+
pub(crate) fn initialize(guest_os_id: u64) {
20+
// We are assuming we are running under a Microsoft hypervisor.
21+
report_os_id(guest_os_id);
22+
}
23+
24+
/// Call before jumping to kernel.
25+
pub(crate) fn uninitialize() {
26+
report_os_id(0);
27+
}

opentmk/src/arch/aarch64/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod hypercall;
2+
pub mod serial;

0 commit comments

Comments
 (0)