diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-11-26 17:11:01 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-11-26 17:11:01 +0100 |
commit | 48980502820f92ecd647d9f454513ee88f382ed7 (patch) | |
tree | fd10366326d8f545b1ae2becb6feb9b637335aeb | |
parent | af20ba67460b79f7c4aee7014756205baba29cd5 (diff) |
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.
-rw-r--r-- | sys/src/9/pc/cga.c | 35 |
1 files changed, 34 insertions, 1 deletions
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; } |