summaryrefslogtreecommitdiff
path: root/src/arch/amd64/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/amd64/cpu')
-rw-r--r--src/arch/amd64/cpu/backtrace.c6
-rw-r--r--src/arch/amd64/cpu/debugger.c5
-rw-r--r--src/arch/amd64/cpu/idt.c24
3 files changed, 22 insertions, 13 deletions
diff --git a/src/arch/amd64/cpu/backtrace.c b/src/arch/amd64/cpu/backtrace.c
index 9e1c9d7..b1d2a2c 100644
--- a/src/arch/amd64/cpu/backtrace.c
+++ b/src/arch/amd64/cpu/backtrace.c
@@ -8,13 +8,13 @@ struct stackframe {
size_t backtrace(void **dst, size_t len) {
struct stackframe *rbp;
- __asm__ volatile ("mov %%rbp, %0" : "=r"(rbp));
+ __asm__ ("mov %%rbp, %0" : "=r"(rbp));
return backtrace_ex(dst, len, rbp->rip, rbp->rbp);
}
size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp) {
struct stackframe *frame = bp;
- __asm__ volatile ("mov %%rbp, %0" : "=r"(frame));
+ __asm__ ("mov %%rbp, %0" : "=r"(frame));
if (len > 0) {
dst[0] = ip;
}
@@ -28,7 +28,7 @@ size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp) {
void log_backtrace() {
struct stackframe *rbp;
- __asm__ volatile ("mov %%rbp, %0" : "=r"(rbp));
+ __asm__ ("mov %%rbp, %0" : "=r"(rbp));
log_backtrace_ex(rbp->rip, rbp->rbp);
}
diff --git a/src/arch/amd64/cpu/debugger.c b/src/arch/amd64/cpu/debugger.c
index 4d9d3c3..0f48b84 100644
--- a/src/arch/amd64/cpu/debugger.c
+++ b/src/arch/amd64/cpu/debugger.c
@@ -376,7 +376,7 @@ static int debugger_prompt(struct isr_regs *state) {
}
}
-void debugger(struct isr_regs *state, int cause) {
+void debugger(struct isr_regs *volatile state, int cause) {
struct dr6 dr6;
__asm__ volatile ("mov %%dr6, %0" : "=r"(dr6));
@@ -398,7 +398,8 @@ void debugger(struct isr_regs *state, int cause) {
dbg_steps = 0;
dbg_continue = 0;
- ((struct rflags *)&state->rflags)->tf = 0;
+ struct rflags *rflags = (struct rflags *) &state->rflags;
+ rflags->tf = 0;
if (dr6.b0) {
state->rip += bkps[0].instr_len;
diff --git a/src/arch/amd64/cpu/idt.c b/src/arch/amd64/cpu/idt.c
index c286199..3e98b55 100644
--- a/src/arch/amd64/cpu/idt.c
+++ b/src/arch/amd64/cpu/idt.c
@@ -5,6 +5,7 @@
#include "idt.h"
#include "backtrace.h"
#include "debugger.h"
+#include "../paging.h"
#include "../bindings.h"
#include "../drivers/pic.h"
@@ -72,6 +73,10 @@ void idt_init(void) {
__asm__ volatile ("lidt %0" : : "m"(idtr));
}
+#define EX_DEBUG 0x01
+#define EX_BREAKPOINT 0x03
+#define EX_PAGE_FAULT 0x0e
+
// Intel manual vol 3 ch 6.3.1
char *EXCEPTIONS[] = {
"Division Error",
@@ -109,27 +114,30 @@ char *EXCEPTIONS[] = {
};
void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *state) {
+ uint64_t cr2;
+
switch (exception) {
- case 0x01: // debug
+ case EX_DEBUG: // debug
debugger(state, DEBUG_DBG);
return;
- case 0x03: // breakpoint
+ case EX_BREAKPOINT: // breakpoint
debugger(state, DEBUG_INT3);
return;
+ case EX_PAGE_FAULT:
+ // page faults store the offending address in cr2
+ __asm__ volatile ("mov %%cr2, %0" : "=r"(cr2));
+ if (!kload_page((void *)cr2))
+ return;
}
kputs("\n\n!!! EXCEPTION !!!\n");
kprintf("0x%02lX %s\n", exception, EXCEPTIONS[exception]);
kprintf("Error code 0x%lX\n", code);
-
- // page faults store the offending address in cr2
- if (exception == 0x0E) {
- uint64_t cr2;
- __asm__ volatile ("mov %%cr2, %0" : "=r"(cr2));
+ if (exception == EX_PAGE_FAULT) {
kprintf("Page fault address: 0x%lX\n", cr2);
}
-
+
kputs("\n");
log_backtrace_ex((void *)state->rip, (void *)state->rbp);