fix/kernel: Fixed LAPIC r/w
This commit is contained in:
parent
3892fc04c4
commit
03cc8ff8de
2 changed files with 21 additions and 3 deletions
|
@ -232,6 +232,9 @@ void paging_init(void)
|
||||||
}
|
}
|
||||||
memset(kernel_pagemap, 0, PAGE_SIZE);
|
memset(kernel_pagemap, 0, PAGE_SIZE);
|
||||||
|
|
||||||
|
if (_supports_large_pages())
|
||||||
|
log_early("Support for 2MB pages is present");
|
||||||
|
|
||||||
/* Map kernel stack */
|
/* Map kernel stack */
|
||||||
uint64_t stack_top = ALIGN_UP(kstack_top, PAGE_SIZE);
|
uint64_t stack_top = ALIGN_UP(kstack_top, PAGE_SIZE);
|
||||||
for (uint64_t addr = stack_top - (16 * 1024); addr < stack_top; addr += PAGE_SIZE)
|
for (uint64_t addr = stack_top - (16 * 1024); addr < stack_top; addr += PAGE_SIZE)
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <sys/kpanic.h>
|
#include <sys/kpanic.h>
|
||||||
|
|
||||||
|
#define LAPIC_REG_ALIGN 16
|
||||||
|
#define LAPIC_REG_SIZE 4
|
||||||
|
|
||||||
atomic_uintptr_t lapic_msr = 0;
|
atomic_uintptr_t lapic_msr = 0;
|
||||||
atomic_uintptr_t lapic_base_atomic = 0;
|
atomic_uintptr_t lapic_base_atomic = 0;
|
||||||
|
|
||||||
|
@ -19,7 +22,13 @@ void lapic_write(uint32_t offset, uint32_t value)
|
||||||
log_early("error: LAPIC not initialized!");
|
log_early("error: LAPIC not initialized!");
|
||||||
kpanic(NULL, "LAPIC write attempted before initialization");
|
kpanic(NULL, "LAPIC write attempted before initialization");
|
||||||
}
|
}
|
||||||
base[offset / 4] = value;
|
if (offset % LAPIC_REG_ALIGN != 0)
|
||||||
|
{
|
||||||
|
log_early("error: Misaligned LAPIC offset 0x%x", offset);
|
||||||
|
kpanic(NULL, "Invalid LAPIC register offset");
|
||||||
|
}
|
||||||
|
volatile uint32_t *reg = base + (offset / LAPIC_REG_SIZE);
|
||||||
|
*reg = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lapic_read(uint32_t offset)
|
uint32_t lapic_read(uint32_t offset)
|
||||||
|
@ -30,7 +39,13 @@ uint32_t lapic_read(uint32_t offset)
|
||||||
log_early("error: LAPIC not initialized!");
|
log_early("error: LAPIC not initialized!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return base[offset / 4];
|
if (offset % LAPIC_REG_ALIGN != 0)
|
||||||
|
{
|
||||||
|
log_early("error: Misaligned LAPIC offset 0x%x", offset);
|
||||||
|
kpanic(NULL, "Invalid LAPIC register offset");
|
||||||
|
}
|
||||||
|
volatile uint32_t *reg = base + (offset / LAPIC_REG_SIZE);
|
||||||
|
return *reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lapic_init(void)
|
void lapic_init(void)
|
||||||
|
@ -72,4 +87,4 @@ void lapic_enable(void)
|
||||||
lapic_write(LAPIC_TPR, 0);
|
lapic_write(LAPIC_TPR, 0);
|
||||||
uint32_t id = lapic_read(LAPIC_ID) >> 24;
|
uint32_t id = lapic_read(LAPIC_ID) >> 24;
|
||||||
log_early("LAPIC enabled and initialized for CPU %u", id);
|
log_early("LAPIC enabled and initialized for CPU %u", id);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue