From ecdbc9fd7a1dd56927e9ae0f239e2940fc7d3b52 Mon Sep 17 00:00:00 2001 From: Harry Chen Date: Sun, 7 Apr 2019 18:36:29 +0800 Subject: [PATCH] Switch to uart2 on malta to get interrupts (not working) Signed-off-by: Harry Chen --- kernel/Makefile | 8 +++++++- kernel/src/arch/mipsel/board/malta/mod.rs | 10 +++++++++- kernel/src/arch/mipsel/interrupt.rs | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 9466a82..d7d1df1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -134,7 +134,13 @@ qemu_opts += \ -kernel $(kernel_img) else ifeq ($(arch), mipsel) -ifeq ($(board), $(filter $(board), malta mipssim)) +ifeq ($(board), malta) +qemu_opts += \ + -machine $(board) \ + -serial null -serial null -serial mon:stdio \ + -kernel $(kernel_img) +endif +ifeq ($(board), mipssim) qemu_opts += \ -machine $(board) \ -serial mon:stdio \ diff --git a/kernel/src/arch/mipsel/board/malta/mod.rs b/kernel/src/arch/mipsel/board/malta/mod.rs index 0c594ef..67d5a8f 100644 --- a/kernel/src/arch/mipsel/board/malta/mod.rs +++ b/kernel/src/arch/mipsel/board/malta/mod.rs @@ -1,5 +1,6 @@ use once::*; use alloc::string::String; +use mips::registers::cp0; #[path = "../../../../drivers/serial/16550_reg.rs"] pub mod serial; @@ -12,7 +13,14 @@ pub mod consts; /// Initialize serial port first pub fn init_serial_early() { assert_has_not_been_called!("board::init must be called only once"); - serial::init(0xb80003f8); + // initialize serial driver + serial::init(0xbf000900); + // Enable serial interrupt + unsafe { + let mut status = cp0::status::read(); + status.enable_hard_int2(); + cp0::status::write(status); + } println!("Hello QEMU Malta!"); } diff --git a/kernel/src/arch/mipsel/interrupt.rs b/kernel/src/arch/mipsel/interrupt.rs index d85539e..19c0aad 100644 --- a/kernel/src/arch/mipsel/interrupt.rs +++ b/kernel/src/arch/mipsel/interrupt.rs @@ -75,7 +75,7 @@ pub extern fn rust_trap(tf: &mut TrapFrame) { fn interrupt_dispatcher(tf: &mut TrapFrame) { let pint = tf.cause.pending_interrupt(); - trace!(" Interrupt {:?} ", tf.cause.pending_interrupt()); + trace!(" Interrupt {:08b} ", pint); if (pint & 0b100_000_00) != 0 { timer(); } else if (pint & 0b011_111_00) != 0 { @@ -86,7 +86,6 @@ fn interrupt_dispatcher(tf: &mut TrapFrame) { } fn external() { - // TODO // true means handled, false otherwise let handlers = [try_process_serial, try_process_drivers]; for handler in handlers.iter() { @@ -99,6 +98,7 @@ fn external() { fn try_process_serial() -> bool { match super::io::getchar_option() { Some(ch) => { + trace!("Get char {} from serial", ch); crate::trap::serial(ch); true }