summaryrefslogtreecommitdiffstats
path: root/userprog/exception.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-06-19 01:44:56 +0200
committermanuel <manuel@mausz.at>2012-06-19 01:44:56 +0200
commite88a8c4c379d721e9901752d440a05295087da11 (patch)
treeb89070c525614267811a10b77a4dbc49ffd96b03 /userprog/exception.c
parentd9e0c55d118d0a3923b440b7811f8d1d6db9e1d7 (diff)
downloadprogos-e88a8c4c379d721e9901752d440a05295087da11.tar.gz
progos-e88a8c4c379d721e9901752d440a05295087da11.tar.bz2
progos-e88a8c4c379d721e9901752d440a05295087da11.zip
implement page table and use it for lazy loading of segments
Diffstat (limited to 'userprog/exception.c')
-rw-r--r--userprog/exception.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/userprog/exception.c b/userprog/exception.c
index 17620ad..54621fa 100644
--- a/userprog/exception.c
+++ b/userprog/exception.c
@@ -5,6 +5,7 @@
5#include "threads/interrupt.h" 5#include "threads/interrupt.h"
6#include "threads/thread.h" 6#include "threads/thread.h"
7#include "threads/vaddr.h" 7#include "threads/vaddr.h"
8#include "vm/page.h"
8 9
9/* Number of page faults processed. */ 10/* Number of page faults processed. */
10static long long page_fault_cnt; 11static long long page_fault_cnt;
@@ -121,12 +122,13 @@ kill (struct intr_frame *f)
121 description of "Interrupt 14--Page Fault Exception (#PF)" in 122 description of "Interrupt 14--Page Fault Exception (#PF)" in
122 [IA32-v3a] section 5.15 "Exception and Interrupt Reference". */ 123 [IA32-v3a] section 5.15 "Exception and Interrupt Reference". */
123static void 124static void
124page_fault (struct intr_frame *f) 125page_fault (struct intr_frame *f)
125{ 126{
126 bool not_present; /* True: not-present page, false: writing r/o page. */ 127 bool not_present; /* True: not-present page, false: writing r/o page. */
127 bool write; /* True: access was write, false: access was read. */ 128 bool write; /* True: access was write, false: access was read. */
128 bool user; /* True: access by user, false: access by kernel. */ 129 bool user; /* True: access by user, false: access by kernel. */
129 void *fault_addr; /* Fault address. */ 130 void *fault_addr; /* Fault address. */
131 struct page_table_entry *pte;
130 132
131 /* Obtain faulting address, the virtual address that was 133 /* Obtain faulting address, the virtual address that was
132 accessed to cause the fault. It may point to code or to 134 accessed to cause the fault. It may point to code or to
@@ -153,6 +155,17 @@ page_fault (struct intr_frame *f)
153 body, adding code that brings in the page to 155 body, adding code that brings in the page to
154 which fault_addr refers. */ 156 which fault_addr refers. */
155 if (is_user_vaddr(fault_addr)) { 157 if (is_user_vaddr(fault_addr)) {
158 pte = page_table_fetch (&thread_current ()->page_table, pg_round_down (fault_addr));
159 if (pte != NULL)
160 page_load (pte);
161 else
162 {
163 printf ("Page fault %p\n", pte);
164 kill (f);
165 }
166
167 //TODO
168#if 0
156 if (! user) { 169 if (! user) {
157 /* syscall exception; set eax and eip */ 170 /* syscall exception; set eax and eip */
158 f->eip = (void*)f->eax; 171 f->eip = (void*)f->eax;
@@ -162,6 +175,7 @@ page_fault (struct intr_frame *f)
162 /* user process access violation */ 175 /* user process access violation */
163 thread_exit(); 176 thread_exit();
164 } 177 }
178#endif
165 } else { 179 } else {
166 printf ("Page fault at %p: %s error %s page in %s context.\n", 180 printf ("Page fault at %p: %s error %s page in %s context.\n",
167 fault_addr, 181 fault_addr,