From fb5c9ac6a87c7e3dcd90dea8a9a35bfeabf8ce6d Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 23 Jun 2014 23:18:28 +0800 Subject: [PATCH] add printd --- drivers/keyboard.c | 6 +++++- drivers/vga.c | 32 ++++++++++++++++++++++++++++++++ include/printk.h | 3 ++- kernel/clock.c | 3 +-- kernel/init.c | 10 ++++++---- kernel/printk.c | 15 +++++++++++++-- kernel/syscall.S | 1 + 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/drivers/keyboard.c b/drivers/keyboard.c index 2c0f9f8..f3cf6a9 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -25,6 +25,7 @@ void poweroff(); void ide_debug(); void ide_status(); void debug_sched(); +void vga_toggle(); void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { @@ -34,7 +35,7 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) if(scan_code == 0x01) // Esc reboot(); - printk("%02x", scan_code); + printk("[%02x]", scan_code); if(scan_code == 0x13) // r ide_debug(); @@ -45,6 +46,9 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) if(scan_code == 0x14) // t debug_sched(); + if(scan_code == 0x3B) // F1 + vga_toggle(); + if((cnsl_rd_q.head+1) == cnsl_rd_q.tail) goto end; diff --git a/drivers/vga.c b/drivers/vga.c index 8046161..882435d 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -142,3 +142,35 @@ void vga_puts(const char *buf, unsigned char color) p++; } } + + +#define VIDEO_DBG_LINE 30 + +void vga_toggle() +{ + static bool dbg = true; + unsigned long addr = 0; + if(dbg) + { + addr += VIDEO_DBG_LINE*CHARS_PER_LINE; + } + + dbg = !dbg; + + outb(VGA_CRTC_START_ADDR_H,VGA_CRTC_ADDR); + outb((addr>>8)&0xFF,VGA_CRTC_DATA); + outb(VGA_CRTC_START_ADDR_L,VGA_CRTC_ADDR); + outb((addr)&0xFF, VGA_CRTC_DATA); +} + +void vga_dbg_puts(unsigned int line, const char *buf, unsigned char color) +{ + 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; *p; ++i, ++p) + { + pv[i] = vga_char(*p, color); + } +} diff --git a/include/printk.h b/include/printk.h index 48a707b..3f5d314 100644 --- a/include/printk.h +++ b/include/printk.h @@ -16,4 +16,5 @@ #pragma once -int printk(char *fmtstr, ...); +int printk(char *fmtstr, ...); +int printd(unsigned int line, const char *fmtstr, ...); diff --git a/kernel/clock.c b/kernel/clock.c index 8bc7cd2..5dd66df 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -20,6 +20,5 @@ void clk_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) jiffies++; printk("^"); - //printk("^%d^ ", jiffies); - //printk("%s ", dev_id); + printd(0, "clock: %d", jiffies); } diff --git a/kernel/init.c b/kernel/init.c index 7711f45..20a4317 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -21,7 +21,7 @@ Desc gdt[NGDT]; char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE))); -static unsigned int eid = 1; +static unsigned int eid = 2; void debug_sem(); void init_task_entry() { @@ -31,14 +31,15 @@ void init_task_entry() while(1) { i++; + if(i == id*100) { printk("---READ---%d\n", id); debug_sem(); printk("---END----%d\n", id); } - printk("%d", id); - asm("sti;hlt;"); + printd(id, "task:%d cnt:%d", id, i); + //asm("sti;"); } } @@ -68,9 +69,10 @@ void root_task_entry() } + int cnt; while(1) { - printk("r"); + printd(1, "root_task cnt %d", cnt++); asm("sti;hlt;"); //sysc_test(); //syscall0(SYSC_TEST); diff --git a/kernel/printk.c b/kernel/printk.c index a32b5f4..b53a5c1 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -15,12 +15,23 @@ *-------------------------------------------------------------------------- */ -char pkbuf[1024]; -extern void vga_puts(const char *buf, unsigned char color); +extern void vga_puts(const char *buf, unsigned char color); +extern void vga_dbg_puts(unsigned long line, const char *buf, unsigned char color); + int printk(const char *fmtstr, ...) { + char pkbuf[1024]; char *args = (char*)(((char*)&fmtstr)+4); vsprintf(pkbuf, fmtstr, args); vga_puts(pkbuf,0x2); return 0; } + +int printd(unsigned int line, const char *fmtstr, ...) +{ + char pkbuf[1024]; + char *args = (char*)(((char*)&fmtstr)+4); + vsprintf(pkbuf, fmtstr, args); + vga_dbg_puts(line, pkbuf,0x2); + return 0; +} diff --git a/kernel/syscall.S b/kernel/syscall.S index 6dbce73..0124d36 100644 --- a/kernel/syscall.S +++ b/kernel/syscall.S @@ -76,6 +76,7 @@ ret_from_fork_user: ret_from_fork_krnl: movl PT_REGS_EDX(%esp), %edx + sti call *%edx #call do_exit -- 2.44.0