From: AceVest Date: Sat, 5 Jul 2014 15:36:45 +0000 (+0800) Subject: support read partition on my laptop X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=c8725043363d540b2ddd72795373518cbb7ad9ca;p=kernel.git support read partition on my laptop --- diff --git a/drivers/ide.c b/drivers/ide.c index 03c5340..6c11252 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -386,16 +386,14 @@ void ide_dma_pci_lba48() } typedef struct { - unsigned char a; - unsigned char b; - unsigned char c; - unsigned char d; - unsigned char type; - unsigned char f; - unsigned char g; - unsigned char h; - unsigned int lba; - unsigned int sect_cnt; + u8_t a; + u8_t b; + u16_t lbah; // Lba High + u8_t type; + u8_t f; + u16_t scnth; // Sector Count High + u32_t lba; // Lba Low + u32_t scnt; // Sector Count } hd_part_t ; @@ -403,12 +401,25 @@ typedef struct { char *ide_init_buf = 0; void ide_init_intr() { + //printk("%s\n", __func__); drv.irq_cnt++; u8_t status = inb(REG_STATUS(0)); + status = inb(drv.bus_status); + if(0 == (status & PCI_IDE_STATUS_INTR)) + { + return ; + } + + status |= PCI_IDE_STATUS_INTR; + outb(status, drv.bus_status); + outb(0x00, drv.bus_cmd); + insl(REG_DATA(0), ide_init_buf, (512>>2)); + outb(PCI_IDE_CMD_STOP, drv.bus_cmd); + ide_init_inted = true; } @@ -426,55 +437,16 @@ void ide_init_wait_intr() void ide_init_wait_read(u64 lba, char *buf) { ide_init_buf = buf; + ide_intr_func = ide_init_intr; _ide_cmd_out(0, 1, lba, HD_CMD_READ_EXT, true); ide_init_wait_intr(); } -#if 0 -void ide_read_partition(u64_t lba, bool extended) -{ - unsigned int i; - char *buf = kmalloc(512, 0); - if(buf == 0) - panic("no memory"); - - ide_init_wait_read(lba, buf); - - u16_t sig = *((u16_t *) (buf+510)); - if(sig != 0xAA55) - panic("bad partition sect"); - - hd_part_t *p = (hd_part_t *)(buf+PARTITION_TABLE_OFFSET); - printk("-------------------------\n"); - for(i=0; itype == 0) - continue; - - u64_t part_lba = p->lba; // TODO - u64_t part_scnt = p->sect_cnt; - - if(p->type == 0x05) - printk(" Partition[%d] [%02x] LBA %d %d\n", i, p->type, (unsigned int)part_lba, (unsigned int)((extended?drv.ext_lba_base:0)+part_lba)); - else - printk(" Partition[%d] [%02x] LBA %d %d\n", i, p->type, (unsigned int)part_lba, (unsigned int)(lba+part_lba)); - - if(p->type == 0x05) - { - if(drv.ext_lba_base == 0) - drv.ext_lba_base =part_lba; - - - ide_read_partition(part_lba+(extended?drv.ext_lba_base:0), true); - } - } - - kfree(buf); -} -#endif - void ide_read_extended_partition(u64_t lba, unsigned int inx) { + if(inx >= MAX_SUPPORT_PARTITION_CNT) + return ; + unsigned int i; char *buf = kmalloc(512, 0); if(buf == 0) @@ -494,8 +466,10 @@ void ide_read_extended_partition(u64_t lba, unsigned int inx) if(p->type == 0) continue; - u64_t part_lba = lba + p->lba; // TODO - u64_t part_scnt = p->sect_cnt; + //u64_t part_lba = lba + (p->lba|((p->lbah*1ULL)<<32)); + //u64_t part_scnt= p->scnt | ((p->scnth*1ULL)<<32); + u64_t part_lba = lba + p->lba; + u64_t part_scnt = p->scnt; if(p->type != 0x05) { @@ -532,13 +506,15 @@ void ide_read_partition() unsigned int ext_inx = ~0U; - for(i=1; itype == 0) continue; - u64_t part_lba = p->lba; // TODO - u64_t part_scnt = p->sect_cnt; + //u64_t part_lba = p->lba|((p->lbah*1ULL)<<32); + //u64_t part_scnt= p->scnt | ((p->scnth*1ULL)<<32); + u64_t part_lba = p->lba; + u64_t part_scnt = p->scnt; drv.part[i].lba_start = part_lba; drv.part[i].lba_end = part_lba+part_scnt; @@ -559,18 +535,7 @@ void ide_read_partition() kfree(buf); if(ext_inx != ~0U) - ide_read_extended_partition(drv.part[ext_inx].lba_start, 5); -} - - - -void ide_init_partition() -{ - ide_intr_func = ide_init_intr; - - ide_read_partition(); - - ide_intr_func = ide_default_intr; + ide_read_extended_partition(drv.part[ext_inx].lba_start, 4); } void ide_init() @@ -584,5 +549,7 @@ void ide_init() ide_printd(); #endif - ide_init_partition(); + ide_read_partition(); + + ide_intr_func = ide_default_intr; } diff --git a/drivers/vga.c b/drivers/vga.c index 8964ecc..00c639c 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -242,6 +242,7 @@ void vga_dbg_puts(unsigned int line, const char *buf, unsigned char color) for(i=0; *p; ++i, ++p) { + color = 0x1F; pv[i] = vga_char(*p, color); } } diff --git a/fs/fs.c b/fs/fs.c index 8d7d41e..c98d4ad 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -62,78 +62,6 @@ void setup_fs() return ; - //int j = 0xF0000000; - //while(j--); - - -/* - minor = 5; - if(minor >= 5) - { - for(i=0; i<4; i++) - { - p = (pPartition)(buf+PARTS_POS) + i; - if(p->Type == 0x05) - break; - } - assert(i<4); - //read_ext_part(0, p->AbsoluteSectNo); - read_ext_part(p->AbsoluteSectNo, 0); - } -*/ -#if 0 - outb(0x00, 0x1F1); - outb(1, 0x1F2); - outb(0x00, 0x1F3); - outb(0x00, 0x1F4); - outb(0x00, 0x1F5); - outb(0xE0, 0x1F6); - outb(0xEC, 0x1F7); - while(!(inb(0x1F7) & 0x08)){} - /* - while(1) - { - printk("%02x ", inb(0x1F7)); - }*/ - asm("cld;rep;insw;"::"c"(256), "d"(0x1F0), "D"(buf)); - - for(i=0; i<512; i++) - printk("%02x ", buf[i]); -#endif - -#if 0 -#define SZ 512 - hd_read(ROOT_DEV, 0, buf, SZ); - //hd_read(0, 1, buf+512, 512); - //hd_read(0,0,buf, 1023); - pPartition p; -#if 0 - for(i=0; iState, p->Head, p->StartSC, p->Type, - p->EndHead, p->EndSC, p->AbsoluteSectNo, p->PartitionSize); - } -#endif - -#if 0 - int j, k; - j = 0x10000; - while(j--) - { - k = 0x10000; - while(k--); - } -#endif } void init_file_table() diff --git a/kernel/setup.c b/kernel/setup.c index 6d6ac65..2e78ea7 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -25,7 +25,6 @@ extern void detect_cpu(); extern void setup_sysc(); extern void setup_pci(); extern void set_tss(); -extern void show_logo(); extern void setup_tasks(); extern void setup_root_dev(); extern void ide_init(); @@ -66,7 +65,7 @@ void setup_kernel() printk("kernel: %08x - %08x\n", &kernel_begin, &kernel_end); init_mm(); - //while(1); + setup_gdt(); setup_idt(); setup_gate(); @@ -95,7 +94,6 @@ void setup_kernel() printk("%s\n", version); - open_irq(0); return; while(1); // TODO MODIFY CODE BELOW @@ -104,7 +102,5 @@ void setup_kernel() setup_root_dev(); setup_fs(); setup_ext2(); - - show_logo(); } diff --git a/kernel/system.c b/kernel/system.c index 9aeeae0..84586d4 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -132,7 +132,7 @@ void setup_irqs() request_irq(i, default_irq_handler, "default", "default"); } - for(i=1; i<16; i++) + for(i=0; i<16; i++) open_irq(i); enable_irq(); diff --git a/scripts/grub.cfg b/scripts/grub.cfg index b2e8467..7fc3b72 100644 --- a/scripts/grub.cfg +++ b/scripts/grub.cfg @@ -8,5 +8,5 @@ insmod ext2 root=(hd0,msdos1) menuentry 'Kernel' --class os { - multiboot /boot/Kernel root=(hd0,0) debug=1 + multiboot /boot/Kernel root=0 }