More ints stuff

interupts
E. Almqvist 3 years ago
parent 7cdd3157cd
commit afc74a8ec9
  1. 28
      kernel/interupt.c
  2. 5
      kernel/interupt.h
  3. 0
      kernel/isr.asm
  4. 2
      kernel/kernel.c
  5. 1
      kernel/kernel.h
  6. 3
      lib/types.h

@ -13,14 +13,10 @@ typedef struct {
uint base; uint base;
} __attribute__((packed)) idtr; } __attribute__((packed)) idtr;
void init_IDT(uint type_attr) {
__attribute__((aligned(4))) __attribute__((aligned(4)))
static idt_entry IDT[256]; static idt_entry IDT[IDT_MAX_DESCS];
static idtr IDTR; static idtr IDTR;
}
__attribute__((noreturn))
void exception_handler(void);
void exception_handler() { void exception_handler() {
__asm__ __volatile__("cli; hlt"); __asm__ __volatile__("cli; hlt");
} }
@ -30,3 +26,25 @@ void interupt_handler() {
// handle stuff // handle stuff
__asm__("popa; leave; iret"); __asm__("popa; leave; iret");
} }
void idt_set_desc(uint8 idx, void* isr, uint8 flags) {
idt_entry* desc = &IDT[idx]; // get descriptor
desc->offset_1 = (uint) isr & 0xffff;
desc->selector = 0x05; // kernel code selector for the GDT (null is 0x0 - 0x4 => code is 0x05 to something...)
desc->reserved = 0;
desc->type_attr = flags;
desc->offset_2 = (uint) isr >> 16;
}
extern void* isr_stub_table[];
void idt_init() {
IDTR.base = (uintptr) &IDT[0]; // base offset
IDTR.limit = (uint16) sizeof(idt_entry) * IDT_MAX_DESCS - 1;
for (uint8 idx = 0; idx < 32; idx++)
idt_set_desc(idx, isr_stub_table[idx], 0x8e);
__asm__ __volatile__("lidt %0" : : "m"(IDTR));
__asm__ __volatile__("sti");
}

@ -1,7 +1,12 @@
#include "../lib/types.h" #include "../lib/types.h"
#define IDT_MAX_DESCS 256
__attribute__((noreturn)) __attribute__((noreturn))
void exception_handler(); void exception_handler();
__attribute__((noreturn)) __attribute__((noreturn))
void interupt_handler(); void interupt_handler();
void idt_set_desc(uint8, void*, uint8);
void idt_init();

@ -60,6 +60,8 @@ void print_kernel_stats() {
} }
void kernel_init() { void kernel_init() {
idt_init(); // Enable interupts
vga_init(); // Initialize the screen first vga_init(); // Initialize the screen first
// i.e. clear the screen et cetera. // i.e. clear the screen et cetera.

@ -1,3 +1,4 @@
#include "interupt.h"
#include "memory.h" #include "memory.h"
#include "paging.h" #include "paging.h"
#include "../drivers/vga.h" #include "../drivers/vga.h"

@ -10,8 +10,9 @@ typedef unsigned char uint8;
typedef short int int16; typedef short int int16;
typedef unsigned short int uint16; typedef unsigned short int uint16;
// MISC // POINTERS
typedef char* pointer; typedef char* pointer;
typedef unsigned long int uintptr;
// BOOL // BOOL
typedef int bool; typedef int bool;

Loading…
Cancel
Save