Index: arch/mips32/src/mm/tlb.c
===================================================================
--- arch/mips32/src/mm/tlb.c	(revision b6b576cff6e554b94baf578554e7488d2ac08253)
+++ arch/mips32/src/mm/tlb.c	(revision e898a8d77f67f8d3d4d935a99363c68ad93f35af)
@@ -88,5 +88,6 @@
 {
 	entry_lo_t lo;
-	entry_hi_t hi;	
+	entry_hi_t hi;
+	asid_t asid;
 	__address badvaddr;
 	pte_t *pte;
@@ -94,5 +95,9 @@
 	badvaddr = cp0_badvaddr_read();
 
-	spinlock_lock(&AS->lock);		
+	spinlock_lock(&AS->lock);
+	asid = AS->asid;
+	spinlock_unlock(&AS->lock);
+
+	page_table_lock(AS, true);
 
 	pte = find_mapping_and_check(badvaddr);
@@ -105,5 +110,5 @@
 	pte->a = 1;
 
-	prepare_entry_hi(&hi, AS->asid, badvaddr);
+	prepare_entry_hi(&hi, asid, badvaddr);
 	prepare_entry_lo(&lo, pte->g, pte->p, pte->d, pte->cacheable, pte->pfn);
 
@@ -123,9 +128,9 @@
 	tlbwr();
 
-	spinlock_unlock(&AS->lock);
+	page_table_unlock(AS, true);
 	return;
 	
 fail:
-	spinlock_unlock(&AS->lock);
+	page_table_unlock(AS, true);
 	tlb_refill_fail(istate);
 }
@@ -155,6 +160,6 @@
 	tlbp();
 	index.value = cp0_index_read();
-	
-	spinlock_lock(&AS->lock);	
+
+	page_table_lock(AS, true);	
 	
 	/*
@@ -192,9 +197,9 @@
 	tlbwi();
 
-	spinlock_unlock(&AS->lock);	
+	page_table_unlock(AS, true);
 	return;
 	
 fail:
-	spinlock_unlock(&AS->lock);
+	page_table_unlock(AS, true);
 	tlb_invalid_fail(istate);
 }
@@ -224,6 +229,6 @@
 	tlbp();
 	index.value = cp0_index_read();
-	
-	spinlock_lock(&AS->lock);	
+
+	page_table_lock(AS, true);	
 	
 	/*
@@ -268,9 +273,9 @@
 	tlbwi();
 
-	spinlock_unlock(&AS->lock);	
+	page_table_unlock(AS, true);
 	return;
 	
 fail:
-	spinlock_unlock(&AS->lock);
+	page_table_unlock(AS, true);
 	tlb_modified_fail(istate);
 }
@@ -350,4 +355,5 @@
 		 * Resort to higher-level page fault handler.
 		 */
+		page_table_unlock(AS, true);
 		if (as_page_fault(badvaddr)) {
 			/*
@@ -355,27 +361,15 @@
 			 * The mapping ought to be in place.
 			 */
+			page_table_lock(AS, true);
 			pte = page_mapping_find(AS, badvaddr);
 			ASSERT(pte && pte->p);
 			return pte;
+		} else {
+			page_table_lock(AS, true);
+			printf("Page fault.\n");
+			return NULL;
 		}
-	}
-
-	/*
-	 * Handler cannot succeed if badvaddr has no mapping.
-	 */
-	if (!pte) {
-		printf("No such mapping.\n");
-		return NULL;
-	}
-
-	/*
-	 * Handler cannot succeed if the mapping is marked as invalid.
-	 */
-	if (!pte->p) {
-		printf("Invalid mapping.\n");
-		return NULL;
-	}
-
-	return pte;
+		
+	}
 }
 
