Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3255669)
raw | patch | inline | side by side (parent: 3255669)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Fri, 27 Jun 2014 14:16:32 +0000 (22:16 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:33 +0000 (10:45 +0800) |
| drivers/ide.c | patch | blob | history | |
| drivers/keyboard.c | patch | blob | history | |
| drivers/vga.c | patch | blob | history | |
| kernel/clock.c | patch | blob | history | |
| kernel/init.c | patch | blob | history | |
| kernel/printk.c | patch | blob | history | |
| setup/setup.c | patch | blob | history |
diff --git a/drivers/ide.c b/drivers/ide.c
--- a/drivers/ide.c
+++ b/drivers/ide.c
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
--- a/drivers/keyboard.c
+++ b/drivers/keyboard.c
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)
{
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
--- a/drivers/vga.c
+++ b/drivers/vga.c
#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)
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; ++i)
+ {
+ memset(vga_screen + i, 0, sizeof(vga_screen_t));
+ vga_screen[i].id = i;
+ vga_screen[i].base = (vga_char_t *) (VIDEO_ADDR + i*MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
+ memset(vga_screen[i].base, 0, MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
+ }
+ bvga = 1;
+}
-void vga_toggle()
+
+
+void vga_switch(unsigned int nr)
+{
+ if(nr >= 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
--- a/kernel/clock.c
+++ b/kernel/clock.c
jiffies++;
printk("^");
- printd(0, "clock: %d", jiffies);
+ printd(0, "clock:%d", jiffies);
}
diff --git a/kernel/init.c b/kernel/init.c
--- a/kernel/init.c
+++ b/kernel/init.c
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));
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
--- a/kernel/printk.c
+++ b/kernel/printk.c
*--------------------------------------------------------------------------
*/
-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
--- a/setup/setup.c
+++ b/setup/setup.c
extern void reboot();
extern void cnsl_init();
+extern void vga_init();
#define HZ 10
#define CLOCK_TICK_RATE 1193180
{
extern char kernel_begin, kernel_end;
+ vga_init();
+
printk("kernel: %08x - %08x\n", &kernel_begin, &kernel_end);
init_mm();