feat: idek
This commit is contained in:
parent
4534f1da14
commit
93d09b1930
4 changed files with 21 additions and 21 deletions
|
@ -238,7 +238,7 @@ void paging_init(void)
|
||||||
vmap(kernel_pagemap, addr, phys, VMM_PRESENT | VMM_WRITE | VMM_NX);
|
vmap(kernel_pagemap, addr, phys, VMM_PRESENT | VMM_WRITE | VMM_NX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map physical memory */
|
/* Map physical memory */
|
||||||
for (uint64_t i = 0; i < memmap->entry_count; i++)
|
for (uint64_t i = 0; i < memmap->entry_count; i++)
|
||||||
{
|
{
|
||||||
if (!memmap->entries[i]->base || !memmap->entries[i]->length)
|
if (!memmap->entries[i]->base || !memmap->entries[i]->length)
|
||||||
|
|
|
@ -100,15 +100,6 @@ void emk_entry(void)
|
||||||
gdt_init();
|
gdt_init();
|
||||||
idt_init();
|
idt_init();
|
||||||
|
|
||||||
/* Setup SMP */
|
|
||||||
if (!mp_request.response)
|
|
||||||
{
|
|
||||||
kpanic(NULL, "Failed to get MP request");
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_response = mp_request.response;
|
|
||||||
smp_init();
|
|
||||||
|
|
||||||
/* Setup physical memory*/
|
/* Setup physical memory*/
|
||||||
if (!hhdm_request.response)
|
if (!hhdm_request.response)
|
||||||
{
|
{
|
||||||
|
@ -169,6 +160,15 @@ void emk_entry(void)
|
||||||
*c = 32;
|
*c = 32;
|
||||||
kfree(c);
|
kfree(c);
|
||||||
|
|
||||||
|
/* Setup SMP */
|
||||||
|
if (!mp_request.response)
|
||||||
|
{
|
||||||
|
kpanic(NULL, "Failed to get MP request");
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_response = mp_request.response;
|
||||||
|
smp_init();
|
||||||
|
|
||||||
/* Setup ACPI */
|
/* Setup ACPI */
|
||||||
rsdp_response = rsdp_request.response;
|
rsdp_response = rsdp_request.response;
|
||||||
if (!rsdp_response)
|
if (!rsdp_response)
|
||||||
|
@ -176,13 +176,13 @@ void emk_entry(void)
|
||||||
kpanic(NULL, "Failed to get RSDP request");
|
kpanic(NULL, "Failed to get RSDP request");
|
||||||
}
|
}
|
||||||
acpi_init();
|
acpi_init();
|
||||||
|
madt_init(); // Also init MADT, to prepare for APIC
|
||||||
|
|
||||||
/* Disable legacy PIC to prepare for APIC */
|
/* Disable legacy PIC to prepare for APIC */
|
||||||
outb(0x21, 0xff);
|
outb(0x21, 0xff);
|
||||||
outb(0xA1, 0xff);
|
outb(0xA1, 0xff);
|
||||||
|
|
||||||
/* Setup APIC */
|
/* Setup APIC */
|
||||||
madt_init();
|
|
||||||
lapic_init();
|
lapic_init();
|
||||||
|
|
||||||
/* Finished */
|
/* Finished */
|
||||||
|
|
|
@ -17,7 +17,6 @@ void acpi_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_rsdp_t *rsdp = (acpi_rsdp_t *)vallocat(kvm_ctx, 1, VALLOC_RW, rsdp_response->address);
|
acpi_rsdp_t *rsdp = (acpi_rsdp_t *)vallocat(kvm_ctx, 1, VALLOC_RW, rsdp_response->address);
|
||||||
|
|
||||||
if (memcmp(rsdp->signature, "RSD PTR", 7) != 0)
|
if (memcmp(rsdp->signature, "RSD PTR", 7) != 0)
|
||||||
kpanic(NULL, "Invalid RSDP signature!");
|
kpanic(NULL, "Invalid RSDP signature!");
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include <sys/acpi/madt.h>
|
#include <sys/acpi/madt.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <mm/vmm.h>
|
#include <mm/vmm.h>
|
||||||
#include <boot/emk.h>
|
#include <stdatomic.h>
|
||||||
|
|
||||||
uint64_t lapic_msr = 0;
|
atomic_uintptr_t lapic_msr = 0;
|
||||||
volatile uint64_t *lapic_base = 0;
|
volatile uint64_t *lapic_base = 0;
|
||||||
|
|
||||||
void lapic_write(uint32_t offset, uint32_t value)
|
void lapic_write(uint32_t offset, uint32_t value)
|
||||||
|
@ -16,8 +16,9 @@ void lapic_write(uint32_t offset, uint32_t value)
|
||||||
log_early("warning: LAPIC not initialized!");
|
log_early("warning: LAPIC not initialized!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
||||||
*reg = value;
|
atomic_store((_Atomic uint32_t *)reg, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lapic_read(uint32_t offset)
|
uint32_t lapic_read(uint32_t offset)
|
||||||
|
@ -27,16 +28,16 @@ uint32_t lapic_read(uint32_t offset)
|
||||||
log_early("warning: LAPIC not initialized!");
|
log_early("warning: LAPIC not initialized!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
volatile uint32_t *reg = (volatile uint32_t *)((uint8_t *)lapic_base + offset);
|
||||||
uint32_t value = *reg;
|
return atomic_load((_Atomic uint32_t *)reg);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lapic_init()
|
void lapic_init()
|
||||||
{
|
{
|
||||||
lapic_msr = rdmsr(LAPIC_BASE);
|
uint64_t msr = rdmsr(LAPIC_BASE);
|
||||||
lapic_base = (volatile uint64_t *)(lapic_msr & ~(0xffff));
|
atomic_store(&lapic_msr, msr);
|
||||||
/* Change the lapic address that we got from MADT earlier */
|
lapic_base = (volatile uint64_t *)(msr & ~(0xffff));
|
||||||
lapic_addr = (uint64_t)lapic_base;
|
atomic_store(&lapic_addr, (uint64_t)lapic_base);
|
||||||
log_early("New LAPIC base: 0x%lx", lapic_base);
|
log_early("New LAPIC base: 0x%lx", lapic_base);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue