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

Rejigger cga and some console code.

上级 69d390f1
...@@ -75,9 +75,6 @@ start: ...@@ -75,9 +75,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
cpuid cpuid
...@@ -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); void
cgaputc(int c)
static void
cgaputs(const char *s)
{ {
uint8 *p, *ep; int pos;
p = (uint8*)s; // Cursor position: col + 80*row.
ep = p+strlen(s); 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) --pos;
} 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));
}
for (; p < ep; p++) outb(CRTPORT, 14);
cgaputc(*p); outb(CRTPORT+1, pos>>8);
outb(CRTPORT, 15);
outb(CRTPORT+1, pos);
crt[pos] = ' ' | 0x0700;
} }
void void
cgaputc(char c) initcga(void)
{ {
char *p;
int i; int i;
if(c == '\n') { for (i = 0; i < 80*25; i++)
cursor += 80 - cursor%80; crt[i] = 0x0f20;
} else {
screen[cursor] = color | c;
cursor++;
}
if(cursor == 25*80) {
memmove((void*)screen+80*2, (void*)screen+80*3, 80*(25-3)*2);
for(i=0; i<80; i++)
screen[(24*80+i)] = color | (' ' & 0xff);
cursor -= 80;
}
}
void outb(CRTPORT, 14);
initcga(void) outb(CRTPORT+1, 0);
{ outb(CRTPORT, 15);
// Assume boot.S set up the screen. outb(CRTPORT+1, 0);
// We're just taking over the cursor position.
cursor = 2*80;
setcursor(cursor);
cgaputs("cga...\n"); // Announce that we're here.
setcursor(cursor); 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 *);
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论