Implemented IDT

This commit is contained in:
Arnau Camprubí 2022-06-18 00:44:37 +02:00
pare 2160a41e81
commit 29093837a3
S'han modificat 7 arxius amb 97 adicions i 1 eliminacions

Veure arxiu

@ -0,0 +1,16 @@
[bits 32]
global i686_idt_load
i686_idt_load:
; New call frame
push ebp
mov ebp, esp
; Load IDT
mov eax, [ebp + 8]
lidt [eax]
; Restore call frame
mov esp, ebp
pop ebp
ret

Veure arxiu

@ -0,0 +1,41 @@
#include "idt.h"
#include "../../util/binary.h"
typedef struct{
uint16_t base_low;
uint16_t segment_selector;
uint8_t reserved;
uint8_t flags;
uint16_t base_high;
} idt_entry;
typedef struct{
uint16_t limit;
idt_entry *ptr;
} idt_descriptor;
idt_entry g_idt[256];
idt_descriptor g_idt_descriptor = {sizeof(g_idt) - 1, g_idt};
void __attribute__((cdecl)) i686_idt_load(idt_descriptor *descriptor);
void i686_idt_set_gate(int interrupt, void *base, uint16_t segment_descriptor, uint8_t flags){
g_idt[interrupt].base_low = ((uint32_t)base) & 0xFFFF;
g_idt[interrupt].segment_selector = segment_descriptor;
g_idt[interrupt].reserved = 0;
g_idt[interrupt].flags = flags;
g_idt[interrupt].base_high = ((uint32_t)base >> 16) & 0xFFFF;
}
void i686_idt_enable_gate(int interrupt){
FLAG_SET(g_idt[interrupt].flags, IDT_FLAG_PRESENT);
}
void i686_idt_disable_gate(int interrupt){
FLAG_UNSET(g_idt[interrupt].flags, IDT_FLAG_PRESENT);
}
void i686_idt_initialize(){
i686_idt_load(&g_idt_descriptor);
}

Veure arxiu

@ -0,0 +1,23 @@
#pragma once
#include <stdint.h>
typedef enum{
IDT_FLAG_GATE_TASK = 0x5,
IDT_FLAG_GATE_16BIT_INT = 0x6,
IDT_FLAG_GATE_16BIT_TRAP = 0x7,
IDT_FLAG_GATE_32BIT_INT = 0xE,
IDT_FLAG_GATE_32BIT_TRAP = 0xF,
IDT_FLAG_RING0 = (0 << 5),
IDT_FLAG_RING1 = (1 << 5),
IDT_FLAG_RING2 = (2 << 5),
IDT_FLAG_RING3 = (3 << 5),
IDT_FLAG_PRESENT = 0x80,
} idt_flags;
void i686_idt_initialize();
void i686_idt_enable_gate(int interrupt);
void i686_idt_disable_gate(int interrupt);
void i686_idt_set_gate(int interrupt, void *base, uint16_t segment_descriptor, uint8_t flags);

6
src/kernel/hal/hal.c Normal file
Veure arxiu

@ -0,0 +1,6 @@
#include "hal.h"
#include "../arch/i686/idt.h"
void hal_initialize(){
i686_idt_initialize();
}

3
src/kernel/hal/hal.h Normal file
Veure arxiu

@ -0,0 +1,3 @@
#pragma once
void hal_initialize();

Veure arxiu

@ -1,9 +1,12 @@
#include <stdint.h>
#include "stdio.h"
#include "hal/hal.h"
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
hal_initialize();
puts("\x1b[33mWARNING\x1b[0m");
printf(": amazing %s ahead!\n", "math");
printf("%i+%i=%i\n", 1, 1, 2);
for(;;); // Halt here
for(;;); // Halt here
}

4
src/kernel/util/binary.h Normal file
Veure arxiu

@ -0,0 +1,4 @@
#pragma once
#define FLAG_SET(x, flag) (x) |= (flag)
#define FLAG_UNSET(x, flag) (x) &= ~(flag)