]> Zhao Yanbai Git Server - kernel.git/commitdiff
read partition table
authorAceVest <zhaoyanbai@126.com>
Wed, 2 Jul 2014 16:12:17 +0000 (00:12 +0800)
committerAceVest <zhaoyanbai@126.com>
Wed, 2 Jul 2014 16:12:17 +0000 (00:12 +0800)
drivers/ide.c
drivers/ide.h
drivers/keyboard.c
drivers/vga.c
fs/ext2.c
fs/fs.c
include/printk.h
include/system.h
kernel/pci.c
kernel/printk.c
kernel/setup.c

index 7d6e49e3c8a05ac954d39333ca5f48966dd607d2..3fc7d4a97705e84e7043d6d0bbd09e07d9ab7287 100644 (file)
@@ -94,22 +94,23 @@ void ide_printd()
 {
     printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt,  drv.dma_cnt, drv.irq_cnt);
 }
-void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
+
+void _ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd, bool pio)
 {
     drv.pio_cnt++;
     drv.read_mode = cmd;
 
     ide_printd();
 
-    outb(0x00,                      REG_CTL(dev));
+    outb(0x00|(pio?0:HD_CTL_NIEN),  REG_CTL(dev));
     outb(0x40,                      REG_DEVSEL(dev));
 
-    outb(0,                         REG_NSECTOR(dev));    // High
+    outb((u8)((sect_cnt>>8)&0xFF),  REG_NSECTOR(dev));    // High
     outb((u8)((sect_nr>>24)&0xFF),  REG_LBAL(dev));
     outb((u8)((sect_nr>>32)&0xFF),  REG_LBAM(dev));
     outb((u8)((sect_nr>>40)&0xFF),  REG_LBAH(dev));
 
-    outb((u8)nsect,                 REG_NSECTOR(dev));    // Low
+    outb((u8)((sect_cnt>>0)&0xFF),  REG_NSECTOR(dev));    // Low
     outb((u8)((sect_nr>> 0)&0xFF),  REG_LBAL(dev));
     outb((u8)((sect_nr>> 8)&0xFF),  REG_LBAM(dev));
     outb((u8)((sect_nr>>16)&0xFF),  REG_LBAH(dev));
@@ -117,6 +118,36 @@ void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
     outb(cmd,                       REG_CMD(dev));
 }
 
+void ide_wait_ready()
+{
+    u32 retires = 100;
+    
+    do
+    {
+        int drq_retires = 100000;
+        while(!hd_drq(dev) && --drq_retires)
+            /* do nothing */;
+
+        if(drq_retires != 0)
+            break;
+    }while(--retires);
+
+    if(retires == 0)
+        panic("hard disk is not ready");
+}
+
+
+void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd)
+{
+    _ide_cmd_out(dev, sect_cnt, sect_nr, cmd, true);
+}
+
+void ide_wait_read(dev_t dev, u32 sect_cnt, u64 sect_nr, char *buf)
+{
+    _ide_cmd_out(dev, sect_cnt, sect_nr, HD_CMD_READ_EXT, false);
+    ide_wait_ready();
+    insl(REG_DATA(dev), buf, (sect_cnt*512)>>2);
+}
 
 void dump_pci_ide();
 
@@ -196,9 +227,10 @@ void ide_irq()
 
 void print_ide_identify(const char *buf)
 {
-    char    *p;
-    short    *ident;
-    int    i;
+    char *p;
+    short *ident;
+    int i, j;
+    unsigned char c;
 
     ident = (short *) buf;
 
@@ -209,9 +241,14 @@ void print_ide_identify(const char *buf)
 
     p = (char *) (ident+10);
     for(i=0; i<20; i++)
-    {
         hd_sn[i] = p[i];
+    for(j=0; j<20; j+=2)
+    {
+        c = hd_sn[j];
+        hd_sn[j] = hd_sn[j+1];
+        hd_sn[j+1] = c;
     }
+
     hd_sn[i] = 0;
 
     p = (char *) (ident+27);
@@ -219,6 +256,12 @@ void print_ide_identify(const char *buf)
     {
         hd_model[i] = p[i];
     }
+    for(j=0; j<20; j+=2)
+    {
+        c = hd_model[j];
+        hd_model[j] = hd_model[j+1];
+        hd_model[j+1] = c;
+    }
     hd_model[i] = 0;
 
 
@@ -235,24 +278,11 @@ void print_ide_identify(const char *buf)
 
 void ide_read_identify()
 {
-    outb(0x02, REG_CTL(0));
-    outb(0x40,                      REG_DEVSEL(dev));
+    outb(HD_CTL_NIEN,               REG_CTL(0));
+    outb(0x00,                      REG_DEVSEL(dev));
     outb(HD_CMD_IDENTIFY,           REG_CMD(dev));
 
-    u32 retires = 100;
-    
-    do
-    {
-        int drq_retires = 100000;
-        while(!hd_drq(dev) && --drq_retires)
-            /* do nothing */;
-
-        if(drq_retires != 0)
-            break;
-    }while(--retires);
-
-    if(retires == 0)
-        panic("hard disk is not ready");
+    ide_wait_ready();
 
     insl(REG_DATA(0), buf, 512>>2);
     print_ide_identify(buf);
@@ -268,7 +298,6 @@ unsigned long gprdt = 0;
     inb(HD_CHL0_CTL_BASE);  \
 }
 
-
 void ide_dma_pci_lba48()
 {
     drv.dma_cnt ++;
@@ -344,6 +373,13 @@ void ide_dma_pci_lba48()
     inb(drv.bus_status);
 }
 
+typedef struct {
+    unsigned int a;
+    unsigned int b;
+    unsigned int lba;
+    unsigned int sect_cnt;
+} hd_part_t ;
+
 void ide_init()
 {
     memset((void *)&drv, 0, sizeof(drv));
@@ -353,4 +389,16 @@ 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++;
+    }
+
+    u16_t sig = *((u16_t *) (data+510));
+    printk("IDE_INIT______READ %04x\n", sig);
 }
index 99a825288d74bcfa8c2aef6505d7ae44dbe7ddb1..ef85db4c98bff487c7b46f2417b4699b25738ce5 100644 (file)
@@ -53,11 +53,11 @@ extern unsigned int HD_CHL1_CTL_BASE;
 #define     HD_CMD_IDENTIFY     0xEC
 
 #define HD_CTL            0
-#define     HD_CTL_NORETRY      0x80    /* disable access retry */
-#define     HD_CTL_NOECC        0x40    /* disable ecc retry */
-#define     HD_CTL_EIGHTHEADS   0x08    /* more than 8 heads */
-#define     HD_CTL_RESET        0x04    /* reset controller */
-#define     HD_CTL_DISABLE_INT  0x02    /* disable interrupts */
+#define     HD_CTL_HOB          0x80    /* high order byte (LBA-48bit) */
+//#define     HD_CTL_NOECC        0x40  /* disable ecc retry */
+//#define     HD_CTL_EIGHTHEADS   0x08  /* more than 8 heads */
+#define     HD_CTL_SRST         0x04    /* soft reset controller */
+#define     HD_CTL_NIEN         0x02    /* disable interrupts */
 
 #define     HD_GET_CHL(dev)     (0)     /* only support channel 0 */
 #define     HD_GET_DEV(dev)     (0)     /* only support one hard disk */
@@ -116,3 +116,7 @@ extern unsigned int HD_CHL1_CTL_BASE;
     #define PCI_IDE_STATUS_DRV1     0x40
     #define PCI_IDE_STATUS_SIMPLEX  0x80
 #define PCI_IDE_PRDT    4
+
+
+
+#define PARTITION_TABLE_OFFSET  0x1BE
index 54354b292043238fba9b04ee7ee149863eb4a98e..48d6013b52328534d3a6d5f6d81aa36041e38b0a 100644 (file)
@@ -81,8 +81,7 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id)
 
     if(scan_code == 0x43);  // F9
     if(scan_code == 0x44);  // F10
-    if(scan_code == 0x57)   // F11
-        poweroff();
+    if(scan_code == 0x57);  // F11
     if(scan_code == 0x58)   // F12
         vga_dbg_toggle();
 
index 501d4f64c982cb68fe98c554daacbd99c9d4f7ec..8964eccdb026c62bdce32f97c956424a9160626a 100644 (file)
@@ -42,6 +42,7 @@ typedef struct {
 } vga_screen_t;
 
 #define VGA_MAX_SCREEN_CNT      4
+unsigned int vga_screen_cnt() {return VGA_MAX_SCREEN_CNT;}
 vga_screen_t vga_screen[VGA_MAX_SCREEN_CNT] = {
     {
         0,
index 009bc20ad0fa472687c4a07c476fd6e2a444b1d7..bc0df523f9cb5ac9cef57ca2553787242e9b5f91 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -18,7 +18,7 @@
 unsigned int ext2_start_sect;
 Inode    ext2_root_inode;
 
-void hd_read(Dev dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ }
+void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ }
 void    ext2_read_block(int block_id, char *buf);
 static void ext2_print_group_descriptor(pGroupDesc p);
 static void ext2_print_inode(pInode p);
diff --git a/fs/fs.c b/fs/fs.c
index d3d568f5ed60e760e064d45a9c4f6ac360b5b10a..8d7d41eb079c947de8750e872487bf9bfe223bd2 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
 #include <system.h>
 #define SECT_SIZE    512
 
-File    file_table[NR_FILES]
-    __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
+File file_table[NR_FILES] __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
 extern unsigned int ext2_start_sect;
-void    hd_read(Dev dev, u64 sect_nr, void *buf, u32 count);
-void    init_file_table();
-void    save_boot_part(int n, pPartition p, u32 base_sect);
-void    read_ext_part(u32 base, u32 offset);
+void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count);
+void init_file_table();
+void save_boot_part(int n, pPartition p, u32 base_sect);
+void read_ext_part(u32 base, u32 offset);
 
-void    setup_fs()
+void setup_fs()
 {
     int i, minor;
     pPartition p;
@@ -137,7 +136,7 @@ void    setup_fs()
 #endif
 }
 
-void    init_file_table()
+void init_file_table()
 {
     int i;
 
@@ -149,7 +148,7 @@ void    init_file_table()
     }
 }
 
-void    save_boot_part(int n, pPartition p, u32 base_sect)
+void save_boot_part(int n, pPartition p, u32 base_sect)
 {
     if(p->Type == 0x05)
         panic("partition should not be extended");
@@ -161,7 +160,7 @@ void    save_boot_part(int n, pPartition p, u32 base_sect)
 }
 
 static unsigned int ext_part = 5;
-void    read_ext_part(u32 base, u32 offset)
+void read_ext_part(u32 base, u32 offset)
 {
     unsigned char *buf;
     pPartition p;
@@ -195,4 +194,3 @@ void    read_ext_part(u32 base, u32 offset)
 
     free_virt_pages(buf);
 }
-
index 5d70088a3233b6b2d3e08b776a3b890a1fb23ddd..eaa3f13d0427c0df35cdbd85bccff81ee2a03bfd 100644 (file)
@@ -16,6 +16,7 @@
 
 #pragma once
 
+void switch_printk_screen();
 int printk(char *fmtstr, ...);
 int printd(unsigned int line, const char *fmtstr, ...);
 
index acd783448710a7b3049965d102cf63f8de897a8a..3dca32f5a44510cfdbbfe8282c84557d3194803b 100644 (file)
@@ -154,26 +154,26 @@ typedef struct pt_regs
     u16    ss, _ss;
 } __attribute__((packed)) pt_regs_t;
 
-typedef    unsigned long    Dev, *pDev;
+typedef unsigned long dev_t;
 
 typedef struct system
 {
-    u32    mmap_addr;
-    u32    mmap_size;    // Byte
+    u32 mmap_addr;
+    u32 mmap_size;    // Byte
 
-    u32    mm_lower;    // KB
-    u32    mm_upper;    // KB
-    u64    mm_size;    // Byte
+    u32 mm_lower;    // KB
+    u32 mm_upper;    // KB
+    u64 mm_size;    // Byte
 
-    u32    page_count;
-    pPage    page_map;
-    u32    page_bitmap;
+    u32 page_count;
+    pPage page_map;
+    u32   page_bitmap;
 
     u32 *page_dir;
-    u32    *pte_start;
-    u32    *pte_end;
+    u32 *pte_start;
+    u32 *pte_end;
 
-    u32    kernel_end;
+    u32 kernel_end;
 
     // +-------+-------+-------+-------+
     // | drive | part1 | part2 | part3 |
@@ -181,13 +181,13 @@ typedef struct system
     // Partition numbers always start from zero.
     // Unused partition bytes must be set to 0xFF.
     // More Infomation see 'info multiboot'
-    u32    boot_device;
+    u32 boot_device;
 
-    Dev    root_dev;
+    dev_t root_dev;
 #define CMD_LINE_SIZE    128
-    char    *cmdline;
+    char *cmdline;
 
-    u32    debug;
+    u32 debug;
 } System, *pSystem;
 
 extern    System system;
index a50665844ed4b5608374a5515640bd64bc34396d..87052f77b039542ba01a79fb4f1148af31b6030d 100644 (file)
@@ -402,6 +402,8 @@ pci_info_t pci_info[] = {
 const char *pci_get_info(unsigned int classcode, unsigned int progif)
 {
     pci_info_t *p = pci_info;
+    const char *s = 0;
+
     while(p->code != 0 || p->flag != 0 || p->info != 0)
     {
         unsigned long code = classcode;
@@ -413,10 +415,19 @@ const char *pci_get_info(unsigned int classcode, unsigned int progif)
         }
 
         if(p->code == code)
-            return p->info;
+        {
+            if(p->flag == 0)
+            {
+                return p->info;
+            }
+            else
+            {
+                s = p->info;
+            }
+        }
 
         p++;
     }
 
-    return 0;
+    return s;
 }
index 7839b8b03485f0fb5b93889375f4c48bd211c2d7..5818ee86afbb8287bbb81360911ea45250235d58 100644 (file)
 extern void vga_puts(unsigned int nr, const char *buf, unsigned char color);
 extern void vga_dbg_puts(unsigned long line, const char *buf, unsigned char color);
 
+unsigned int printk_screen_nr = 0;
+
+extern unsigned int vga_screen_cnt();
+void switch_printk_screen()
+{
+    printk_screen_nr++;
+    printk_screen_nr %= vga_screen_cnt();
+}
+
 char pkbuf[1024];
-extern int bvga;
 int printk(const char *fmtstr, ...)
 {
     char *args = (char*)(((char*)&fmtstr)+4);
     vsprintf(pkbuf, fmtstr, args);
-    vga_puts(0, pkbuf,0x2);
+    vga_puts(printk_screen_nr, pkbuf, 0x2);
     return 0;
 }
 
@@ -33,6 +41,6 @@ int printd(unsigned int line, const char *fmtstr, ...)
 {
     char *args = (char*)(((char*)&fmtstr)+4);
     vsprintf(pdbuf, fmtstr, args);
-    vga_dbg_puts(line, pdbuf,0x7);
+    vga_dbg_puts(line, pdbuf, 0x7);
     return 0;
 }
index df12110f71d3dd9bf10b8c11f0d58a019c0c6d31..fc42ac69b4a9cfd2dd04640feef47c337d93fb45 100644 (file)
@@ -84,9 +84,9 @@ void setup_kernel()
     setup_tasks();
 
     setup_irqs();
-    
+    switch_printk_screen();
     setup_pci();
-
+    switch_printk_screen();
     void ide_init();
     ide_init();