Page fault: more information

This commit is contained in:
Mathieu Maret 2021-10-26 21:57:45 +02:00
parent fbb51dff0f
commit 4aa093034b
4 changed files with 31 additions and 14 deletions

View File

@ -390,6 +390,27 @@ vaddr_t cpu_context_get_SP(const struct cpu_state *ctxt)
return (vaddr_t)ctxt;
}
uint32_t cpu_context_get_EX_err(const struct cpu_state *ctxt)
{
assert(NULL != ctxt);
/* This is the Err_code of the interrupted context (ie kernel or user
context). */
return ctxt->error_code;
}
vaddr_t cpu_context_get_EX_faulting_vaddr(const struct cpu_state *ctxt)
{
assert(NULL != ctxt);
// A page fault has occurred.
// The faulting address is stored in the CR2 register.
vaddr_t faulting_address;
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
return faulting_address;
}
void cpu_context_dump(const struct cpu_state *ctxt)
{
printf("CPU: eip=%x esp=%x eflags=%x cs=%x ds=%x ss=%x err=%x", (unsigned)ctxt->eip,

View File

@ -17,13 +17,13 @@
.globl cpu_context_switch
.type cpu_context_switch, @function
cpu_context_switch:
// arg2= to_context -- esp+68
// arg1= from_context -- esp+64
// caller ip -- esp+60
pushf // (eflags) esp+56
pushl %cs // (cs) esp+52
pushl $resume_pc // (ip) esp+48
pushl $0 // (error code) esp+12+8x4
// arg2= to_context -- esp+64
// arg1= from_context -- esp+60
// caller ip -- esp+56
pushf // (eflags) esp+52
pushl %cs // (cs) esp+48
pushl $resume_pc // (ip) esp+44
pushl $0 // (error code) esp+12+7x4
pushl %ebp
pushl %eax
pushl %ecx

View File

@ -51,14 +51,10 @@ void print_handler(struct cpu_state *frame, ulong intr)
void pagefault_handler(struct cpu_state *frame, ulong intr)
{
// A page fault has occurred.
// The faulting address is stored in the CR2 register.
uint32_t faulting_address;
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
struct kthread *current = getCurrentThread();
printf("page fault while in thread %s at 0x%x 0x%x\n", current->name, faulting_address,
cpu_context_get_PC(frame));
printf("page fault while in thread %s code at 0x%x when trying to access 0x%x err_code 0x%x\n", current->name,
cpu_context_get_PC(frame), cpu_context_get_EX_faulting_vaddr(frame), cpu_context_get_EX_err(frame));
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", intr);
(void)intr;
for (;;)

View File

@ -156,7 +156,7 @@ void cpu_context_dump(const struct cpu_state *ctxt);
* Return the argument passed by the CPU upon exception, as stored in the
* saved context
*/
uint32_t cpu_context_get_EX_info(const struct cpu_state *ctxt);
uint32_t cpu_context_get_EX_err(const struct cpu_state *ctxt);
/**
* Return the faulting address of the exception