From: acevest Date: Mon, 23 Sep 2024 08:57:32 +0000 (+0800) Subject: 若不支持LBA48则不继续启动内核 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=bc2056ed078e8910924e0b3f8edc638de3d8a3d6;p=kernel.git 若不支持LBA48则不继续启动内核 --- diff --git a/drivers/ata.c b/drivers/ata.c index 97cea06..9174396 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -202,7 +202,7 @@ void ide_ata_init() { ide_drive_type = "ATA"; } else { if (ata_read_identify_packet(drv_no, 1, &status, identify)) { - printk("ATAPI DEVICE\n"); + // printk("ATAPI DEVICE\n"); drv->present = 1; drv->type = IDE_DRIVE_TYPE_ATAPI; ide_drive_type = "ATAPI"; @@ -237,7 +237,7 @@ void ide_ata_init() { // Bit 0: 1 表示设备支持软重置。 uint16_t devtype = identify[ATA_IDENT_DEVTYPE]; - printk("device type %04X\n", devtype); + // printk("device type %04X\n", devtype); // 第49个word的第8个bit位表示是否支持DMA // 第83个word的第10个bit位表示是否支持LBA48,为1表示支持。 @@ -245,14 +245,27 @@ void ide_ata_init() { // printk("%04x %04x %d %d\n", identify[49], 1 << 8, identify[49] & (1 << 8), (identify[49] & (1 << 8)) != 0); if ((identify[49] & (1 << 8)) != 0) { drv->dma = 1; + } else { + // panic("your ide disk drive do not support DMA"); } - u64 max_lba = *(u64 *)(identify + 100); + u64 max_lba = 0; + + // printk("identity[83] %04X\n", identify[83]); if ((identify[83] & (1 << 10)) != 0) { drv->lba48 = 1; - drv->max_lba = max_lba; + max_lba = *(u64 *)(identify + 100); + } else { + // panic("your ide disk drive do not support LBA48"); + max_lba = (identify[61] << 16) | identify[60]; } + + drv->max_lba = max_lba; + + // assert(drv->lba48 == 1); + // assert(drv->max_lba != 0); + // assert(drv->dma == 1); #if 1 uint16_t ata_major = identify[80]; uint16_t ata_minor = identify[81]; @@ -272,9 +285,8 @@ void ide_ata_init() { printk("ATA/ATAPI-4 "); } - printk("%04X %02X\n", ata_major, ata_minor); + printk("[Major %04X Minor %02X]\n", ata_major, ata_minor); #endif - printk("Ultra DMA modes: %04x\n", identify[88]); #if 0 uint16_t x = identify[222]; @@ -291,9 +303,11 @@ void ide_ata_init() { break; } #endif - printk("hard disk %s %s size: %u MB\n", drv->dma == 1 ? "DMA" : "", drv->lba48 == 1 ? "LBA48" : "LBA28", + printk("%s %s size: %u MB ", drv->dma == 1 ? "DMA" : "", drv->lba48 == 1 ? "LBA48" : "LBA28", (max_lba * 512) >> 20); + printk("Ultra DMA modes: %04x\n", identify[88]); + char s[64]; ata_read_identity_string(identify, 10, 19, s); printk("SN: %s\n", s); @@ -312,6 +326,16 @@ void ide_ata_init() { drv->partions[0].lba_start = 0; drv->partions[0].lba_end = drv->max_lba; } + + for (int i = 0; i < MAX_IDE_DRIVE_CNT; i++) { + int drv_no = i; + ide_drive_t *drv = ide_drives + drv_no; + if (drv->present) { + assert(drv->dma == 1); + assert(drv->lba48 == 1); + assert(drv->max_lba > 0); + } + } } void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t *b) { @@ -343,10 +367,10 @@ void read_partition_table(ide_drive_t *drv, uint32_t mbr_ext_offset, uint32_t lb char *sect = kmalloc(SECT_SIZE, 0); #if 1 - // part_no == 0 代表整场硬盘 + // part_no == 0 代表整块硬盘 tmp_ide_disk_read(MAKE_DISK_DEV(drv->drv_no, 0), lba_partition_table, 1, sect); #else - // part_no == 0 代表整场硬盘 + // part_no == 0 代表整块硬盘 r.dev = MAKE_DISK_DEV(drv->drv_no, 0); r.command = DISK_REQ_READ; r.pos = lba_partition_table; diff --git a/drivers/ide.c b/drivers/ide.c index de5c35c..2f955f5 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -134,7 +134,7 @@ void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) { // printk("ide irq %d handler pci status: 0x%02x\n", irq, ata_pci_bus_status()); int channel = irq == ide_pci_controller[0].irq_line ? 0 : 1; - printk("ide[%d] irq %d handler\n", channel, irq); + // printk("ide[%d] irq %d handler\n", channel, irq); ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel; atomic_inc(&ide_ctrl->irq_cnt); diff --git a/drivers/ide.h b/drivers/ide.h index 8cf5125..5162ea5 100644 --- a/drivers/ide.h +++ b/drivers/ide.h @@ -205,8 +205,8 @@ typedef struct _ide_drive { int type; int present; int drv_no; - int dma; - uint64_t lba48; + int dma; // 是否支持DMA + int lba48; // 是否支持LBA48 uint64_t max_lba; ide_pci_controller_t *ide_pci_controller; diff --git a/drivers/pci.c b/drivers/pci.c index e18cd32..1a5c10e 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -148,7 +148,7 @@ pci_device_t *pci_find_device_by_classcode(unsigned int classcode) { const char *pci_intr_pin(int pin) { switch (pin) { case 0: - return "NOINTPIN"; + return "NONE#"; case 1: return "INTA#"; case 2: @@ -190,10 +190,10 @@ void dump_pci_dev() { break; } #else - for (int bar_inx = 0; bar_inx < BARS_CNT; bar_inx++) { - printk("%08x ", pci->bars[bar_inx]); - } - printk("\n"); + // for (int bar_inx = 0; bar_inx < BARS_CNT; bar_inx++) { + // printk("%08x ", pci->bars[bar_inx]); + // } + // printk("\n"); #endif } } diff --git a/kernel/fork.c b/kernel/fork.c index 961d854..07046e6 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -98,7 +98,7 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { // printd("child regs: %x %x\n", child_regs, regs); memcpy(child_regs, regs, sizeof(*regs)); - //child_regs->eflags |= 0x200; + // child_regs->eflags |= 0x200; if (flags & FORK_KRNL) { strcpy(tsk->name, (char *)(child_regs->eax)); @@ -106,7 +106,7 @@ int do_fork(pt_regs_t *regs, unsigned long flags) { } else { child_regs->eip = *((unsigned long *) && fork_child); } - printk("%s fork %s EFLAGS %08x\n", current->name, tsk->name, regs->eflags); + printk("%s fork %s EFLAGS %08x\n", current->name, tsk->name, regs->eflags); // 这一句已经不需要了,通过fork_child已经能给子进程返回0了 // child_regs->eax = 0; diff --git a/kernel/setup.c b/kernel/setup.c index cca48b3..6bf2142 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -91,7 +91,7 @@ void setup_kernel() { boot_delay(DEFAULT_BOOT_DELAY_TICKS); extern tty_t *const monitor_tty; - tty_switch(monitor_tty); + // tty_switch(monitor_tty); boot_delay(DEFAULT_BOOT_DELAY_TICKS); diff --git a/kernel/task_disk.c b/kernel/task_disk.c index e78883d..bef99d5 100644 --- a/kernel/task_disk.c +++ b/kernel/task_disk.c @@ -98,8 +98,13 @@ void disk_task_entry(void *arg) { assert(MAKE_DISK_DEV(drv_no, part_id) == r->dev); uint64_t pos = r->pos + drv->partions[part_id].lba_start; - //printk("pos %lu partid %d lba end %lu\n", pos, part_id, drv->partions[part_id].lba_end); - assert(pos < drv->partions[part_id].lba_end); + // printk("pos %lu partid %d lba end %lu\n", pos, part_id, drv->partions[part_id].lba_end); + // assert(pos < drv->partions[part_id].lba_end); + if ((pos >= drv->partions[part_id].lba_end)) { + printk("pos %lu partid %d lba %u %u\n", pos, part_id, drv->partions[part_id].lba_start, + drv->partions[part_id].lba_end); + panic("INVARG"); + } // init_completion(&ide_ctrl->intr_complete); diff --git a/kernel/task_user.c b/kernel/task_user.c index 8356609..47ca131 100644 --- a/kernel/task_user.c +++ b/kernel/task_user.c @@ -51,7 +51,7 @@ void __ring3text__ __attribute__((__aligned__(PAGE_SIZE))) ring3_entry() { : "=a"(__sysc_ret__) : "a"(SYSC_WAIT), "c"(ring3_entry)); - for (int i = 100000000; i > 0; i--) { + for (int i = 10000000; i > 0; i--) { for (int j = 1; j > 0; j--) { asm("nop;nop;nop;"); } diff --git a/kernel/wait.c b/kernel/wait.c index 601feac..d987955 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -58,7 +58,7 @@ volatile void __wake_up(wait_queue_head_t *head, int nr) { irq_save(flags); list_for_each_entry_safe(p, tmp, &head->task_list, entry) { assert(p->task != NULL); - printk("wakeup %s\n", p->task->name); + // printk("wakeup %s\n", p->task->name); p->task->state = TASK_READY; p->task->reason = "wake_up";