fix interrupts and time
todo: gdt
This commit is contained in:
parent
75c2759e5a
commit
201a9d8ed1
@ -1,4 +1,6 @@
|
|||||||
[lib]
|
[lib]
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
|
104
boot.s
104
boot.s
@ -16,59 +16,63 @@ align 4
|
|||||||
dd MBFLAGS
|
dd MBFLAGS
|
||||||
dd CHECKSUM
|
dd CHECKSUM
|
||||||
|
|
||||||
; %macro isr_err_stub 1
|
%macro isr_err_stub 1
|
||||||
; isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
; call exception_handler
|
push %1 ; Передаем номер прерывания как аргумент
|
||||||
; iret
|
call exception_handler
|
||||||
; %endmacro
|
pop eax ; Убираем аргумент из стека (если нужно)
|
||||||
|
iret
|
||||||
|
%endmacro
|
||||||
|
|
||||||
; %macro isr_no_err_stub 1
|
%macro isr_no_err_stub 1
|
||||||
; isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
; call exception_handler
|
push %1 ; Передаем номер прерывания как аргумент
|
||||||
; iret
|
call exception_handler
|
||||||
; %endmacro
|
pop eax ; Убираем аргумент из стека (если нужно)
|
||||||
|
iret
|
||||||
|
%endmacro
|
||||||
|
|
||||||
; extern exception_handler
|
extern exception_handler
|
||||||
; isr_no_err_stub 0
|
isr_no_err_stub 0
|
||||||
; isr_no_err_stub 1
|
isr_no_err_stub 1
|
||||||
; isr_no_err_stub 2
|
isr_no_err_stub 2
|
||||||
; isr_no_err_stub 3
|
isr_no_err_stub 3
|
||||||
; isr_no_err_stub 4
|
isr_no_err_stub 4
|
||||||
; isr_no_err_stub 5
|
isr_no_err_stub 5
|
||||||
; isr_no_err_stub 6
|
isr_no_err_stub 6
|
||||||
; isr_no_err_stub 7
|
isr_no_err_stub 7
|
||||||
; isr_err_stub 8
|
isr_err_stub 8
|
||||||
; isr_no_err_stub 9
|
isr_no_err_stub 9
|
||||||
; isr_err_stub 10
|
isr_err_stub 10
|
||||||
; isr_err_stub 11
|
isr_err_stub 11
|
||||||
; isr_err_stub 12
|
isr_err_stub 12
|
||||||
; isr_err_stub 13
|
isr_err_stub 13
|
||||||
; isr_err_stub 14
|
isr_err_stub 14
|
||||||
; isr_no_err_stub 15
|
isr_no_err_stub 15
|
||||||
; isr_no_err_stub 16
|
isr_no_err_stub 16
|
||||||
; isr_err_stub 17
|
isr_err_stub 17
|
||||||
; isr_no_err_stub 18
|
isr_no_err_stub 18
|
||||||
; isr_no_err_stub 19
|
isr_no_err_stub 19
|
||||||
; isr_no_err_stub 20
|
isr_no_err_stub 20
|
||||||
; isr_no_err_stub 21
|
isr_no_err_stub 21
|
||||||
; isr_no_err_stub 22
|
isr_no_err_stub 22
|
||||||
; isr_no_err_stub 23
|
isr_no_err_stub 23
|
||||||
; isr_no_err_stub 24
|
isr_no_err_stub 24
|
||||||
; isr_no_err_stub 25
|
isr_no_err_stub 25
|
||||||
; isr_no_err_stub 26
|
isr_no_err_stub 26
|
||||||
; isr_no_err_stub 27
|
isr_no_err_stub 27
|
||||||
; isr_no_err_stub 28
|
isr_no_err_stub 28
|
||||||
; isr_no_err_stub 29
|
isr_no_err_stub 29
|
||||||
; isr_err_stub 30
|
isr_err_stub 30
|
||||||
; isr_no_err_stub 31
|
isr_no_err_stub 31
|
||||||
|
|
||||||
; global isr_stub_table
|
global isr_stub_table
|
||||||
; isr_stub_table:
|
isr_stub_table:
|
||||||
; %assign i 0
|
%assign i 0
|
||||||
; %rep 32
|
%rep 32
|
||||||
; dd isr_stub_%+i ; use DQ instead if targeting 64-bit
|
dd isr_stub_%+i ; use DQ instead if targeting 64-bit
|
||||||
; %assign i i+1
|
%assign i i+1
|
||||||
; %endrep
|
%endrep
|
||||||
|
|
||||||
; The multiboot standard does not define the value of the stack pointer register
|
; The multiboot standard does not define the value of the stack pointer register
|
||||||
; (esp) and it is up to the kernel to provide a stack. This allocates room for a
|
; (esp) and it is up to the kernel to provide a stack. This allocates room for a
|
||||||
|
@ -60,12 +60,12 @@ static mut IDT: [IDTEntry; IDT_MAX_DESCRIPTORS] = [IDTEntry {
|
|||||||
offset_mid: 0,
|
offset_mid: 0,
|
||||||
}; IDT_MAX_DESCRIPTORS];
|
}; IDT_MAX_DESCRIPTORS];
|
||||||
|
|
||||||
// static mut VECTORS: [bool; 32] = [false; 32];
|
static mut VECTORS: [bool; 32] = [false; 32];
|
||||||
static mut IDTR: IDTDescriptor = IDTDescriptor { limit: 0, base: 0 };
|
static mut IDTR: IDTDescriptor = IDTDescriptor { limit: 0, base: 0 };
|
||||||
|
|
||||||
// extern "C" {
|
extern "C" {
|
||||||
// static ist_stub_table: [u32; 32];
|
static isr_stub_table: [u32; 32];
|
||||||
// }
|
}
|
||||||
|
|
||||||
pub unsafe fn idt_set_descriptor(vector: u8, handler: u32, type_attr: u8) {
|
pub unsafe fn idt_set_descriptor(vector: u8, handler: u32, type_attr: u8) {
|
||||||
IDT[vector as usize] = IDTEntry {
|
IDT[vector as usize] = IDTEntry {
|
||||||
@ -78,18 +78,27 @@ pub unsafe fn idt_set_descriptor(vector: u8, handler: u32, type_attr: u8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn load_idt() {
|
pub unsafe fn load_idt() {
|
||||||
IDTR.base = &IDT as *const _ as u32;
|
IDTR.base = &raw const IDT as *const _ as u32;
|
||||||
IDTR.limit = (size_of::<IDTEntry>() * IDT_MAX_DESCRIPTORS - 1) as u16;
|
IDTR.limit = (size_of::<IDTEntry>() * IDT_MAX_DESCRIPTORS - 1) as u16;
|
||||||
|
|
||||||
// for vector in 0..32 {
|
for vector in 0..32 {
|
||||||
// idt_set_descriptor(vector, ist_stub_table[vector as usize], 0x8E);
|
idt_set_descriptor(vector, isr_stub_table[vector as usize], 0x8E);
|
||||||
// VECTORS[vector as usize] = true;
|
VECTORS[vector as usize] = true;
|
||||||
// }
|
}
|
||||||
|
|
||||||
asm!("lidt [{}]", in(reg) &IDTR);
|
asm!("lidt [{}]", in(reg) &raw const IDTR);
|
||||||
asm!("sti");
|
asm!("sti");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn exception_handler(error_type: u8) {
|
||||||
|
unsafe {
|
||||||
|
log_error(&format!("Unknown error 0x{:X}", error_type));
|
||||||
|
asm!("cli; hlt");
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn is_apic_available() -> bool {
|
unsafe fn is_apic_available() -> bool {
|
||||||
if !APIC_ENABLED {
|
if !APIC_ENABLED {
|
||||||
return false;
|
return false;
|
||||||
@ -106,12 +115,6 @@ unsafe fn is_apic_available() -> bool {
|
|||||||
(edx & (1 << 9)) != 0
|
(edx & (1 << 9)) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe extern "C" fn exception_handler() {
|
|
||||||
log_error("Unknown error");
|
|
||||||
asm!("cli; hlt");
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn send_apic_eoi() {
|
unsafe fn send_apic_eoi() {
|
||||||
write_volatile(APIC_EOI as *mut u32, 0);
|
write_volatile(APIC_EOI as *mut u32, 0);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ pub fn init_pit() {
|
|||||||
log_info("PIT initialized");
|
log_info("PIT initialized");
|
||||||
log_info(&format!("{}", pit_handler as u32));
|
log_info(&format!("{}", pit_handler as u32));
|
||||||
|
|
||||||
idt_set_descriptor(0x20, pit_handler as u32, 0x8E);
|
idt_set_descriptor(0x20, pit_handler as u32, 0);
|
||||||
log_info("PIT registered");
|
log_info("PIT registered");
|
||||||
load_idt();
|
load_idt();
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#![feature(lang_items)]
|
#![allow(internal_features, dead_code, unused)]
|
||||||
#![feature(alloc_error_handler)]
|
#![feature(lang_items, alloc_error_handler, rustc_private, abi_x86_interrupt)]
|
||||||
#![feature(rustc_private)]
|
|
||||||
#![feature(abi_x86_interrupt)]
|
|
||||||
|
|
||||||
|
|
||||||
#[lang = "eh_personality"]
|
#[lang = "eh_personality"]
|
||||||
|
Loading…
Reference in New Issue
Block a user