diff options
Diffstat (limited to 'kernel/con.c')
| -rw-r--r-- | kernel/con.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/kernel/con.c b/kernel/con.c index 2000fbc..5a9d2e9 100644 --- a/kernel/con.c +++ b/kernel/con.c @@ -5,6 +5,7 @@ */ #include <asm/io.h> +#include <kernel/tty.h> #include <stdarg.h> #include <stdint.h> #include <stdio.h> @@ -12,6 +13,14 @@ #define COLS 80 #define ROWS 25 +/* internal function prototypes */ +static void con_write(void); + +struct tty_struct tty_con = { + .init = NULL, + .write = &con_write +}; + static uint8_t *vram = (uint8_t*) 0xB8000; static int pos; @@ -91,6 +100,40 @@ static int con_puts(char *s) { return 0; } +/* same as con_puts() but deals with bytes rather than strings */ +static void con_write(void) { + char c; + int copied = 0; + uint8_t *p = &vram[pos]; + struct tty_queue *q = &tty_con.wqueue; + + while(q->pread != q->pwrite) { + c = q->buf[q->pread]; + if(c == '\n') { + pos = (int) (p - vram); + pos = ((pos / (COLS << 1)) + 1) * (COLS << 1); + p = &vram[pos]; + } else { + *p = c; + p += 2; + } + + q->pread = (q->pread + 1) % TTY_BUF_SIZE; + copied = 1; + + pos = (int) (p - vram); + + if(pos >= (COLS * ROWS) << 1) + scroll_up(); + } + + /* update the cursor position */ + cursorpos(pos); + + if(copied) + wake_up(&q->waiting); +} + int printk(char *fmt, ...) { int ret; char buf[1024]; |
