mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Use IST for kernel stacks for NMI, #DF, #PF
We started actually running up against the page boundary for kernel stacks and thus double-faulting on page faults from kernel space. So I finally added IST stacks. Note that we currently just increment/decrement the IST entry by a page when we enter the handler to avoid clobbering on re-entry, but this means: * these handlers need to be able to operate with only a page of stack * kernel stacks always have to be >1 pages * the amount of nesting possible is tied to the kernel stack size. These seem fine for now, but we should maybe find a way to use something besides g_kernel_stacks to set up the IST stacks if/when this becomes an issue.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "device_manager.h"
|
||||
#include "frame_allocator.h"
|
||||
#include "gdt.h"
|
||||
#include "io.h"
|
||||
#include "log.h"
|
||||
#include "msr.h"
|
||||
@@ -117,6 +118,29 @@ memory_initialize_post_ctors(args::header &kargs)
|
||||
reinterpret_cast<uintptr_t>(kargs.page_tables),
|
||||
kargs.table_count);
|
||||
|
||||
using memory::frame_size;
|
||||
using memory::kernel_stack_pages;
|
||||
constexpr size_t stack_size = kernel_stack_pages * frame_size;
|
||||
|
||||
for (int ist = 1; ist <= 3; ++ist) {
|
||||
uintptr_t bottom = g_kernel_stacks.get_section();
|
||||
log::debug(logs::boot, "Installing IST%d stack at %llx", ist, bottom);
|
||||
|
||||
// Pre-realize and xerothese stacks, they're no good
|
||||
// if they page fault
|
||||
kutil::memset(reinterpret_cast<void*>(bottom), 0, stack_size);
|
||||
|
||||
// Skip two entries to be the null frame
|
||||
tss_set_ist(ist, bottom + stack_size - 2 * sizeof(uintptr_t));
|
||||
}
|
||||
|
||||
#define ISR(i, s, name) if (s) { idt_set_ist(i, s); }
|
||||
#define EISR(i, s, name) if (s) { idt_set_ist(i, s); }
|
||||
#define IRQ(i, q, name)
|
||||
#include "interrupt_isrs.inc"
|
||||
#undef IRQ
|
||||
#undef EISR
|
||||
#undef ISR
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user