Browse Source

main: initialize programming language runtime once only

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
Zhouqi Jiang 10 months ago
parent
commit
af501aed89
2 changed files with 13 additions and 3 deletions
  1. 1 1
      src/dynamic.rs
  2. 12 2
      src/main.rs

+ 1 - 1
src/dynamic.rs

@@ -27,7 +27,7 @@ pub struct DynamicInfo {
 
 const DYNAMIC_INFO_VALID_ADDRESSES: Range<usize> = 0x1000..0xf000;
 const NEXT_ADDR_VALID_ADDRESSES: Range<usize> = 0x80000000..0x90000000;
-const MAGIC: usize = 0x4942534f;
+pub(crate) const MAGIC: usize = 0x4942534f;
 const SUPPORTED_VERSION: Range<usize> = 2..3;
 
 pub struct DynamicReadError {

+ 12 - 2
src/main.rs

@@ -55,9 +55,17 @@ unsafe extern "C" fn start() -> ! {
         // 1. Turn off interrupt
         "   csrw    mie, zero",
         // 2. Initialize programming langauge runtime
-        // only clear bss if hartid is zero
+        // only clear bss if hartid matches preferred boot hart id
         "   csrr    t0, mhartid",
-        "   bnez    t0, 2f",
+        "   ld      t1, 0(a2)",
+        "   li      t2, {magic}",
+        "   bne     t1, t2, 3f",
+        "   ld      t2, 40(a2)",
+        "   bne     t0, t2, 2f",
+        "   j       4f",
+        "3:",
+        "   j       3b", // TODO multi hart preempt for runtime init
+        "4:",
         // clear bss segment
         "   la      t0, sbss
             la      t1, ebss
@@ -76,6 +84,7 @@ unsafe extern "C" fn start() -> ! {
             addi    t4, t4, 8
             j       1b",
         "2: ",
+        // TODO wait before boot-hart initializes runtime
         // 3. Prepare stack for each hart
         "   la      sp, {stack}",
         "   li      t0, {stack_size_per_hart}",
@@ -90,6 +99,7 @@ unsafe extern "C" fn start() -> ! {
         // 5. Jump to following boot sequences
         "   csrw    mepc, a0",
         "   mret",
+        magic = const dynamic::MAGIC,
         stack_size_per_hart = const LEN_STACK_PER_HART,
         stack = sym STACK,
         main = sym main,