Newer
Older
#include "param.h"
struct spinlock console_lock;
// Copy console output to parallel port, which you can tell
// .bochsrc to copy to the stdout:
// parport1: enabled=1, file="/dev/stdout"
for(i = 0; !(inb(0x378+1) & 0x80) && i < 12800; i++)
;
outb(0x378+0, c);
outb(0x378+2, 0x08|0x04|0x01);
outb(0x378+2, 0x08);
ushort *crt = (ushort*) 0xB8000; // base of CGA memory
// cursor position, 16 bits, col + 80*row
outb(crtport, 14);
ind = inb(crtport + 1) << 8;
outb(crtport, 15);
ind |= inb(crtport + 1);
c &= 0xff;
if(c == '\n'){
ind -= (ind % 80);
ind += 80;
} else {
c |= 0x0700; // black on white
crt[ind] = c;
ind -= 80;
memset(crt + ind, 0, sizeof(crt[0]) * ((24 * 80) - ind));
}
outb(crtport, 14);
outb(crtport + 1, ind >> 8);
outb(crtport, 15);
outb(crtport + 1, ind);
void
printint(int xx, int base, int sgn)
{
char buf[16];
char digits[] = "0123456789ABCDEF";
int i = 0, neg = 0;
if(sgn && xx < 0){
neg = 1;
x = 0 - xx;
} else {
x = xx;
}
do {
buf[i++] = digits[x % base];
} while((x /= base) != 0);
if(neg)
buf[i++] = '-';
int i, c, state, locking;
uint *argp;
char *s;
locking = use_console_lock;
if(locking)
argp = (uint*)(void*)&fmt + 1;
state = 0;
switch(state){
case 0:
if(c == '%')
break;
case '%':
switch(c){
case 'd':
printint(*argp++, 10, 1);
break;
case 'x':
case 'p':
printint(*argp++, 16, 0);
break;
case 's':
s = (char*)*argp++;
if(s == 0)
s = "(null)";
for(; *s; s++)
cons_putc(*s);
break;
case '%':
cons_putc('%');
break;
default:
// Print unknown % sequence to draw attention.
getcallerpcs(&s, pcs);
for(i=0; i<10; i++)
cprintf(" %p", pcs[i]);
struct {
uchar buf[KBD_BUF];
int r;
int w;
struct spinlock lock;
} kbd;
static uint shift;
static uchar *charcode[4] = {
normalmap,
shiftmap,
ctlmap,
ctlmap
};
// Key released
data = (shift & E0ESC ? data : data & 0x7F);
shift &= ~(shiftcode[data] | E0ESC);
// Last character was an E0 escape; or with 0x80
data |= 0x80;
shift &= ~E0ESC;
}
shift |= shiftcode[data];
shift ^= togglecode[data];
c = charcode[shift & (CTL | SHIFT)][data];
if(shift & CAPSLOCK) {
if('a' <= c && c <= 'z')
switch(c){
case 0:
// Ignore unknown keystrokes.
break;
case C('T'):
cprintf("#"); // Let user know we're still alive.
break;
case C('P'):
procdump();
break;
default:
if(((kbd.w + 1) % KBD_BUF) != kbd.r){
kbd.buf[kbd.w++] = c;
if(kbd.w >= KBD_BUF)
kbd.w = 0;
wakeup(&kbd.r);
int
console_read(int minor, char *dst, int n)
{
if(c == C('D')){ // EOF
if(n < target){
// Save ^D for next time, to make sure
// caller gets a 0-byte result.
}
break;
}
*dst++ = c;
cons_putc(c);
initlock(&console_lock, "console");
devsw[CONSOLE].write = console_write;
devsw[CONSOLE].read = console_read;