From: AceVest Date: Mon, 7 Jul 2014 16:03:27 +0000 (+0800) Subject: read root device from cmdline X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=61fdc4e2b6cd9dda2c465700e89ed8d34a20c19f;p=kernel.git read root device from cmdline --- diff --git a/boot/boot.c b/boot/boot.c index 59d4a26..a2e3e74 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -19,10 +19,14 @@ struct boot_params boot_params __attribute__((aligned(32))); +void parse_cmdline(const char *cmdline); + void init_boot_params(multiboot_info_t *p) { boot_params.cmdline = (char *) p->cmdline; + parse_cmdline(boot_params.cmdline); + // KB to Bytes // no need to concern about 64bit boot_params.mem_lower = p->mem_lower << 10; diff --git a/boot/cmdline.c b/boot/cmdline.c index 2937e01..b37eaaf 100644 --- a/boot/cmdline.c +++ b/boot/cmdline.c @@ -15,99 +15,32 @@ #include #include -void get_variable_value(const char *name, char *value); - -void parse_root_dev() +static void get_value(const char *name, char *value) { - char value[128]; - int n; - get_variable_value("root", value); - - /* 目前只支持通道一的一个硬盘 */ - /* - printk("D:%s\n", value); - assert( value[0] == '(' && - value[1] == 'h' && - value[2] == 'd' && - value[3] == '0' && - value[4] == ','); - */ - value[0] = '('; - value[1] = 'h'; - value[2] = 'd'; - value[3] = '0'; - value[4] = ')'; - value[5] = ','; - value[6] = '0'; - value[7] = '\0'; - n = atoi(value+5); - - system.root_dev = MAKE_DEV(DEV_MAJOR_HD, n+1); -} -void parse_debug() -{ - char value[128]; - int n; - get_variable_value("debug", value); - n = atoi(value); + const char *p; + if(0 != (p = strstr(system.cmdline, name)) ) + { + if(0 != (p = strstr(p, "="))) + { + p++; + while(*p != ' ' && *p != 0) + *value++ = *p++; + } + } - system.debug = (n != 0); + *value = 0; } -void parse_cmdline(char *cmdline) +void parse_cmdline(const char *cmdline) { + char value[128]; system.cmdline = cmdline; printk("cmdline: %s\n", system.cmdline); - parse_root_dev(); - parse_debug(); -#if 0 - get_variable_value("root", value); - printk("root : %s\n", value, n); - get_variable_value("debug", value); - n = atoi(value); - printk("debug : %s %d\n", value, n); - while(1); -#endif -} - - -void get_variable_value(const char *name, char *value) -{ - char *p = system.cmdline; - char buf[256]; - int i; - *value = 0; - - while(*p) - { - while(*p != ' ') - { - if(*p++ == 0) - return; - } - p++; - i = 0; - while(*p != '=' && *p != 0) - buf[i++] = *p++; - if(*p++ == 0) - return; - buf[i] = 0; - //printk("%s %s %d\n",buf, name, strcmp(buf, name)); - - if(strcmp(buf, name) != 0) - { - while(*p != ' ' && *p != 0) - p++; - continue; - } - - i = 0; - while(*p != ' ' && *p != 0) - value[i++] = *p++; - value[i] = 0; - //printk("DD %s", value); - return ; - } + get_value("root", value); + printk("root device %s\n", value); + assert(value[0]=='h' && value[1]=='d' && value[2] == 'a'); + system.root_dev = MAKE_DEV(DEV_MAJOR_HD, atoi(value+3)); + printk("root device %08x\n", system.root_dev); } diff --git a/drivers/ide.c b/drivers/ide.c index a9a2586..56f8902 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -73,9 +73,9 @@ unsigned int HD_CHL1_CMD_BASE = 0x170; unsigned int HD_CHL0_CTL_BASE = 0x3F6; unsigned int HD_CHL1_CTL_BASE = 0x376; -void ide_printd() +void ide_printl() { - printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt, drv.dma_cnt, drv.irq_cnt); + printl(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_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd) @@ -83,7 +83,7 @@ void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd) drv.pio_cnt++; drv.read_mode = cmd; - ide_printd(); + ide_printl(); outb(0x00, REG_CTL(dev)); outb(0x40|0x00, REG_DEVSEL(dev)); @@ -124,7 +124,7 @@ void ide_do_read(u64_t lba, u32_t scnt, char *buf) while(true) { - printl("%s pid %d is going to wait\n", __func__, sysc_getpid()); + printd("%s pid %d is going to wait\n", __func__, sysc_getpid()); task->state = TASK_WAIT; irq_save(flags); finish = r->finish; @@ -134,10 +134,10 @@ void ide_do_read(u64_t lba, u32_t scnt, char *buf) break; schedule(); - printl("%s pid %d is running\n", __func__, sysc_getpid()); + printd("%s pid %d is running\n", __func__, sysc_getpid()); } - printl("%s pid %d is really running\n", __func__, sysc_getpid()); + printd("%s pid %d is really running\n", __func__, sysc_getpid()); task->state = TASK_RUNNING; del_wait_queue(&r->wait, &wait); } @@ -180,7 +180,7 @@ void ide_pci_init(pci_device_t *pci) HD_CHL1_CTL_BASE = pci->bars[3] ? pci->bars[3] : HD_CHL1_CTL_BASE; printk("channel0: cmd %04x ctl %04x channel1: cmd %04x ctl %04x\n", HD_CHL0_CMD_BASE, HD_CHL0_CTL_BASE, HD_CHL1_CMD_BASE, HD_CHL1_CTL_BASE); - printd(18, "channel0: cmd %04x ctl %04x channel1: cmd %04x ctl %04x", HD_CHL0_CMD_BASE, HD_CHL0_CTL_BASE, HD_CHL1_CMD_BASE, HD_CHL1_CTL_BASE); + printl(18, "channel0: cmd %04x ctl %04x channel1: cmd %04x ctl %04x", HD_CHL0_CMD_BASE, HD_CHL0_CTL_BASE, HD_CHL1_CMD_BASE, HD_CHL1_CTL_BASE); } @@ -211,7 +211,7 @@ void init_pci_controller(unsigned int classcode) if(pci != 0 && pci->intr_line < 16) { printk("Found PCI Vendor %04x Device %04x Class %04x IntrLine %d\n", pci->vendor, pci->device, pci->classcode, pci->intr_line); - printd(17, "Found PCI Vendor %04x Device %04x Class %04x IntrLine %d", pci->vendor, pci->device, pci->classcode, pci->intr_line); + printl(17, "Found PCI Vendor %04x Device %04x Class %04x IntrLine %d", pci->vendor, pci->device, pci->classcode, pci->intr_line); ide_pci_init(pci); drv.pci = pci; } @@ -246,10 +246,10 @@ void ide_default_intr() sig = *((u16_t *) (dma_data+510)); } - ide_printd(); + ide_printl(); - printl(" hard disk sig %04x read mode %x cnt %d\n", sig, drv.read_mode, drv.irq_cnt); - printd(MPL_IDE_INTR, "hard disk sig %x read mode %x cnt %d", sig, drv.read_mode, drv.irq_cnt); + printd(" hard disk sig %04x read mode %x cnt %d\n", sig, drv.read_mode, drv.irq_cnt); + printl(MPL_IDE_INTR, "hard disk sig %x read mode %x cnt %d", sig, drv.read_mode, drv.irq_cnt); outb(PCI_IDE_CMD_STOP, drv.bus_cmd); @@ -289,7 +289,7 @@ void ide_dma_pci_lba48() prd.eot = 1; gprdt = va2pa(&prd); - printd(16, "gprdt %08x &prdt %08x prd.addr %08x addr %08x", + printl(16, "gprdt %08x &prdt %08x prd.addr %08x addr %08x", gprdt, &prd, prd.addr, addr); outb(PCI_IDE_CMD_STOP, drv.bus_cmd); @@ -379,7 +379,7 @@ void ide_read_extended_partition(u64_t lba, unsigned int inx) panic("bad partition sect"); hd_part_t *p = (hd_part_t *)(buf+PARTITION_TABLE_OFFSET); - printl("%s:%d lba %d \n", __func__, __LINE__, lba); + printd("%s:%d lba %d \n", __func__, __LINE__, lba); for(i=0; iweight, cnt++); + printl(MPL_TASK_1+id-1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, cnt++); int v = debug_wait_queue_get(); printk("task:%d wait queue get %d\n", id, v); } @@ -52,7 +52,7 @@ void root_task_entry() int cnt = 0; while(1) { - printd(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++); + printl(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++); asm("sti;hlt;"); //sysc_test(); //syscall0(SYSC_TEST); diff --git a/kernel/irq.c b/kernel/irq.c index 0c4b7e9..6ab45b2 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -58,7 +58,7 @@ __attribute__ ((regparm(1))) void irq_handler(pt_regs_t *regs) unsigned long esp; asm("movl %%esp, %%eax":"=a"(esp)); - printd(MPL_PREEMPT, "current %08x preempt %d esp %08x", current, current->preempt_cnt, esp); + printl(MPL_PREEMPT, "current %08x preempt %d esp %08x", current, current->preempt_cnt, esp); p->chip->ack(irq); sti(); diff --git a/kernel/printk.c b/kernel/printk.c index 7e9e5c6..bfe105a 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -16,7 +16,7 @@ */ 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); +extern void vga_dbg_puts(unsigned int line, unsigned int offset, const char *buf); unsigned int printk_screen_nr = 0; @@ -36,22 +36,21 @@ int printk(const char *fmtstr, ...) return 0; } -//char plbuf[1024]; -int printl(const char *fmtstr, ...) +int printd(const char *fmtstr, ...) { - char *plbuf = (char *)kmalloc(1024, 0); + char *pdbuf = (char *)kmalloc(1024, 0); char *args = (char*)(((char*)&fmtstr)+4); - vsprintf(pkbuf, fmtstr, args); - vga_puts(3, pkbuf, 0x4); - kfree(plbuf); + vsprintf(pdbuf, fmtstr, args); + vga_puts(3, pdbuf, 0x4); + kfree(pdbuf); return 0; } -char pdbuf[1024]; -int printd(unsigned int line, const char *fmtstr, ...) +char plobuf[1024]; +int printlo(unsigned int line, unsigned int offset, const char *fmtstr, ...) { char *args = (char*)(((char*)&fmtstr)+4); - vsprintf(pdbuf, fmtstr, args); - vga_dbg_puts(line, pdbuf, 0x7); + vsprintf(plobuf, fmtstr, args); + vga_dbg_puts(line, offset, plobuf); return 0; } diff --git a/kernel/setup.c b/kernel/setup.c index a6558a8..fbe4998 100644 --- a/kernel/setup.c +++ b/kernel/setup.c @@ -79,6 +79,8 @@ void setup_kernel() cnsl_init(); + printl(MPL_TITLE, " SYSTEM MONITOR"); + printl(MPL_ROOTDEV, "root device %08x", system.root_dev); setup_tasks(); diff --git a/kernel/wait.c b/kernel/wait.c index 92f15a9..658ae85 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -59,7 +59,7 @@ int debug_wait_queue_get() while(1) { - printl("pid %d is going to wait\n", sysc_getpid()); + printd("pid %d is going to wait\n", sysc_getpid()); task->state = TASK_WAIT; disable_irq(); @@ -72,10 +72,10 @@ int debug_wait_queue_get() break; schedule(); - printl("pid %d is running\n", sysc_getpid()); + printd("pid %d is running\n", sysc_getpid()); } - printl("pid %d is really running\n", sysc_getpid()); + printd("pid %d is really running\n", sysc_getpid()); task->state = TASK_RUNNING; del_wait_queue(&debug_wq, &wait); diff --git a/lib/string.c b/lib/string.c index 82663bf..ad82cd8 100644 --- a/lib/string.c +++ b/lib/string.c @@ -73,3 +73,31 @@ void memset(void *dest, char ch, size_t size) char *d = (char *) dest; while(size--) *d++ = ch; } + +int memcmp(const void *a, const void *b, size_t count) +{ + const unsigned char *sa, *sb; + int delta = 0; + for(sa=a, sb=b; count>0; ++sa, ++sb, --count) + if((delta = *sa - *sb) != 0) + break; + return delta; +} + +char *strstr(const char *a, const char *b) +{ + size_t la, lb; + lb = strlen(b); + if(lb == 0) + return (char *) a; + la = strlen(a); + while(la >= lb) + { + la--; + if(memcmp(a, b, lb) == 0) + return (char *)a; + a++; + } + + return 0; +} diff --git a/scripts/grub.cfg b/scripts/grub.cfg index 7fc3b72..536311e 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=0 + multiboot /boot/Kernel root=hda0 }