fix interrupts and time

todo: gdt
This commit is contained in:
MeexReay 2025-02-03 00:19:12 +03:00
parent 75c2759e5a
commit 201a9d8ed1
5 changed files with 79 additions and 71 deletions

View File

@ -1,4 +1,6 @@
[lib]
test = false
bench = false
crate-type = ["staticlib"]
[package]

104
boot.s
View File

@ -16,59 +16,63 @@ align 4
dd MBFLAGS
dd CHECKSUM
; %macro isr_err_stub 1
; isr_stub_%+%1:
; call exception_handler
; iret
; %endmacro
%macro isr_err_stub 1
isr_stub_%+%1:
push %1 ; Передаем номер прерывания как аргумент
call exception_handler
pop eax ; Убираем аргумент из стека (если нужно)
iret
%endmacro
; %macro isr_no_err_stub 1
; isr_stub_%+%1:
; call exception_handler
; iret
; %endmacro
%macro isr_no_err_stub 1
isr_stub_%+%1:
push %1 ; Передаем номер прерывания как аргумент
call exception_handler
pop eax ; Убираем аргумент из стека (если нужно)
iret
%endmacro
; extern exception_handler
; isr_no_err_stub 0
; isr_no_err_stub 1
; isr_no_err_stub 2
; isr_no_err_stub 3
; isr_no_err_stub 4
; isr_no_err_stub 5
; isr_no_err_stub 6
; isr_no_err_stub 7
; isr_err_stub 8
; isr_no_err_stub 9
; isr_err_stub 10
; isr_err_stub 11
; isr_err_stub 12
; isr_err_stub 13
; isr_err_stub 14
; isr_no_err_stub 15
; isr_no_err_stub 16
; isr_err_stub 17
; isr_no_err_stub 18
; isr_no_err_stub 19
; isr_no_err_stub 20
; isr_no_err_stub 21
; isr_no_err_stub 22
; isr_no_err_stub 23
; isr_no_err_stub 24
; isr_no_err_stub 25
; isr_no_err_stub 26
; isr_no_err_stub 27
; isr_no_err_stub 28
; isr_no_err_stub 29
; isr_err_stub 30
; isr_no_err_stub 31
extern exception_handler
isr_no_err_stub 0
isr_no_err_stub 1
isr_no_err_stub 2
isr_no_err_stub 3
isr_no_err_stub 4
isr_no_err_stub 5
isr_no_err_stub 6
isr_no_err_stub 7
isr_err_stub 8
isr_no_err_stub 9
isr_err_stub 10
isr_err_stub 11
isr_err_stub 12
isr_err_stub 13
isr_err_stub 14
isr_no_err_stub 15
isr_no_err_stub 16
isr_err_stub 17
isr_no_err_stub 18
isr_no_err_stub 19
isr_no_err_stub 20
isr_no_err_stub 21
isr_no_err_stub 22
isr_no_err_stub 23
isr_no_err_stub 24
isr_no_err_stub 25
isr_no_err_stub 26
isr_no_err_stub 27
isr_no_err_stub 28
isr_no_err_stub 29
isr_err_stub 30
isr_no_err_stub 31
; global isr_stub_table
; isr_stub_table:
; %assign i 0
; %rep 32
; dd isr_stub_%+i ; use DQ instead if targeting 64-bit
; %assign i i+1
; %endrep
global isr_stub_table
isr_stub_table:
%assign i 0
%rep 32
dd isr_stub_%+i ; use DQ instead if targeting 64-bit
%assign i i+1
%endrep
; 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

View File

@ -60,12 +60,12 @@ static mut IDT: [IDTEntry; IDT_MAX_DESCRIPTORS] = [IDTEntry {
offset_mid: 0,
}; 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 };
// extern "C" {
// static ist_stub_table: [u32; 32];
// }
extern "C" {
static isr_stub_table: [u32; 32];
}
pub unsafe fn idt_set_descriptor(vector: u8, handler: u32, type_attr: u8) {
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() {
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;
// for vector in 0..32 {
// idt_set_descriptor(vector, ist_stub_table[vector as usize], 0x8E);
// VECTORS[vector as usize] = true;
// }
for vector in 0..32 {
idt_set_descriptor(vector, isr_stub_table[vector as usize], 0x8E);
VECTORS[vector as usize] = true;
}
asm!("lidt [{}]", in(reg) &IDTR);
asm!("lidt [{}]", in(reg) &raw const IDTR);
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 {
if !APIC_ENABLED {
return false;
@ -106,12 +115,6 @@ unsafe fn is_apic_available() -> bool {
(edx & (1 << 9)) != 0
}
pub unsafe extern "C" fn exception_handler() {
log_error("Unknown error");
asm!("cli; hlt");
loop {}
}
unsafe fn send_apic_eoi() {
write_volatile(APIC_EOI as *mut u32, 0);
}

View File

@ -44,7 +44,7 @@ pub fn init_pit() {
log_info("PIT initialized");
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");
load_idt();

View File

@ -1,10 +1,9 @@
#![no_std]
#![no_main]
#![feature(lang_items)]
#![feature(alloc_error_handler)]
#![feature(rustc_private)]
#![feature(abi_x86_interrupt)]
#![allow(internal_features, dead_code, unused)]
#![feature(lang_items, alloc_error_handler, rustc_private, abi_x86_interrupt)]
#[lang = "eh_personality"]