Browse Source

Merge pull request #19 from guttatus/bootflow

fix(prototyper): fixed mtime trap context save and restore bug
Luo Jia / Zhouqi Jiang 5 months ago
parent
commit
baffef08a4
2 changed files with 15 additions and 5 deletions
  1. 3 3
      prototyper/src/sbi/logger.rs
  2. 12 2
      prototyper/src/sbi/trap.rs

+ 3 - 3
prototyper/src/sbi/logger.rs

@@ -25,12 +25,12 @@ impl log::Log for Logger {
         let color_code: u8 = match record.level() {
             Level::Error => 31,
             Level::Warn => 93,
-            Level::Info => 34,
-            Level::Debug => 32,
+            Level::Info => 32,
+            Level::Debug => 36,
             Level::Trace => 90,
         };
         println!(
-            "\x1b[{color_code}m[{:>5}] {}\x1b[0m",
+            "\x1b[1;37m[RustSBI] \x1b[1;{color_code}m{:^5}\x1b[0m - {}",
             record.level(),
             record.args(),
         );

+ 12 - 2
prototyper/src/sbi/trap.rs

@@ -56,11 +56,16 @@ unsafe extern "C" fn mtimer() {
         // mscratch: S sp
         "   csrrw sp, mscratch, sp",
         // 保护
-        "   addi  sp, sp, -4*8
+        "   addi  sp, sp, -9*8
             sd    ra, 0*8(sp)
             sd    a0, 1*8(sp)
             sd    a1, 2*8(sp)
             sd    a2, 3*8(sp)
+            sd    a3, 4*8(sp)
+            sd    a4, 5*8(sp)
+            sd    a5, 6*8(sp)
+            sd    a6, 7*8(sp)
+            sd    a7, 8*8(sp)
         ",
         // 清除 mtimecmp
         "    call  {clear_mtime}",
@@ -73,7 +78,12 @@ unsafe extern "C" fn mtimer() {
             ld    a0, 1*8(sp)
             ld    a1, 2*8(sp)
             ld    a2, 3*8(sp)
-            addi  sp, sp,  4*8
+            ld    a3, 4*8(sp)
+            ld    a4, 5*8(sp)
+            ld    a5, 6*8(sp)
+            ld    a6, 7*8(sp)
+            ld    a7, 8*8(sp)
+            addi  sp, sp,  9*8
         ",
         // 换栈:
         // sp      : S sp