pic: enable legacy pic serial interrupts
This commit is contained in:
parent
667d01e418
commit
9a4ff385bd
12 changed files with 201 additions and 33 deletions
78
dev/apic.c
78
dev/apic.c
|
|
@ -1,5 +1,3 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
||||||
#include <kernel/common.h>
|
|
||||||
#include <kernel/acpi.h>
|
#include <kernel/acpi.h>
|
||||||
#include <kernel/mem.h>
|
#include <kernel/mem.h>
|
||||||
#include <dev/apic.h>
|
#include <dev/apic.h>
|
||||||
|
|
@ -9,25 +7,59 @@
|
||||||
|
|
||||||
static void *madt_entries[0x20];
|
static void *madt_entries[0x20];
|
||||||
static int n_madt_entries = 0;
|
static int n_madt_entries = 0;
|
||||||
|
|
||||||
static uintptr_t ioapic_addr = 0;
|
static uintptr_t ioapic_addr = 0;
|
||||||
|
static uintptr_t lapic_addr = 0;
|
||||||
|
static uint8_t lapic_id = 0;
|
||||||
|
|
||||||
static const char *madt_entry_types[] = {
|
static const char *madt_entry_types[] = {
|
||||||
"LAPIC", "IOAPIC", "IOAPIC_IRQ_SRC_OVRD", "IOAPIC_NMI_SRC", "LAPIC_NMI", "LAPIC_ADDR_OVRD", "INVALID",
|
"LAPIC", "IOAPIC", "IOAPIC_IRQ_SRC_OVRD", "IOAPIC_NMI_SRC", "LAPIC_NMI", "LAPIC_ADDR_OVRD", "INVALID",
|
||||||
"INVALID", "INVALID", "CPU_LOCAL_X2_APIC"
|
"INVALID", "INVALID", "CPU_LOCAL_X2_APIC"
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t ioapic_read(uintptr_t addr, uint8_t reg)
|
inline uint32_t ioapic_read(uintptr_t addr, uint8_t reg)
|
||||||
{
|
{
|
||||||
*(volatile uint32_t *)(addr) = reg;
|
*(volatile uint32_t *)(addr) = reg;
|
||||||
return *(volatile uint32_t *)(addr + 0x10);
|
return *(volatile uint32_t *)(addr + 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioapic_write(uintptr_t addr, uint8_t reg, uint32_t value)
|
inline void ioapic_write(uintptr_t addr, uint8_t reg, uint32_t value)
|
||||||
{
|
{
|
||||||
*(volatile uint32_t *)(addr) = reg;
|
*(volatile uint32_t *)(addr) = reg;
|
||||||
*(volatile uint32_t *)(addr + 0x10) = value;
|
*(volatile uint32_t *)(addr + 0x10) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ioapic_redirect_insert(uint8_t irq, uint8_t isr, uint8_t low_active, uint8_t level_trigger)
|
||||||
|
{
|
||||||
|
int entryno = 0x10 + irq * 2;
|
||||||
|
struct apic_redirect entry;
|
||||||
|
entry.isr = isr;
|
||||||
|
entry.delv_mode = 0;
|
||||||
|
entry.dest_mode = 0;
|
||||||
|
entry.polarity = low_active;
|
||||||
|
entry.trigger = level_trigger;
|
||||||
|
entry.mask = 0;
|
||||||
|
entry.dest = lapic_id;
|
||||||
|
|
||||||
|
ioapic_write(ioapic_addr, entryno, entry.low);
|
||||||
|
ioapic_write(ioapic_addr, entryno + 1, entry.high);
|
||||||
|
|
||||||
|
entryno += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint32_t lapic_read(uintptr_t addr, unsigned int regoffset)
|
||||||
|
{
|
||||||
|
volatile uint32_t *lapic = (volatile uint32_t *)addr;
|
||||||
|
return lapic[regoffset >> 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint32_t lapic_write(uintptr_t addr, unsigned int regoffset, uint32_t value)
|
||||||
|
{
|
||||||
|
volatile uint32_t *lapic = (volatile uint32_t *)addr;
|
||||||
|
lapic[regoffset >> 2] = value;
|
||||||
|
return lapic[regoffset >> 2];
|
||||||
|
}
|
||||||
|
|
||||||
int madt_parse_next_entry(int offset)
|
int madt_parse_next_entry(int offset)
|
||||||
{
|
{
|
||||||
if ((unsigned)offset >= (__madt->h.length - 1))
|
if ((unsigned)offset >= (__madt->h.length - 1))
|
||||||
|
|
@ -41,9 +73,12 @@ int madt_parse_next_entry(int offset)
|
||||||
|
|
||||||
/* Can't declare variables inside switch statement */
|
/* Can't declare variables inside switch statement */
|
||||||
struct madt_ioapic *m_ioapic = (struct madt_ioapic *)madt;
|
struct madt_ioapic *m_ioapic = (struct madt_ioapic *)madt;
|
||||||
|
struct madt_lapic *m_lapic = (struct madt_lapic *)madt;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MADT_LAPIC:
|
case MADT_LAPIC:
|
||||||
|
lapic_id = m_lapic->apic_id;
|
||||||
|
printf(LOG_INFO "LAPIC ID: %xh\n", m_lapic->apic_id);
|
||||||
break;
|
break;
|
||||||
case MADT_IOAPIC:
|
case MADT_IOAPIC:
|
||||||
ioapic_addr = m_ioapic->ioapic_addr;
|
ioapic_addr = m_ioapic->ioapic_addr;
|
||||||
|
|
@ -71,24 +106,41 @@ int madt_parse_next_entry(int offset)
|
||||||
return offset + len;
|
return offset + len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apic_eoi()
|
||||||
|
{
|
||||||
|
lapic_write(lapic_addr, 0xB0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void apic_init()
|
void apic_init()
|
||||||
{
|
{
|
||||||
if (__madt == NULL) {
|
if (__madt == NULL) {
|
||||||
printf(LOG_WARN "Failed to locate MADT\n");
|
printf(LOG_WARN "Failed to locate MADT\n");
|
||||||
} else {
|
return;
|
||||||
/* First variable entry in MADT */
|
|
||||||
int offset = 0x2C;
|
|
||||||
int length = __madt->h.length;
|
|
||||||
printf(LOG_INFO "MADT Length: %x\n", length);
|
|
||||||
|
|
||||||
while ((offset = madt_parse_next_entry(offset)))
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ioapic_addr += hhdm_start;
|
int offset = 0x2C;
|
||||||
|
int length = __madt->h.length;
|
||||||
|
printf(LOG_INFO "MADT Length: %x\n", length);
|
||||||
|
|
||||||
|
while ((offset = madt_parse_next_entry(offset)))
|
||||||
|
;
|
||||||
|
|
||||||
|
lapic_addr = __madt->lapic_addr;
|
||||||
|
|
||||||
printf(LOG_INFO "IOAPIC ADDR: %X\n", ioapic_addr);
|
printf(LOG_INFO "IOAPIC ADDR: %X\n", ioapic_addr);
|
||||||
|
printf(LOG_INFO "LAPIC ADDR : %X\n", lapic_addr);
|
||||||
|
|
||||||
|
uint32_t r = ioapic_read(ioapic_addr, 0);
|
||||||
|
r |= 0x04000000;
|
||||||
|
|
||||||
|
ioapic_write(ioapic_addr, 0, r);
|
||||||
|
printf(LOG_WARN "IOAPIC ID:%x\n", r);
|
||||||
|
|
||||||
|
printf(LOG_WARN "LAPIC_ID:%xh\n", lapic_id);
|
||||||
|
ioapic_redirect_insert(4, 0x21, 0, 0);
|
||||||
|
/* Set spurious interrupt vector to 0xFF and enable the LAPIC */
|
||||||
|
lapic_id = lapic_write(lapic_addr, 0xF0, 0x1FF);
|
||||||
|
printf(LOG_WARN "%x\n", lapic_id);
|
||||||
|
|
||||||
printf(LOG_SUCCESS "APIC initialized\n");
|
printf(LOG_SUCCESS "APIC initialized\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ int serial_init()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outb(COM1 | 1, 0x01); /* Enable interrupts */
|
||||||
outb(COM1 | 4, 0x0F); /* Enter normal operation */
|
outb(COM1 | 4, 0x0F); /* Enter normal operation */
|
||||||
printf(LOG_SUCCESS "Serial COM1 initialized\n");
|
printf(LOG_SUCCESS "Serial COM1 initialized\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -36,3 +37,11 @@ void serial_write(char c)
|
||||||
|
|
||||||
outb(COM1, c);
|
outb(COM1, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serial_trap()
|
||||||
|
{
|
||||||
|
while ((inb(COM1 | 5) & 0x01) == 0)
|
||||||
|
;
|
||||||
|
char c = inb(COM1);
|
||||||
|
printf("%c", c);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ struct madt_x2_lapic {
|
||||||
struct apic_redirect {
|
struct apic_redirect {
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint64_t vector : 8;
|
uint64_t isr : 8;
|
||||||
uint64_t delv_mode : 3;
|
uint64_t delv_mode : 3;
|
||||||
uint64_t dest_mode : 1;
|
uint64_t dest_mode : 1;
|
||||||
uint64_t delv_status : 1;
|
uint64_t delv_status : 1;
|
||||||
|
|
@ -118,16 +118,20 @@ struct apic_redirect {
|
||||||
uint64_t mask : 1;
|
uint64_t mask : 1;
|
||||||
uint64_t reserved : 39;
|
uint64_t reserved : 39;
|
||||||
uint64_t dest : 8;
|
uint64_t dest : 8;
|
||||||
};
|
} PACKED;
|
||||||
struct {
|
struct {
|
||||||
uint32_t low;
|
uint32_t low;
|
||||||
uint32_t high;
|
uint32_t high;
|
||||||
};
|
} PACKED;
|
||||||
};
|
};
|
||||||
} PACKED;
|
} PACKED;
|
||||||
|
|
||||||
void apic_init();
|
void apic_init();
|
||||||
int madt_parse_next_entry(int offset);
|
int madt_parse_next_entry(int offset);
|
||||||
|
uint32_t ioapic_read(uintptr_t addr, uint8_t reg);
|
||||||
|
void ioapic_write(uintptr_t addr, uint8_t reg, uint32_t value);
|
||||||
|
uint32_t lapic_read(uintptr_t addr, unsigned int regoffset);
|
||||||
|
uint32_t lapic_write(uintptr_t addr, unsigned int regoffset, uint32_t value);
|
||||||
|
|
||||||
#endif /* __ASM__ */
|
#endif /* __ASM__ */
|
||||||
#endif /* _APIC_H_ */
|
#endif /* _APIC_H_ */
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,13 @@
|
||||||
|
|
||||||
#define COM1 0x3F8
|
#define COM1 0x3F8
|
||||||
|
|
||||||
|
#ifndef __ASM__
|
||||||
|
|
||||||
|
void isr_serial_input();
|
||||||
|
void isr_serial_input_1();
|
||||||
void serial_write(char c);
|
void serial_write(char c);
|
||||||
int serial_init();
|
int serial_init();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _SERIAL_H_ */
|
#endif /* _SERIAL_H_ */
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,11 @@
|
||||||
#define GDT_ACCESS_DATA_RING3 0b11110010
|
#define GDT_ACCESS_DATA_RING3 0b11110010
|
||||||
#define GDT_ACCESS_CODE_RING3 0b11111010
|
#define GDT_ACCESS_CODE_RING3 0b11111010
|
||||||
|
|
||||||
|
#define GDT_SEGMENT_CODE_RING0 0x28
|
||||||
|
|
||||||
#ifndef __ASM__
|
#ifndef __ASM__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <kernel/common.h>
|
||||||
|
|
||||||
struct gdt_desc {
|
struct gdt_desc {
|
||||||
uint16_t limit;
|
uint16_t limit;
|
||||||
|
|
@ -22,12 +24,12 @@ struct gdt_desc {
|
||||||
uint8_t access;
|
uint8_t access;
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
uint8_t base_3;
|
uint8_t base_3;
|
||||||
};
|
} PACKED;
|
||||||
|
|
||||||
struct gdtr {
|
struct gdtr {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
};
|
} PACKED;
|
||||||
|
|
||||||
extern struct gdtr __gdtr;
|
extern struct gdtr __gdtr;
|
||||||
extern struct gdt_desc __gdt[GDT_NUMDESC];
|
extern struct gdt_desc __gdt[GDT_NUMDESC];
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#ifndef __ASM__
|
#ifndef __ASM__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <kernel/common.h>
|
||||||
|
|
||||||
struct irqdesc {
|
struct irqdesc {
|
||||||
uint16_t offset_low;
|
uint16_t offset_low;
|
||||||
|
|
@ -21,14 +21,16 @@ struct irqdesc {
|
||||||
uint16_t offset_mid;
|
uint16_t offset_mid;
|
||||||
uint32_t offset_high;
|
uint32_t offset_high;
|
||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
};
|
} PACKED;
|
||||||
|
|
||||||
struct idtr {
|
struct idtr {
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
};
|
} PACKED;
|
||||||
|
|
||||||
void idt_init();
|
void idt_init();
|
||||||
|
void cli();
|
||||||
|
void sti();
|
||||||
|
|
||||||
extern struct idtr __idtr;
|
extern struct idtr __idtr;
|
||||||
extern struct irqdesc __idt[IDT_NUM_VECTORS];
|
extern struct irqdesc __idt[IDT_NUM_VECTORS];
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,9 @@ static inline uint8_t inb(uint16_t port)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void iowait()
|
||||||
|
{
|
||||||
|
outb(0x80, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _PIO_H_ */
|
#endif /* _PIO_H_ */
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ __idt:
|
||||||
|
|
||||||
.global gdt_load
|
.global gdt_load
|
||||||
gdt_load:
|
gdt_load:
|
||||||
lgdt (__gdtr)
|
lgdt __gdtr
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.global idt_load
|
.global idt_load
|
||||||
idt_load:
|
idt_load:
|
||||||
lidt (__idtr)
|
lidt __idtr
|
||||||
ret
|
ret
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,14 @@ void gdt_init()
|
||||||
gdt_insert(0, 0, 0);
|
gdt_insert(0, 0, 0);
|
||||||
gdt_insert(1, GDT_ACCESS_CODE_RING0, 0xA0);
|
gdt_insert(1, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||||
gdt_insert(2, GDT_ACCESS_DATA_RING0, 0xC0);
|
gdt_insert(2, GDT_ACCESS_DATA_RING0, 0xC0);
|
||||||
gdt_insert(3, GDT_ACCESS_CODE_RING3, 0xA0);
|
gdt_insert(3, GDT_ACCESS_CODE_RING0, 0xA0);
|
||||||
gdt_insert(4, GDT_ACCESS_DATA_RING3, 0xC0);
|
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.size = (sizeof(__gdt) - 1);
|
||||||
__gdtr.offset = (uint64_t)__gdt;
|
__gdtr.offset = (uint64_t)__gdt;
|
||||||
|
|
||||||
gdt_load();
|
gdt_load();
|
||||||
|
|
||||||
printf(LOG_SUCCESS "GDT initialized\n");
|
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 */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
#include <kernel/common.h>
|
||||||
|
#include <kernel/gdt.h>
|
||||||
#include <kernel/idt.h>
|
#include <kernel/idt.h>
|
||||||
|
#include <dev/serial.h>
|
||||||
#include <stdio.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,
|
exception_decl(0x00);
|
||||||
void *func)
|
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);
|
uintptr_t f = (uintptr_t)(func);
|
||||||
struct irqdesc *irqdesc = (__idt + gate);
|
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()
|
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.size = (IDT_SIZE - 1);
|
||||||
__idtr.offset = (uint64_t)__idt;
|
__idtr.offset = (uint64_t)__idt;
|
||||||
idt_load();
|
idt_load();
|
||||||
|
|
|
||||||
13
init/main.c
13
init/main.c
|
|
@ -5,7 +5,7 @@
|
||||||
#include <kernel/idt.h>
|
#include <kernel/idt.h>
|
||||||
#include <kernel/mem.h>
|
#include <kernel/mem.h>
|
||||||
|
|
||||||
#include <dev/apic.h>
|
#include <dev/pic.h>
|
||||||
#include <dev/serial.h>
|
#include <dev/serial.h>
|
||||||
|
|
||||||
#include <limine/limine.h>
|
#include <limine/limine.h>
|
||||||
|
|
@ -31,17 +31,22 @@ void kmain(void)
|
||||||
bss_start = (uintptr_t)(&__bss_start);
|
bss_start = (uintptr_t)(&__bss_start);
|
||||||
bss_end = (uintptr_t)(&__bss_end);
|
bss_end = (uintptr_t)(&__bss_end);
|
||||||
|
|
||||||
serial_init();
|
|
||||||
gdt_init();
|
gdt_init();
|
||||||
idt_init();
|
idt_init();
|
||||||
|
|
||||||
|
serial_init();
|
||||||
|
|
||||||
/* Initialize early kernel memory array */
|
/* Initialize early kernel memory array */
|
||||||
const uintptr_t one_gb = 0x40000000;
|
const uintptr_t one_gb = 0x40000000;
|
||||||
char kmem[one_gb] ALIGN(0x1000);
|
char kmem[one_gb] ALIGN(0x1000);
|
||||||
mem_early_init(kmem, one_gb);
|
mem_early_init(kmem, one_gb);
|
||||||
|
|
||||||
acpi_init();
|
cli();
|
||||||
apic_init();
|
pic_mask(4, 0);
|
||||||
|
pic_init();
|
||||||
|
sti();
|
||||||
|
|
||||||
|
printf("# ");
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ void mem_early_init(char *mem, size_t len)
|
||||||
|
|
||||||
kmap(kpaddr, kvaddr, kernel_size, attrs.val);
|
kmap(kpaddr, kvaddr, kernel_size, attrs.val);
|
||||||
kmap(0x0000, hhdm_start, 0x100000000, attrs.val);
|
kmap(0x0000, hhdm_start, 0x100000000, attrs.val);
|
||||||
kmap(0x1000, 0x1000, 0x100000000, attrs.val);
|
kmap(0x0000, 0x0000, 0x100000000, attrs.val);
|
||||||
|
|
||||||
uintptr_t pml4_paddr = (uintptr_t)pml4;
|
uintptr_t pml4_paddr = (uintptr_t)pml4;
|
||||||
pml4_paddr -= hhdm_start;
|
pml4_paddr -= hhdm_start;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue