Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d860c4a

Browse files
cxdongvijaydhanraj
authored andcommittedSep 29, 2024·
dm: Add initial device model project
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 <chuanxiao.dong@intel.com>
1 parent de89810 commit d860c4a

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed
 

‎Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ members = [
1616
"syscall",
1717
# init process
1818
"init",
19+
# device model application
20+
"dm",
1921
]
2022

2123

‎Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ IGVMBIN = bin/igvmbld
4545
IGVMMEASURE = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmmeasure"
4646
IGVMMEASUREBIN = bin/igvmmeasure
4747
INITELF = "target/x86_64-unknown-none/${TARGET_PATH}/init"
48+
DMELF = "target/x86_64-unknown-none/${TARGET_PATH}/dm"
4849

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

137-
user: bin/init
138+
bin/dm: bin
139+
cargo build --manifest-path dm/Cargo.toml ${CARGO_ARGS} --bin dm
140+
objcopy -O elf64-x86-64 --strip-unneeded ${DMELF} $@
141+
142+
user: bin/init bin/dm
138143

139144
${FS_BIN}: bin
140145
ifneq ($(FS_FILE), none)
@@ -177,7 +182,7 @@ bin/svsm-test.bin: bin/stage1-test
177182

178183
clippy:
179184
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude igvmbuilder --exclude igvmmeasure -- -D warnings
180-
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
185+
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings
181186
RUSTFLAGS="--cfg fuzzing" cargo clippy --package svsm-fuzz --all-features --target=x86_64-unknown-linux-gnu -- -D warnings
182187
cargo clippy --workspace --all-features --tests --target=x86_64-unknown-linux-gnu -- -D warnings
183188

‎dm/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "dm"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "dm"
8+
path = "src/main.rs"
9+
test = false
10+
11+
[dependencies]
12+
syscall = { path = "../syscall" }
13+
14+
[lints]
15+
workspace = true

‎dm/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
fn main() {
3+
println!("cargo:rustc-link-arg-bin=dm=-nostdlib");
4+
println!("cargo:rustc-link-arg-bin=dm=-no-pie");
5+
println!("cargo:rustc-link-arg-bin=dm=-Tdm/dm.lds");
6+
}

‎dm/dm.lds

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
OUTPUT_ARCH(i386:x86-64)
2+
3+
SECTIONS
4+
{
5+
.text : {
6+
*(.text)
7+
*(.text.*)
8+
}
9+
. = ALIGN(4096);
10+
.rodata : { *(.rodata) *(.rodata.*) }
11+
. = ALIGN(4096);
12+
.data : { *(.data) *(.data.*) }
13+
. = ALIGN(4096);
14+
.bss : {
15+
*(.bss) *(.bss.*)
16+
. = ALIGN(4096);
17+
}
18+
. = ALIGN(4096);
19+
}
20+
21+
ENTRY(dm_start)

‎dm/src/main.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
//
3+
// Copyright (c) 2024 Intel Corporation.
4+
//
5+
// Author: Chuanxiao Dong <chuanxiao.dong@intel.com>
6+
7+
#![no_std]
8+
#![no_main]
9+
10+
use core::panic::PanicInfo;
11+
use syscall::exit;
12+
13+
fn dm_exit() -> ! {
14+
exit(0);
15+
}
16+
17+
#[no_mangle]
18+
pub extern "C" fn dm_start() -> ! {
19+
dm_exit();
20+
}
21+
22+
#[panic_handler]
23+
fn panic(_info: &PanicInfo<'_>) -> ! {
24+
dm_exit();
25+
}

0 commit comments

Comments
 (0)
Please sign in to comment.