This commit is contained in:
Michael Zhang 2024-12-05 16:58:05 -06:00
parent 0bbf694137
commit be4a7a3e80
8 changed files with 35 additions and 17 deletions

View file

@ -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

2
Cargo.lock generated
View file

@ -3,5 +3,5 @@
version = 3
[[package]]
name = "eos0"
name = "kernel"
version = "0.1.0"

View file

@ -1,6 +1,9 @@
[package]
name = "eos0"
name = "kernel"
version = "0.1.0"
edition = "2021"
[profile.dev]
panic = "abort"
[dependencies]

View file

@ -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

View file

@ -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 \

3
src/asm/entry.S Normal file
View file

@ -0,0 +1,3 @@
.global _entry
_entry:
call start

View file

@ -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)
}
}

View file

@ -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() {