diff --git a/kernel/src/arch/mipsel/board/thinpad/consts.rs b/kernel/src/arch/mipsel/board/thinpad/consts.rs index b59309a..98f0a5e 100644 --- a/kernel/src/arch/mipsel/board/thinpad/consts.rs +++ b/kernel/src/arch/mipsel/board/thinpad/consts.rs @@ -1,3 +1,3 @@ /// board specific constants pub const MEMORY_END: usize = 0x8080_0000; -pub const KERNEL_HEAP_SIZE: usize = 0x0020_0000; +pub const KERNEL_HEAP_SIZE: usize = 0x0044_0000; diff --git a/kernel/src/arch/mipsel/board/thinpad/mod.rs b/kernel/src/arch/mipsel/board/thinpad/mod.rs index 2afb19f..12a55e2 100644 --- a/kernel/src/arch/mipsel/board/thinpad/mod.rs +++ b/kernel/src/arch/mipsel/board/thinpad/mod.rs @@ -21,6 +21,7 @@ pub fn init_serial_early() { pub fn init_driver() { // TODO: add possibly more drivers // timer::init(); + fb::init(); } pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult { diff --git a/kernel/src/arch/mipsel/boot/linker.ld b/kernel/src/arch/mipsel/boot/linker.ld index 420430d..0e4d0bb 100644 --- a/kernel/src/arch/mipsel/boot/linker.ld +++ b/kernel/src/arch/mipsel/boot/linker.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(riscv) ENTRY(_start) -BASE_ADDRESS = 0x80100000; +BASE_ADDRESS = 0x80000000; SECTIONS { diff --git a/kernel/src/arch/mipsel/consts.rs b/kernel/src/arch/mipsel/consts.rs index 84ae103..b3dcc5b 100644 --- a/kernel/src/arch/mipsel/consts.rs +++ b/kernel/src/arch/mipsel/consts.rs @@ -2,7 +2,7 @@ /// pub use super::board::consts::*; -pub const KERNEL_OFFSET: usize = 0x80100000; +pub const KERNEL_OFFSET: usize = 0x80000000; pub const MEMORY_OFFSET: usize = 0x8000_0000; diff --git a/kernel/src/arch/mipsel/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 7fb6fd0..071142b 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -11,4 +11,7 @@ pub mod console; pub fn init() { board::init_driver(); console::init(); + if let Some(con) = console::CONSOLE.lock().as_mut() { + con.clear(); + } } diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 56757c4..60abde3 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -29,6 +29,9 @@ pub fn init() { status.enable_soft_int1(); // Enable clock interrupt status.enable_hard_int5(); + // Enable serial interrupt + #[cfg(feature = "board_thinpad")] + status.enable_hard_int0(); cp0::status::write(status); } @@ -209,6 +212,11 @@ fn reserved_inst(tf: &mut TrapFrame) -> bool { let sel = (inst >> 6) & 0b111; let format = inst & 0b111111; + if inst == 0x42000020 { + // ignore WAIT + return true; + } + if opcode == 0b011111 && format == 0b111011 { // RDHWR if rd == 29 && sel == 0 { diff --git a/kernel/src/drivers/bus/mod.rs b/kernel/src/drivers/bus/mod.rs index cee2283..56ee0cb 100644 --- a/kernel/src/drivers/bus/mod.rs +++ b/kernel/src/drivers/bus/mod.rs @@ -1,3 +1,3 @@ -#[cfg(any(target_arch = "x86_64", target_arch = "mips"))] +#[cfg(any(target_arch = "x86_64", all(target_arch = "mips", feature = "board_malta")))] pub mod pci; pub mod virtio_mmio; diff --git a/kernel/src/drivers/serial/simple_uart.rs b/kernel/src/drivers/serial/simple_uart.rs index 9b34494..ee5c569 100644 --- a/kernel/src/drivers/serial/simple_uart.rs +++ b/kernel/src/drivers/serial/simple_uart.rs @@ -2,6 +2,7 @@ use crate::util::{read, write}; use core::fmt::{Arguments, Result, Write}; +use spin::Mutex; #[derive(Debug, Clone, Copy)] pub struct SerialPort { @@ -15,6 +16,10 @@ const UART_STATUS_CTS: u8 = 0x1; // clear to send signal const UART_STATUS_DR: u8 = 0x2; // data ready signal impl SerialPort { + fn new() -> SerialPort { + SerialPort { base: 0 } + } + pub fn init(&mut self, base: usize) { self.base = base; } @@ -49,12 +54,6 @@ impl SerialPort { pub fn putfmt(&mut self, fmt: Arguments) { self.write_fmt(fmt).unwrap(); } - - pub fn lock(&self) -> SerialPort { - self.clone() - } - - pub fn force_unlock(&self) {} } impl Write for SerialPort { @@ -72,7 +71,10 @@ impl Write for SerialPort { } } -pub static SERIAL_PORT: SerialPort = SerialPort { base: 0 }; +// pub static SERIAL_PORT: SerialPort = SerialPort { base: 0xa3000000 }; +lazy_static! { + pub static ref SERIAL_PORT: Mutex = Mutex::new(SerialPort::new()); +} pub fn init(base: usize) { SERIAL_PORT.lock().init(base); diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 15c290c..44cdc25 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -13,6 +13,7 @@ //! mipssim/malta(MIPS) -- 10MB use super::HEAP_ALLOCATOR; +use core::mem; pub use crate::arch::paging::*; use crate::consts::{KERNEL_OFFSET, MEMORY_OFFSET}; use crate::sync::SpinNoIrqLock; @@ -138,11 +139,13 @@ pub fn handle_page_fault(addr: usize) -> bool { pub fn init_heap() { use crate::consts::KERNEL_HEAP_SIZE; - static mut HEAP: [u8; KERNEL_HEAP_SIZE] = [0; KERNEL_HEAP_SIZE]; + const machine_align: usize = mem::size_of::(); + const heap_block: usize = KERNEL_HEAP_SIZE / machine_align; + static mut HEAP: [usize; heap_block] = [0; heap_block]; unsafe { HEAP_ALLOCATOR .lock() - .init(HEAP.as_ptr() as usize, KERNEL_HEAP_SIZE); + .init(HEAP.as_ptr() as usize, heap_block * machine_align); } info!("heap init end"); } diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index 7004ae9..89b8e01 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -6,7 +6,7 @@ use crate::process::*; use alloc::string::String; use alloc::vec::Vec; -#[cfg(not(feature = "run_cmdline"))] +#[cfg(not(any(feature = "run_cmdline", feature = "board_thinpad")))] pub fn add_user_shell() { // the busybox of alpine linux can not transfer env vars into child process // Now we use busybox from @@ -38,6 +38,21 @@ pub fn add_user_shell() { } } +#[cfg(feature = "board_thinpad")] +pub fn run_user_shell() { + if let Ok(inode) = ROOT_INODE.lookup("sh") { + let data = inode.read_as_vec().unwrap(); + processor().manager().add(Thread::new_user( + data.as_slice(), + "sh", + vec!["sh".into()], + Vec::new(), + )); + } else { + processor().manager().add(Thread::new_kernel(shell, 0)); + } +} + #[cfg(feature = "run_cmdline")] pub fn add_user_shell() { use crate::drivers::CMDLINE;