diff --git a/src/device/mod.rs b/src/device/mod.rs index 5825ff5..965e083 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -5,6 +5,7 @@ use syscall::io::{Pio, Io}; pub mod cpu; pub mod local_apic; pub mod pic; +pub mod pit; pub mod rtc; pub mod serial; pub mod hpet; @@ -17,16 +18,9 @@ pub unsafe fn init(active_table: &mut ActivePageTable){ pub unsafe fn init_noncore(active_table: &mut ActivePageTable) { { if let Some(ref hpet) = ACPI_TABLE.lock().hpet { - // Disable the PIT - // TODO: Move PIT driver to kernel, and just don't enable it in the first place if we have an HPET - let mut pit_cmd = Pio::::new(0x43); - let mut pit_c0 = Pio::::new(0x40); - - pit_cmd.write(0x30); - pit_c0.write(0); - pit_c0.write(0); - hpet::init(hpet, active_table); + } else { + pit::init(); } } diff --git a/src/device/pit.rs b/src/device/pit.rs new file mode 100644 index 0000000..4c2fb34 --- /dev/null +++ b/src/device/pit.rs @@ -0,0 +1,20 @@ +use syscall::io::{Io, Pio}; + +pub static mut CHAN0: Pio = Pio::new(0x40); +pub static mut CHAN1: Pio = Pio::new(0x41); +pub static mut CHAN2: Pio = Pio::new(0x42); +pub static mut COMMAND: Pio = Pio::new(0x43); + +static SELECT_CHAN0: u8 = 0; +static LOHI: u8 = 0x30; +static MODE3: u8 = 3; + +static CHAN0_DIVISOR: u16 = 2685; + +pub unsafe fn init() { + COMMAND.write(SELECT_CHAN0 | LOHI | MODE3); + CHAN0.write((CHAN0_DIVISOR & 0xFF) as u8); + CHAN0.write((CHAN0_DIVISOR >> 8) as u8); + + println!("Using PIT"); +}