code: 9ferno

Download patch

ref: b6edae9552d2c802fbb1d9b9a6af0de2ee6bf1f9
parent: 1daffb595e063fdfb42da7ee86d202d5055bd0a1
author: 9ferno <gophone2015@gmail.com>
date: Sun Aug 8 14:55:03 EDT 2021

cleaned up the memory debug prints

--- a/os/pc64/memory.c
+++ b/os/pc64/memory.c
@@ -274,7 +274,7 @@
 u64
 upaalloc(u64 pa, u32 size, u32 align)
 {
-	print("before memmapalloc pa 0x%p size 0x%x %d\n",
+	DP("before memmapalloc pa 0x%p size 0x%x %d\n",
 		pa, size, size);
 	// memmapdump();
 	return memmapalloc(pa, size, align, MemUPA);
@@ -389,7 +389,6 @@
 		if((s = getconf("e820")) == nil)
 			return -1;
 
-	print("e820scan %s\n", s);
 	for(;;){
 		while(*s == ' ')
 			s++;
@@ -617,17 +616,11 @@
 	 */
 	memmapadd(16*MB, (u32)-16*MB, MemUPA);
 
-		print("------before lowraminit -----\n");
-		memmapdump();
-		print("-----------\n");
 	/*
 	 * Discover conventional RAM, ROMs and UMBs.
 	 */
 	lowraminit();
 
-		print("------after lowraminit -----\n");
-		memmapdump();
-		print("-----------\n");
 	/*
 	 * Discover more RAM and map to KZERO.
 	 */
@@ -672,13 +665,7 @@
 	uintptr base, size;
 	Confmem *cm;
 
-		print("------ before umbexclude -----\n");
-		memmapdump();
-		print("-----------\n");
 	umbexclude();
-		print("------ after umbexclude -----\n");
-		memmapdump();
-		print("-----------\n");
 	for(base = memmapnext(-1, MemUMB); base != -1; base = memmapnext(base, MemUMB)){
 		size = memmapsize(base, BY2PG) & ~(BY2PG-1);
 		if(size != 0)
@@ -706,9 +693,7 @@
 		cm++;
 	}
 
-	print("-----------\n");
-	if(1) memmapdump();
-	print("-----------\n");
+	memmapdump();
 	// showpagetables((uintptr*)PML4ADDR);
 	//showpagetables((uintptr*)PML4ADDR);
 }
--- a/os/port/memmap.c
+++ b/os/port/memmap.c
@@ -26,7 +26,36 @@
 static void
 dump1(Mapent *e)
 {
-	print("%.16llux-%.16llux %lux\n", e->addr, e->addr + e->size, e->type);
+	char tstr[64], *ep;
+	int n;
+	u32 type;
+
+	memset(tstr, '\0', 64);
+	if(e->type & Allocated)
+		strncpy(tstr, "Allocated ", 64);
+	n = strlen(tstr);
+	type = e->type & 0xf;
+	switch(type){
+		case 0:
+			 strncpy(tstr+n, "unbacked physical address", 64-n);
+			break;
+		case 1:
+			 strncpy(tstr+n, "upper memory block (<16MB)", 64-n);
+			break;
+		case 2:
+			 strncpy(tstr+n, "physical memory", 64-n);
+			break;
+		case 3:
+			 strncpy(tstr+n, "ACPI tables", 64-n);
+			break;
+		case 4:
+			 strncpy(tstr+n, "Reserved don't allocate", 64-n);
+			break;
+		default:
+			 strncpy(tstr+n, "unknown type", 64-n);
+	}
+	print("%.16llux-%.16llux %lux	%s\n",
+		e->addr, e->addr + e->size, e->type, (char*)tstr);
 }
 
 static int
@@ -145,11 +174,13 @@
 {
 	int i;
 
+	print("-----memmap dump------\n");
 	lock(&mapalloc);
 	sort();
 	for(i = 0; i < mapalloc.n; i++)
 		dump1(&mapalloc.a[i]);
 	unlock(&mapalloc);
+	print("----------------------\n");
 }
 
 uvlong
@@ -210,8 +241,6 @@
 {
 	Mapent *i, *e;
 
-	print("memmapalloc addr 0x%p size 0x%zx %zd align 0x%zx type 0x%x\n",
-		addr, size, size, align, type);
 	type &= ~Allocated;
 	lock(&mapalloc);
 	sort();
@@ -225,12 +254,9 @@
 			if(addr - i->addr >= i->size)
 				goto Fail;
 		}
-		print("memmapalloc addr 0x%p i->addr 0x%p size 0x%zx %zd i->size 0x%zx %zd\n",
-			addr, i->addr, size, size, i->size, i->size);
 		if(addr - i->addr + size > i->size)
 			goto Fail;
 Alloc:
-		print("memmapalloc insert addr 0x%p size 0x%zx %zd\n", addr, size, size);
 		if(size > 0 && !insert(addr, size, type|Allocated))
 			goto Fail;
 		unlock(&mapalloc);