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

Rejigger cga and some console code.

上级 69d390f1
......@@ -74,9 +74,6 @@ start:
# Initialize stack.
movl $PADDR(stack+STACK), %esp
# Initialize screen.
call initscreen
# Check for page size extensions.
movl $1, %eax
......@@ -192,47 +189,6 @@ bootpanic:
movb %bl, (%esi)
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
.comm stack, STACK
......
#include "types.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
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
cgaputc(char c)
cgaputc(int c)
{
int i;
if(c == '\n') {
cursor += 80 - cursor%80;
} 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;
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) --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));
}
outb(CRTPORT, 14);
outb(CRTPORT+1, pos>>8);
outb(CRTPORT, 15);
outb(CRTPORT+1, pos);
crt[pos] = ' ' | 0x0700;
}
void
initcga(void)
{
// Assume boot.S set up the screen.
// We're just taking over the cursor position.
cursor = 2*80;
setcursor(cursor);
cgaputs("cga...\n");
setcursor(cursor);
char *p;
int i;
for (i = 0; i < 80*25; i++)
crt[i] = 0x0f20;
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);
void bwrite(struct buf*);
// cga.c
void cgaputc(char c);
void cgaputc(int c);
// condvar.c
void initcondvar(struct condvar *, char *);
......
......@@ -39,7 +39,7 @@ uartintr(void)
void
inituart(void)
{
char *p;
char *p;
// Turn off the FIFO
outb(COM1+2, 0);
......@@ -65,6 +65,6 @@ inituart(void)
ioapicenable(IRQ_COM1, 0);
// Announce that we're here.
for(p="uart...\n"; *p; p++)
for(p="uart..\n"; *p; p++)
uartputc(*p);
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论