x86: move page fault handler to where it belongs
This commit is contained in:
parent
bc917d8651
commit
89f3393b8b
4 changed files with 73 additions and 27 deletions
|
@ -63,6 +63,16 @@ struct x86_page_directory {
|
|||
struct x86_page_directory_entry entries[1024];
|
||||
} __aligned(PAGE_SIZE);
|
||||
|
||||
/* page fault status code bits */
|
||||
#define X86_PF_PRESENT (1u << 0)
|
||||
#define X86_PF_WRITE (1u << 1)
|
||||
#define X86_PF_USER (1u << 2)
|
||||
#define X86_PF_RESERVED (1u << 3)
|
||||
#define X86_PF_INSTR (1u << 4)
|
||||
#define X86_PF_PKEY (1u << 5)
|
||||
#define X86_PF_SHADOW_STACK (1u << 6)
|
||||
#define X86_PF_SGX (1u << 15)
|
||||
|
||||
/**
|
||||
* @brief Arch dependent virtual memory information data structure (x86 version).
|
||||
* Outside of `/arch/x86`, this is treated as a completely obfuscated type,
|
||||
|
|
|
@ -37,6 +37,8 @@ struct x86_trap_frame {
|
|||
u32 eax;
|
||||
} __packed;
|
||||
|
||||
void x86_print_regs(const struct x86_trap_frame *frame);
|
||||
|
||||
extern void _x86_isr_divide_error(void);
|
||||
__asmlink void x86_isr_divide_error(struct x86_trap_frame *frame);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include <arch/page.h>
|
||||
#include <arch/trap.h>
|
||||
|
||||
#include <gay/cdefs.h>
|
||||
#include <gay/config.h>
|
||||
|
@ -218,6 +219,46 @@ void put_page(uintptr_t phys)
|
|||
pagemap[index] &= ~(1lu << bit);
|
||||
}
|
||||
|
||||
void x86_isr_page_fault(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
void *address;
|
||||
__asm__ volatile(
|
||||
" mov %%cr2, %0 \n"
|
||||
: "=r"(address)
|
||||
:
|
||||
);
|
||||
|
||||
const char *space;
|
||||
if (error_code & X86_PF_USER)
|
||||
space = "user";
|
||||
else
|
||||
space = "kernel";
|
||||
|
||||
const char *rwx;
|
||||
if (error_code & X86_PF_WRITE)
|
||||
rwx = "write to";
|
||||
else if (error_code & X86_PF_INSTR)
|
||||
rwx = "exec at";
|
||||
else
|
||||
rwx = "read from";
|
||||
|
||||
const char *present;
|
||||
if (error_code & X86_PF_PRESENT)
|
||||
present = "";
|
||||
else
|
||||
present = " non-mapped";
|
||||
|
||||
kprintf("\n########## B O N K ##########\n");
|
||||
kprintf("Illegal %s %s%s address %p!\n", space, rwx, present, address);
|
||||
x86_print_regs(frame);
|
||||
kprintf("system halted");
|
||||
__asm__ volatile(
|
||||
" cli \n"
|
||||
"1: hlt \n"
|
||||
" jmp 1b \n"
|
||||
);
|
||||
}
|
||||
|
||||
uintptr_t virt_to_phys(void *virt)
|
||||
{
|
||||
size_t pd_index = ((uintptr_t)virt >> PAGE_SIZE_LOG2) / 1024;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <gay/kprintf.h>
|
||||
|
||||
static void print_regs(struct x86_trap_frame *context)
|
||||
void x86_print_regs(const struct x86_trap_frame *context)
|
||||
{
|
||||
u32 esp;
|
||||
if (context->hw_frame->cs == X86_USER_CS)
|
||||
|
@ -24,84 +24,84 @@ static void print_regs(struct x86_trap_frame *context)
|
|||
void x86_isr_divide_error(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Divide Error\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_debug_exception(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Debug Exception\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_nmi(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Nonmaskable Interrupt\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_breakpoint(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Breakpoint\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_overflow(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Overflow\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_bound_range_exceeded(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Bound Range Exceeded\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_invalid_opcode(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Invalid Opcode\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_device_not_available(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Device Not Available\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_double_fault(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Double Fault (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_invalid_tss(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Invalid TSS (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_segment_not_present(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Segment Not Present (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_stack_segment_fault(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Stack Segment Fault (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
@ -109,56 +109,49 @@ void x86_isr_general_protection(struct x86_trap_frame *frame, u32 error_code)
|
|||
{
|
||||
kprintf("General Protection Fault (external = %d, table = %d, index = %d)\n",
|
||||
error_code & 1, (error_code >> 1) & 3, (error_code >> 3));
|
||||
print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_page_fault(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Page Fault (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_x87_fpu_error(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("x87 FPU Error\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_alignment_check(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Alignment Check (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_machine_check(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Machine Check\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_simd_floating_point_exception(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("SIMD Floating Point Exception\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_virtualization_exception(struct x86_trap_frame *frame)
|
||||
{
|
||||
kprintf("Virtualization Exception\n");
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
void x86_isr_control_protection_exception(struct x86_trap_frame *frame, u32 error_code)
|
||||
{
|
||||
kprintf("Control Protection Exception (error = %p)\n", (void *)error_code);
|
||||
print_regs(frame);
|
||||
x86_print_regs(frame);
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue