From: acevest Date: Thu, 1 Jun 2023 05:48:10 +0000 (+0800) Subject: 硬盘dma检查目的地址不能跨64K边界 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=92ddc72c90c507c8e0a71f395c7fc40c0edc80f6;p=kernel.git 硬盘dma检查目的地址不能跨64K边界 --- diff --git a/drivers/ata.c b/drivers/ata.c index 900822d..78b37e8 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -119,15 +119,16 @@ void ata_init() { // 第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 @@ -140,9 +141,9 @@ void ata_init() { 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]); } } @@ -225,8 +226,14 @@ void ata_dma_read_ext(int dev, uint64_t pos, uint16_t count, void *dest) { // 配置描述符表 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); @@ -372,4 +379,4 @@ unsigned int ATA_CHL0_CMD_BASE = 0x1F0; 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; diff --git a/drivers/keyboard.c b/drivers/keyboard.c index dea5b29..4cb4359 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -73,6 +73,9 @@ extern tty_t default_tty; 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); @@ -118,7 +121,8 @@ void kbd_debug(uint8_t 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); } diff --git a/include/system.h b/include/system.h index 7e920eb..d353804 100644 --- a/include/system.h +++ b/include/system.h @@ -268,6 +268,7 @@ extern volatile int reenter; #define DEFAULT_BOOT_DELAY_TICKS 30 void boot_delay(int ticks); + #endif #endif //_SYSTEM_H diff --git a/kernel/assert.c b/kernel/assert.c index 639a202..933c95f 100644 --- a/kernel/assert.c +++ b/kernel/assert.c @@ -13,9 +13,10 @@ #include 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;"); } } diff --git a/kernel/setup.c b/kernel/setup.c index 4270530..d27faab 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -15,6 +15,7 @@ */ #include #include +#include #include #include @@ -37,12 +38,11 @@ extern void reboot(); 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", @@ -64,7 +64,8 @@ void setup_kernel() { 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); diff --git a/kernel/system.c b/kernel/system.c index 4bd43a2..124d6f2 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -38,27 +38,6 @@ extern char _idtr[6]; 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. diff --git a/kernel/task_root.c b/kernel/task_root.c index 5721beb..898196d 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -137,7 +137,7 @@ void taskB_entry() { } void taskC_entry() { - current->priority = 19; + current->priority = 17; while (1) { sysc_wait(1); diff --git a/kernel/tty.c b/kernel/tty.c index 8c0a289..21976e0 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -84,10 +84,6 @@ void init_tty(tty_t *tty, const char *name, unsigned long base) { 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);