Clean up termemu and add a new kernel vga logging mechanism

This commit is contained in:
Kevin Lange 2015-06-01 00:20:02 -07:00
parent 027d979fbc
commit 20c9535d29
5 changed files with 219 additions and 8 deletions

1
kernel/include/termemu.h Symbolic link
View File

@ -0,0 +1 @@
../../userspace/gui/terminal/lib/termemu.h

View File

@ -174,6 +174,17 @@ static void tasklet(void * data, char * name) {
write_string("Now let's debug the primary PATA drive:\n");
debug_ata_primary();
reset();
write_string("Here's /\n");
fg = 6;
list_files("/");
reset();
write_string("Here's /home");
fg = 6;
list_files("/home");
reset();
}
static int vgadbg_init(void) {

181
modules/vgalog.c Normal file
View File

@ -0,0 +1,181 @@
#include <system.h>
#include <printf.h>
#include <module.h>
#include <logging.h>
#include "../userspace/gui/terminal/lib/termemu.c"
static unsigned short * textmemptr = (unsigned short *)0xB8000;
static void placech(unsigned char c, int x, int y, int attr) {
unsigned short *where;
unsigned att = attr << 8;
where = textmemptr + (y * 80 + x);
*where = c | att;
}
static char vga_to_ansi[] = {
0, 4, 2, 6, 1, 5, 3, 7,
8,12,10,14, 9,13,11,15
};
static int current_fg = 0x07;
static int current_bg = 0x10;
static int cur_x = 0;
static int cur_y = 0;
term_state_t * ansi_state = NULL;
static int write_string(char * s) {
int written = 0;
while (*s) {
switch (*s) {
case '\n':
cur_x = 0;
cur_y++;
break;
case '\b':
if (cur_x > 0) cur_x--;
placech(' ', cur_x, cur_y, (vga_to_ansi[current_fg] & 0xF) | (vga_to_ansi[current_bg] << 4));
break;
default:
placech(*s, cur_x, cur_y, (vga_to_ansi[current_fg] & 0xF) | (vga_to_ansi[current_bg] << 4));
cur_x++;
break;
}
if (cur_x == 80) {
cur_x = 0;
cur_y++;
}
if (cur_y == 25) {
memmove(textmemptr, (textmemptr + 80), sizeof(unsigned short) * 80 * 24);
memset(textmemptr + 80 * 24, 0x00, 80 * sizeof(unsigned short));
cur_y = 24;
}
s++;
written++;
}
return written;
}
static void term_write(char c) {
char foo[] = {c,0};
write_string(foo);
}
static uint32_t vga_write(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
/* XXX do some terminal processing like we did in the old days */
size_t i = 0;
while (*buffer && i < size) {
ansi_put(ansi_state, *buffer);
buffer++;
i++;
}
return i;
}
static fs_node_t _vga_fnode = {
.name = "vga_log",
.write = vga_write,
};
static void term_scroll(int how_much) {
for (int i = 0; i < how_much; ++i) {
memmove(textmemptr, (textmemptr + 80), sizeof(unsigned short) * 80 * 24);
memset(textmemptr + 80 * 24, 0x00, 80 * sizeof(unsigned short));
}
}
static void term_set_cell(int x, int y, uint32_t c) {
placech(c, x, y, (vga_to_ansi[current_fg] & 0xF) | (vga_to_ansi[current_bg] << 4));
}
static void term_set_csr(int x, int y) {
cur_x = x;
cur_y = y;
}
static int term_get_csr_x() {
return cur_x;
}
static int term_get_csr_y() {
return cur_y;
}
static void term_set_csr_show(uint8_t on) {
return;
}
static void term_set_colors(uint32_t fg, uint32_t bg) {
current_fg = fg;
current_bg = bg;
}
static void term_redraw_cursor() {
return;
}
static void input_buffer_stuff(char * str) {
return;
}
static void set_term_font_size(float s) {
/* Do nothing */
}
static void set_title(char * c) {
/* Do nothing */
}
static void term_clear(int i) {
memset(textmemptr, 0x00, sizeof(unsigned short) * 80 * 25);
}
term_callbacks_t term_callbacks = {
/* writer*/
&term_write,
/* set_color*/
&term_set_colors,
/* set_csr*/
&term_set_csr,
/* get_csr_x*/
&term_get_csr_x,
/* get_csr_y*/
&term_get_csr_y,
/* set_cell*/
&term_set_cell,
/* cls*/
&term_clear,
/* scroll*/
&term_scroll,
/* redraw_cursor*/
&term_redraw_cursor,
/* input_buffer_stuff*/
&input_buffer_stuff,
/* set_font_size*/
&set_term_font_size,
/* set_title*/
&set_title,
};
static int vgadbg_init(void) {
memset(textmemptr, 0x00, sizeof(unsigned short) * 80 * 25);
ansi_state = ansi_init(ansi_state, 80, 25, &term_callbacks);
debug_file = &_vga_fnode;
debug_level = 1;
write_string("VGA Debug Logging is enabled.\n");
return 0;
}
static int vgadbg_fini(void) {
return 0;
}
MODULE_DEF(vgalog, vgadbg_init, vgadbg_fini);

View File

@ -8,12 +8,24 @@
#include "termemu.h"
#ifdef _KERNEL_
# include <system.h>
# include <types.h>
# include <logging.h>
static void _spin_lock(volatile int * foo) { return; }
static void _spin_unlock(volatile int * foo) { return; }
# define rgba(r,g,b,a) (((uint32_t)a * 0x1000000) + ((uint32_t)r * 0x10000) + ((uint32_t)g * 0x100) + ((uint32_t)b * 0x1))
# define rgb(r,g,b) rgba(r,g,b,0xFF)
#else
#include <stdlib.h>
#include <math.h>
#include <syscall.h>
#include "lib/graphics.h"
#include "lib/spinlock.h"
#include "lib/graphics.h"
#define _spin_lock spin_lock
#define _spin_unlock spin_unlock
#endif
#define MAX_ARGS 1024
@ -44,11 +56,11 @@ static void ansi_buf_add(term_state_t * s, char c) {
s->buffer[s->buflen] = '\0';
}
static int to_eight(uint32_t codepoint, uint8_t * out) {
static int to_eight(uint32_t codepoint, char * out) {
memset(out, 0x00, 7);
if (codepoint < 0x0080) {
out[0] = (uint8_t)codepoint;
out[0] = (char)codepoint;
} else if (codepoint < 0x0800) {
out[0] = 0xC0 | (codepoint >> 6);
out[1] = 0x80 | (codepoint & 0x3F);
@ -159,11 +171,13 @@ static void _ansi_put(term_state_t * s, char c) {
case 1:
callbacks->redraw_cursor();
break;
#ifndef _KERNEL_
case 1555:
if (argc > 1) {
callbacks->set_font_size(atof(argv[1]));
}
break;
#endif
default:
break;
}
@ -389,7 +403,7 @@ static void _ansi_put(term_state_t * s, char c) {
case ANSI_DSR:
{
char out[24];
sprintf(out, "\033[%d;%dR", callbacks->get_csr_y + 1, callbacks->get_csr_x + 1);
sprintf(out, "\033[%d;%dR", callbacks->get_csr_y() + 1, callbacks->get_csr_x() + 1);
callbacks->input_buffer_stuff(out);
}
break;
@ -479,7 +493,7 @@ static void _ansi_put(term_state_t * s, char c) {
return;
} else {
/* Still escaped */
if (c == '\n' || s->buflen > 256) {
if (c == '\n' || s->buflen == 255) {
ansi_dump_buffer(s);
callbacks->writer(c);
s->buflen = 0;
@ -505,9 +519,9 @@ static void _ansi_put(term_state_t * s, char c) {
}
void ansi_put(term_state_t * s, char c) {
spin_lock(&s->lock);
_spin_lock(&s->lock);
_ansi_put(s, c);
spin_unlock(&s->lock);
_spin_unlock(&s->lock);
}
term_state_t * ansi_init(term_state_t * s, int w, int y, term_callbacks_t * callbacks_in) {

View File

@ -1,7 +1,11 @@
#ifndef _TERMEMU_H__
#define _TERMEMU_H__
#ifdef _KERNEL_
# include <types.h>
#else
#include <stdint.h>
#endif
#define TERM_BUF_LEN 128