提交 e2fb4373 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Rejigger cga and some console code.

上级 69d390f1
...@@ -74,9 +74,6 @@ start: ...@@ -74,9 +74,6 @@ start:
# Initialize stack. # Initialize stack.
movl $PADDR(stack+STACK), %esp movl $PADDR(stack+STACK), %esp
# Initialize screen.
call initscreen
# Check for page size extensions. # Check for page size extensions.
movl $1, %eax movl $1, %eax
...@@ -192,47 +189,6 @@ bootpanic: ...@@ -192,47 +189,6 @@ bootpanic:
movb %bl, (%esi) movb %bl, (%esi)
jmp 2b jmp 2b
initscreen:
pushal
# Initialize screen.
# 25 lines of white on black.
cld
movl $CGATEXTMEM, %edi
movl $0x0f20, %eax
movl $(80*25), %ecx
rep stosw
# Hide cursor at beginning of first line.
movw $0, %di
call setcursor
popal
ret
.globl setcursor
setcursor:
pushl %edx
pushl %eax
pushl %ebx
movl %edi, %ebx
movw $0x3d4, %dx
movw $14, %ax
outb %al, %dx
movw $0x3d5, %dx
movb %bh, %al
outb %al, %dx
movw $0x3d4, %dx
movw $15, %ax
outb %al, %dx
movw $0x3d5, %dx
movb %bl, %al
outb %al, %dx
popl %ebx
popl %eax
popl %edx
ret
# Initial stack # Initial stack
.comm stack, STACK .comm stack, STACK
......
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.h"
#include "x86.h"
static volatile u16 *screen = (u16*)(KBASE+0xb8000); #define BACKSPACE 0x100
#define CRTPORT 0x3d4
static volatile u16 *crt = (u16*)(KBASE + 0xb8000); // CGA memory
// Black background, (high intensity) white foreground // Black background, (high intensity) white foreground
static int color = ((0 << 4) | 15) << 8; static int color = ((0 << 4) | 15) << 8;
static int cursor;
extern void setcursor(int);
static void
cgaputs(const char *s)
{
uint8 *p, *ep;
p = (uint8*)s;
ep = p+strlen(s);
for (; p < ep; p++)
cgaputc(*p);
}
void void
cgaputc(char c) cgaputc(int c)
{ {
int i; int pos;
if(c == '\n') { // Cursor position: col + 80*row.
cursor += 80 - cursor%80; outb(CRTPORT, 14);
} else { pos = inb(CRTPORT+1) << 8;
screen[cursor] = color | c; outb(CRTPORT, 15);
cursor++; pos |= inb(CRTPORT+1);
}
if(cursor == 25*80) { if(c == '\n')
memmove((void*)screen+80*2, (void*)screen+80*3, 80*(25-3)*2); pos += 80 - pos%80;
for(i=0; i<80; i++) else if(c == BACKSPACE){
screen[(24*80+i)] = color | (' ' & 0xff); if(pos > 0) --pos;
cursor -= 80; } else
crt[pos++] = (c&0xff) | color;
if((pos/80) >= 24){ // Scroll up.
memmove((void*)crt, (void*)crt+80, sizeof(crt[0])*23*80);
pos -= 80;
memset((void*)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;
} }
void void
initcga(void) initcga(void)
{ {
// Assume boot.S set up the screen. char *p;
// We're just taking over the cursor position. int i;
cursor = 2*80;
setcursor(cursor); for (i = 0; i < 80*25; i++)
crt[i] = 0x0f20;
cgaputs("cga...\n");
setcursor(cursor); outb(CRTPORT, 14);
outb(CRTPORT+1, 0);
outb(CRTPORT, 15);
outb(CRTPORT+1, 0);
// Announce that we're here.
for(p="cga..\n"; *p; p++)
cgaputc(*p);
} }
...@@ -36,7 +36,7 @@ void brelse(struct buf*, int writer); ...@@ -36,7 +36,7 @@ void brelse(struct buf*, int writer);
void bwrite(struct buf*); void bwrite(struct buf*);
// cga.c // cga.c
void cgaputc(char c); void cgaputc(int c);
// condvar.c // condvar.c
void initcondvar(struct condvar *, char *); void initcondvar(struct condvar *, char *);
......
...@@ -39,7 +39,7 @@ uartintr(void) ...@@ -39,7 +39,7 @@ uartintr(void)
void void
inituart(void) inituart(void)
{ {
char *p; char *p;
// Turn off the FIFO // Turn off the FIFO
outb(COM1+2, 0); outb(COM1+2, 0);
...@@ -65,6 +65,6 @@ inituart(void) ...@@ -65,6 +65,6 @@ inituart(void)
ioapicenable(IRQ_COM1, 0); ioapicenable(IRQ_COM1, 0);
// Announce that we're here. // Announce that we're here.
for(p="uart...\n"; *p; p++) for(p="uart..\n"; *p; p++)
uartputc(*p); uartputc(*p);
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论