summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-10-16 16:42:22 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-10-16 16:42:22 -0400
commitd8aca3ff2501f9a77e22e5afb7a30380aed205af (patch)
treea27db1749a35aea07317406f170a2d9b2a799ce7 /lib
parent548506392b789f58b1556a6ffca917441e1d89fd (diff)
downloadjove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.tar.gz
jove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.tar.bz2
jove-kernel-d8aca3ff2501f9a77e22e5afb7a30380aed205af.zip
remove explicit framebuffer in kernel. reduce locking in syscalls
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c13
-rw-r--r--lib/string.h1
-rw-r--r--lib/virtterm.c128
-rw-r--r--lib/virtterm.h19
4 files changed, 13 insertions, 148 deletions
diff --git a/lib/string.c b/lib/string.c
index 28436d5..f4d42fb 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -46,5 +46,16 @@ char *str_toupper(char *s, size_t n)
int strncmp(const char *s1, const char *s2, size_t n)
{
- return memcmp(s1, s2, n);
+ size_t i = 0;
+ for(; s1[i] && s2[i] && i < n; i++) {
+ int diff = s1[i] - s2[i];
+ if(diff) return diff;
+ }
+ return s1[i] - s2[i];
+}
+
+char *strncpy(size_t n, char *restrict s1, const char *restrict s2)
+{
+ for(size_t i = 0; s2[i] && i < n; i++) s1[i] = s2[i];
+ return s1;
}
diff --git a/lib/string.h b/lib/string.h
index bdcb0dd..1696032 100644
--- a/lib/string.h
+++ b/lib/string.h
@@ -12,5 +12,6 @@ char c_toupper(char c);
char *str_toupper(char *s, size_t n);
int strncmp(const char *s1, const char *s2, size_t n);
+char *strncpy(size_t n, char *restrict s1, const char *restrict s2);
#endif
diff --git a/lib/virtterm.c b/lib/virtterm.c
deleted file mode 100644
index ce759be..0000000
--- a/lib/virtterm.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include "virtterm.h"
-#include "boot/cmdline.h"
-#include "boot/initrd.h"
-#include "hal/obj.h"
-#include "proc/init.h"
-#include "jove.h"
-#include "hal/framebuffer.h"
-#include "sys/objdir.h"
-#include "lib/printf.h"
-#include "lib/psf.h"
-#include "lib/string.h"
-
-struct psf1_header *s_font = NULL;
-
-struct virtterm s_init_vtty = { 0 };
-
-static void
-vt_blit(struct virtterm *vtty, jove_owned_obj_t *fb, const uint8_t *glyph)
-{
- uint32_t buffer[s_font->char_height << 3];
- size_t cursor_x = vtty->cursor_col * 9;
- size_t cursor_y = vtty->cursor_row * s_font->char_height;
-
- for(size_t y = 0; y < s_font->char_height; y++) {
- uint8_t mask = 1 << 7;
- for(size_t x = 0; x < 8; x++) {
- buffer[x + (y << 3)] = glyph[y] & mask ? vtty->cursor_fg : vtty->cursor_bg;
- mask >>=1;
- }
- }
- fb_blit(fb, buffer, cursor_x, cursor_y, 8, s_font->char_height);
- vtty->cursor_col++;
-}
-
-static void
-vt_putc(struct virtterm *vtty, jove_owned_obj_t *fb, char c)
-{
- const uint8_t *glyph = &s_font->bitmap[(size_t)c * s_font->char_height];
-
- switch(c) {
- case '\n':
- vtty->cursor_col = 0;
- vtty->cursor_row++;
- break;
- default:
- vt_blit(vtty, fb, glyph);
- break;
- }
-
- if(vtty->cursor_col >= vtty->width) {
- vtty->cursor_col = 0;
- vtty->cursor_row++;
- }
- if(vtty->cursor_row >= vtty->height) {
- vtty->cursor_row = 0;
- }
-}
-
-int
-vt_write(jove_owned_obj_t *obj, const char *s, size_t n)
-{
- if(obj_gettype(obj) != JOVE_OBJ_VIRTTERM) {
- reterr(EBADOBJ);
- }
-
- struct virtterm *vtty = obj_deref(obj);
- jove_owned_obj_t *fb_obj = objdir_getlocal(_rootdir_obj, vtty->fb_obj);
- if(obj_gettype(fb_obj) != JOVE_OBJ_FRAMEBUFFER) {
- obj_release(fb_obj);
- reterr(EBADOBJ);
- }
-
- for(size_t i = 0; i < n; i++) {
- vt_putc(vtty, fb_obj, s[i]);
- }
-
- obj_release(fb_obj);
- return 0;
-}
-
-void
-vt_init()
-{
- const char *font_path = cmdline_getarg("font");
- if(font_path == NULL) {
- kprintf("Kernel commandline is missing 'font' argument. VTT is disabled.");
- return;
- }
-
- jove_owned_obj_t *initrd_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_INITRD_I);
- if(obj_gettype(initrd_obj) != JOVE_OBJ_OBJDIR) {
- kprintf("Initrd is not present. VTT is disabled.\n");
- obj_release(initrd_obj);
- return;
- }
-
- jove_owned_obj_t *file_obj = initrd_seek(initrd_obj, font_path);
- if(file_obj != NULL) {
- s_font = initrd_file_data(file_obj);
- obj_release(file_obj);
- }
-
- obj_release(initrd_obj);
-
- if(s_font == NULL) {
- kprintf("Could not find file %s in initrd. VTT is disabled.\n", font_path);
- return;
- }
- if(s_font->magic != PSF1_FONT_MAGIC) {
- kprintf("Font '%s' does not match magic number! VTT is disabled.\n", font_path);
- return;
- }
-
- s_init_vtty.fb_obj = INIT_ROOTDIR_FRAMEBUFFER_I;
- s_init_vtty.cursor_fg = 0x00FFFFFF;
-
- {
- jove_owned_obj_t *fb_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_FRAMEBUFFER_I);
- s_init_vtty.width = fb_width(fb_obj) / 9;
- s_init_vtty.height = fb_height(fb_obj) / s_font->char_height;
- obj_release(fb_obj);
-
- jove_owned_obj_t *vt_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_VIRTTERM_I);
- obj_settype(vt_obj, JOVE_OBJ_VIRTTERM);
- obj_setvalue(vt_obj, (uintmax_t)&s_init_vtty);
- obj_release(vt_obj);
- }
-}
diff --git a/lib/virtterm.h b/lib/virtterm.h
deleted file mode 100644
index 08e22e9..0000000
--- a/lib/virtterm.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _JOVE_LIB_VIRTTERM_H
-#define _JOVE_LIB_VIRTTERM_H 1
-
-#include <stddef.h>
-#include "hal/obj.h"
-
-struct virtterm
-{
- size_t fb_obj;
- size_t cursor_col, cursor_row;
- size_t width, height;
- uint32_t cursor_fg, cursor_bg;
-};
-
-int vt_write(jove_owned_obj_t *obj, const char *s, size_t n);
-
-void vt_init(void);
-
-#endif