Added arch framework for handling page faults
[akaros.git] / kern / arch / i686 / trap.c
index 7cbed53..b0fb60e 100644 (file)
@@ -15,6 +15,7 @@
 #include <trap.h>
 #include <monitor.h>
 #include <process.h>
 #include <trap.h>
 #include <monitor.h>
 #include <process.h>
+#include <mm.h>
 #include <stdio.h>
 #include <slab.h>
 #include <syscall.h>
 #include <stdio.h>
 #include <slab.h>
 #include <syscall.h>
@@ -184,9 +185,9 @@ trap_dispatch(trapframe_t *tf)
                case T_SYSCALL:
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
                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);
                        // syscall code wants an edible reference for current
                        proc_incref(current, 1);
-print_trapframe(tf);
                        tf->tf_regs.reg_eax =
                                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_eax =
                                syscall(current, tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,
                                        tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx,
@@ -338,12 +339,16 @@ page_fault_handler(trapframe_t *tf)
 
        // LAB 4: Your code here.
 
 
        // 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)
 }
 
 void sysenter_init(void)
@@ -363,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,
        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,
                                                 tf->tf_regs.reg_ecx,
                                                 tf->tf_regs.reg_ebx,
                                                 tf->tf_regs.reg_edi,