From: AceVest Date: Fri, 27 Jun 2014 14:16:32 +0000 (+0800) Subject: support multi screen X-Git-Tag: 0.3.0~44 X-Git-Url: http://zhaoyanbai.com/repos/man.rndc.html?a=commitdiff_plain;h=9bb3a6f320cddf44efed44bab0f034e0b4489c48;p=kernel.git support multi screen --- diff --git a/drivers/ide.c b/drivers/ide.c index bcaf720..1b2d7c6 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -116,15 +116,10 @@ void ide_debug() ide_cmd_out(0, nsect, sect_nr, HD_CMD_READ_EXT); - printk("ide_debug\n"); + printd(4, "ide_debug\n"); } DECLARE_MUTEX(mutex); -void debug_sem() -{ - down(&mutex); - ide_debug(); -} void init_pci_controller(unsigned int vendor, unsigned int device) { diff --git a/drivers/keyboard.c b/drivers/keyboard.c index c263536..aba279f 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -25,7 +25,7 @@ void poweroff(); void ide_debug(); void ide_status(); void debug_sched(); -void vga_toggle(); +void vga_dbg_toggle(); int debug_wait_queue_put(unsigned int v); void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { @@ -46,24 +46,31 @@ 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(scan_code == 0x39) // Space + vga_dbg_toggle(); + + if(scan_code == 0x3B) // F1 + vga_switch(0); if(scan_code == 0x3C) // F2 - debug_wait_queue_put(0); + vga_switch(1); if(scan_code == 0x3D) // F3 - debug_wait_queue_put(1); + vga_switch(2); if(scan_code == 0x3E) // F4 + vga_switch(3); + + if(scan_code == 0x43) // F9 + debug_wait_queue_put(0); + if(scan_code == 0x44) // F10 + debug_wait_queue_put(1); + if(scan_code == 0x57) // F11 debug_wait_queue_put(2); + if(scan_code == 0x58) // F12 + debug_wait_queue_put(7); #if 1 - printd(10, "CNSL HEAD : %d", cnsl_rd_q.head); - if((cnsl_rd_q.head+1) == cnsl_rd_q.tail) - goto end; - - cnsl_rd_q.data[cnsl_rd_q.head++] = (char) scan_code; - -end: + 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 882435d..f941b13 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -29,25 +29,40 @@ typedef struct { #define LINES_PER_SCREEN 25 #define CHARS_PER_LINE 80 #define BYTES_PER_LINE (sizeof(vga_char_t)*CHARS_PER_LINE) +#define MAX_LINES_PER_SCREEN 32 #define TAB_ALIGN 4 #define TAB_MASK (TAB_ALIGN-1) +typedef struct { + unsigned int id; + vga_char_t *base; + unsigned int offset; +} vga_screen_t; + +#define VGA_MAX_SCREEN_CNT 4 +vga_screen_t vga_screen[VGA_MAX_SCREEN_CNT] = { + { + 0, + (vga_char_t *)VIDEO_ADDR, + 0 + }, +}; -static unsigned int g_offset = 0; +static vga_screen_t *vga_current_screen = vga_screen + 0; -static void set_offset(unsigned int x, unsigned int y) +static void set_offset(vga_screen_t *s, unsigned int x, unsigned int y) { - g_offset = (y * CHARS_PER_LINE) + x; + s->offset = (y * CHARS_PER_LINE) + x; } -static unsigned int xpos() +static unsigned int xpos(vga_screen_t *s) { - return (g_offset % CHARS_PER_LINE); + return (s->offset % CHARS_PER_LINE); } -static unsigned int ypos() +static unsigned int ypos(vga_screen_t *s) { - return (g_offset / CHARS_PER_LINE); + return (s->offset / CHARS_PER_LINE); } vga_char_t vga_char(unsigned char c, unsigned char f) @@ -59,108 +74,156 @@ vga_char_t vga_char(unsigned char c, unsigned char f) return x; } -void vga_set_cursor_pos() +void vga_set_cursor_pos(vga_screen_t *s) { + unsigned int base = s->id*MAX_LINES_PER_SCREEN*CHARS_PER_LINE; + unsigned int offset = base + s->offset; + base = s->id*MAX_LINES_PER_SCREEN*CHARS_PER_LINE; + offset = base + s->offset; + outb(VGA_CRTC_CURSOR_H, VGA_CRTC_ADDR); - outb((g_offset>>8) & 0xFF, VGA_CRTC_DATA); + outb((offset>>8) & 0xFF, VGA_CRTC_DATA); outb(VGA_CRTC_CURSOR_L, VGA_CRTC_ADDR); - outb(g_offset & 0xFF, VGA_CRTC_DATA); + outb(offset & 0xFF, VGA_CRTC_DATA); } -void vga_clear(unsigned int b, unsigned int e) +void vga_clear(vga_screen_t *s, unsigned int b, unsigned int e) { - vga_char_t *base = (vga_char_t *) VIDEO_ADDR; + if(e <= b) + return ; + + vga_char_t *base = s->base; base += b; memset((void *)base, 0, (e-b)*sizeof(vga_char_t)); } -void vga_scroll_up() +void vga_scroll_up(vga_screen_t *s) { - int delta = ypos() + 1 - LINES_PER_SCREEN; + int delta = ypos(s) + 1 - LINES_PER_SCREEN; if(delta <= 0) return; - vga_char_t *base = (vga_char_t *) VIDEO_ADDR; + vga_char_t *base = s->base; //(vga_char_t *) VIDEO_ADDR; vga_char_t *head = base + delta*CHARS_PER_LINE; vga_char_t *empt = base + (LINES_PER_SCREEN-delta)*CHARS_PER_LINE; memcpy((void *)base, (void *)head, (empt-base)*sizeof(vga_char_t)); //memset((void *)empt, 0, delta*BYTES_PER_LINE); - vga_clear((LINES_PER_SCREEN-delta)*CHARS_PER_LINE, LINES_PER_SCREEN*CHARS_PER_LINE); + vga_clear(s, (LINES_PER_SCREEN-delta)*CHARS_PER_LINE, LINES_PER_SCREEN*CHARS_PER_LINE); - set_offset(xpos(), ypos() - delta); + set_offset(s, xpos(s), ypos(s) - delta); } -void vga_putc(const unsigned char c, const unsigned char color) +void vga_putc(vga_screen_t *s, const unsigned char c, const unsigned char color) { - vga_char_t * const pv = (vga_char_t * const) VIDEO_ADDR; + vga_char_t *pv = s->base; bool need_clear = true; - unsigned int old_offset = g_offset; + unsigned int old_offset = s->offset; switch(c) { case '\r': - set_offset(0, ypos()); + set_offset(s, 0, ypos(s)); break; case '\n': - set_offset(0, ypos() + 1); + set_offset(s, 0, ypos(s) + 1); break; case '\t': - set_offset((xpos() + 1 + TAB_MASK) & ~TAB_MASK, ypos()); + set_offset(s, (xpos(s) + 1 + TAB_MASK) & ~TAB_MASK, ypos(s)); break; default: need_clear = false; - pv[g_offset] = vga_char(c, color); - set_offset(xpos()+1, ypos()); + pv[s->offset] = vga_char(c, color); + set_offset(s, xpos(s)+1, ypos(s)); break; } if(need_clear) { - vga_clear(old_offset, g_offset); + vga_clear(s, old_offset, s->offset); } - vga_scroll_up(); + vga_scroll_up(s); - vga_set_cursor_pos(); + if(vga_current_screen == s) + vga_set_cursor_pos(s); } -void vga_puts(const char *buf, unsigned char color) + +void vga_puts(unsigned int nr, const char *buf, unsigned char color) { + if(nr >= VGA_MAX_SCREEN_CNT) + return ; + char *p = (char *) buf; + vga_screen_t *s = vga_screen + nr; while(*p) { - vga_putc(*p, color); + vga_putc(s, *p, color); p++; } } +void __vga_switch(unsigned int offset) +{ + outb(VGA_CRTC_START_ADDR_H, VGA_CRTC_ADDR); + outb((offset>>8)&0xFF, VGA_CRTC_DATA); + outb(VGA_CRTC_START_ADDR_L, VGA_CRTC_ADDR); + outb((offset)&0xFF, VGA_CRTC_DATA); +} -#define VIDEO_DBG_LINE 30 +int bvga = 0; +void vga_init() +{ + unsigned int i; + for(i=1; i= VGA_MAX_SCREEN_CNT) + return ; + + vga_screen_t *s = vga_screen + nr; + + vga_current_screen = s; + + unsigned int offset = 0 + (s->base - (vga_char_t*)VIDEO_ADDR); + + __vga_switch(offset); +} + +#define VIDEO_DBG_LINE ((VGA_MAX_SCREEN_CNT)*(MAX_LINES_PER_SCREEN)) + +void vga_dbg_toggle() { static bool dbg = true; - unsigned long addr = 0; + unsigned int offset = 0; if(dbg) { - addr += VIDEO_DBG_LINE*CHARS_PER_LINE; + offset += 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); + + __vga_switch(offset); } void vga_dbg_puts(unsigned int line, const char *buf, unsigned char color) diff --git a/kernel/clock.c b/kernel/clock.c index 5dd66df..c098386 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -20,5 +20,5 @@ void clk_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) jiffies++; printk("^"); - printd(0, "clock: %d", jiffies); + printd(0, "clock:%d", jiffies); } diff --git a/kernel/init.c b/kernel/init.c index 88bfaa3..ecb2d49 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -32,28 +32,15 @@ void init_task_entry() while(1) { i++; - - if(i == id*100) - { - printk("---READ---%d\n", id); - debug_sem(); - printk("---END----%d\n", id); - } printd(id+1, "task:%d [%08x] cnt:%d preempt_cnt %d", id, current, i, current->preempt_cnt); int v = debug_wait_queue_get(); printk("task:%d wait queue get %d\n", id, v); - //asm("sti;"); } } void root_task_entry() { -#if 0 - while(1) { - asm("sti;hlt;"); - } -#endif { pt_regs_t regs; memset((void*)®s, 0, sizeof(regs)); @@ -75,9 +62,8 @@ void root_task_entry() int cnt; 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(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); asm("sti;hlt;"); //sysc_test(); //syscall0(SYSC_TEST); diff --git a/kernel/printk.c b/kernel/printk.c index 90aa06e..7839b8b 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -15,15 +15,16 @@ *-------------------------------------------------------------------------- */ -extern void vga_puts(const char *buf, unsigned char color); +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); char pkbuf[1024]; +extern int bvga; int printk(const char *fmtstr, ...) { char *args = (char*)(((char*)&fmtstr)+4); vsprintf(pkbuf, fmtstr, args); - vga_puts(pkbuf,0x2); + vga_puts(0, pkbuf,0x2); return 0; } diff --git a/setup/setup.c b/setup/setup.c index 9adf6df..6d316ce 100644 --- a/setup/setup.c +++ b/setup/setup.c @@ -34,6 +34,7 @@ extern void setup_ext2(); extern void reboot(); extern void cnsl_init(); +extern void vga_init(); #define HZ 10 #define CLOCK_TICK_RATE 1193180 @@ -60,6 +61,8 @@ void setup_kernel() { extern char kernel_begin, kernel_end; + vga_init(); + printk("kernel: %08x - %08x\n", &kernel_begin, &kernel_end); init_mm();