git: 9front

Download patch

ref: cb3734b6a61b9156124191b246bf3eb24e6e0301
parent: f986534954d7695d00c7b8caf6c623b851328047
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 26 12:11:01 EST 2017

cga: capture cga console contents on boot, make sure cgapos is in range

to capture bios and bootloader messages, convert the contents
on the screen to kmesg.

on machines without legacy cga, the cga registers read out as
0xFF, resuting in out of bounds cgapos. so set cgapos to 0 in
that case.

--- a/sys/src/9/pc/cga.c
+++ b/sys/src/9/pc/cga.c
@@ -169,13 +169,46 @@
 	unlock(&cgascreenlock);
 }
 
+static void
+cgatokmesg(void)
+{
+	int i, n;
+	char *p;
+
+	ilock(&kmesg.lk);
+	n = kmesg.n;
+	for(i = cgapos-2; i >= 0 && n < sizeof kmesg.buf-UTFmax-1; i -= 2){
+		if((i % Width) == Width-2)
+			n++;
+		n += runelen(cp437[CGASCREENBASE[i]]);
+	}
+	n -= kmesg.n;
+	if(n > 0){
+		memmove(kmesg.buf+n, kmesg.buf, kmesg.n);
+		kmesg.n += n;
+		p = kmesg.buf;
+		for(i += 2; i >= 0 && i < cgapos && p < kmesg.buf+n; i += 2){
+			p += runetochar(p, &cp437[CGASCREENBASE[i]]);
+			if((i % Width) == Width-2)
+				*p++ = '\n';
+		}
+	}
+	iunlock(&kmesg.lk);
+}
+
 void
 screeninit(void)
 {
-
 	cgapos = cgaregr(0x0E)<<8;
 	cgapos |= cgaregr(0x0F);
 	cgapos *= 2;
+
+	if(cgapos >= Width*Height){
+		cgapos = 0;
+		movecursor();
+	}
+
+	cgatokmesg();
 
 	screenputs = cgascreenputs;
 }
--