From: acevest Date: Sun, 21 Nov 2021 14:39:13 +0000 (+0800) Subject: 加入按扇区读硬盘功能 X-Git-Url: http://zhaoyanbai.com/repos/man.nsec3hash.html?a=commitdiff_plain;h=9515e283bc31c0189be24ecef7669b4ed2bb86b9;p=kernel.git 加入按扇区读硬盘功能 --- diff --git a/drivers/ata.c b/drivers/ata.c index 8ee4e34..6296939 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -50,14 +50,7 @@ void ata_read_data(int dev, int sect_cnt, void *dst) { insl(REG_DATA(dev), dst, void ata_read_identify(int dev) { outb(0x00, REG_CTL(dev)); outb(0x00 | ((dev & 0x01) << 4), REG_DEVICE(dev)); // 根据文档P113,这里不用指定bit5, bit7,直接指示DRIVE就行 - - unsigned long flags; - irq_save(flags); - outb(ATA_CMD_IDENTIFY, REG_CMD(dev)); - wait_on_ide(); - - irq_restore(flags); } void ata_init() { @@ -83,6 +76,22 @@ void ata_init() { u64 lba = *(u64 *)(identify + 100); printk("hard disk size: %u MB\n", (lba * 512) >> 20); } + + // TODO REMOVE + mbr_buf = kmalloc(SECT_SIZE, 0); + r.command = DISK_REQ_READ; + r.pos = 1; + r.count = 1; + r.buf = mbr_buf; + send_disk_request(&r); + + uint16_t *p = (uint16_t *)mbr_buf; + for (int i = 0; i < 256; i++) { + if (i % 12 == 0) { + printk("\n[%03d] ", i * 2); + } + printk("%04x ", p[i]); + } } void ata_read_identify_old(int dev) { // 这里所用的dev是逻辑编号 ATA0、ATA1下的Master、Salve的dev分别为0,1,2,3 diff --git a/kernel/semaphore.c b/kernel/semaphore.c index 278d339..857dca1 100644 --- a/kernel/semaphore.c +++ b/kernel/semaphore.c @@ -67,10 +67,8 @@ void up(semaphore_t *s) { // if (likely(list_empty(&s->wait_list))) { if (list_empty(&s->wait_list)) { - printk("++++++\n"); s->cnt++; } else { - printk("upupupuppupupup\n"); __up(s); } diff --git a/kernel/task_disk.c b/kernel/task_disk.c index 3d29af2..f6d8f4c 100644 --- a/kernel/task_disk.c +++ b/kernel/task_disk.c @@ -103,7 +103,12 @@ void disk_task_entry() { void ata_read_identify(int dev); ata_read_identify(dev); break; - + case DISK_REQ_READ: + assert(r->count > 0); + assert(r->buf != NULL); + void ata_dma_read_ext(int dev, uint64_t pos, uint16_t count, void *dest); + ata_dma_read_ext(dev, r->pos, r->count, r->buf); + break; default: break; }