Browse Source

Modify test kernel console

luojia65 4 years ago
parent
commit
8d81b98952
3 changed files with 10 additions and 7 deletions
  1. 2 6
      platform/qemu/src/main.rs
  2. 2 0
      test-kernel/Cargo.toml
  3. 6 1
      test-kernel/src/console.rs

+ 2 - 6
platform/qemu/src/main.rs

@@ -123,13 +123,9 @@ unsafe extern "C" fn start() -> ! {
 }
 
 #[export_name = "main"]
-fn main() -> ! {
+extern "C" fn main(_mhartid: usize, dtb_pa: usize) -> ! {
+    // dtb_pa is put into a1 register on qemu boot
     // Ref: https://github.com/qemu/qemu/blob/aeb07b5f6e69ce93afea71027325e3e7a22d2149/hw/riscv/boot.c#L243
-    let dtb_pa = unsafe {
-        let dtb_pa: usize;
-        llvm_asm!("":"={a1}"(dtb_pa));
-        dtb_pa
-    };
 
     if mp_hook() {
         // init

+ 2 - 0
test-kernel/Cargo.toml

@@ -8,3 +8,5 @@ edition = "2018"
 
 [dependencies]
 riscv = "0.6"
+spin = "0.7"
+lazy_static = { version = "1", features = ["spin_no_std"] }

+ 6 - 1
test-kernel/src/console.rs

@@ -1,5 +1,6 @@
 use crate::sbi::*;
 use core::fmt::{self, Write};
+use spin::Mutex;
 
 struct Stdout;
 
@@ -17,7 +18,11 @@ impl Write for Stdout {
 
 #[allow(unused)]
 pub fn print(args: fmt::Arguments) {
-    Stdout.write_fmt(args).unwrap();
+    STDOUT.lock().write_fmt(args).unwrap();
+}
+
+lazy_static::lazy_static! {
+    static ref STDOUT: Mutex<Stdout> = Mutex::new(Stdout);
 }
 
 #[macro_export]