summaryrefslogtreecommitdiffstats
path: root/boot
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 /boot
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 'boot')
-rw-r--r--boot/boot.h19
-rw-r--r--boot/cmdline.c2
-rw-r--r--boot/cmdline.h9
-rw-r--r--boot/initrd.c98
-rw-r--r--boot/initrd.h14
-rw-r--r--boot/limine/framebuffer.c82
-rw-r--r--boot/limine/memorymap.c11
-rw-r--r--boot/limine/modules.c64
-rw-r--r--boot/limine/start.c8
9 files changed, 94 insertions, 213 deletions
diff --git a/boot/boot.h b/boot/boot.h
new file mode 100644
index 0000000..1fca074
--- /dev/null
+++ b/boot/boot.h
@@ -0,0 +1,19 @@
+#ifndef _JOVE_BOOT_H
+#define _JOVE_BOOT_H 1
+
+#include "hal/obj.h"
+
+struct kernel_module
+{
+ jove_obj_t *shmem;
+ char path[128];
+};
+
+jove_owned_obj_t *boot_getmodule(const char *path);
+
+void cmdline_init(char *cmdline);
+void cmdline_print(void);
+const char *cmdline_getarg(const char *key);
+
+
+#endif
diff --git a/boot/cmdline.c b/boot/cmdline.c
index 06a6169..13edf40 100644
--- a/boot/cmdline.c
+++ b/boot/cmdline.c
@@ -1,5 +1,5 @@
#include "config.h"
-#include "cmdline.h"
+#include "boot.h"
#include <stddef.h>
#include "lib/string.h"
#include "lib/printf.h"
diff --git a/boot/cmdline.h b/boot/cmdline.h
deleted file mode 100644
index aa5da43..0000000
--- a/boot/cmdline.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef _JOVE_BOOT_CMDLINE_H
-#define _JOVE_BOOT_CMDLINE_H 1
-
-void cmdline_init(char *cmdline);
-
-void cmdline_print(void);
-const char *cmdline_getarg(const char *key);
-
-#endif
diff --git a/boot/initrd.c b/boot/initrd.c
deleted file mode 100644
index e998c08..0000000
--- a/boot/initrd.c
+++ /dev/null
@@ -1,98 +0,0 @@
-#include "initrd.h"
-#include "arch/x86_64/hal/obj.h"
-#include "proc/init.h"
-#include "jove.h"
-#include "lib/printf.h"
-#include "lib/tar.h"
-#include "lib/string.h"
-#include "hal/obj.h"
-#include "hal/memory.h"
-#include "sys/objdir.h"
-
-extern uintptr_t _initrd_module;
-
-PAGEALIGN jove_objdir_t s_initrd_objdir = { 0 };
-
-#define CHECK_IF_INITRD(obj) \
- if(obj_gettype(obj) != JOVE_OBJ_INITRD_FILE) { \
- reterr(EBADOBJ); \
- }
-
-const char*
-initrd_file_name(jove_owned_obj_t *obj)
-{
- CHECK_IF_INITRD(obj);
- struct tar_header *file = obj_deref(obj);
- return tar_filename(file);
-}
-
-size_t
-initrd_file_size(jove_owned_obj_t *obj)
-{
- CHECK_IF_INITRD(obj);
- struct tar_header *file = obj_deref(obj);
- return tar_filesize(file);
-}
-
-void*
-initrd_file_data(jove_owned_obj_t *obj)
-{
- CHECK_IF_INITRD(obj);
- union tar_block *file = obj_deref(obj);
- return &(file[1]);
-}
-
-jove_owned_obj_t*
-initrd_seek(jove_owned_obj_t *objdir, const char *path)
-{
- if(obj_gettype(objdir) != JOVE_OBJ_OBJDIR) {
- reterr(EBADOBJ);
- }
- for(size_t i = 0; i < OBJDIR_ENTRIES; i++) {
- jove_owned_obj_t *file_obj = objdir_getlocal(objdir, i);
- if(obj_gettype(file_obj) != JOVE_OBJ_INITRD_FILE) {
- goto loop_continue;
- }
- const char *filepath = initrd_file_name(file_obj);
- if(filepath == NULL) {
- goto loop_continue;
- }
-
- if(strncmp(path, filepath, strlen(filepath)+1) == 0) {
- return file_obj;
- }
-loop_continue:
- obj_release(file_obj);
- }
-
- return NULL;
-}
-
-void initrd_setup(void)
-{
- kprintf("Loading initrd from bootloader:\n");
- {
- jove_owned_obj_t *initrd_objdir_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_INITRD_I);
- obj_settype(initrd_objdir_obj, JOVE_OBJ_OBJDIR);
- obj_setvalue(initrd_objdir_obj, (uintmax_t)&s_initrd_objdir);
-
- size_t initrd_files = 0;
- union tar_block *block = phys_tovirt(_initrd_module);
- for(;;) {
- struct tar_header *header = &block->header;
- if(*header->filename == 0) break;
-
- size_t file_size = tar_filesize(header);
- kprintf("File: %s, Size: %i\n", tar_filename(header), file_size);
- {
- jove_owned_obj_t *initrd_file_obj = objdir_getlocal(initrd_objdir_obj, initrd_files++);
- obj_settype(initrd_file_obj, JOVE_OBJ_INITRD_FILE);
- obj_setvalue(initrd_file_obj, (uintmax_t)block);
- obj_release(initrd_file_obj);
- }
-
- block = &block[((file_size + 511) / 512) + 1];
- }
- obj_release(initrd_objdir_obj);
- }
-}
diff --git a/boot/initrd.h b/boot/initrd.h
deleted file mode 100644
index c56b6f8..0000000
--- a/boot/initrd.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef _JOVE_BOOT_INITRD_H
-#define _JOVE_BOOT_INITRD_H 1
-
-#include "hal/obj.h"
-
-const char *initrd_file_name(jove_owned_obj_t *obj);
-size_t initrd_file_size(jove_owned_obj_t *obj);
-void *initrd_file_data(jove_owned_obj_t *obj);
-
-jove_owned_obj_t *initrd_seek(jove_owned_obj_t *objdir, const char *name);
-
-void initrd_setup(void);
-
-#endif
diff --git a/boot/limine/framebuffer.c b/boot/limine/framebuffer.c
deleted file mode 100644
index a7ee04c..0000000
--- a/boot/limine/framebuffer.c
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "arch/x86_64/hal/obj.h"
-#include "jove.h"
-#include "lib/printf.h"
-#include "limine.h"
-#include "proc/init.h"
-#include "sys/objdir.h"
-#include "hal/framebuffer.h"
-
-extern struct limine_framebuffer_response *_limine_framebuffers;
-
-#define CHECK_IF_FB(obj) \
- if(obj_gettype(obj) != JOVE_OBJ_FRAMEBUFFER) { \
- reterr(EBADOBJ); \
- }
-
-size_t
-fb_width(jove_owned_obj_t *obj)
-{
- CHECK_IF_FB(obj);
- struct limine_framebuffer *fb = obj_deref(obj);
- return fb->width;
-}
-
-size_t
-fb_height(jove_owned_obj_t *obj)
-{
- CHECK_IF_FB(obj);
- struct limine_framebuffer *fb = obj_deref(obj);
- return fb->height;
-}
-
-int
-fb_blit(jove_owned_obj_t *obj,
- uint32_t *data,
- size_t x, size_t y,
- size_t width, size_t height)
-{
- CHECK_IF_FB(obj);
- struct limine_framebuffer *fb = obj_deref(obj);
-
- uint32_t *fb_address = fb->address;
- for(size_t oline = 0; oline < height; oline++) {
- size_t line = oline + y;
- uint32_t *line_data = &data[oline * width];
- for(size_t ocol = 0; ocol < width; ocol++) {
- size_t col = ocol + x;
- fb_address[line * (fb->pitch >> 2) + col] = line_data[ocol];
- }
- }
- return 0;
-}
-
-void
-fb_init()
-{
- if(_limine_framebuffers->framebuffer_count == 0) {
- return;
- }
- struct limine_framebuffer *fb = _limine_framebuffers->framebuffers[0];
- size_t fb_bytes = fb->width * fb->height * (fb->bpp / 8);
- void *fb_virt = fb_remap((uintptr_t)fb->address, fb_bytes);
-
- //void *fb_virt = fb->address;
- if(fb_virt == NULL) {
- kprintf("Unable to remap framebuffer.\n");
- return;
- }
-
- kprintf("framebuffer: phys address %p\n", (uintptr_t)fb->address);
- kprintf("framebuffer: virt address %p\n", fb_virt);
- kprintf("framebuffer: width %ipx\n", fb->width);
- kprintf("framebuffer: height %ipx\n", fb->height);
- kprintf("framebuffer: %i bpp\n", fb->bpp);
-
- fb->address = fb_virt;
- {
- jove_owned_obj_t *fb_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_FRAMEBUFFER_I);
- obj_settype(fb_obj, JOVE_OBJ_FRAMEBUFFER);
- obj_setvalue(fb_obj, (uintptr_t)fb);
- obj_release(fb_obj);
- }
-}
diff --git a/boot/limine/memorymap.c b/boot/limine/memorymap.c
index c558e75..7ce1da8 100644
--- a/boot/limine/memorymap.c
+++ b/boot/limine/memorymap.c
@@ -66,10 +66,11 @@ mem_setup_regions(void)
region_new(region_obj, entry->base, entry->length / 0x1000);
obj_release(region_obj);
}
- }
- if(entry->type == LIMINE_MEMMAP_RESERVED |
- entry->type == LIMINE_MEMMAP_ACPI_NVS |
- entry->type == LIMINE_MEMMAP_ACPI_TABLES)
+ }else
+ if(entry->type == LIMINE_MEMMAP_RESERVED ||
+ entry->type == LIMINE_MEMMAP_ACPI_NVS ||
+ entry->type == LIMINE_MEMMAP_ACPI_TABLES ||
+ entry->type == LIMINE_MEMMAP_FRAMEBUFFER)
{
intmax_t hw_pages = entry->length >> 12;
uintptr_t base = entry->base;
@@ -90,6 +91,8 @@ mem_setup_regions(void)
hw_pages -= 4096;
base += (4096ULL << 12);
}
+ }else{
+ klogf("Kmem %p : %p %s\n", entry->base, entry->length, limine_mmap_entry_type_str[entry->type]);
}
}
}
diff --git a/boot/limine/modules.c b/boot/limine/modules.c
new file mode 100644
index 0000000..669883e
--- /dev/null
+++ b/boot/limine/modules.c
@@ -0,0 +1,64 @@
+#include "boot/boot.h"
+#include "limine.h"
+#include "hal/obj.h"
+#include "hal/memory.h"
+#include "lib/printf.h"
+#include "lib/string.h"
+#include "proc/init.h"
+#include "panic/panic.h"
+
+static jove_objdir_t s_kmodules_objdir;
+extern struct limine_module_response *_limine_module_resp;
+
+static struct kernel_module s_modules[BOOT_MAX_MODULES];
+
+jove_owned_obj_t*
+boot_getmodule(const char *key) {
+ for(size_t i = 0; i < BOOT_MAX_MODULES; i++) {
+ if(strncmp(s_modules[i].path, key, 128) == 0)
+ return obj_take(s_modules[i].shmem);
+ }
+ errno = ENOTFOUND;
+ return NULL;
+}
+
+void
+mem_setup_modules(void)
+{
+ jove_owned_obj_t *modules_objdir = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_MODULES_I);
+ obj_settype(modules_objdir, JOVE_OBJ_OBJDIR);
+ obj_setvalue(modules_objdir, (uintptr_t)&s_kmodules_objdir);
+ jove_obj_t *modules_objdir_obj = obj_release(modules_objdir);
+
+ if(_limine_module_resp == NULL) {
+ kpanic("Limine failed to provide modules.\n");
+ }
+
+ kprintf("%s: Modules provided by Limine:\n", __func__);
+ for(size_t i = 0; i < _limine_module_resp->module_count; i++) {
+ struct limine_file *module = _limine_module_resp->modules[i];
+ if(i >= BOOT_MAX_MODULES) {
+ klogf("Maximum number of modules exceeded (%i). Some modules will be inaccessable\n", BOOT_MAX_MODULES);
+ return;
+ }
+
+ klogf("%p File %s at %p size %x\n", module, module->path, module->address, module->size);
+
+ physaddr_t module_base = phys_fromvirt((virtaddr_t)module->address);
+ size_t module_pages = (module->size + 0xFFF) / 0x1000;
+ if(module_pages > SHMEMORY_MAX_PAGES) {
+ klogf("Module exceeds length maximum (%i vs %i). Some data will be non-addressable\n",
+ module_pages, SHMEMORY_MAX_PAGES);
+ module_pages = 0xFFF;
+ }
+
+ jove_owned_obj_t *module_shmem = objdir_getlocal(modules_objdir_obj, i);
+ obj_settype(module_shmem, JOVE_OBJ_SHMEMORY);
+ obj_setvalue(module_shmem, module_base | module_pages);
+
+ s_modules[i] = (struct kernel_module) {
+ .shmem = obj_release(module_shmem)
+ };
+ strncpy(128, s_modules[i].path, module->path);
+ }
+}
diff --git a/boot/limine/start.c b/boot/limine/start.c
index 803c1de..17016ce 100644
--- a/boot/limine/start.c
+++ b/boot/limine/start.c
@@ -2,7 +2,7 @@
#include <stddef.h>
#include "api/init.h"
-#include "boot/cmdline.h"
+#include "boot/boot.h"
#include "limine.h"
void _start(void);
@@ -65,6 +65,7 @@ void *_kernel_physptr = NULL;
void *_initrd_module = NULL;
struct limine_framebuffer_response *_limine_framebuffers;
struct limine_memmap_response *_limine_memmap_resp = NULL;
+struct limine_module_response *_limine_module_resp = NULL;
__attribute__((noreturn))
void
@@ -72,14 +73,11 @@ _start(void)
{
_kernel_physptr = (void*)executable_address_req.response->physical_base;
_limine_memmap_resp = memmap_req.response;
+ _limine_module_resp = module_req.response;
_limine_framebuffers = framebuffer_request.response;
extern struct init_payload _init_payload;
_init_payload.rsdp = (void*)((uintptr_t)rsdp_request.response->address & 0xFFFFFFFF);
-
- if(module_req.response->module_count > 0) {
- _initrd_module = module_req.response->modules[0]->address;
- }
cmdline_init(cmdline_req.response->cmdline);