feat/kernel: Started on LAPIC
This commit is contained in:
parent
242ab03274
commit
4534f1da14
5 changed files with 63 additions and 1 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -24,7 +24,8 @@
|
|||
"lapic.h": "c",
|
||||
"spinlock.h": "c",
|
||||
"fb.h": "c",
|
||||
"acpi.h": "c"
|
||||
"acpi.h": "c",
|
||||
"madt.h": "c"
|
||||
},
|
||||
"editor.formatOnPaste": true,
|
||||
"editor.formatOnSave": true,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#define CPU_H
|
||||
|
||||
#include <stdnoreturn.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static inline noreturn void hlt()
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <arch/smp.h>
|
||||
#include <sys/acpi.h>
|
||||
#include <sys/acpi/madt.h>
|
||||
#include <sys/apic/lapic.h>
|
||||
|
||||
__attribute__((used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
||||
__attribute__((used, section(".limine_requests"))) static volatile struct limine_memmap_request memmap_request = {
|
||||
|
@ -182,6 +183,7 @@ void emk_entry(void)
|
|||
|
||||
/* Setup APIC */
|
||||
madt_init();
|
||||
lapic_init();
|
||||
|
||||
/* Finished */
|
||||
log_early("%s", LOG_SEPARATOR);
|
||||
|
|
42
kernel/src/sys/apic/lapic.c
Normal file
42
kernel/src/sys/apic/lapic.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* EMK 1.0 Copyright (c) 2025 Piraterna */
|
||||
#include <sys/apic/lapic.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <sys/acpi/madt.h>
|
||||
#include <util/log.h>
|
||||
#include <mm/vmm.h>
|
||||
#include <boot/emk.h>
|
||||
|
||||
uint64_t lapic_msr = 0;
|
||||
volatile uint64_t *lapic_base = 0;
|
||||
|
||||
void lapic_write(uint32_t offset, uint32_t value)
|
||||
{
|
||||
if (!lapic_base)
|
||||
{
|
||||
log_early("warning: LAPIC not initialized!");
|
||||
return;
|
||||
}
|
||||
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
||||
*reg = value;
|
||||
}
|
||||
|
||||
uint32_t lapic_read(uint32_t offset)
|
||||
{
|
||||
if (!lapic_base)
|
||||
{
|
||||
log_early("warning: LAPIC not initialized!");
|
||||
return 0;
|
||||
}
|
||||
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
||||
uint32_t value = *reg;
|
||||
return value;
|
||||
}
|
||||
|
||||
void lapic_init()
|
||||
{
|
||||
lapic_msr = rdmsr(LAPIC_BASE);
|
||||
lapic_base = (volatile uint64_t *)(lapic_msr & ~(0xffff));
|
||||
/* Change the lapic address that we got from MADT earlier */
|
||||
lapic_addr = (uint64_t)lapic_base;
|
||||
log_early("New LAPIC base: 0x%lx", lapic_base);
|
||||
}
|
16
kernel/src/sys/apic/lapic.h
Normal file
16
kernel/src/sys/apic/lapic.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* EMK 1.0 Copyright (c) 2025 Piraterna */
|
||||
#ifndef LAPIC_H
|
||||
#define LAPIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define LAPIC_BASE 0x1b
|
||||
#define LAPIC_REGOFF_LAPICID 0x20
|
||||
#define LAPIC_REGOFF_EOI 0xB0
|
||||
#define LAPIC_REGOFF_SPIV 0xF0
|
||||
|
||||
uint32_t lapic_read(uint32_t offset);
|
||||
void lapic_write(uint32_t offset, uint32_t value);
|
||||
void lapic_init();
|
||||
|
||||
#endif // LAPIC_H
|
Loading…
Add table
Add a link
Reference in a new issue