From be4a7a3e8062483e252907a816a36798c42583c7 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 5 Dec 2024 16:58:05 -0600 Subject: [PATCH] wip --- .cargo/config.toml | 10 ++++++++-- Cargo.lock | 2 +- Cargo.toml | 5 ++++- Makefile | 11 +++++------ scripts/start.sh | 9 ++++++--- src/asm/entry.S | 3 +++ src/ld/kernel.ld | 9 +++++++-- src/main.rs | 3 +-- 8 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 src/asm/entry.S diff --git a/.cargo/config.toml b/.cargo/config.toml index 74fc137..7455ae8 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,8 +2,14 @@ target = "riscv64gc-unknown-none-elf" [target.riscv64gc-unknown-none-elf] -rustflags = ["-C", "link-arg=-Tsrc/ld/kernel.ld"] -runner = "./scripts/start.sh" +rustflags = [ + "--print", + "link-args", + "-C", + "link-arg=--script", + "-C", + "link-arg=src/ld/kernel.ld", +] [term] verbose = true diff --git a/Cargo.lock b/Cargo.lock index 09719f8..0dd1539 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "eos0" +name = "kernel" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 3045943..350045b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,9 @@ [package] -name = "eos0" +name = "kernel" version = "0.1.0" edition = "2021" +[profile.dev] +panic = "abort" + [dependencies] diff --git a/Makefile b/Makefile index 030026e..d1e4940 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ -KERNEL = target/riscv64gc-unknown-none-elf/debug/xv6-riscv-rust -SOURCES := $(shell find -name "*.rs") +KERNEL = target/riscv64gc-unknown-none-elf/debug/kernel +SOURCES := $(shell find . -name "*.rs") + +.PHONY: $(KERNEL) $(KERNEL): $(SOURCES) - cargo build - -fs.img: mkfs/mkfs README.md $(UPROGS) - mkfs/mkfs fs.img README.md $(UPROGS) + cargo rustc diff --git a/scripts/start.sh b/scripts/start.sh index d4adc4f..c9d7e36 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -x + KERNEL=$1 shift @@ -8,7 +10,8 @@ qemu-system-riscv64 \ -machine virt \ -bios none \ -m 3G \ - -smp 3 \ - # -drive file=fs.img,if=none,format=raw,id=x0 \ - -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \ + -d trace:exec_tb \ -kernel "$KERNEL" + + # -smp 3 \ + # -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \ diff --git a/src/asm/entry.S b/src/asm/entry.S new file mode 100644 index 0000000..ea3b692 --- /dev/null +++ b/src/asm/entry.S @@ -0,0 +1,3 @@ +.global _entry +_entry: + call start diff --git a/src/ld/kernel.ld b/src/ld/kernel.ld index 9207f40..03d4625 100644 --- a/src/ld/kernel.ld +++ b/src/ld/kernel.ld @@ -3,10 +3,15 @@ ENTRY(_entry) SECTIONS { /* - It seems that QEMU jumps to 0x8000000 after setting up memory, so we want + It seems that QEMU jumps to 0x80000000 after setting up memory, so we want our kernel code to begin here. TODO: Is there an authoritative source that says that this is the address? + How to test this: Run QEMU using -d trace:exec_tb and see where the PC goes */ - . = 0x8000000; + . = 0x80000000; + + .text : { + *(.text) + } } diff --git a/src/main.rs b/src/main.rs index 0587db5..5559c4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,7 @@ fn panic_handler(_: &PanicInfo) -> ! { static HELLO: &[u8] = b"Hello World!"; -#[no_mangle] -pub extern "C" fn _start() -> ! { +pub extern "C" fn start() -> ! { let vga_buffer = 0xb8000 as *mut u8; for (i, &byte) in HELLO.iter().enumerate() {