Move PIT config into rust

This commit is contained in:
greg
2015-11-23 23:20:27 -08:00
parent cf9c7085c6
commit 7cb8affb2d
2 changed files with 31 additions and 17 deletions

View File

@@ -38,6 +38,34 @@ pub extern fn rust_handle_timer() {
timer_callback(gtc);
}
#[no_mangle]
pub extern fn rust_setup_PIT() {
PIT::configure_PIT(PIT::MILLISECOND_CONSTANT);
}
mod PIT {
use x86_asm::{outb, inb, iowait};
const PIT_CH0: u16 = 0x40;
const PIT_MODE_CMD: u16 = 0x43;
//channel 0, low-byte/hi-byte, rate generator
const TIMER_CONFIG_SPECIFIER: u8 = 0b00_11_010_0;
//generate ticks at about 1000.15 Hz
pub const MILLISECOND_CONSTANT: u16 = 1193;
pub fn configure_PIT(timer_divider: u16) {
unsafe {
outb(PIT_MODE_CMD, TIMER_CONFIG_SPECIFIER);
let low_bits = (timer_divider & 0xff) as u8;
let high_bits = (timer_divider >> 8) as u8;
outb(PIT_CH0, low_bits);
outb(PIT_CH0, high_bits);
}
}
}
mod PIC {
use x86_asm::{outb, inb, iowait};

View File

@@ -11,7 +11,9 @@ long_mode_start:
; print "OKAY"
call setup_SSE
call setup_IDT
call setup_PIT
extern rust_setup_PIT
call rust_setup_PIT
;call setup_PIT
extern rust_setup_PIC
call rust_setup_PIC
extern rust_main
@@ -159,19 +161,3 @@ idt64:
dq idt64
; --------- end of IDT section --------
setup_PIT:
%define PIT_CH0 0x40
%define PIT_MODE_CMD 0x43
%define TIMER_CONSTANT 1193 ;generates ticks at 1000.15 Hz
mov al, 0b00_11_010_0 ; channel 0, low-byte/hi-byte, rate generator
out PIT_MODE_CMD, al
mov ax, TIMER_CONSTANT
out PIT_CH0, al
mov al, ah
out PIT_CH0, al
ret