// 第49个word的第8个bit位表示是否支持DMA
// 第83个word的第10个bit位表示是否支持LBA48,为1表示支持。
// 第100~103个word的八个字节表示user的LBA最大值
- printk("%04x %04x %d %d\n", identify[49], 1 << 8, identify[49] & (1 << 8), (identify[49] & (1 << 8)) != 0);
+ printd("disk identify %04x %04x %d %d\n", identify[49], 1 << 8, identify[49] & (1 << 8),
+ (identify[49] & (1 << 8)) != 0);
if ((identify[49] & (1 << 8)) != 0) {
- printk("support DMA\n");
+ printd("support DMA\n");
}
if ((identify[83] & (1 << 10)) != 0) {
- printk("support LBA48\n");
+ printd("support LBA48\n");
u64 lba = *(u64 *)(identify + 100);
- printk("hard disk size: %u MB\n", (lba * 512) >> 20);
+ printd("hard disk size: %u MB\n", (lba * 512) >> 20);
}
// TODO REMOVE
uint16_t *p = (uint16_t *)mbr_buf;
for (int i = 0; i < 256; i++) {
if (i % 12 == 0) {
- printk("\n[%03d] ", i * 2);
+ printd("\n[%03d] ", i * 2);
}
- printk("%04x.", p[i]);
+ printd("%04x.", p[i]);
}
}
// 配置描述符表
unsigned long dest_paddr = va2pa(dest);
+
+ // 不能跨64K边界
+ const uint32_t size = count * SECT_SIZE;
+ const uint32_t _64K = 1 << 16;
+ assert(((dest_paddr + size) & _64K) == (dest_paddr & _64K));
+
ide_pci_controller.prdt[0].phys_addr = dest_paddr;
- ide_pci_controller.prdt[0].byte_count = SECT_SIZE;
+ ide_pci_controller.prdt[0].byte_count = size;
ide_pci_controller.prdt[0].reserved = 0;
ide_pci_controller.prdt[0].eot = 1;
outl(va2pa(ide_pci_controller.prdt), ide_pci_controller.bus_prdt);
unsigned int ATA_CHL1_CMD_BASE = 0x170;
unsigned int ATA_CHL0_CTL_BASE = 0x3F6;
-unsigned int ATA_CHL1_CTL_BASE = 0x376;
\ No newline at end of file
+unsigned int ATA_CHL1_CTL_BASE = 0x376;
extern tty_t monitor_tty;
extern tty_t debug_tty;
+static tty_t *ttys[] = {&default_tty, &monitor_tty, &debug_tty};
+static int tty_no = 0;
+
void kbd_debug(uint8_t scan_code) {
static unsigned long kbd_cnt = 0;
// printl(MPL_KEYBOARD, "keyboard irq: %d scan code %02x", kbd_cnt++, scan_code);
}
if (scan_code == 0x58) { // F12
- current_tty = current_tty != &default_tty ? &default_tty : &monitor_tty;
+ // current_tty = current_tty != &default_tty ? &default_tty : &monitor_tty;
+ current_tty = ttys[++tty_no % (sizeof(ttys) / sizeof(ttys[0]))];
tty_switch(current_tty);
}
#define DEFAULT_BOOT_DELAY_TICKS 30
void boot_delay(int ticks);
+
#endif
#endif //_SYSTEM_H
#include <printk.h>
void assert_fail(char *exp, char *file, unsigned int line, const char *func) {
+ asm("cli");
printl(MPL_DEBUG, "%s:%d: %s: Assertion \'%s\' failed.\n", file, line, func, exp);
printk("%s:%d: %s: Assertion \'%s\' failed.\n", file, line, func, exp);
while (1) {
- asm("cli;hlt;");
+ asm("hlt;");
}
}
*/
#include <bits.h>
#include <printk.h>
+#include <string.h>
#include <system.h>
#include <tty.h>
extern void cnsl_init();
#define VERSION "0.3.1"
-const char *version = "Kernel version " VERSION " @ " BUILDER
+const char *version = "KERNEL v" VERSION " @" BUILDER
" ["__DATE__
" " __TIME__
"]"
-
- "\n";
+ "\n\n";
void setup_kernel() {
printk("sysenter esp mode: %s\n",
cnsl_init();
boot_delay(DEFAULT_BOOT_DELAY_TICKS);
- printl(MPL_TITLE, " KERNEL MONITOR");
+ const char *title = "KERNEL MONITOR";
+ printlxy(MPL_TITLE, (80 - strlen(title)) / 2, title);
setup_tasks();
boot_delay(DEFAULT_BOOT_DELAY_TICKS);
volatile int reenter = -1;
-#if 0
-void setup_gdt_before_pageing() {
- pDesc pdesc;
- // change to new gdt.
- asm volatile("sgdt _gdtr");
- Desc *_gdt = (Desc *)va2pa(gdt);
- memcpy((void *)_gdt, (void *)(_gdtr + 2), *((uint16_t *)(_gdtr + 0)));
-
- //
- *((uint16_t *)(_gdtr + 0)) = NGDT * sizeof(Desc);
- *((uint32_t *)(_gdtr + 2)) = (uint32_t)_gdt;
- asm volatile("sgdt _gdtr");
- memcpy(_gdt + INDEX_UCODE, _gdt + INDEX_KCODE, sizeof(Desc));
- memcpy(_gdt + INDEX_UDATA, _gdt + INDEX_KDATA, sizeof(Desc));
- pdesc = _gdt + INDEX_UCODE;
- pdesc->seg.DPL = 3;
- pdesc = _gdt + INDEX_UDATA;
- pdesc->seg.DPL = 3;
-}
-#endif
-
void setup_gdt() {
pDesc pdesc;
// change to new gdt.
}
void taskC_entry() {
- current->priority = 19;
+ current->priority = 17;
while (1) {
sysc_wait(1);
void init_ttys() {
assert(irq_disabled());
- // 先备份default_tty在分页前用到的xpos, ypos
- unsigned int xpos = default_tty.xpos;
- unsigned int ypos = default_tty.ypos;
-
init_tty(&default_tty, "tty.default", VADDR + 0 * TTY_VRAM_SIZE);
init_tty(&monitor_tty, "tty.monitor", VADDR + 1 * TTY_VRAM_SIZE);
init_tty(&debug_tty, "tty.debug", VADDR + 7 * TTY_VRAM_SIZE);