From: AceVest Date: Fri, 27 Jun 2014 15:08:29 +0000 (+0800) Subject: monitor print line X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=dea0df6626912dcd7ba36c7d99ac3586c066c237;p=kernel.git monitor print line --- diff --git a/drivers/ide.c b/drivers/ide.c index 1b2d7c6..35f7f6f 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -27,6 +27,8 @@ typedef struct _ide_drv { pci_device_t *pci; u32_t iobase; + unsigned long cmd_out_cnt; + unsigned long irq_cnt; } ide_drive_t; ide_drive_t drv; @@ -74,8 +76,15 @@ void ide_pci_init(pci_device_t *pci) 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); } + +void ide_printd() +{ + printd(MPL_IDE, "ide cmd cnt %d irq cnt %d", drv.cmd_out_cnt, drv.irq_cnt); +} void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd) { + drv.cmd_out_cnt++; + outb(0x00, REG_CTL(dev)); outb(0x40, REG_DEVSEL(dev)); @@ -90,6 +99,8 @@ void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd) outb((u8)((sect_nr>>16)&0xFF), REG_LBAH(dev)); outb(cmd, REG_CMD(dev)); + + ide_printd(); } @@ -100,7 +111,6 @@ void ide_status() u8_t idest = inb(REG_STATUS(0)); u8_t pcist = inb(drv.iobase+PCI_IDE_STATUS); printk(" ide status %02x pci status %02x\n", idest, pcist); - } @@ -115,8 +125,6 @@ void ide_debug() nsect = (count + SECT_SIZE -1)/SECT_SIZE; ide_cmd_out(0, nsect, sect_nr, HD_CMD_READ_EXT); - - printd(4, "ide_debug\n"); } DECLARE_MUTEX(mutex); @@ -137,7 +145,7 @@ void ide_irq() { u8_t status = inb(REG_STATUS(0)); - memset(buf, 0xEE, 1024); + drv.irq_cnt++; status = inb(drv.iobase+PCI_IDE_STATUS); if(0 == (status & PCI_IDE_STATUS_INTR)) @@ -151,7 +159,8 @@ void ide_irq() insl(REG_DATA(0), buf, (512>>2)); u16_t sig = *((u16_t *) (buf+510)); - printd(11, "hard disk data %04x", sig); + printk("hard disk data %04x\n", sig); + ide_printd(); up(&mutex); } @@ -224,8 +233,9 @@ void ide_read_identify() void ide_init() { + memset((void *)&drv, 0, sizeof(drv)); init_pci_controller(PCI_VENDORID_INTEL, 0x2829); init_pci_controller(PCI_VENDORID_INTEL, 0x7010); ide_read_identify(); - printd(6, "BUFF ADDR %08x", buf); + ide_printd(); } diff --git a/drivers/keyboard.c b/drivers/keyboard.c index aba279f..745e967 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -27,11 +27,15 @@ void ide_status(); void debug_sched(); void vga_dbg_toggle(); int debug_wait_queue_put(unsigned int v); + +unsigned long kbd_cnt = 0; void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { unsigned char scan_code; scan_code = inb(0x60); + printd(MPL_KEYBOARD, "keyboard:%d scan code %02x", kbd_cnt++, scan_code); + if(scan_code == 0x01) // Esc reboot(); @@ -46,10 +50,6 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) if(scan_code == 0x14) // t debug_sched(); - if(scan_code == 0x39) // Space - vga_dbg_toggle(); - - if(scan_code == 0x3B) // F1 vga_switch(0); if(scan_code == 0x3C) // F2 @@ -59,17 +59,22 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) if(scan_code == 0x3E) // F4 vga_switch(3); - if(scan_code == 0x43) // F9 + if(scan_code == 0x3F) // F5 debug_wait_queue_put(0); - if(scan_code == 0x44) // F10 + if(scan_code == 0x40) // F6 debug_wait_queue_put(1); - if(scan_code == 0x57) // F11 + if(scan_code == 0x41) // F7 debug_wait_queue_put(2); - if(scan_code == 0x58) // F12 + if(scan_code == 0x42) // F8 debug_wait_queue_put(7); + if(scan_code == 0x43); // F9 + if(scan_code == 0x44); // F10 + if(scan_code == 0x57); // F11 + if(scan_code == 0x58) // F12 + vga_dbg_toggle(); + #if 1 - printd(10, "CNSL HEAD : %d", cnsl_rd_q.head++); cnsl_rd_q.data[0] = (char) scan_code; wake_up(&cnsl_rd_q.wait); #endif diff --git a/drivers/vga.c b/drivers/vga.c index f941b13..db2e656 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -11,6 +11,7 @@ */ #include +#include typedef struct { u8_t c; @@ -81,10 +82,13 @@ void vga_set_cursor_pos(vga_screen_t *s) base = s->id*MAX_LINES_PER_SCREEN*CHARS_PER_LINE; offset = base + s->offset; + unsigned long flags; + irq_save(flags); outb(VGA_CRTC_CURSOR_H, VGA_CRTC_ADDR); outb((offset>>8) & 0xFF, VGA_CRTC_DATA); outb(VGA_CRTC_CURSOR_L, VGA_CRTC_ADDR); outb(offset & 0xFF, VGA_CRTC_DATA); + irq_restore(flags); } void vga_clear(vga_screen_t *s, unsigned int b, unsigned int e) diff --git a/include/printk.h b/include/printk.h index 3f5d314..f8da30a 100644 --- a/include/printk.h +++ b/include/printk.h @@ -18,3 +18,16 @@ int printk(char *fmtstr, ...); int printd(unsigned int line, const char *fmtstr, ...); + +// monitor print line +enum { + MPL_CLOCK, + MPL_KEYBOARD, + MPL_IDE, + MPL_PREEMPT, + MPL_ROOT, + MPL_TASK_1, + MPL_TASK_2, + MPL_END +}; + diff --git a/include/task.h b/include/task.h index 80a2470..0215fd7 100644 --- a/include/task.h +++ b/include/task.h @@ -47,7 +47,7 @@ typedef union task_union unsigned long esp; unsigned long eip; - unsigned long weight; + long weight; pid_t pid; pid_t ppid; diff --git a/kernel/init.c b/kernel/init.c index ecb2d49..737d80e 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -21,18 +21,15 @@ Desc gdt[NGDT]; char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE))); -static unsigned int eid = 1; -void debug_sem(); int debug_wait_queue_get(); void init_task_entry() { - printk("%s\n", __func__); - unsigned int id = eid++; - int i = 0; + int cnt = 0; + pid_t id = sysc_getpid(); + while(1) { - i++; - printd(id+1, "task:%d [%08x] cnt:%d preempt_cnt %d", id, current, i, current->preempt_cnt); + printd(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); } @@ -59,11 +56,10 @@ void root_task_entry() } - int cnt; + int cnt = 0; while(1) { - printd(1, "root_task [%08x] cnt:%d preempt_cnt %d", current, cnt++, root_task.preempt_cnt); - printd(9, "pid %d ppid %d state %d weight %d", root_task.pid, root_task.ppid, root_task.state, root_task.weight); + printd(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 82bd50e..0c4b7e9 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -40,8 +40,6 @@ irq_desc_t no_irq_desc = .depth = 0 }; -static int preempt = 0; - __attribute__ ((regparm(1))) void irq_handler(pt_regs_t *regs) { unsigned int irq = regs->irq; @@ -56,24 +54,11 @@ __attribute__ ((regparm(1))) void irq_handler(pt_regs_t *regs) irq_action_t *action = p->action; - //atomic_inc(&(current->preempt_cnt)); - atomic_inc(&preempt); + atomic_inc(&(current->preempt_cnt)); unsigned long esp; - printd(8, "preempt : %d", preempt); - //asm("movl %%esp, %%eax":"=a"(esp)); - //printd(8, "preempt_cnt:%d current %08x esp %08x", current->preempt_cnt, current, esp); - //printk("preempt_cnt:%d current %08x esp %08x\n", current->preempt_cnt, current, esp); - -#if 0 - esp >>= 16; - if(esp != 0xC013 && esp != 0xC7FF) - { - asm("cli"); - printk("FUCK\n"); - while(1); - } -#endif + asm("movl %%esp, %%eax":"=a"(esp)); + printd(MPL_PREEMPT, "current %08x preempt %d esp %08x", current, current->preempt_cnt, esp); p->chip->ack(irq); sti(); @@ -85,8 +70,7 @@ __attribute__ ((regparm(1))) void irq_handler(pt_regs_t *regs) cli(); p->chip->enable(irq); - atomic_dec(&preempt); - //atomic_dec(&(current->preempt_cnt)); + atomic_dec(&(current->preempt_cnt)); } diff --git a/kernel/sched.c b/kernel/sched.c index 31cc824..59d8f11 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -168,13 +168,7 @@ unsigned long schedule() task_union *next = sel; if(prev != sel) - { - //unsigned long flags; - //irq_save(flags); - //LOAD_CR3(root_task.cr3); context_switch(prev, next); - //irq_restore(flags); - } } void debug_sched()