From a744131663e21fcc3f49ca00a88a5d1c1b6d8ac3 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Sun, 28 Apr 2019 17:28:17 +0800 Subject: [PATCH 1/7] Fix compilation error for thinpad Signed-off-by: Harry Chen --- kernel/src/drivers/bus/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/src/drivers/bus/mod.rs b/kernel/src/drivers/bus/mod.rs index cee22831..56ee0cb9 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; From ff0fa2489703f7779d256ddeb38335df444e3e99 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Sun, 28 Apr 2019 20:28:58 +0800 Subject: [PATCH 2/7] Move kernel to the beginning of physical memory to save space Signed-off-by: Harry Chen --- kernel/src/arch/mipsel/boot/linker.ld | 2 +- kernel/src/arch/mipsel/consts.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/mipsel/boot/linker.ld b/kernel/src/arch/mipsel/boot/linker.ld index 420430da..0e4d0bb5 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 84ae103e..b3dcc5be 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; From cbad1f2ceb9e6dcd6bcf718f71aa6a1c802226c4 Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Mon, 29 Apr 2019 11:55:58 +0800 Subject: [PATCH 3/7] Update simple_uart --- kernel/src/drivers/serial/simple_uart.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/src/drivers/serial/simple_uart.rs b/kernel/src/drivers/serial/simple_uart.rs index 9b344940..ee5c5694 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); From b45d75c16871ec95019b43c8e30dbab62d8f038e Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Tue, 30 Apr 2019 00:10:39 +0800 Subject: [PATCH 4/7] Align base address in init_heap(). --- kernel/src/memory.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index f98f1ad5..a20a70be 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -1,4 +1,5 @@ use super::HEAP_ALLOCATOR; +use core::mem; pub use crate::arch::paging::*; use crate::consts::MEMORY_OFFSET; use crate::process::process_unsafe; @@ -114,11 +115,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"); } From 2140ec6bef6cf21a86850757f6f26f9f9357463d Mon Sep 17 00:00:00 2001 From: Yuhao Zhou Date: Tue, 30 Apr 2019 06:34:34 +0800 Subject: [PATCH 5/7] Add thinpad settings. --- kernel/src/arch/mipsel/board/thinpad/consts.rs | 2 +- kernel/src/arch/mipsel/interrupt.rs | 8 ++++++++ kernel/src/shell.rs | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/mipsel/board/thinpad/consts.rs b/kernel/src/arch/mipsel/board/thinpad/consts.rs index b59309a8..db1971f7 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 = 0x0038_0000; diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index 56757c43..60abde3a 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/shell.rs b/kernel/src/shell.rs index 000ad633..74b63305 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 run_user_shell() { if let Ok(inode) = ROOT_INODE.lookup("busybox") { let data = inode.read_as_vec().unwrap(); @@ -21,6 +21,21 @@ pub fn run_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 run_user_shell() { let cmdline = CMDLINE.read(); From 582268ec21082f6b58d4d9db4cefdb345686f26c Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Tue, 30 Apr 2019 13:31:14 +0800 Subject: [PATCH 6/7] Enable framebuffer support for thinpad Signed-off-by: Harry Chen --- kernel/src/arch/mipsel/board/thinpad/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/src/arch/mipsel/board/thinpad/mod.rs b/kernel/src/arch/mipsel/board/thinpad/mod.rs index dae1f929..fcb7117c 100644 --- a/kernel/src/arch/mipsel/board/thinpad/mod.rs +++ b/kernel/src/arch/mipsel/board/thinpad/mod.rs @@ -23,6 +23,10 @@ pub fn init_serial_early() { pub fn init_driver() { // TODO: add possibly more drivers // timer::init(); + fb::init(); + if let Some(fb) = fb::FRAME_BUFFER.lock().as_mut() { + fb.clear(); + } } pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult { From e94fe1564eb0149c64a7b235e2763915abb91445 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Mon, 6 May 2019 10:48:27 +0800 Subject: [PATCH 7/7] Init console on ThinPad, seems not wworking properly Signed-off-by: Harry Chen --- kernel/src/arch/mipsel/board/thinpad/consts.rs | 2 +- kernel/src/arch/mipsel/board/thinpad/mod.rs | 3 --- kernel/src/arch/mipsel/driver/mod.rs | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/src/arch/mipsel/board/thinpad/consts.rs b/kernel/src/arch/mipsel/board/thinpad/consts.rs index db1971f7..98f0a5ec 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 = 0x0038_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 fcb7117c..836d300a 100644 --- a/kernel/src/arch/mipsel/board/thinpad/mod.rs +++ b/kernel/src/arch/mipsel/board/thinpad/mod.rs @@ -24,9 +24,6 @@ pub fn init_driver() { // TODO: add possibly more drivers // timer::init(); fb::init(); - if let Some(fb) = fb::FRAME_BUFFER.lock().as_mut() { - fb.clear(); - } } pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult { diff --git a/kernel/src/arch/mipsel/driver/mod.rs b/kernel/src/arch/mipsel/driver/mod.rs index 0cf6ad0c..4c1645b2 100644 --- a/kernel/src/arch/mipsel/driver/mod.rs +++ b/kernel/src/arch/mipsel/driver/mod.rs @@ -13,4 +13,7 @@ pub fn init() { assert_has_not_been_called!("driver::init must be called only once"); board::init_driver(); console::init(); + if let Some(con) = console::CONSOLE.lock().as_mut() { + con.clear(); + } }