]> Zhao Yanbai Git Server - kernel.git/commitdiff
add test read hard disk partition code
authorAceVest <zhaoyanbai@126.com>
Fri, 4 Jul 2014 16:44:48 +0000 (00:44 +0800)
committerAceVest <zhaoyanbai@126.com>
Fri, 4 Jul 2014 16:44:48 +0000 (00:44 +0800)
drivers/ide.c
kernel/setup.c
lib/vsprintf.c

index 3fc7d4a97705e84e7043d6d0bbd09e07d9ab7287..ed84e578ce7b9fed0443b13a5caaf31d900ed571 100644 (file)
@@ -103,7 +103,7 @@ void _ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd, bool pio)
     ide_printd();
 
     outb(0x00|(pio?0:HD_CTL_NIEN),  REG_CTL(dev));
-    outb(0x40,                      REG_DEVSEL(dev));
+    outb(0x40|0x10,                 REG_DEVSEL(dev));
 
     outb((u8)((sect_cnt>>8)&0xFF),  REG_NSECTOR(dev));    // High
     outb((u8)((sect_nr>>24)&0xFF),  REG_LBAL(dev));
@@ -278,7 +278,7 @@ void print_ide_identify(const char *buf)
 
 void ide_read_identify()
 {
-    outb(HD_CTL_NIEN,               REG_CTL(0));
+    outb(HD_CTL_NIEN,               REG_CTL(dev));
     outb(0x00,                      REG_DEVSEL(dev));
     outb(HD_CMD_IDENTIFY,           REG_CMD(dev));
 
@@ -374,12 +374,78 @@ void ide_dma_pci_lba48()
 }
 
 typedef struct {
-    unsigned int a;
-    unsigned int b;
+    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;
 } hd_part_t ;
 
+#if 1
+void spartition(u64_t sect_nr, u64_t base)
+{
+    base += sect_nr;
+    printk("SECT NR %d\n", sect_nr);
+    char *part_buf=kmalloc(1024, 0);
+    ide_wait_read(0, 1, base, part_buf);
+
+    hd_part_t *p = (hd_part_t *)(part_buf+PARTITION_TABLE_OFFSET);
+    int i;
+    u64_t ext = ~0UL;
+    for(i=0; i<4; ++i)
+    {
+        if(p->type == 0)
+            continue;
+        printk(" Partition[%d] [%02x] LBA %d SectCnt %d\n", i, p->type, (unsigned int)(base+p->lba), (unsigned int)(base+p->lba+p->sect_cnt));
+        if(p->type == 0x05)
+            ext = p->lba;
+
+        p++;
+    }
+
+    printk("--------------------------------------------------%d\n", ext);
+    if(ext != ~0UL)
+        spartition(ext, base);
+}
+#endif
+
+static int f = 0;
+void partition(u64_t base)
+{
+    char *part_buf = kmalloc(1024, 0);
+    ide_wait_read(0, 1, base, part_buf);
+
+    hd_part_t *p = (hd_part_t *)(part_buf+PARTITION_TABLE_OFFSET);
+
+    u16_t sig = *((u16_t *) (part_buf+510));
+    //printk("---------------------------------------------%d    [%04x]\n", x, sig);
+    printk("---------------------------------------------<%d> \n", (unsigned int) base);
+
+    int i;
+    for(i=0; i<4; ++i)
+    {
+        if(p->type == 0)
+            continue;
+        printk(" Partition[%d] [%02x] LBA %d cnt %d LBABASE %d LBAEND %d\n", i, p->type, p->lba, p->sect_cnt, (unsigned int)(base+p->lba), (unsigned int)(base+p->lba+p->sect_cnt));
+
+        if(p->type == 0x05)
+        {
+            f++;
+            if(f > 1)
+                partition(p->lba+43008);
+            else
+                partition(p->lba+0);
+        }
+
+        p++;
+    }
+}
+
 void ide_init()
 {
     memset((void *)&drv, 0, sizeof(drv));
@@ -389,15 +455,8 @@ void ide_init()
     ide_read_identify();
     ide_printd();
 #endif
-    ide_wait_read(0, 1, 0, data);
-
-    hd_part_t *p = (hd_part_t *)(data+PARTITION_TABLE_OFFSET);
-    int i;
-    for(i=0; i<4; ++i)
-    {
-        printk(" Partition %d LBA %d SectCnt %d\n", i, p->lba, p->sect_cnt);
-        p++;
-    }
+    //spartition(0, 0);
+    partition(0);
 
     u16_t sig = *((u16_t *) (data+510));
     printk("IDE_INIT______READ %04x\n", sig);
index fc42ac69b4a9cfd2dd04640feef47c337d93fb45..4717c07510ecbf60b57ff0d144290eb8618a5908 100644 (file)
@@ -89,11 +89,11 @@ void setup_kernel()
     switch_printk_screen();
     void ide_init();
     ide_init();
+    switch_printk_screen();
 
     detect_cpu();
 
     printk("%s\n", version);
-    printd(0, "-----------------------------------------------------------");
 
     return;
     while(1); // TODO MODIFY CODE BELOW
index 010efa3a3f4073893b1b2c576c8da28c4e0c4718..5514c23f02856aff13b0ae887f0a60aaad0dd65a 100644 (file)
@@ -90,37 +90,13 @@ int vsprintf(char *buf, const char *fmt, char *args)
         case 'd':
             itoa(tmp, *((int*)args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);           
-#if 0
-            char_cnt -= strlen(tmp);
-            if(char_cnt > 0)
-            {
-                while(char_cnt--)
-                *p++ = char_fill;
-            }
-            strcpy(p, tmp);
-            p += strlen(tmp);
-#endif
             break;
         case 's':
             p += write_buf(p, (const char *)*((unsigned int *) args), char_fill, char_cnt, align);           
-#if 0
-            strcpy(p, (const char *)*((unsigned int *) args));
-            p += strlen((const char *)*((unsigned int *) args));
-#endif
             break;
         case 'x':
             itox(tmp, *((unsigned int *) args));
             p += write_buf(p, tmp, char_fill, char_cnt, align);           
-#if 0
-            char_cnt -= strlen(tmp);
-            if(char_cnt > 0)
-            {
-                while(char_cnt--)
-                 *p++ = char_fill;
-            }
-            strcpy(p, tmp);
-            p += strlen(tmp);
-#endif
             break;
         default:
             break;