From b5d7e80747a61c3fdcc7b2a54088806edf57b894 Mon Sep 17 00:00:00 2001 From: buhe Date: Thu, 28 Oct 2021 14:02:38 +0800 Subject: [PATCH] fix bug --- os/src/console.rs | 2 +- os/src/main.rs | 5 +++-- os/src/mmu/memory_set.rs | 20 +++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/os/src/console.rs b/os/src/console.rs index 54d9a81..7cd1963 100644 --- a/os/src/console.rs +++ b/os/src/console.rs @@ -2,7 +2,7 @@ use core::fmt::{self, Write}; use crate::{driver::print_with_lcd, scall_sbi::put_char}; -struct STDOUT; +pub struct STDOUT; impl Write for STDOUT { fn write_str(&mut self, s: &str) -> core::fmt::Result { diff --git a/os/src/main.rs b/os/src/main.rs index 4fcf9ff..d6d5c79 100644 --- a/os/src/main.rs +++ b/os/src/main.rs @@ -40,7 +40,6 @@ fn clear_bss() { #[no_mangle] extern "C" fn rust_main(_hartid: usize, device_tree_paddr: usize) -> ! { - println!("{}", logo::LOGO); // println!("hart id is {}", hartid); // println!("dtb addr is 0x{:x}", device_tree_paddr); #[repr(C)] @@ -63,9 +62,11 @@ extern "C" fn rust_main(_hartid: usize, device_tree_paddr: usize) -> ! { clear_bss(); heap::init(); + driver::init(); mmu::init(); trap::init(); - driver::init(); + + println!("{}", logo::LOGO); #[cfg(test)] test_main(); diff --git a/os/src/mmu/memory_set.rs b/os/src/mmu/memory_set.rs index 6766b3f..d52141e 100644 --- a/os/src/mmu/memory_set.rs +++ b/os/src/mmu/memory_set.rs @@ -3,6 +3,8 @@ use super::{PTEFlags, PageTable, PageTableEntry}; use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum}; use super::{StepByOne, VPNRange}; use crate::config::{MEMORY_END, MMIO, PAGE_SIZE, TRAMPOLINE, TRAP_CONTEXT, USER_STACK_SIZE}; +use core::fmt::{self, Write}; +use crate::console::STDOUT; use alloc::collections::BTreeMap; use alloc::sync::Arc; use alloc::vec::Vec; @@ -76,14 +78,14 @@ impl MemorySet { // map trampoline memory_set.map_trampoline(); // map kernel sections - println!(".text [{:#x}, {:#x})", stext as usize, etext as usize); - println!(".rodata [{:#x}, {:#x})", srodata as usize, erodata as usize); - println!(".data [{:#x}, {:#x})", sdata as usize, edata as usize); - println!( + writeln!(STDOUT, ".text [{:#x}, {:#x})", stext as usize, etext as usize); + writeln!(STDOUT, ".rodata [{:#x}, {:#x})", srodata as usize, erodata as usize); + writeln!(STDOUT, ".data [{:#x}, {:#x})", sdata as usize, edata as usize); + writeln!(STDOUT, ".bss [{:#x}, {:#x})", sbss_with_stack as usize, ebss as usize ); - println!("mapping .text section"); + writeln!(STDOUT, "mapping .text section"); memory_set.push( MapArea::new( (stext as usize).into(), @@ -93,7 +95,7 @@ impl MemorySet { ), None, ); - println!("mapping .rodata section"); + writeln!(STDOUT, "mapping .rodata section"); memory_set.push( MapArea::new( (srodata as usize).into(), @@ -103,7 +105,7 @@ impl MemorySet { ), None, ); - println!("mapping .data section"); + writeln!(STDOUT, "mapping .data section"); memory_set.push( MapArea::new( (sdata as usize).into(), @@ -113,7 +115,7 @@ impl MemorySet { ), None, ); - println!("mapping .bss section"); + writeln!(STDOUT, "mapping .bss section"); memory_set.push( MapArea::new( (sbss_with_stack as usize).into(), @@ -123,7 +125,7 @@ impl MemorySet { ), None, ); - println!("mapping physical memory"); + writeln!(STDOUT, "mapping physical memory"); memory_set.push( MapArea::new( (ekernel as usize).into(),