From 48980502820f92ecd647d9f454513ee88f382ed7 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 26 Nov 2017 17:11:01 +0100 Subject: 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. --- sys/src/9/pc/cga.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'sys/src') diff --git a/sys/src/9/pc/cga.c b/sys/src/9/pc/cga.c index b07652b0c..528db05f4 100644 --- a/sys/src/9/pc/cga.c +++ b/sys/src/9/pc/cga.c @@ -169,14 +169,47 @@ cgascreenputs(char* s, int n) 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; } -- cgit v1.2.3