diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-15 03:25:51 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-15 03:26:17 -0400 |
commit | 5e8cf84fb8fb2821eb948ffd2fddafd18b18e8cc (patch) | |
tree | e816489c6b23afa83360faf27c0c493a1e81f0db /src/sys | |
parent | 40bca9deb5f81e57907e5614846678a46bcc1a49 (diff) |
kern: cons: Finish string writing logic
- Wrap on X overflow
- Wrap on Y overflow
- Keep track of max console width and height
- Add console enable/disable control
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/include/io/cons/cons.h | 1 | ||||
-rw-r--r-- | src/sys/include/sys/syslog.h | 2 | ||||
-rw-r--r-- | src/sys/io/cons/cons.c | 62 | ||||
-rw-r--r-- | src/sys/os/os_init.c | 1 | ||||
-rw-r--r-- | src/sys/os/os_syslog.c | 16 |
5 files changed, 59 insertions, 23 deletions
diff --git a/src/sys/include/io/cons/cons.h b/src/sys/include/io/cons/cons.h index 7b0543e..4ae99a0 100644 --- a/src/sys/include/io/cons/cons.h +++ b/src/sys/include/io/cons/cons.h @@ -40,6 +40,7 @@ struct cons_scr { size_t text_x; size_t text_y; size_t max_col; + size_t max_row; uint32_t scr_bg; uint32_t scr_fg; }; diff --git a/src/sys/include/sys/syslog.h b/src/sys/include/sys/syslog.h index a8b24c2..ceaef73 100644 --- a/src/sys/include/sys/syslog.h +++ b/src/sys/include/sys/syslog.h @@ -31,10 +31,12 @@ #define _SYS_SYSLOG_H_ 1 #include <stdarg.h> +#include <stdbool.h> #if defined(_KERNEL) void vprintf(const char *fmt, va_list *ap); void printf(const char *fmt, ...); +void syslog_toggle(bool enable); #endif /* _KERNEL */ #endif /* !_SYS_SYSLOG */ diff --git a/src/sys/io/cons/cons.c b/src/sys/io/cons/cons.c index 182da95..f95bf0f 100644 --- a/src/sys/io/cons/cons.c +++ b/src/sys/io/cons/cons.c @@ -39,6 +39,7 @@ #define DEFAULT_BG 0x000000 #define DEFAULT_FG 0xB57614 #define FONT_WIDTH 8 +#define FONT_HEIGHT 20 struct cons_scr g_root_scr; @@ -59,6 +60,27 @@ fb_get_index(uint32_t pitch, uint32_t x, uint32_t y) } /* + * Fill a screen with a desired background + * color + * + * @bg: Background color to fill screen + */ +static void +fill_screen(struct cons_scr *scr, uint32_t bg) +{ + struct bootvar_fb *fbvars; + size_t len; + + if (scr == NULL) { + return; + } + + fbvars = &scr->fbvars; + len = fbvars->width * fbvars->pitch; + memset(fbvars->io, bg, len); +} + +/* * Plot a single character onto the screen * * @scr: Screen to plot onto @@ -106,40 +128,33 @@ cons_putstr(struct cons_scr *scr, const char *str, size_t len) return -EINVAL; } - spinlock_acquire(&scr->lock); ch.bg = scr->scr_bg; ch.fg = scr->scr_fg; ch.y = scr->text_y; ch.x = scr->text_x; + spinlock_acquire(&scr->lock); for (size_t i = 0; i < len; ++i) { ch.c = str[i]; cons_putch(scr, &ch); - ch.x += FONT_WIDTH; - } - - return len; -} + scr->text_x += FONT_WIDTH; -/* - * Fill a screen with a desired background - * color - * - * @bg: Background color to fill screen - */ -static void -fill_screen(struct cons_scr *scr, uint32_t bg) -{ - struct bootvar_fb *fbvars; - size_t len; + /* Handle console x overflow */ + if (scr->text_x >= scr->max_col - FONT_WIDTH) { + scr->text_x = 0; + scr->text_y += FONT_HEIGHT; + } - if (scr == NULL) { - return; + /* Handle console y overflow */ + if (scr->text_y >= scr->max_row - FONT_HEIGHT) { + scr->text_x = 0; + scr->text_y = 0; + fill_screen(scr, scr->scr_bg); + } } - fbvars = &scr->fbvars; - len = fbvars->width * fbvars->pitch; - memset(fbvars->io, bg, len); + spinlock_release(&scr->lock); + return len; } /* @@ -180,7 +195,8 @@ cons_init(void) /* Set up screen state */ g_root_scr.scr_bg = DEFAULT_BG; g_root_scr.scr_fg = DEFAULT_FG; - g_root_scr.max_col = fbvars->width / 4; + g_root_scr.max_col = fbvars->width; + g_root_scr.max_row = fbvars->height; fill_screen(&g_root_scr, g_root_scr.scr_bg); return 0; } diff --git a/src/sys/os/os_init.c b/src/sys/os/os_init.c index 66e8aca..b56ab94 100644 --- a/src/sys/os/os_init.c +++ b/src/sys/os/os_init.c @@ -18,6 +18,7 @@ main(void) vm_init(); cons_init(); + syslog_toggle(true); panic("end of kernel reached\n"); for (;;); diff --git a/src/sys/os/os_syslog.c b/src/sys/os/os_syslog.c index b0e07dc..b6d30b7 100644 --- a/src/sys/os/os_syslog.c +++ b/src/sys/os/os_syslog.c @@ -30,10 +30,18 @@ #include <sys/types.h> #include <machine/uart.h> /* shared */ #include <sys/syslog.h> +#include <io/cons/cons.h> #include <os/spinlock.h> #include <string.h> #include <stdarg.h> +/* + * If this value is true, data will be written to + * the video console, otherwise only serial logging + * will be used. + */ +static bool cons_enabled = false; + static void syslog_write(const char *str, size_t len) { @@ -41,6 +49,8 @@ syslog_write(const char *str, size_t len) spinlock_acquire(&lock); for (int i = 0; i < len; ++i) { + if (cons_enabled) + cons_putstr(&g_root_scr, str, 1); uart_write(*str++); } spinlock_release(&lock); @@ -64,3 +74,9 @@ printf(const char *fmt, ...) vprintf(fmt, &ap); va_end(ap); } + +void +syslog_toggle(bool enable) +{ + cons_enabled = enable; +} |