Newer
Older
// Console input and output.
// Input is from the keyboard only.
// Output is written to the screen and the printer port.
static ushort *crt = (ushort*)0xb8000; // CGA memory
static 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"
if(c == BACKSPACE)
c = '\b';
outb(LPTPORT+0, c);
outb(LPTPORT+2, 0x08|0x04|0x01);
outb(LPTPORT+2, 0x08);
int pos;
// Cursor position: col + 80*row.
outb(CRTPORT, 14);
pos = inb(CRTPORT+1) << 8;
outb(CRTPORT, 15);
pos |= inb(CRTPORT+1);
if(c == '\n')
pos += 80 - pos%80;
else if(c == BACKSPACE){
if(pos > 0)
crt[--pos] = ' ' | 0x0700;
crt[pos++] = (c&0xff) | 0x0700; // black on white
if((pos/80) >= 24){ // Scroll up.
memmove(crt, crt+80, sizeof(crt[0])*23*80);
pos -= 80;
memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
}
outb(CRTPORT, 14);
outb(CRTPORT+1, pos>>8);
outb(CRTPORT, 15);
outb(CRTPORT+1, pos);
crt[pos] = ' ' | 0x0700;
}
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.
uint r; // Read index
uint w; // Write index
uint e; // Edit index
console_intr(int (*getc)(void))
acquire(&input.lock);
while((c = getc()) >= 0){
switch(c){
case C('P'): // Process listing.
procdump();
break;
case C('U'): // Kill line.
while(input.e != input.w &&
input.buf[(input.e-1) % INPUT_BUF] != '\n'){
input.e--;
cons_putc(BACKSPACE);
}
break;
case C('H'): // Backspace
if(input.e != input.w){
input.e--;
cons_putc(BACKSPACE);
}
break;
default:
if(c != 0 && input.e-input.r < INPUT_BUF){
cons_putc(c);
if(c == '\n' || c == C('D') || input.e == input.r+INPUT_BUF){
input.w = input.e;
wakeup(&input.r);
}
}
break;
sleep(&input.r, &input.lock);
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;
initlock(&console_lock, "console");
initlock(&input.lock, "console input");
devsw[CONSOLE].write = console_write;
devsw[CONSOLE].read = console_read;
void
panic(char *s)
{
int i;
uint pcs[10];
cprintf(s);