From 015cc72aa42d223111436b579d14e8b823437205 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Wed, 3 Apr 2019 13:53:34 +0800 Subject: [PATCH] Fix malta drivers Signed-off-by: Harry Chen --- kernel/Cargo.toml | 6 +- kernel/Makefile | 4 +- kernel/src/arch/mipsel/board/malta/fb.rs | 2 + kernel/src/arch/mipsel/board/malta/mod.rs | 2 +- kernel/src/arch/mipsel/board/malta/serial.rs | 115 ++++++++++--------- 5 files changed, 70 insertions(+), 59 deletions(-) diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 6f32b9d..936a813 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -13,7 +13,9 @@ authors = [ "chenqiuhao ", "maoyuchaxue ", "Jiajie Chen ", - "chyyuu " + "chyyuu ", + "Shengqi Chen ", + "Yuhao Zhou " ] [features] @@ -26,6 +28,8 @@ board_raspi3 = ["bcm2837", "link_user"] raspi3_use_generic_timer = ["bcm2837/use_generic_timer"] # for mipsel qemu malta machine board_malta = [] +# for thinpad +board_thinpad = [] # Hard link user program link_user = [] # Run cmdline instead of user shell, useful for automatic testing diff --git a/kernel/Makefile b/kernel/Makefile index 07b74ce..19d0c88 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -113,11 +113,13 @@ qemu_opts += \ -kernel $(kernel_img) else ifeq ($(arch), mipsel) +ifeq ($(board), malta) qemu_opts += \ -machine $(board) \ - -serial null -serial null -serial mon:stdio \ + -serial none -serial none -serial mon:stdio \ -kernel $(kernel_img) endif +endif ifdef d qemu_opts += -d $(d) diff --git a/kernel/src/arch/mipsel/board/malta/fb.rs b/kernel/src/arch/mipsel/board/malta/fb.rs index 89c4321..7023e5e 100644 --- a/kernel/src/arch/mipsel/board/malta/fb.rs +++ b/kernel/src/arch/mipsel/board/malta/fb.rs @@ -2,6 +2,8 @@ lazy_static! { pub static ref FRAME_BUFFER: Mutex> = Mutex::new(None); } +pub struct Framebuffer {} + pub struct FramebufferInfo {} pub enum ColorDepth {} \ No newline at end of file diff --git a/kernel/src/arch/mipsel/board/malta/mod.rs b/kernel/src/arch/mipsel/board/malta/mod.rs index ae61c69..0a3f750 100644 --- a/kernel/src/arch/mipsel/board/malta/mod.rs +++ b/kernel/src/arch/mipsel/board/malta/mod.rs @@ -8,7 +8,7 @@ pub mod console; /// Initialize serial port first pub fn init_serial_early() { assert_has_not_been_called!("board::init must be called only once"); - serial::init(); + serial::init(0xbf000900); println!("Hello QEMU Malta!"); } diff --git a/kernel/src/arch/mipsel/board/malta/serial.rs b/kernel/src/arch/mipsel/board/malta/serial.rs index 4a20383..2ee0a4e 100644 --- a/kernel/src/arch/mipsel/board/malta/serial.rs +++ b/kernel/src/arch/mipsel/board/malta/serial.rs @@ -1,23 +1,75 @@ use core::fmt::{Write, Result, Arguments}; use core::ptr::{read_volatile, write_volatile}; -struct SerialPort {}; +struct SerialPort { + base: usize +} impl SerialPort { fn new() -> SerialPort { SerialPort { } } + + pub fn init(&mut self, base: usize) { + self.base = base; + // Turn off the FIFO + write(self.base + COM_FCR, 0 as u8); + // Set speed; requires DLAB latch + write(self.base + COM_LCR, COM_LCR_DLAB); + write(self.base + COM_DLL, (115200 / 9600) as u8); + write(self.base + COM_DLM, 0 as u8); + + // 8 data bits, 1 stop bit, parity off; turn off DLAB latch + write(self.base + COM_LCR, COM_LCR_WLEN8 & !COM_LCR_DLAB); + + // No modem controls + write(self.base + COM_MCR, 0 as u8); + // Enable rcv interrupts + write(self.base + COM_IER, COM_IER_RDI); + } + + /// non-blocking version of putchar() + fn putchar(&mut self, c: u8) { + write(self.base + COM_TX, c); + } + + /// blocking version of getchar() + pub fn getchar(&mut self) -> char { + loop { + if (read::(self.base + COM_LSR) & COM_LSR_DATA) == 0 { + break; + } + } + let c = read::(self.base + COM_RX); + match c { + 255 => '\0', // null + c => c as char, + } + } + + /// non-blocking version of getchar() + pub fn getchar_option(&mut self) -> Option { + match read::(self.base + COM_LSR) & COM_LSR_DATA { + 0 => None, + _ => Some(read::(self.base + COM_RX) as u8 as char), + } + } + + pub fn putfmt(&mut self, fmt: Arguments) { + self.write_fmt(fmt).unwrap(); + } + } impl Write for SerialPort { fn write_str(&mut self, s: &str) -> Result { for c in s.bytes() { if c == 127 { - putchar(8); - putchar(b' '); - putchar(8); + self.putchar(8); + self.putchar(b' '); + self.putchar(8); } else { - putchar(c); + self.putchar(c); } } Ok(()) @@ -34,55 +86,6 @@ fn read(addr: usize) -> T { read_volatile(cell); } -/// non-blocking version of putchar() -fn putchar(c: u8) { - write(COM1 + COM_TX, c); -} - -/// blocking version of getchar() -pub fn getchar() -> char { - loop { - if (read::(COM1 + COM_LSR) & COM_LSR_DATA) == 0 { - break; - } - } - let c = read::(COM1 + COM_RX); - match c { - 255 => '\0', // null - c => c as char, - } -} - -/// non-blocking version of getchar() -pub fn getchar_option() -> Option { - match read::(COM1 + COM_LSR) & COM_LSR_DATA { - 0 => None, - else => Some(read::(COM1 + COM_RX) as u8 as char), - } -} - -pub fn putfmt(fmt: Arguments) { - SerialPort.write_fmt(fmt).unwrap(); -} - -pub fn init() { - // Turn off the FIFO - write(COM1 + COM_FCR, 0 as u8); - // Set speed; requires DLAB latch - write(COM1 + COM_LCR, COM_LCR_DLAB); - write(COM1 + COM_DLL, (115200 / 9600) as u8); - write(COM1 + COM_DLM, 0 as u8); - - // 8 data bits, 1 stop bit, parity off; turn off DLAB latch - write(COM1 + COM_LCR, COM_LCR_WLEN8 & !COM_LCR_DLAB); - - // No modem controls - write(COM1 + COM_MCR, 0 as u8); - // Enable rcv interrupts - write(COM1 + COM_IER, COM_IER_RDI); -} - -const COM1 :usize = 0xbf000900; // 16550 Base Address const COM_RX :usize = 0; // In: Receive buffer (DLAB=0) const COM_TX :usize = 0; // Out: Transmit buffer (DLAB=0) @@ -109,6 +112,6 @@ lazy_static! { pub static ref SERIAL_PORT: Mutex = Mutex::new(SerialPort::new()); } -pub fn init() { - SERIAL_PORT.lock().init(); +pub fn init(base: usize) { + SERIAL_PORT.lock().init(base); } \ No newline at end of file