Added arch framework for handling page faults
[akaros.git] / kern / arch / i686 / trap.c
index 5a6a2bd..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>
@@ -185,16 +186,10 @@ trap_dispatch(trapframe_t *tf)
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
 
-                       // default return value is 0 if syscall doesn't return
-                       // e.g. for fork or yield
-                       intreg_t syscallno = tf->tf_regs.reg_eax;
-                       tf->tf_regs.reg_eax = 0;
-                       set_errno(tf,0);
-
                        // syscall code wants an edible reference for current
                        proc_incref(current, 1);
                        tf->tf_regs.reg_eax =
-                               syscall(current, syscallno, tf->tf_regs.reg_edx,
+                               syscall(current, tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,
                                        tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx,
                                        tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
                        proc_decref(current, 1);
@@ -344,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)
@@ -365,17 +364,11 @@ void sysenter_callwrapper(struct Trapframe *tf)
        // save a per-core reference to the tf
        set_current_tf(tf);
 
-       // default return value is 0 if syscall doesn't return
-       // e.g. for fork or yield
-       intreg_t syscallno = tf->tf_regs.reg_eax;
-       tf->tf_regs.reg_eax = 0;
-       set_errno(tf,0);
-
        // syscall code wants an edible reference for current
        proc_incref(current, 1);
        tf->tf_regs.reg_eax = (intreg_t) syscall(current,
-                                                syscallno,
-                                                tf->tf_regs.reg_edx,
+                                                tf->tf_regs.reg_eax,
+                                                tf->tf_regs.reg_esi,
                                                 tf->tf_regs.reg_ecx,
                                                 tf->tf_regs.reg_ebx,
                                                 tf->tf_regs.reg_edi,