This commit is contained in:
Michael Zhang 2024-03-21 08:33:51 -05:00
parent e9ad65f77f
commit ca02b44b71
7 changed files with 43 additions and 17 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

3
run.sh
View file

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