Added arch framework for handling page faults
[akaros.git] / kern / arch / i686 / trap.c
index 8915ca8..b0fb60e 100644 (file)
@@ -15,6 +15,7 @@
 #include <trap.h>
 #include <monitor.h>
 #include <process.h>
+#include <mm.h>
 #include <stdio.h>
 #include <slab.h>
 #include <syscall.h>
@@ -156,6 +157,8 @@ print_trapframe(trapframe_t *tf)
        spin_lock_irqsave(&ptf_lock);
        cprintf("TRAP frame at %p on core %d\n", tf, core_id());
        print_regs(&tf->tf_regs);
+       cprintf("  gs   0x----%04x\n", tf->tf_gs);
+       cprintf("  fs   0x----%04x\n", tf->tf_fs);
        cprintf("  es   0x----%04x\n", tf->tf_es);
        cprintf("  ds   0x----%04x\n", tf->tf_ds);
        cprintf("  trap 0x%08x %s\n", tf->tf_trapno, trapname(tf->tf_trapno));
@@ -182,6 +185,7 @@ trap_dispatch(trapframe_t *tf)
                case T_SYSCALL:
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
+
                        // syscall code wants an edible reference for current
                        proc_incref(current, 1);
                        tf->tf_regs.reg_eax =
@@ -335,12 +339,16 @@ page_fault_handler(trapframe_t *tf)
 
        // LAB 4: Your code here.
 
-       // Destroy the environment that caused the fault.
-       cprintf("[%08x] user fault va %08x ip %08x from core %d\n",
-               current->pid, fault_va, tf->tf_eip, core_id());
-       print_trapframe(tf);
-       proc_incref(current, 1);
-       proc_destroy(current);
+       // TODO: compute correct access type
+       if(handle_page_fault(current,fault_va,PROT_READ))
+       {
+               // Destroy the environment that caused the fault.
+               cprintf("[%08x] user fault va %08x ip %08x from core %d\n",
+                       current->pid, fault_va, tf->tf_eip, core_id());
+               print_trapframe(tf);
+               proc_incref(current, 1);
+               proc_destroy(current);
+       }
 }
 
 void sysenter_init(void)
@@ -360,7 +368,7 @@ void sysenter_callwrapper(struct Trapframe *tf)
        proc_incref(current, 1);
        tf->tf_regs.reg_eax = (intreg_t) syscall(current,
                                                 tf->tf_regs.reg_eax,
-                                                tf->tf_regs.reg_edx,
+                                                tf->tf_regs.reg_esi,
                                                 tf->tf_regs.reg_ecx,
                                                 tf->tf_regs.reg_ebx,
                                                 tf->tf_regs.reg_edi,