Move PIC offsets

Can't make this work from within rust for some reason, use asm
This commit is contained in:
greg
2015-11-23 02:17:45 -08:00
parent 9f3c1f8f29
commit b5e78209e6
2 changed files with 64 additions and 9 deletions

View File

@@ -20,21 +20,39 @@ pub extern fn rust_setup_PIC() {
}
mod PIC {
use x86_asm::out;
use x86_asm::{outb, inb};
const PIC1_COMMAND: u16 = 0x20;
const PIC2_COMMAND: u16 = 0xa0;
const PIC1_DATA: u16 = 0x21;
const PIC2_DATA: u16 = 0xa1;
const INITIALIZE: u8 = 0x11;
const ENVIRONMENT: u8 = 0x01; //I don't really know what this does
pub fn setup_PIC() {
let interrupt_mask1: u8 = 0xfc;
let interrupt_mask2: u8 = 0xff;
unsafe {
out(PIC1_DATA, interrupt_mask1);
out(PIC2_DATA, interrupt_mask2);
asm!("cli");
outb(PIC1_COMMAND, INITIALIZE);
outb(PIC2_COMMAND, INITIALIZE);
// change IRQ offsets to int 32-47
outb(PIC1_DATA, 32);
outb(PIC2_DATA, 40);
outb(PIC1_DATA, 0x4); //master: slave IRQ location (IRQ 2)
outb(PIC2_DATA, 0x2); //slave: cascade identity
outb(PIC1_DATA, ENVIRONMENT);
outb(PIC2_DATA, ENVIRONMENT);
outb(PIC1_DATA, interrupt_mask1);
outb(PIC2_DATA, interrupt_mask2);
asm!("sti");
}
}
@@ -42,9 +60,15 @@ mod PIC {
mod x86_asm {
pub unsafe fn out(port: u16, value: u8) {
pub unsafe fn outb(port: u16, value: u8) {
asm!("outb %%dx, %%al" : : "dx" (port), "al"(value));
}
pub unsafe fn inb(port: u16) -> u8{
let inval: u8;
asm!("inb %dx, %al" : "={al}"(inval) : "{dx}"(port));
return inval;
}
}
#[no_mangle]

View File

@@ -14,8 +14,9 @@ long_mode_start:
call setup_SSE
call setup_IDT
call setup_PIT
extern rust_setup_PIC
call rust_setup_PIC
;extern rust_setup_PIC
;call rust_setup_PIC
call setup_PIC
extern rust_main
call rust_main
; rust main returned, print `OS returned!`
@@ -161,8 +162,8 @@ handle_timer:
setup_IDT:
lidt [idt64.pointer]
load_IDT_entry handle_timer, 8
load_IDT_entry handle_keyboard, 9
load_IDT_entry handle_timer, 32
load_IDT_entry handle_keyboard, 33
ret
@@ -170,7 +171,6 @@ setup_PIT:
%define PIT_CH0 0x40
%define PIT_MODE_CMD 0x43
%define TIMER_CONSTANT 1193 ;generates ticks at 1000.15 Hz
cli
mov al, 0b00_11_010_0 ; channel 0, low-byte/hi-byte, rate generator
out PIT_MODE_CMD, al
@@ -180,7 +180,38 @@ setup_PIT:
mov al, ah
out PIT_CH0, al
ret
setup_PIC:
;initialize
mov al, 0x11
out 0x20, al
out 0xa0, al
; vector offsets
mov al, 32
out 0x21, al
mov al, 40
out 0xa1, al
;master/slave wiring
mov al, 4
out 0x21, al
mov al, 2
out 0xa1, al
;additional info
mov al, 1
out 0x21, al
out 0xa1, al
mov al, 0xfc
out 0x21, al
mov al, 0xff
out 0xa1, al
sti
ret
idt64: