shithub: riscv

Download patch

ref: e289fd8ccdfb081f16f02a025e53421aab7f90b7
parent: 0850718033bb8c4a89628aa08659d1fc573d1491
author: cinap_lenrek <[email protected]>
date: Sun Feb 2 00:10:58 EST 2014

pc64: fix vmap

VMAP address calculation was all wrong resulting
in vmaps get mapped into KZERO map.

--- a/sys/src/9/pc64/mmu.c
+++ b/sys/src/9/pc64/mmu.c
@@ -149,7 +149,7 @@
 	if(va >= KZERO)
 		return va-KZERO;
 	if(va >= VMAP)
-		return va-VMAP;
+		return va-(VMAP-(-KZERO));
 	panic("paddr: va=%#p pc=%#p", va, getcallerpc(&v));
 	return 0;
 }
@@ -260,7 +260,7 @@
 			pte = mmuwalk(pml4, va, ++l, 0);
 			if(pte && (*pte & PTESIZE)){
 				flags |= PTESIZE;
-				z = va & PGLSZ(l)-1;
+				z = va & (PGLSZ(l)-1);
 				va -= z;
 				pa -= z;
 				size += z;
@@ -442,6 +442,7 @@
 	if(pte == 0 || (*pte & PTEVALID) == 0)
 		panic("kunmap: va=%#p", va);
 	*pte = 0;
+	mmuflushtlb();
 	splx(x);
 }
 
@@ -454,12 +455,12 @@
 	uintptr va;
 	int o;
 
-	if(size <= 0 || pa & ~0xffffffffull)
+	if(size <= 0 || pa >= -VMAP)
 		panic("vmap: pa=%#p size=%d pc=%#p", pa, size, getcallerpc(&pa));
 	if(cankaddr(pa) >= size)
 		va = pa+KZERO;
 	else
-		va = pa+VMAP;
+		va = pa+(VMAP-(-KZERO));
 	/*
 	 * might be asking for less than a page.
 	 */