Init IDT
This commit is contained in:
@ -55,7 +55,7 @@ static uint64_t gdt_curretbase(void) {
|
||||
return gdtr.base;
|
||||
}
|
||||
|
||||
void gdt_setenty(GdtEntry *entry, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
|
||||
void gdt_setentry(GdtEntry *entry, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran) {
|
||||
entry->baselow = base & 0xffff;
|
||||
entry->basemid = (base >> 16) & 0xff;
|
||||
entry->basehigh = (base >> 24) & 0xff;
|
||||
@ -74,7 +74,7 @@ void gdt_init(void) {
|
||||
uint64_t tss_base = (uint64_t)&tss;
|
||||
uint32_t tss_limit = sizeof(tss) - 1;
|
||||
|
||||
gdt_setenty(&curgdt->tsslow, tss_base & 0xFFFFFFFF, tss_limit, GDT_PRESENT | GDT_TSS, 0x0);
|
||||
gdt_setentry(&curgdt->tsslow, tss_base & 0xFFFFFFFF, tss_limit, GDT_PRESENT | GDT_TSS, 0x0);
|
||||
|
||||
GdtEntry *tsshigh = &curgdt->tsshigh;
|
||||
tsshigh->baselow = (tss_base >> 32) & 0xffff;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "kprintf.h"
|
||||
#include "serial.h"
|
||||
#include "gdt.h"
|
||||
#include "idt.h"
|
||||
|
||||
void hal_init(void) {
|
||||
if (!serial_init()) {
|
||||
@ -11,6 +12,7 @@ void hal_init(void) {
|
||||
}
|
||||
LOG("hal", "serial init\n");
|
||||
gdt_init();
|
||||
idt_init();
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void hal_hang(void) {
|
||||
|
25
kernel/hal/x86_64/idt.c
Normal file
25
kernel/hal/x86_64/idt.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdint.h>
|
||||
#include "idt.h"
|
||||
#include "kprintf.h"
|
||||
|
||||
#define ENTRIES 256
|
||||
static IdtGate idtgates[ENTRIES] = {0};
|
||||
static Idt idt;
|
||||
|
||||
void idt_setgate(int i, uint64_t handler, uint8_t flags) {
|
||||
idtgates[i].isrlow = (uint16_t)handler;
|
||||
idtgates[i].kernelcs = 40;
|
||||
idtgates[i].ist = 0;
|
||||
idtgates[i].resv = 0;
|
||||
idtgates[i].attrs = flags;
|
||||
idtgates[i].isrmid = (uint16_t)(handler >> 16);
|
||||
idtgates[i].isrhigh = (uint16_t)(handler >> 32);
|
||||
}
|
||||
|
||||
void idt_init(void) {
|
||||
idt.base = (uint64_t)&idtgates;
|
||||
idt.limit = ENTRIES * sizeof(IdtGate) - 1;
|
||||
asm volatile("lidt %0" :: "m"(idt) : "memory");
|
||||
|
||||
LOG("idt", "idt init\n");
|
||||
}
|
24
kernel/hal/x86_64/idt.h
Normal file
24
kernel/hal/x86_64/idt.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef HAL_IDT_H_
|
||||
#define HAL_IDT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "compiler/attr.h"
|
||||
|
||||
typedef struct {
|
||||
uint16_t isrlow;
|
||||
uint16_t kernelcs;
|
||||
uint8_t ist;
|
||||
uint8_t attrs;
|
||||
uint16_t isrmid;
|
||||
uint32_t isrhigh;
|
||||
uint32_t resv;
|
||||
} PACKED IdtGate;
|
||||
|
||||
typedef struct {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} PACKED Idt;
|
||||
|
||||
void idt_init(void);
|
||||
|
||||
#endif // HAL_IDT_H_
|
Reference in New Issue
Block a user