From 1cde165bb84930fd489c333081891d6208e18865 Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Wed, 10 May 2023 17:31:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=A0=87=E5=87=86=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch1/Cargo.toml | 2 +- ch1/Makefile | 20 ++++++++++++++++++++ ch1/src/lang_items.rs | 1 + ch1/src/lang_items/panic.rs | 8 ++++++++ ch1/src/main.rs | 12 +++++++++--- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 ch1/Makefile create mode 100644 ch1/src/lang_items.rs create mode 100644 ch1/src/lang_items/panic.rs diff --git a/ch1/Cargo.toml b/ch1/Cargo.toml index 9fbc4c2..60b4d6d 100644 --- a/ch1/Cargo.toml +++ b/ch1/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ch1" +name = "os" version = "0.1.0" edition = "2021" diff --git a/ch1/Makefile b/ch1/Makefile new file mode 100644 index 0000000..8781051 --- /dev/null +++ b/ch1/Makefile @@ -0,0 +1,20 @@ + +TARGET := riscv64gc-unknown-none-elf +KERNEL_START := 0x80200000 +MODE := release + + +build: + cargo build --$(MODE) --target=$(TARGET) + +run:build + qemu-system-riscv64 \ + -machine virt \ + -nographic \ + -bios ../bootloader/rustsbi-qemu.bin \ + -device loader,file=target/$(TARGET)/$(MODE)/os.bin,addr=$(KERNEL_START) + + + +clean: + rm -rf ./target \ No newline at end of file diff --git a/ch1/src/lang_items.rs b/ch1/src/lang_items.rs new file mode 100644 index 0000000..3d5f71b --- /dev/null +++ b/ch1/src/lang_items.rs @@ -0,0 +1 @@ +pub mod panic; \ No newline at end of file diff --git a/ch1/src/lang_items/panic.rs b/ch1/src/lang_items/panic.rs new file mode 100644 index 0000000..fac89de --- /dev/null +++ b/ch1/src/lang_items/panic.rs @@ -0,0 +1,8 @@ + + +use core::panic::PanicInfo; + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} \ No newline at end of file diff --git a/ch1/src/main.rs b/ch1/src/main.rs index e7a11a9..afa1a64 100644 --- a/ch1/src/main.rs +++ b/ch1/src/main.rs @@ -1,3 +1,9 @@ -fn main() { - println!("Hello, world!"); -} +#![no_std] +#![no_main] + +mod lang_items; + +// fn main() { +// +// // println!("Hello, world!"); +// }