luojia65 4 lat temu
rodzic
commit
8d47250724
2 zmienionych plików z 38 dodań i 2 usunięć
  1. 37 1
      platform/k210/src/main.rs
  2. 1 1
      platform/qemu/justfile

+ 37 - 1
platform/k210/src/main.rs

@@ -2,6 +2,7 @@
 #![no_main]
 #![no_main]
 #![feature(alloc_error_handler)]
 #![feature(alloc_error_handler)]
 #![feature(global_asm)]
 #![feature(global_asm)]
+#![feature(llvm_asm)]
 
 
 use core::alloc::Layout;
 use core::alloc::Layout;
 use core::panic::PanicInfo;
 use core::panic::PanicInfo;
@@ -27,8 +28,43 @@ fn oom(_layout: Layout) -> ! {
 }
 }
 
 
 
 
-#[export_name = "start"]
+#[export_name = "_start"]
+#[link_section = ".text.entry"] // this is stable
 fn main() -> ! {
 fn main() -> ! {
+    unsafe {
+        llvm_asm!(
+            "
+        csrr    a2, mhartid
+        lui     t0, %hi(_max_hart_id)
+        add     t0, t0, %lo(_max_hart_id)
+        bgtu    a2, t0, _start_abort
+        la      sp, _stack_start
+        lui     t0, %hi(_hart_stack_size)
+        add     t0, t0, %lo(_hart_stack_size)
+    .ifdef __riscv_mul
+        mul     t0, a2, t0
+    .else
+        beqz    a2, 2f  // Jump if single-hart
+        mv      t1, a2
+        mv      t2, t0
+    1:
+        add     t0, t0, t2
+        addi    t1, t1, -1
+        bnez    t1, 1b
+    2:
+    .endif
+        sub     sp, sp, t0
+        csrw    mscratch, zero
+        j _start_success
+        
+    _start_abort:
+        wfi
+        j _start_abort
+    _start_success:
+        
+    "
+        )
+    };
     if mhartid::read() == 0 {
     if mhartid::read() == 0 {
         extern "C" {
         extern "C" {
             fn _sheap();
             fn _sheap();

+ 1 - 1
platform/qemu/justfile

@@ -1,4 +1,4 @@
-target := "riscv64imac-unknown-none-elf"
+target := "riscv64gc-unknown-none-elf"
 mode := "debug"
 mode := "debug"
 build-path := "../../target/" + target + "/" + mode + "/"
 build-path := "../../target/" + target + "/" + mode + "/"
 m-firmware-file := build-path + "rustsbi-qemu"
 m-firmware-file := build-path + "rustsbi-qemu"