Index: arch/mips32/include/mm/tlb.h
===================================================================
--- arch/mips32/include/mm/tlb.h	(revision 92e54312b23a0d09a6d3892f494d70a5f3855624)
+++ arch/mips32/include/mm/tlb.h	(revision 8c5e6c749daf4b1aaa266e21aed9b6fdc3809b02)
@@ -49,5 +49,5 @@
 		unsigned c : 3; 	/* cache coherency attribute */
 		unsigned pfn : 24;	/* frame number */
-		unsigned zero: 2;	/* zero */
+		unsigned : 2;		/* zero */
 	} __attribute__ ((packed));
 	__u32 value;
Index: arch/mips32/src/mm/tlb.c
===================================================================
--- arch/mips32/src/mm/tlb.c	(revision 92e54312b23a0d09a6d3892f494d70a5f3855624)
+++ arch/mips32/src/mm/tlb.c	(revision 8c5e6c749daf4b1aaa266e21aed9b6fdc3809b02)
@@ -45,5 +45,7 @@
 
 static pte_t *find_mapping_and_check(__address badvaddr);
+
 static void prepare_entry_lo(entry_lo_t *lo, bool g, bool v, bool d, int c, __address pfn);
+static void prepare_entry_hi(entry_hi_t *hi, asid_t asid, __address addr);
 
 /** Initialize TLB
@@ -85,17 +87,12 @@
 {
 	entry_lo_t lo;
+	entry_hi_t hi;	
 	__address badvaddr;
 	pte_t *pte;
 
-// debug	
-	entry_hi_t hi;
-
 	badvaddr = cp0_badvaddr_read();
 
-// debug
-	hi.value = cp0_entry_hi_read();
-	printf("TLB Refill: hi.vnp2=%X\n", hi.vpn2);
-	
 	spinlock_lock(&VM->lock);		
+
 	pte = find_mapping_and_check(badvaddr);
 	if (!pte)
@@ -107,4 +104,5 @@
 	pte->a = 1;
 
+	prepare_entry_hi(&hi, VM->asid, badvaddr);
 	prepare_entry_lo(&lo, pte->g, pte->v, pte->d, pte->c, pte->pfn);
 
@@ -112,4 +110,5 @@
 	 * New entry is to be inserted into TLB
 	 */
+	cp0_entry_hi_write(hi.value);
 	if ((badvaddr/PAGE_SIZE) % 2 == 0) {
 		cp0_entry_lo0_write(lo.value);
@@ -141,4 +140,5 @@
 	__address badvaddr;
 	entry_lo_t lo;
+	entry_hi_t hi;
 	pte_t *pte;
 
@@ -148,4 +148,7 @@
 	 * Locate the faulting entry in TLB.
 	 */
+	hi.value = cp0_entry_hi_read();
+	prepare_entry_hi(&hi, hi.asid, badvaddr);
+	cp0_entry_hi_write(hi.value);
 	tlbp();
 	index.value = cp0_index_read();
@@ -205,4 +208,5 @@
 	__address badvaddr;
 	entry_lo_t lo;
+	entry_hi_t hi;
 	pte_t *pte;
 
@@ -212,4 +216,7 @@
 	 * Locate the faulting entry in TLB.
 	 */
+	hi.value = cp0_entry_hi_read();
+	prepare_entry_hi(&hi, hi.asid, badvaddr);
+	cp0_entry_hi_write(hi.value);
 	tlbp();
 	index.value = cp0_index_read();
@@ -379,4 +386,5 @@
 void prepare_entry_lo(entry_lo_t *lo, bool g, bool v, bool d, int c, __address pfn)
 {
+	lo->value = 0;
 	lo->g = g;
 	lo->v = v;
@@ -384,4 +392,9 @@
 	lo->c = c;
 	lo->pfn = pfn;
-	lo->zero = 0;
-}
+}
+
+void prepare_entry_hi(entry_hi_t *hi, asid_t asid, __address addr)
+{
+	hi->value = (((addr/PAGE_SIZE)/2)*PAGE_SIZE*2);
+	hi->asid = asid;
+}
Index: test/mm/mapping1/test.c
===================================================================
--- test/mm/mapping1/test.c	(revision 92e54312b23a0d09a6d3892f494d70a5f3855624)
+++ test/mm/mapping1/test.c	(revision 8c5e6c749daf4b1aaa266e21aed9b6fdc3809b02)
@@ -49,26 +49,28 @@
 	frame0 = frame_alloc(FRAME_KA);
 	frame1 = frame_alloc(FRAME_KA);	
-	
+
+	printf("Writing %L to physical address %P.\n", VALUE0, KA2PA(frame0));
 	*((__u32 *) frame0) = VALUE0;
+	printf("Writing %L to physical address %P.\n", VALUE1, KA2PA(frame1));
 	*((__u32 *) frame1) = VALUE1;
 	
-	printf("Mapping %P to %P.\n", PAGE0, KA2PA(frame0));
-	map_page_to_frame(PAGE0, KA2PA(frame0), PAGE_PRESENT, 0);
-	printf("Mapping %P to %P.\n", PAGE1, KA2PA(frame1));	
-	map_page_to_frame(PAGE1, KA2PA(frame1), PAGE_PRESENT, 0);
+	printf("Mapping virtual address %P to physical address %P.\n", PAGE0, KA2PA(frame0));
+	map_page_to_frame(PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
+	printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1));	
+	map_page_to_frame(PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0);
 	
-	printf("Value at %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));
-	printf("Value at %P is %L.\n", PAGE1, v1 = *((__u32 *) PAGE1));
+	printf("Value at virtual address %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));
+	printf("Value at virtual address %P is %L.\n", PAGE1, v1 = *((__u32 *) PAGE1));
 	
 	ASSERT(v0 == VALUE0);
 	ASSERT(v1 == VALUE1);
 
-	printf("Writing 0 to %P.\n", PAGE0);
+	printf("Writing %X to virtual address %P.\n", 0, PAGE0);
 	*((__u32 *) PAGE0) = 0;
-	printf("Writing 0 to %P.\n", PAGE1);
+	printf("Writing %X to virtual address %P.\n", 0, PAGE1);
 	*((__u32 *) PAGE1) = 0;	
 	
-	printf("Value at %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));	
-	printf("Value at %P is %L.\n", PAGE1, v1 = *((__u32 *) PAGE1));
+	printf("Value at virtual address %P is %X.\n", PAGE0, v0 = *((__u32 *) PAGE0));	
+	printf("Value at virtual address %P is %X.\n", PAGE1, v1 = *((__u32 *) PAGE1));
 
 	ASSERT(v0 == 0);
