pic: enable legacy pic serial interrupts
This commit is contained in:
parent
667d01e418
commit
9a4ff385bd
12 changed files with 201 additions and 33 deletions
|
|
@ -31,10 +31,10 @@ __idt:
|
|||
|
||||
.global gdt_load
|
||||
gdt_load:
|
||||
lgdt (__gdtr)
|
||||
lgdt __gdtr
|
||||
ret
|
||||
|
||||
.global idt_load
|
||||
idt_load:
|
||||
lidt (__idtr)
|
||||
lidt __idtr
|
||||
ret
|
||||
|
|
|
|||
|
|
@ -23,10 +23,14 @@ void gdt_init()
|
|||
gdt_insert(0, 0, 0);
|
||||
gdt_insert(1, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(2, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(3, GDT_ACCESS_CODE_RING3, 0xA0);
|
||||
gdt_insert(4, GDT_ACCESS_DATA_RING3, 0xC0);
|
||||
gdt_insert(3, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(4, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
gdt_insert(5, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||
gdt_insert(6, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||
|
||||
__gdtr.size = (sizeof(__gdt) - 1);
|
||||
__gdtr.offset = (uint64_t)__gdt;
|
||||
|
||||
gdt_load();
|
||||
|
||||
printf(LOG_SUCCESS "GDT initialized\n");
|
||||
|
|
|
|||
85
init/idt.c
85
init/idt.c
|
|
@ -1,11 +1,55 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/gdt.h>
|
||||
#include <kernel/idt.h>
|
||||
#include <dev/serial.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void idt_load();
|
||||
#define exception(_i) _exception_##_i
|
||||
#define exception_decl(_j) void exception(_j)()
|
||||
|
||||
void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment,
|
||||
void *func)
|
||||
exception_decl(0x00);
|
||||
exception_decl(0x01);
|
||||
exception_decl(0x02);
|
||||
exception_decl(0x03);
|
||||
exception_decl(0x04);
|
||||
exception_decl(0x05);
|
||||
exception_decl(0x06);
|
||||
exception_decl(0x07);
|
||||
exception_decl(0x08);
|
||||
exception_decl(0x09);
|
||||
exception_decl(0x0A);
|
||||
exception_decl(0x0B);
|
||||
exception_decl(0x0C);
|
||||
exception_decl(0x0D);
|
||||
exception_decl(0x0E);
|
||||
exception_decl(0x0F);
|
||||
exception_decl(0x10);
|
||||
exception_decl(0x11);
|
||||
exception_decl(0x12);
|
||||
exception_decl(0x13);
|
||||
exception_decl(0x14);
|
||||
exception_decl(0x15);
|
||||
exception_decl(0x16);
|
||||
exception_decl(0x17);
|
||||
exception_decl(0x18);
|
||||
exception_decl(0x19);
|
||||
exception_decl(0x1A);
|
||||
exception_decl(0x1B);
|
||||
exception_decl(0x1C);
|
||||
exception_decl(0x1D);
|
||||
exception_decl(0x1E);
|
||||
exception_decl(0x1F);
|
||||
|
||||
void idt_load();
|
||||
void isr_sched();
|
||||
|
||||
void sched_test()
|
||||
{
|
||||
printf("a");
|
||||
}
|
||||
|
||||
void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment, void *func)
|
||||
{
|
||||
uintptr_t f = (uintptr_t)(func);
|
||||
struct irqdesc *irqdesc = (__idt + gate);
|
||||
|
|
@ -20,6 +64,41 @@ void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment,
|
|||
|
||||
void idt_init()
|
||||
{
|
||||
idt_insert(0x00, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x00));
|
||||
idt_insert(0x01, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x01));
|
||||
idt_insert(0x02, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x02));
|
||||
idt_insert(0x03, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x03));
|
||||
idt_insert(0x04, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x04));
|
||||
idt_insert(0x05, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x05));
|
||||
idt_insert(0x06, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x06));
|
||||
idt_insert(0x07, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x07));
|
||||
idt_insert(0x08, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x08));
|
||||
idt_insert(0x09, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x09));
|
||||
idt_insert(0x0A, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0A));
|
||||
idt_insert(0x0B, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0B));
|
||||
idt_insert(0x0C, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0C));
|
||||
idt_insert(0x0D, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0D));
|
||||
idt_insert(0x0E, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0E));
|
||||
idt_insert(0x0F, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x0F));
|
||||
idt_insert(0x10, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x10));
|
||||
idt_insert(0x11, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x11));
|
||||
idt_insert(0x12, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x12));
|
||||
idt_insert(0x13, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x13));
|
||||
idt_insert(0x14, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x14));
|
||||
idt_insert(0x15, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x15));
|
||||
idt_insert(0x16, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x16));
|
||||
idt_insert(0x17, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x17));
|
||||
idt_insert(0x18, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x18));
|
||||
idt_insert(0x19, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x19));
|
||||
idt_insert(0x1A, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1A));
|
||||
idt_insert(0x1B, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1B));
|
||||
idt_insert(0x1C, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1C));
|
||||
idt_insert(0x1D, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1D));
|
||||
idt_insert(0x1E, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1E));
|
||||
idt_insert(0x1F, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1F));
|
||||
|
||||
idt_insert(0x24, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, isr_serial_input);
|
||||
|
||||
__idtr.size = (IDT_SIZE - 1);
|
||||
__idtr.offset = (uint64_t)__idt;
|
||||
idt_load();
|
||||
|
|
|
|||
13
init/main.c
13
init/main.c
|
|
@ -5,7 +5,7 @@
|
|||
#include <kernel/idt.h>
|
||||
#include <kernel/mem.h>
|
||||
|
||||
#include <dev/apic.h>
|
||||
#include <dev/pic.h>
|
||||
#include <dev/serial.h>
|
||||
|
||||
#include <limine/limine.h>
|
||||
|
|
@ -31,17 +31,22 @@ void kmain(void)
|
|||
bss_start = (uintptr_t)(&__bss_start);
|
||||
bss_end = (uintptr_t)(&__bss_end);
|
||||
|
||||
serial_init();
|
||||
gdt_init();
|
||||
idt_init();
|
||||
|
||||
serial_init();
|
||||
|
||||
/* Initialize early kernel memory array */
|
||||
const uintptr_t one_gb = 0x40000000;
|
||||
char kmem[one_gb] ALIGN(0x1000);
|
||||
mem_early_init(kmem, one_gb);
|
||||
|
||||
acpi_init();
|
||||
apic_init();
|
||||
cli();
|
||||
pic_mask(4, 0);
|
||||
pic_init();
|
||||
sti();
|
||||
|
||||
printf("# ");
|
||||
|
||||
done();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue