Browse Source

update console.c for more info about CGA and 6845 chip

main
yuchen 9 years ago
parent
commit
7f8b5a20fa
1 changed files with 22 additions and 12 deletions
  1. +22
    -12
      labcodes/lab1/kern/driver/console.c

+ 22
- 12
labcodes/lab1/kern/driver/console.c View File

@ -53,29 +53,39 @@ static uint16_t crt_pos;
static uint16_t addr_6845;
/* TEXT-mode CGA/VGA display output */
// CGA Color Graphics Adapter
// CGA显存按照下面的方式映射
// -- 0xB0000 - 0xB7777
// -- 0xB8000 - 0xBFFFF CGA
// 6845IBM PC中的视频控制器
// CPU通过IO地址0x3B4-0x3B56845IO地址0x3D4-0x3D5
// -- 0x3D50x3B5
// -- 0x3D40x3B4,
static void
cga_init(void) {
volatile uint16_t *cp = (uint16_t *)CGA_BUF;
uint16_t was = *cp;
volatile uint16_t *cp = (uint16_t *)CGA_BUF; //CGA_BUF: 0xB8000 ()
uint16_t was = *cp; //
*cp = (uint16_t) 0xA55A;
if (*cp != 0xA55A) {
cp = (uint16_t*)MONO_BUF;
addr_6845 = MONO_BASE;
cp = (uint16_t*)MONO_BUF; // MONO_BUF 0xB0000
addr_6845 = MONO_BASE; //IO地址MONO_BASE: 0x3B4
} else {
*cp = was;
addr_6845 = CGA_BASE;
*cp = was; //
addr_6845 = CGA_BASE; // IO地址 CGA_BASE: 0x3D4
}
// Extract cursor location
// 6845index 0x0E14== ()
// 6845index 0x0F15== ()
// 6845 reg 15 : Cursor Address (Low Byte)
uint32_t pos;
outb(addr_6845, 14);
pos = inb(addr_6845 + 1) << 8;
outb(addr_6845, 14);
pos = inb(addr_6845 + 1) << 8; //()
outb(addr_6845, 15);
pos |= inb(addr_6845 + 1);
pos |= inb(addr_6845 + 1); //()
crt_buf = (uint16_t*) cp;
crt_pos = pos;
crt_buf = (uint16_t*) cp; //crt_buf是CGA显存起始地址
crt_pos = pos; //crt_pos是CGA当前光标位置
}
static bool serial_exists = 0;

Loading…
Cancel
Save