#include "threads/interrupt.h"
#include "threads/thread.h"
+/* Number of page faults processed. */
+static long long page_fault_cnt;
+
static void kill (struct intr_frame *);
static void page_fault (struct intr_frame *);
intr_register (14, 0, INTR_OFF, page_fault, "#PF Page-Fault Exception");
}
+/* Prints exception statistics. */
+void
+exception_print_stats (void)
+{
+ printf ("Exception: %lld page faults\n", page_fault_cnt);
+}
+
/* Handler for an exception (probably) caused by a user process. */
static void
kill (struct intr_frame *f)
/* Obtain faulting address, the virtual address that was
accessed to cause the fault. It may point to code or to
data. It is not necessarily the address of the instruction
- that caused the fault (that's f->eip). */
- asm ("movl %%cr2, %0" : "=r" (fault_addr));
+ that caused the fault (that's f->eip).
+ See [IA32-v2a] "MOV--Move to/from Control Registers" and
+ [IA32-v3] 5.14 "Interrupt 14--Page Fault Exception
+ (#PF)". */
+ asm ("mov %0, %%cr2" : "=r" (fault_addr));
/* Turn interrupts back on (they were only off so that we could
be assured of reading CR2 before it changed). */
intr_enable ();
+ /* Count page faults. */
+ page_fault_cnt++;
+
/* Determine cause. */
not_present = (f->error_code & PF_P) == 0;
write = (f->error_code & PF_W) != 0;