diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:28:04 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-12 10:28:04 +0200 |
| commit | 457a2117706cdaee34f894e67c89da7bf29f6143 (patch) | |
| tree | e3a1a519c5360abcca95732500594c92af9af51c /src/core/idt.c | |
| parent | 39713a3736145483dd3310c3605f940ca34f05c3 (diff) | |
Refactoring
Diffstat (limited to 'src/core/idt.c')
| -rw-r--r-- | src/core/idt.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/idt.c b/src/core/idt.c new file mode 100644 index 0000000..4e08d62 --- /dev/null +++ b/src/core/idt.c @@ -0,0 +1,39 @@ +#include "idt.h" + +struct IDT_REGISTER IDTR={ + 8*IDT_MAX_ENTRY, + 0x0 +}; + +// Interrupt functions (cf int.S) +extern u32 +INT_DEFAULT, +INT_PAGE_FAULT, +INT_CLOCK, +INT_KEYPRESS, +INT_SYSCALL; + + +void idt_init(){ + // Map first default 32 entries + for(int i=0;i<IDT_MAX_ENTRY;i++){ + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_DEFAULT,IDT_INT_GATE},i); + if(i==14) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_PAGE_FAULT,IDT_INT_GATE},i); + if(i==32) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_CLOCK,IDT_INT_GATE},i); + if(i==33) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_KEYPRESS,IDT_INT_GATE},i); + if(i==48) + idt_write_entry((IDT_ENTRY){0x08,(u32)&INT_SYSCALL,IDT_TRAP_GATE},i); + } + // Load IDT + asm("lidtl (IDTR)"); +} + +void idt_write_entry(IDT_ENTRY entry, int id){ + int descriptor[2]; + descriptor[0]=entry.offset & 0xFFFF | entry.segment << 16; + descriptor[1]=entry.type & 0xFFFF | entry.offset & 0xFFFF0000; + memcpy((void*)descriptor, (void *)(IDTR.base+(id*8)),8); +}
\ No newline at end of file |
