From ca02b44b719297565488417cea82c54ede6db8c1 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Thu, 21 Mar 2024 08:33:51 -0500 Subject: [PATCH] update --- CMakeLists.txt | 13 ------------- aarch64-unknown-none.json | 2 +- kernel/src/main.rs | 3 ++- kernel/src/riscv64gc/start.s | 15 +++++++++++++++ kernel/src/spinlock.rs | 2 +- riscv64gc-unknown-none-elf.json | 22 ++++++++++++++++++++++ run.sh | 3 ++- 7 files changed, 43 insertions(+), 17 deletions(-) delete mode 100644 CMakeLists.txt create mode 100644 kernel/src/riscv64gc/start.s create mode 100644 riscv64gc-unknown-none-elf.json diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index f6485c4..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.25) - -project(EOS0 CXX) - -include(FetchContent) -FetchContent_Declare( - Corrosion - GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here -) -FetchContent_MakeAvailable(Corrosion) - -corrosion_import_crate(MANIFEST_PATH kernel/Cargo.toml) diff --git a/aarch64-unknown-none.json b/aarch64-unknown-none.json index 6d0a622..47445c6 100644 --- a/aarch64-unknown-none.json +++ b/aarch64-unknown-none.json @@ -3,7 +3,7 @@ "crt-objects-fallback": "false", "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "disable-redzone": true, - "features": "+v8a,+strict-align,-neon,+fp-armv8", + "features": "-align,-neon", "linker": "rust-lld", "linker-flavor": "gnu-lld", "llvm-target": "aarch64-unknown-none", diff --git a/kernel/src/main.rs b/kernel/src/main.rs index e470826..8902626 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -17,7 +17,8 @@ mod panic; mod spinlock; mod uart; -global_asm!(include_str!("start.s")); +// global_asm!(include_str!("start.s")); +global_asm!(include_str!("riscv64gc/start.s")); #[no_mangle] pub extern "C" fn main() { diff --git a/kernel/src/riscv64gc/start.s b/kernel/src/riscv64gc/start.s new file mode 100644 index 0000000..bf0ce40 --- /dev/null +++ b/kernel/src/riscv64gc/start.s @@ -0,0 +1,15 @@ +.section .text + +.global _entry + +_entry: + la sp, stack0 + li a0, 1024*4 + csrr a1, mhartid + addi a1, a1, 1 + mul a0, a0, a1 + add sp, sp, a0 + call main + +spin: + j spin \ No newline at end of file diff --git a/kernel/src/spinlock.rs b/kernel/src/spinlock.rs index 39ded9d..97a71b5 100644 --- a/kernel/src/spinlock.rs +++ b/kernel/src/spinlock.rs @@ -8,7 +8,7 @@ pub struct SpinLock { impl SpinLock { pub fn init(name: &'static str) -> Self { let mut this_name = [0; 32]; - this_name.copy_from_slice(&name.as_bytes()[..32]); + this_name.copy_from_slice(&name.as_bytes()[..32.min(name.len())]); SpinLock { locked: false, diff --git a/riscv64gc-unknown-none-elf.json b/riscv64gc-unknown-none-elf.json new file mode 100644 index 0000000..b70a5cb --- /dev/null +++ b/riscv64gc-unknown-none-elf.json @@ -0,0 +1,22 @@ +{ + "arch": "riscv64", + "code-model": "medium", + "cpu": "generic-rv64", + "crt-objects-fallback": "false", + "data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128", + "eh-frame-header": false, + "emit-debug-gdb-scripts": true, + "features": "+m,+a,+f,+d,+c", + "linker": "rust-lld", + "linker-flavor": "gnu-lld", + "llvm-abiname": "lp64d", + "llvm-target": "riscv64", + "max-atomic-width": 64, + "panic-strategy": "abort", + "relocation-model": "static", + "pre-link-args": { + "gnu-lld": ["-Taarch64-qemu.ld"] + }, + "supported-sanitizers": ["kernel-address"], + "target-pointer-width": "64" +} diff --git a/run.sh b/run.sh index 40f7281..0f4730c 100755 --- a/run.sh +++ b/run.sh @@ -2,7 +2,7 @@ set -euo pipefail cargo xbuild --target=aarch64-unknown-none.json DEBUG= -# DEBUG="-s -S -d exec" +DEBUG="-s -S -d exec" printf "Running with qemu...\n" set -x @@ -11,5 +11,6 @@ exec qemu-system-aarch64 \ $DEBUG \ -m 1024M \ -cpu cortex-a53 \ + -no-reboot \ -nographic \ -kernel target/aarch64-unknown-none/debug/kernel