COM2. Merge APIC/PIC interface.

master
WangRunji 7 years ago
parent 57fabda398
commit df58911ac4

@ -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);
}

@ -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);
}

@ -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<F>(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<F>(mut page_map: F)
} else {
pic::init();
}
serial::SERIAL.lock().init();
console::init();
serial::init();
keyboard::init();
}

@ -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<Serial> = Mutex::new(Serial::new(0x3F8));
pub static COM1: Mutex<Serial> = Mutex::new(Serial::new(0x3F8));
pub static COM2: Mutex<Serial> = 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<T: Io<Value = u8>> {

@ -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 {

@ -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);
}

@ -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);
}
}

@ -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;

@ -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() {
}
Loading…
Cancel
Save