diff --git a/src/arch/x86_64/driver/console.rs b/src/arch/x86_64/driver/console.rs deleted file mode 100644 index 5ec13ad..0000000 --- a/src/arch/x86_64/driver/console.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub fn init() { - use consts::irq::{IRQ_KBD, IRQ_COM1}; - // TODO set irq handler - // super::pic::enable_irq(IRQ_KBD); - let mut ioapic = super::apic::IOAPIC.lock(); - ioapic.enable(IRQ_KBD, 0); - ioapic.enable(IRQ_COM1, 0); -} \ No newline at end of file diff --git a/src/arch/x86_64/driver/keyboard.rs b/src/arch/x86_64/driver/keyboard.rs new file mode 100644 index 0000000..cb44a0b --- /dev/null +++ b/src/arch/x86_64/driver/keyboard.rs @@ -0,0 +1,7 @@ +pub fn init() { + assert_has_not_been_called!("keyboard::init must be called only once"); + + use consts::irq::*; + use arch::interrupt::enable_irq; + enable_irq(IRQ_KBD); +} \ No newline at end of file diff --git a/src/arch/x86_64/driver/mod.rs b/src/arch/x86_64/driver/mod.rs index ea3f653..f36812d 100644 --- a/src/arch/x86_64/driver/mod.rs +++ b/src/arch/x86_64/driver/mod.rs @@ -4,10 +4,13 @@ pub mod apic; pub mod mp; pub mod serial; pub mod pic; -pub mod console; +pub mod keyboard; pub fn init(mut page_map: F) where F: FnMut(usize) { + + assert_has_not_been_called!(); + // TODO Handle this temp page map. page_map(0); // EBDA for addr in (0xE0000 .. 0x100000).step_by(0x1000) { @@ -28,6 +31,6 @@ pub fn init(mut page_map: F) } else { pic::init(); } - serial::SERIAL.lock().init(); - console::init(); + serial::init(); + keyboard::init(); } \ No newline at end of file diff --git a/src/arch/x86_64/driver/serial.rs b/src/arch/x86_64/driver/serial.rs index 29fe624..b5dd0c7 100644 --- a/src/arch/x86_64/driver/serial.rs +++ b/src/arch/x86_64/driver/serial.rs @@ -1,8 +1,22 @@ +// Copy from Redox + use core::fmt::{self, Write}; use spin::Mutex; use syscall::io::{Io, Pio, Mmio, ReadOnly}; -pub static SERIAL: Mutex = Mutex::new(Serial::new(0x3F8)); +pub static COM1: Mutex = Mutex::new(Serial::new(0x3F8)); +pub static COM2: Mutex = Mutex::new(Serial::new(0x2F8)); + +pub fn init() { + assert_has_not_been_called!("serial::init must be called only once"); + + COM1.lock().init(); + COM2.lock().init(); + use consts::irq::*; + use arch::interrupt::enable_irq; + enable_irq(IRQ_COM1); + enable_irq(IRQ_COM2); +} #[allow(dead_code)] pub struct SerialPort> { diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index 225364b..96ec8c4 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -12,7 +12,8 @@ pub fn init() { let mut idt = Idt::new(); idt.breakpoint.set_handler_fn(breakpoint_handler); idt.double_fault.set_handler_fn(double_fault_handler); - idt[(T_IRQ0 + IRQ_COM1) as usize].set_handler_fn(serial_handler); + idt[(T_IRQ0 + IRQ_COM1) as usize].set_handler_fn(com1_handler); + idt[(T_IRQ0 + IRQ_COM2) as usize].set_handler_fn(com2_handler); idt[(T_IRQ0 + IRQ_KBD) as usize].set_handler_fn(keyboard_handler); idt[(T_IRQ0 + IRQ_TIMER) as usize].set_handler_fn(timer_handler); unsafe { diff --git a/src/arch/x86_64/interrupt/irq.rs b/src/arch/x86_64/interrupt/irq.rs index f1e8b49..7de145a 100644 --- a/src/arch/x86_64/interrupt/irq.rs +++ b/src/arch/x86_64/interrupt/irq.rs @@ -34,18 +34,27 @@ pub extern "x86-interrupt" fn keyboard_handler( ack(IRQ_KBD); } -pub extern "x86-interrupt" fn serial_handler( +pub extern "x86-interrupt" fn com1_handler( stack_frame: &mut ExceptionStackFrame) { - use arch::driver::serial::SERIAL; - println!("\nInterupt: Serial \n{:#?}", stack_frame); - SERIAL.lock().receive(); + use arch::driver::serial::COM1; + println!("\nInterupt: COM1"); + COM1.lock().receive(); ack(IRQ_COM1); } +pub extern "x86-interrupt" fn com2_handler( + stack_frame: &mut ExceptionStackFrame) +{ + use arch::driver::serial::COM2; + println!("\nInterupt: COM2"); + COM2.lock().receive(); + ack(IRQ_COM2); +} + pub extern "x86-interrupt" fn timer_handler( stack_frame: &mut ExceptionStackFrame) { - println!("\nInterupt: Timer \n{:#?}", stack_frame); +// println!("\nInterupt: Timer \n{:#?}", stack_frame); ack(IRQ_TIMER); } \ No newline at end of file diff --git a/src/arch/x86_64/interrupt/mod.rs b/src/arch/x86_64/interrupt/mod.rs index 6c01339..9c6931a 100644 --- a/src/arch/x86_64/interrupt/mod.rs +++ b/src/arch/x86_64/interrupt/mod.rs @@ -1,4 +1,5 @@ use x86_64; +use arch::driver::{apic::IOAPIC, pic}; pub mod irq; @@ -10,4 +11,13 @@ pub unsafe fn enable() { #[inline(always)] pub unsafe fn disable() { x86_64::instructions::interrupts::disable(); +} + +#[inline(always)] +pub fn enable_irq(irq: u8) { + if cfg!(feature = "use_apic") { + IOAPIC.lock().enable(irq, 0); + } else { + pic::enable_irq(irq); + } } \ No newline at end of file diff --git a/src/consts.rs b/src/consts.rs index 6857e53..67ab9b6 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -99,6 +99,7 @@ pub mod irq { pub const T_IRQ0 : u8 = 32; // IRQ 0 corresponds to int T_IRQ pub const IRQ_TIMER : u8 = 0; pub const IRQ_KBD : u8 = 1; + pub const IRQ_COM2 : u8 = 3; pub const IRQ_COM1 : u8 = 4; pub const IRQ_IDE : u8 = 14; pub const IRQ_ERROR : u8 = 19; diff --git a/src/io/mod.rs b/src/io/mod.rs index 4f95262..45239e6 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1,5 +1,5 @@ use core::fmt; -use arch::driver::serial::SERIAL; +use arch::driver::serial::COM1; mod vga_writer; @@ -33,7 +33,7 @@ fn print_in_color(args: fmt::Arguments, color: Color) { let mut writer = vga_writer::VGA_WRITER.lock(); writer.set_color(color); writer.write_fmt(args).unwrap(); - SERIAL.lock().write_fmt(args).unwrap(); + COM1.lock().write_fmt(args).unwrap(); } pub fn print(args: fmt::Arguments) { @@ -42,8 +42,4 @@ pub fn print(args: fmt::Arguments) { pub fn debug(args: fmt::Arguments) { print_in_color(args, Color::LightRed); -} - -pub fn init() { - } \ No newline at end of file