diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 425a6b5e9..638172770 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -56,7 +56,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings + args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings - name: Clippy on svsm-fuzz uses: actions-rs/cargo@v1 diff --git a/Cargo.lock b/Cargo.lock index 577ea5d15..451b15fa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,6 +336,13 @@ dependencies = [ "subtle", ] +[[package]] +name = "dm" +version = "0.1.0" +dependencies = [ + "syscall", +] + [[package]] name = "ecdsa" version = "0.16.9" diff --git a/Cargo.toml b/Cargo.toml index d73ea81b9..59dfac94b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ members = [ "syscall", # init process "init", + # device model application + "dm", ] diff --git a/Makefile b/Makefile index efdb2500c..de55f8c9f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) @@ -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 diff --git a/dm/Cargo.toml b/dm/Cargo.toml new file mode 100644 index 000000000..0032aab13 --- /dev/null +++ b/dm/Cargo.toml @@ -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 diff --git a/dm/build.rs b/dm/build.rs new file mode 100644 index 000000000..298fb377f --- /dev/null +++ b/dm/build.rs @@ -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"); +} diff --git a/dm/dm.lds b/dm/dm.lds new file mode 100644 index 000000000..b8cb91490 --- /dev/null +++ b/dm/dm.lds @@ -0,0 +1,35 @@ +OUTPUT_ARCH(i386:x86-64) + +PHDRS +{ + text PT_LOAD FLAGS(5); /* Read + Execute */ + rodata PT_LOAD FLAGS(4); /* Read-only */ + data PT_LOAD FLAGS(6); /* Read + Write */ + bss PT_LOAD FLAGS(6); /* Read + Write */ +} + +SECTIONS +{ + .text : { + *(.text) + *(.text.*) + } :text + . = ALIGN(4096); + .rodata : { + *(.rodata) + *(.rodata.*) + } :rodata + . = ALIGN(4096); + .data : { + *(.data) + *(.data.*) + } :data + . = ALIGN(4096); + .bss : { + *(.bss) *(.bss.*) + . = ALIGN(4096); + } :bss + . = ALIGN(4096); +} + +ENTRY(dm_start) diff --git a/dm/src/main.rs b/dm/src/main.rs new file mode 100644 index 000000000..f7ea0a532 --- /dev/null +++ b/dm/src/main.rs @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 Intel Corporation. +// +// Author: Chuanxiao Dong + +#![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(); +}