diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-10 15:46:33 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-08-10 15:46:33 -0400 |
commit | 65ba015d6c1f248d36ad01a653bc49637804b15b (patch) | |
tree | a77c3fb3ca7ecac8f65eb9638d152f1e90307d0a /apps/init | |
download | jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.tar.gz jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.tar.bz2 jove-os-65ba015d6c1f248d36ad01a653bc49637804b15b.zip |
working usermode objdir iteration
Diffstat (limited to 'apps/init')
-rw-r--r-- | apps/init/Makefile | 21 | ||||
-rw-r--r-- | apps/init/main.c | 103 | ||||
-rw-r--r-- | apps/init/memory.h | 6 | ||||
-rw-r--r-- | apps/init/x86_64.ld | 10 |
4 files changed, 140 insertions, 0 deletions
diff --git a/apps/init/Makefile b/apps/init/Makefile new file mode 100644 index 0000000..642ca38 --- /dev/null +++ b/apps/init/Makefile @@ -0,0 +1,21 @@ +include $(CONFIG) + +CFILES := $(wildcard *.c) +OFILES := $(patsubst %.c,%.o,$(CFILES)) +OFILES += $(STATICLIBS) + +CFLAGS := -ffreestanding -nostdlib -g +LDFLAGS := -T $(TARGET_MACHINE).ld +OCFLAGS := -O binary \ + --set-section-flags .bss=alloc,load,contents + +all: $(OFILES) + $(LD) $(LDFLAGS) ${OFILES} -o init.elf + objcopy $(OCFLAGS) init.elf $(OUT)/init + +clean: + -rm ${OFILES} + -rm init.elf + +%.o:%.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/apps/init/main.c b/apps/init/main.c new file mode 100644 index 0000000..c8dabdf --- /dev/null +++ b/apps/init/main.c @@ -0,0 +1,103 @@ +#include <stdint.h> +#include <string.h> +#include <kernel/object.h> +#include <jove/jove.h> +#include <jove/object.h> +#include <jove/syscall.h> +#include <jove/arch/x86_64/object-pagemap.h> + +/**This program acts as a memory and process server.*/ + +#define INIT_HEAP_START_BYTES 4096 +__attribute__((section(".bss.heap"))) +uint8_t init_heap[INIT_HEAP_START_BYTES]; +size_t init_heap_start = (uintptr_t)init_heap; + +__attribute__((noreturn)) +static void +spin_fail(void) +{ + for(;;); +} + +void* +init_bumpalloc(size_t bytes) +{ + void *r = (void*)init_heap_start; + init_heap_start += bytes; + return r; +} + +KernelObjectTyped _logObject; +KernelObjectDirectory _untypedDirectory; +KernelObjectDirectory _processorDirectory; +KernelObjectPageMapping _pageMapping; +KernelObjectDirectory _initrd; +KernelObjectMessage _messageObject; + +#define POPULATE_ROOTDIR_MEMB(memb, i) \ +{ KernelObjectTyped *typed = JOVE_OBJECT_TYPED(memb); \ + __rootdir.children[i] = typed; \ + typed->parent = JOVE_OBJECT_TYPED(&__rootdir); \ + typed->membi = i; \ + if(_syscall_invoke_objdir_getmemb(&__rootdir, i, &typed->type) != 0) { \ + jove_kprintf("Failed to populate objdir root member %i\n", i); \ + spin_fail(); \ + } \ +} + +static void +s_populate_rootdir(init_data_t *init_data) +{ + __rootdir.typed.parent = NULL; + __rootdir.children[0] = JOVE_OBJECT_TYPED(&__rootdir); + + POPULATE_ROOTDIR_MEMB(&_logObject, init_data->log_object); + POPULATE_ROOTDIR_MEMB(&_untypedDirectory, init_data->untyped_data_dir); + POPULATE_ROOTDIR_MEMB(&_processorDirectory, init_data->processor_dir); + POPULATE_ROOTDIR_MEMB(&_pageMapping, init_data->pm_object); + POPULATE_ROOTDIR_MEMB(&_initrd, init_data->initrd_dir); + POPULATE_ROOTDIR_MEMB(&_messageObject, init_data->message_object); + + //Populate untyped table + for(int i = 1; i < 256; i++) { + KernelObjectUntyped untyped; + untyped.typed.parent = &_untypedDirectory; + untyped.typed.membi = i; + if(_syscall_invoke_objdir_getmemb(&_untypedDirectory, i, &untyped.typed.type) != 0) { + jove_kprintf("Failed to get member %i of untyped directory\n", i); + spin_fail(); + } + if(untyped.typed.type != KO_MEMORY_UNTYPED) continue; + _untypedDirectory.children[i] = init_bumpalloc(sizeof(KernelObjectUntyped)); + memcpy(_untypedDirectory.children[i], &untyped, sizeof(KernelObjectUntyped)); + + _syscall_invoke_untyped_size(&untyped, &untyped.bytes); + _syscall_invoke_untyped_alignment(&untyped, &untyped.alignment); + + jove_kprintf("Untyped %i size %X align %X\n", i, untyped.bytes, untyped.alignment); + } +} + +void +main(init_data_t *init_data) +{ + libjove_init( + (uintmax_t)init_data->message_object, + (void*)init_data->message_object_address); + jove_kprintf("Hello, Userland!\n"); + + s_populate_rootdir(init_data); + + for(;;); +} + +__attribute__((section(".text.start"))) +__attribute__((naked)) +void +_start(void) +{ + __asm__ volatile("\ + popq %%rdi; \ + jmp main"::); +} diff --git a/apps/init/memory.h b/apps/init/memory.h new file mode 100644 index 0000000..61d16d6 --- /dev/null +++ b/apps/init/memory.h @@ -0,0 +1,6 @@ +#ifndef _INIT_MEMORY_H +#define _INIT_MEMORY_H 1 + + + +#endif diff --git a/apps/init/x86_64.ld b/apps/init/x86_64.ld new file mode 100644 index 0000000..45b08f5 --- /dev/null +++ b/apps/init/x86_64.ld @@ -0,0 +1,10 @@ +OUTPUT_ARCH(i386:x86-64) + +PAGESIZE = CONSTANT(MAXPAGESIZE); + +SECTIONS +{ + . = 0x1000; + .text BLOCK(PAGESIZE) : ALIGN(PAGESIZE) { *(.text.start) *(.text) *(.rodata) } + .data BLOCK(PAGESIZE) : ALIGN(PAGESIZE) { *(.data) *(.bss) } +} |