Skip to content

Commit

Permalink
dm: Add initial device model project
Browse files Browse the repository at this point in the history
The device model is a user mode program which manages VM's life cycles
and handles various vmexits events. The initial version just calls exit()
syscall without doing anything else.

As this is a user mode program, not sure what is the preferred way to
put this project, just put it as a sub folder in coconut-svsm and in the
workspace. If in the workspace is not preferred, this can be changed in
the future.

Signed-off-by: Chuanxiao Dong <[email protected]>
  • Loading branch information
cxdong authored and vijaydhanraj committed Sep 25, 2024
1 parent ca5805e commit f48a766
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ members = [
"syscall",
# init process
"init",
# device model application
"dm",
]


Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ IGVMBIN = bin/igvmbld
IGVMMEASURE = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmmeasure"
IGVMMEASUREBIN = bin/igvmmeasure
INITELF = "target/x86_64-unknown-none/${TARGET_PATH}/init"
DMELF = "target/x86_64-unknown-none/${TARGET_PATH}/dm"

RUSTDOC_OUTPUT = target/x86_64-unknown-none/doc
DOC_SITE = target/x86_64-unknown-none/site
Expand Down Expand Up @@ -134,7 +135,11 @@ bin/init: bin
cargo build --manifest-path init/Cargo.toml ${CARGO_ARGS} --bin init
objcopy -O elf64-x86-64 --strip-unneeded ${INITELF} $@

user: bin/init
bin/dm: bin
cargo build --manifest-path dm/Cargo.toml ${CARGO_ARGS} --bin dm
objcopy -O elf64-x86-64 --strip-unneeded ${DMELF} $@

user: bin/init bin/dm

${FS_BIN}: bin
ifneq ($(FS_FILE), none)
Expand Down Expand Up @@ -177,7 +182,7 @@ bin/svsm-test.bin: bin/stage1-test

clippy:
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude igvmbuilder --exclude igvmmeasure -- -D warnings
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings
RUSTFLAGS="--cfg fuzzing" cargo clippy --package svsm-fuzz --all-features --target=x86_64-unknown-linux-gnu -- -D warnings
cargo clippy --workspace --all-features --tests --target=x86_64-unknown-linux-gnu -- -D warnings

Expand Down
1 change: 1 addition & 0 deletions dm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
15 changes: 15 additions & 0 deletions dm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "dm"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "dm"
path = "src/main.rs"
test = false

[dependencies]
syscall = { path = "../syscall" }

[lints]
workspace = true
6 changes: 6 additions & 0 deletions dm/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
fn main() {
println!("cargo:rustc-link-arg-bin=dm=-nostdlib");
println!("cargo:rustc-link-arg-bin=dm=-no-pie");
println!("cargo:rustc-link-arg-bin=dm=-Tdm/dm.lds");
}
21 changes: 21 additions & 0 deletions dm/dm.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OUTPUT_ARCH(i386:x86-64)

SECTIONS
{
.text : {
*(.text)
*(.text.*)
}
. = ALIGN(4096);
.rodata : { *(.rodata) *(.rodata.*) }
. = ALIGN(4096);
.data : { *(.data) *(.data.*) }
. = ALIGN(4096);
.bss : {
*(.bss) *(.bss.*)
. = ALIGN(4096);
}
. = ALIGN(4096);
}

ENTRY(dm_start)
25 changes: 25 additions & 0 deletions dm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2024 Intel Corporation.
//
// Author: Chuanxiao Dong <[email protected]>

#![no_std]
#![no_main]

use core::panic::PanicInfo;
use syscall::exit;

fn dm_exit() -> ! {
exit(0);
}

#[no_mangle]
pub extern "C" fn dm_start() -> ! {
dm_exit();
}

#[panic_handler]
fn panic(_info: &PanicInfo<'_>) -> ! {
dm_exit();
}

0 comments on commit f48a766

Please sign in to comment.