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;
#include <string.h>
#include <stdlib.h>
-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);
}
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)
drv.pio_cnt++;
drv.read_mode = cmd;
- ide_printd();
+ ide_printl();
outb(0x00, REG_CTL(dev));
outb(0x40|0x00, REG_DEVSEL(dev));
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;
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);
}
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);
}
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;
}
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);
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);
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; i<PARTITION_CNT; ++i, ++p)
{
ide_read_partition();
- ide_printd();
+ ide_printl();
}
unsigned char scan_code;
scan_code = inb(0x60);
- printd(MPL_KEYBOARD, "keyboard:%d scan code %02x", kbd_cnt++, scan_code);
+ printl(MPL_KEYBOARD, "keyboard:%d scan code %02x", kbd_cnt++, scan_code);
if(scan_code == 0x01) // Esc
reboot();
}
}
-void vga_dbg_puts(unsigned int line, const char *buf)
+void vga_dbg_puts(unsigned int line, unsigned int offset, const char *buf)
{
+ assert(line < LINES_PER_SCREEN);
+ assert(offset < CHARS_PER_LINE);
+
int i;
char *p = (char *) buf;
- vga_char_t * const pv = (vga_char_t * const) (VIDEO_ADDR + (VIDEO_DBG_LINE + line) * BYTES_PER_LINE);
-
- for(i=0; i<CHARS_PER_LINE; ++i)
- pv[i] = vga_char(0, vga_dbg_color);
+ vga_char_t * const pv = (vga_char_t * const) (VIDEO_ADDR + (VIDEO_DBG_LINE + line) * BYTES_PER_LINE + offset*sizeof(vga_char_t));
for(i=0; *p; ++i, ++p)
{
void switch_printk_screen();
int printk(const char *fmtstr, ...);
-int printl(const char *fmtstr, ...);
-int printd(unsigned int line, const char *fmtstr, ...);
+int printd(const char *fmtstr, ...);
+int printlo(unsigned int line, unsigned int offset, const char *fmtstr, ...);
+
+#define printl(line, fmt, args...) printlo(line, 0, fmt, ## args)
+#define printll(line, fmt, args...) printlo(line, 0, fmt, ## args)
+#define printlr(line, fmt, args...) printlo(line, 40, fmt, ## args)
// monitor print line
enum {
+ MPL_TITLE,
+ MPL_ROOTDEV,
MPL_CLOCK,
MPL_KEYBOARD,
MPL_IDE,
int strcmp(const char *a, const char *b);
int strncmp(const char *a, const char *b, size_t count);
char *strcat(char *dest, const char *src);
+char *strstr(const char *a, const char *b);
-void *memcpy(void *dest, const void *src, size_t size);
-void memset(void *dest, char ch, size_t size);
+void *memcpy(void *dest, const void *src, size_t size);
+void memset(void *dest, char ch, size_t size);
+int memcmp(const void *a, const void *b, size_t count);
#endif //_STRING_H
dev_t root_dev;
#define CMD_LINE_SIZE 128
- char *cmdline;
+ const char *cmdline;
u32 debug;
} System, *pSystem;
{
jiffies++;
- printl("^");
- printd(MPL_CLOCK, "clock:%d", jiffies);
+ printd("^");
+ printl(MPL_CLOCK, "clock:%d", jiffies);
}
while(1)
{
- printd(MPL_TASK_1+id-1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, 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);
}
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);
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();
*/
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;
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;
}
cnsl_init();
+ printl(MPL_TITLE, " SYSTEM MONITOR");
+ printl(MPL_ROOTDEV, "root device %08x", system.root_dev);
setup_tasks();
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();
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);
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;
+}
root=(hd0,msdos1)
menuentry 'Kernel' --class os {
- multiboot /boot/Kernel root=0
+ multiboot /boot/Kernel root=hda0
}