Browse Source

IDT basics

Signed-off-by: main <magic_rb@redalder.org>
master
main 9 months ago
parent
commit
08af3d7261
Signed by: Magic_RB
GPG Key ID: 08D5287CC5DDCA0E
  1. 12
      src/idt/access.rs
  2. 4
      src/idt/entry.rs
  3. 34
      src/idt/mod.rs
  4. 36
      src/lib.rs
  5. 135
      src/start.S

12
src/idt/access.rs

@ -20,3 +20,15 @@ impl Access {
unsafe { core::mem::transmute::<u8, Ring>((self.0 & 0b01100000) >> 5) }
}
}
impl From<u8> for Access {
fn from(b: u8) -> Self {
Self(b)
}
}
impl Into<u8> for Access {
fn into(self) -> u8 {
self.0
}
}

4
src/idt/entry.rs

@ -19,6 +19,10 @@ impl Entry {
entry
}
pub const fn zeroed() -> Self {
unsafe { core::mem::transmute::<u64, _>(0) }
}
pub fn set_base(&mut self, base: u32) {
self.base_low = (base & 0xFFFF) as u16;
self.base_high = ((base >> 16) & 0xFFFF) as u16;

34
src/idt/mod.rs

@ -9,13 +9,45 @@ pub use self::entry::*;
pub static mut IDT: [ MaybeUninit<Entry> ; 256] = [ MaybeUninit::uninit() ; 256 ];
pub static mut IDT: [ Entry ; 256] = [ Entry::zeroed() ; 256 ];
#[export_name = "_idtp"]
pub static mut IDT_PTR: MaybeUninit<LimitedPointer> = MaybeUninit::uninit();
extern "C" {
#[link_name = "_idt_load"]
pub fn idt_load();
pub fn isr0();
pub fn isr1();
pub fn isr2();
pub fn isr3();
pub fn isr4();
pub fn isr5();
pub fn isr6();
pub fn isr7();
pub fn isr8();
pub fn isr9();
pub fn isr10();
pub fn isr11();
pub fn isr12();
pub fn isr13();
pub fn isr14();
pub fn isr15();
pub fn isr16();
pub fn isr17();
pub fn isr18();
pub fn isr19();
pub fn isr20();
pub fn isr21();
pub fn isr22();
pub fn isr23();
pub fn isr24();
pub fn isr25();
pub fn isr26();
pub fn isr27();
pub fn isr28();
pub fn isr29();
pub fn isr30();
pub fn isr31();
}
#[export_name = "_fault_handler"]

36
src/lib.rs

@ -68,5 +68,41 @@ fn main() {
gdt::gdt_flush();
write!(screen, "\n\nHello");
idt::IDT[0] = idt::Entry::new(idt::isr0 as u32, 0x08, 0x8E.into());
idt::IDT[1] = idt::Entry::new(idt::isr1 as u32, 0x08, 0x8E.into());
idt::IDT[2] = idt::Entry::new(idt::isr2 as u32, 0x08, 0x8E.into());
idt::IDT[3] = idt::Entry::new(idt::isr3 as u32, 0x08, 0x8E.into());
idt::IDT[4] = idt::Entry::new(idt::isr4 as u32, 0x08, 0x8E.into());
idt::IDT[5] = idt::Entry::new(idt::isr5 as u32, 0x08, 0x8E.into());
idt::IDT[6] = idt::Entry::new(idt::isr6 as u32, 0x08, 0x8E.into());
idt::IDT[7] = idt::Entry::new(idt::isr7 as u32, 0x08, 0x8E.into());
idt::IDT[8] = idt::Entry::new(idt::isr8 as u32, 0x08, 0x8E.into());
idt::IDT[9] = idt::Entry::new(idt::isr9 as u32, 0x08, 0x8E.into());
idt::IDT[10] = idt::Entry::new(idt::isr10 as u32, 0x08, 0x8E.into());
idt::IDT[11] = idt::Entry::new(idt::isr11 as u32, 0x08, 0x8E.into());
idt::IDT[12] = idt::Entry::new(idt::isr12 as u32, 0x08, 0x8E.into());
idt::IDT[13] = idt::Entry::new(idt::isr13 as u32, 0x08, 0x8E.into());
idt::IDT[14] = idt::Entry::new(idt::isr14 as u32, 0x08, 0x8E.into());
idt::IDT[15] = idt::Entry::new(idt::isr15 as u32, 0x08, 0x8E.into());
idt::IDT[16] = idt::Entry::new(idt::isr16 as u32, 0x08, 0x8E.into());
idt::IDT[17] = idt::Entry::new(idt::isr17 as u32, 0x08, 0x8E.into());
idt::IDT[18] = idt::Entry::new(idt::isr18 as u32, 0x08, 0x8E.into());
idt::IDT[19] = idt::Entry::new(idt::isr19 as u32, 0x08, 0x8E.into());
idt::IDT[20] = idt::Entry::new(idt::isr20 as u32, 0x08, 0x8E.into());
idt::IDT[21] = idt::Entry::new(idt::isr21 as u32, 0x08, 0x8E.into());
idt::IDT[22] = idt::Entry::new(idt::isr22 as u32, 0x08, 0x8E.into());
idt::IDT[23] = idt::Entry::new(idt::isr23 as u32, 0x08, 0x8E.into());
idt::IDT[24] = idt::Entry::new(idt::isr24 as u32, 0x08, 0x8E.into());
idt::IDT[25] = idt::Entry::new(idt::isr25 as u32, 0x08, 0x8E.into());
idt::IDT[26] = idt::Entry::new(idt::isr26 as u32, 0x08, 0x8E.into());
idt::IDT[27] = idt::Entry::new(idt::isr27 as u32, 0x08, 0x8E.into());
idt::IDT[28] = idt::Entry::new(idt::isr28 as u32, 0x08, 0x8E.into());
idt::IDT[29] = idt::Entry::new(idt::isr29 as u32, 0x08, 0x8E.into());
idt::IDT[30] = idt::Entry::new(idt::isr30 as u32, 0x08, 0x8E.into());
idt::IDT[31] = idt::Entry::new(idt::isr31 as u32, 0x08, 0x8E.into());
idt::idt_load();
write!(screen, "\n\nIDT");
}
}

135
src/start.S

@ -67,270 +67,263 @@ _idt_load:
lidt [_idtp]
ret
global _isr0
global _isr1
global _isr2
global _isr3
global _isr4
global _isr5
global _isr6
global _isr7
global _isr8
global _isr9
global _isr10
global _isr11
global _isr12
global _isr13
global _isr14
global _isr15
global _isr16
global _isr17
global _isr18
global _isr19
global _isr20
global _isr21
global _isr22
global _isr23
global _isr24
global _isr25
global _isr26
global _isr27
global _isr28
global _isr29
global _isr30
global _isr31
global isr0
global isr1
global isr2
global isr3
global isr4
global isr5
global isr6
global isr7
global isr8
global isr9
global isr10
global isr11
global isr12
global isr13
global isr14
global isr15
global isr16
global isr17
global isr18
global isr19
global isr20
global isr21
global isr22
global isr23
global isr24
global isr25
global isr26
global isr27
global isr28
global isr29
global isr30
global isr31
;;; 0: Divide By Zero Exception
_isr0:
isr0:
cli
push byte 0
push byte 0
jmp isr_common_stub
;;; 1: Debug Exception
_isr1:
isr1:
cli
push byte 0
push byte 1
jmp isr_common_stub
;;; 2: Non Maskable Interrupt Exception
_isr2:
isr2:
cli
push byte 0
push byte 2
jmp isr_common_stub
;;; 3: Breakpoint Exception
_isr3:
isr3:
cli
push byte 0
push byte 3
jmp isr_common_stub
;;; 4: Into Detected Overflow Exception
_isr4:
isr4:
cli
push byte 0
push byte 4
jmp isr_common_stub
;;; 5: Out of Bounds Exception
_isr5:
isr5:
cli
push byte 0
push byte 5
jmp isr_common_stub
;;; 6: Invalid Opcode Exception
_isr6:
isr6:
cli
push byte 0
push byte 6
jmp isr_common_stub
;;; 7: No Coprocessor Exception
_isr7:
isr7:
cli
push byte 0
push byte 7
jmp isr_common_stub
;;; 8: Double Fault Exception
_isr8:
isr8:
cli
;; push byte 0
push byte 10
jmp isr_common_stub
;;; 9: Coprocessor Segment Overrun Exception
_isr9:
isr9:
cli
push byte 0
push byte 9
jmp isr_common_stub
;;; 10: Bad TSS Exception
_isr10:
isr10:
cli
;; push byte 0
push byte 10
jmp isr_common_stub
;;; 11: Segment Not Present Exception
_isr11:
isr11:
cli
;; push byte 0
push byte 11
jmp isr_common_stub
;;; 12: Stack Fault Exception
_isr12:
isr12:
cli
;; push byte 0
push byte 12
jmp isr_common_stub
;;; 13: General Protection Fault Exception
_isr13:
isr13:
cli
;; push byte 0
push byte 13
jmp isr_common_stub
;;; 14: Page Fault Exception
_isr14:
isr14:
cli
;; push byte 0
push byte 14
jmp isr_common_stub
;;; 15: Unknown Interrupt Exception
_isr15:
isr15:
cli
push byte 0
push byte 15
jmp isr_common_stub
;;; 16: Coprocessor Fault Exception
_isr16:
isr16:
cli
push byte 0
push byte 16
jmp isr_common_stub
;;; 17: Alignment Check Exception (486+)
_isr17:
isr17:
cli
push byte 0
push byte 17
jmp isr_common_stub
;;; 18: Machine Check Exception (Pentium/586+)
_isr18:
isr18:
cli
push byte 0
push byte 18
jmp isr_common_stub
;;; 19: Reserved Exception
_isr19:
isr19:
cli
push byte 0
push byte 19
jmp isr_common_stub
;;; 21: Reserved Exception
_isr20:
isr20:
cli
push byte 0
push byte 20
jmp isr_common_stub
;;; 21: Reserved Exception
_isr21:
isr21:
cli
push byte 0
push byte 21
jmp isr_common_stub
;;; 22: Reserved Exception
_isr22:
isr22:
cli
push byte 0
push byte 22
jmp isr_common_stub
;;; 23: Reserved Exception
_isr23:
isr23:
cli
push byte 0
push byte 23
jmp isr_common_stub
;;; 24: Reserved Exception
_isr24:
isr24:
cli
push byte 0
push byte 24
jmp isr_common_stub
;;; 25: Reserved Exception
_isr25:
isr25:
cli
push byte 0
push byte 25
jmp isr_common_stub
;;; 26: Reserved Exception
_isr26:
isr26:
cli
push byte 0
push byte 26
jmp isr_common_stub
;;; 27: Reserved Exception
_isr27:
isr27:
cli
push byte 0
push byte 27
jmp isr_common_stub
;;; 28: Reserved Exception
_isr28:
isr28:
cli
push byte 0
push byte 28
jmp isr_common_stub
;;; 29: Reserved Exception
_isr29:
isr29:
cli
push byte 0
push byte 29
jmp isr_common_stub
;;; 30: Reserved Exception
_isr30:
isr30:
cli
push byte 0
push byte 30
jmp isr_common_stub
;;; 31: Reserved Exception
_isr31:
isr31:
cli
push byte 0
push byte 31
jmp isr_common_stub
;;; 32: Reserved Exception
_isr32:
cli
push byte 0
push byte 32
jmp isr_common_stub
;;; We call a C function in here. We need to let the assembler know
;;; that '_fault_handler' exists in another file
extern _fault_handler

Loading…
Cancel
Save