Fixed PIC initialization in rust
I think I just had the inline assembly wrong, so outb wasn't working properly
This commit is contained in:
@@ -20,7 +20,7 @@ pub extern fn rust_setup_PIC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod PIC {
|
mod PIC {
|
||||||
use x86_asm::{outb, inb};
|
use x86_asm::{outb, inb, iowait};
|
||||||
|
|
||||||
const PIC1_COMMAND: u16 = 0x20;
|
const PIC1_COMMAND: u16 = 0x20;
|
||||||
const PIC2_COMMAND: u16 = 0xa0;
|
const PIC2_COMMAND: u16 = 0xa0;
|
||||||
@@ -38,20 +38,30 @@ mod PIC {
|
|||||||
asm!("cli");
|
asm!("cli");
|
||||||
|
|
||||||
outb(PIC1_COMMAND, INITIALIZE);
|
outb(PIC1_COMMAND, INITIALIZE);
|
||||||
|
iowait();
|
||||||
outb(PIC2_COMMAND, INITIALIZE);
|
outb(PIC2_COMMAND, INITIALIZE);
|
||||||
|
iowait();
|
||||||
|
|
||||||
// change IRQ offsets to int 32-47
|
// change IRQ offsets to int 32-47
|
||||||
outb(PIC1_DATA, 32);
|
outb(PIC1_DATA, 32);
|
||||||
|
iowait();
|
||||||
outb(PIC2_DATA, 40);
|
outb(PIC2_DATA, 40);
|
||||||
|
iowait();
|
||||||
|
|
||||||
outb(PIC1_DATA, 0x4); //master: slave IRQ location (IRQ 2)
|
outb(PIC1_DATA, 0x4); //master: slave IRQ location (IRQ 2)
|
||||||
|
iowait();
|
||||||
outb(PIC2_DATA, 0x2); //slave: cascade identity
|
outb(PIC2_DATA, 0x2); //slave: cascade identity
|
||||||
|
iowait();
|
||||||
|
|
||||||
outb(PIC1_DATA, ENVIRONMENT);
|
outb(PIC1_DATA, ENVIRONMENT);
|
||||||
|
iowait();
|
||||||
outb(PIC2_DATA, ENVIRONMENT);
|
outb(PIC2_DATA, ENVIRONMENT);
|
||||||
|
iowait();
|
||||||
|
|
||||||
outb(PIC1_DATA, interrupt_mask1);
|
outb(PIC1_DATA, interrupt_mask1);
|
||||||
|
iowait();
|
||||||
outb(PIC2_DATA, interrupt_mask2);
|
outb(PIC2_DATA, interrupt_mask2);
|
||||||
|
iowait();
|
||||||
|
|
||||||
asm!("sti");
|
asm!("sti");
|
||||||
}
|
}
|
||||||
@@ -60,8 +70,12 @@ mod PIC {
|
|||||||
|
|
||||||
mod x86_asm {
|
mod x86_asm {
|
||||||
|
|
||||||
|
pub unsafe fn iowait() {
|
||||||
|
outb(0x80, 0x0);
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe fn outb(port: u16, value: u8) {
|
pub unsafe fn outb(port: u16, value: u8) {
|
||||||
asm!("outb %%dx, %%al" : : "dx" (port), "al"(value));
|
asm!("outb %al, %dx" : : "{dx}" (port), "{al}"(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn inb(port: u16) -> u8{
|
pub unsafe fn inb(port: u16) -> u8{
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ long_mode_start:
|
|||||||
call setup_SSE
|
call setup_SSE
|
||||||
call setup_IDT
|
call setup_IDT
|
||||||
call setup_PIT
|
call setup_PIT
|
||||||
;extern rust_setup_PIC
|
extern rust_setup_PIC
|
||||||
;call rust_setup_PIC
|
call rust_setup_PIC
|
||||||
call setup_PIC
|
|
||||||
extern rust_main
|
extern rust_main
|
||||||
call rust_main
|
call rust_main
|
||||||
; rust main returned, print `OS returned!`
|
; rust main returned, print `OS returned!`
|
||||||
@@ -198,38 +197,6 @@ setup_PIT:
|
|||||||
|
|
||||||
ret
|
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:
|
idt64:
|
||||||
resb 50*16
|
resb 50*16
|
||||||
.pointer:
|
.pointer:
|
||||||
|
|||||||
Reference in New Issue
Block a user