diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-15 15:51:13 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-15 15:51:13 -0400 |
commit | 5d73ba1059771f3226c1f45d41a9e3f52d68ee3d (patch) | |
tree | d1a93562ddff3810162d5180c3fe3cda58e24dad | |
parent | 76ee61642d9d5c7d2abb8b92adec7ec59bd8791a (diff) | |
download | jove-os-5d73ba1059771f3226c1f45d41a9e3f52d68ee3d.tar.gz jove-os-5d73ba1059771f3226c1f45d41a9e3f52d68ee3d.tar.bz2 jove-os-5d73ba1059771f3226c1f45d41a9e3f52d68ee3d.zip |
begin init staging refactormain
-rw-r--r-- | apps/init/Makefile | 25 | ||||
-rw-r--r-- | apps/init/arch/x86_64/link.ld | 11 | ||||
-rw-r--r-- | apps/init/arch/x86_64/load.c | 3 | ||||
-rw-r--r-- | apps/init/arch/x86_64/paging.c | 14 | ||||
-rw-r--r-- | apps/init/arch/x86_64/start.c | 11 | ||||
-rw-r--r-- | apps/init/main.c | 32 | ||||
-rw-r--r-- | apps/init/memory.h | 10 | ||||
-rw-r--r-- | apps/init/stage1/initrd.h | 5 | ||||
-rw-r--r-- | apps/init/stage1/kprint.c | 15 | ||||
-rw-r--r-- | apps/init/stage1/kprint.h | 7 | ||||
-rw-r--r-- | apps/init/stage1/main.c | 24 | ||||
-rw-r--r-- | apps/init/stage1/memory.h | 6 | ||||
-rw-r--r-- | apps/init/stage1/stage1.h | 12 | ||||
-rw-r--r-- | apps/init/stage1/x86_64/syscall.c | 19 | ||||
-rw-r--r-- | compile_commands.json | 4 | ||||
-rwxr-xr-x | initrd/files/bin/init | bin | 20816 -> 1520 bytes | |||
m--------- | kernel | 0 |
17 files changed, 101 insertions, 97 deletions
diff --git a/apps/init/Makefile b/apps/init/Makefile index 1834d0b..679f2c4 100644 --- a/apps/init/Makefile +++ b/apps/init/Makefile @@ -1,22 +1,21 @@ include $(CONFIG) -CFILES := $(wildcard *.c) -CFILES += $(wildcard arch/$(TARGET_MACHINE)/*.c) -OFILES := $(patsubst %.c,%.o,$(CFILES)) -OFILES += $(STATICLIBS) +STAGE1_CFILES := $(wildcard stage1/*.c) +STAGE1_CFILES += $(wildcard stage1/$(TARGET_MACHINE)/*.c) +STAGE1_OFILES := $(patsubst %.c,%.o,$(STAGE1_CFILES)) -CFLAGS := -ffreestanding -nostdlib -g -LDFLAGS := -T arch/$(TARGET_MACHINE)/link.ld -OCFLAGS := -O binary \ - --set-section-flags .bss=alloc,load,contents +STAGE2_CFILES := $(wildcard stage2/*.c) +STAGE2_CFILES += $(wildcard stage2/$(TARGET_MACHINE)/*.c) -all: $(OFILES) - $(LD) $(LDFLAGS) ${OFILES} -o init.elf - objcopy $(OCFLAGS) init.elf $(OUT)/init +STAGE1_CFLAGS := -ffreestanding -nostdlib -I. +STAGE1_LDFLAGS := + +all: $(STAGE1_OFILES) + $(CC) $(STAGE1_CFLAGS) $(STAGE1_LDFLAGS) ${STAGE1_OFILES} -o $(OUT)/init clean: -rm ${OFILES} -rm init.elf -%.o:%.c - $(CC) $(CFLAGS) -c $< -o $@ +stage1/%.o:stage1/%.c + $(CC) $(STAGE1_CFLAGS) -c $< -o $@ diff --git a/apps/init/arch/x86_64/link.ld b/apps/init/arch/x86_64/link.ld deleted file mode 100644 index 79da5cb..0000000 --- a/apps/init/arch/x86_64/link.ld +++ /dev/null @@ -1,11 +0,0 @@ -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) } - __program_end = .; -} diff --git a/apps/init/arch/x86_64/load.c b/apps/init/arch/x86_64/load.c deleted file mode 100644 index c318428..0000000 --- a/apps/init/arch/x86_64/load.c +++ /dev/null @@ -1,3 +0,0 @@ -#include <elf.h> - - diff --git a/apps/init/arch/x86_64/paging.c b/apps/init/arch/x86_64/paging.c deleted file mode 100644 index 1423bec..0000000 --- a/apps/init/arch/x86_64/paging.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "../../memory.h" -#include "jove/object-dir.h" -#include "kernel/object.h" -#include <jove/arch/x86_64/object-pagemap.h> -#include <jove/arch/x86_64/pager.h> -#include <stdbool.h> - -extern void __libjove_pager_init(uint8_t); - -void -pager_setup(void) -{ - __libjove_pager_init(INIT_OBJECT_PAGEMAP); -} diff --git a/apps/init/arch/x86_64/start.c b/apps/init/arch/x86_64/start.c deleted file mode 100644 index 8329523..0000000 --- a/apps/init/arch/x86_64/start.c +++ /dev/null @@ -1,11 +0,0 @@ -extern void main(void*); - -__attribute__((section(".text.start"))) -__attribute__((naked)) -void -_start(void) -{ - __asm__ volatile("\ - popq %%rdi; \ - jmp main"::); -} diff --git a/apps/init/main.c b/apps/init/main.c deleted file mode 100644 index b802bf4..0000000 --- a/apps/init/main.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <kernel/object.h> -#include <jove/jove.h> -#include <jove/object.h> -#include <jove/syscall.h> - -#include "memory.h" - -/**This program acts as a memory and process server.*/ - -__attribute__((noreturn)) -static void -spin_fail(void) -{ - for(;;); -} - -extern void __libjove_init(uint8_t, void*); -extern void __libjove_init_untypeddir(uint8_t); -extern void __libjove_heap_init(uintptr_t); - -void -main(void *message_ptr) -{ - __libjove_init(INIT_OBJECT_MESSAGE, message_ptr); - __libjove_init_untypeddir(INIT_OBJECT_UNTYPED_DIR); - pager_setup(); - - __libjove_heap_init((uintptr_t)message_ptr + KO_MESSAGE_BYTES); - jove_kprintf("Hello, Userland!\n"); - - for(;;); -} diff --git a/apps/init/memory.h b/apps/init/memory.h deleted file mode 100644 index 378de60..0000000 --- a/apps/init/memory.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _INIT_MEMORY_H -#define _INIT_MEMORY_H 1 - -#include <jove/object.h> - -extern KernelObjectDirectory untypedDirectory; - -void pager_setup(); - -#endif diff --git a/apps/init/stage1/initrd.h b/apps/init/stage1/initrd.h new file mode 100644 index 0000000..b4bec79 --- /dev/null +++ b/apps/init/stage1/initrd.h @@ -0,0 +1,5 @@ +#ifndef INIT_STAGE1_INITRD_H +#define INIT_STAGE1_INITRD_H 1 + + +#endif diff --git a/apps/init/stage1/kprint.c b/apps/init/stage1/kprint.c new file mode 100644 index 0000000..57e10f5 --- /dev/null +++ b/apps/init/stage1/kprint.c @@ -0,0 +1,15 @@ +#include "stage1.h" +#include <kernel/syscall.h> + +void +kputc(char c) +{ + _syscall_payload[0] = c; + syscall_invoke_noret(SYSCALL_DEBUG_PUTC); +} + +void +kputs(const char *s) +{ + for(; *s; s++) kputc(*s); +} diff --git a/apps/init/stage1/kprint.h b/apps/init/stage1/kprint.h new file mode 100644 index 0000000..ea71012 --- /dev/null +++ b/apps/init/stage1/kprint.h @@ -0,0 +1,7 @@ +#ifndef INIT_STAGE1_KPRINT_H +#define INIT_STAGE1_KPRINT_H 1 + +void kputc(char c); +void kputs(const char *s); + +#endif diff --git a/apps/init/stage1/main.c b/apps/init/stage1/main.c new file mode 100644 index 0000000..90e663d --- /dev/null +++ b/apps/init/stage1/main.c @@ -0,0 +1,24 @@ +#include "stage1.h" +#include "kprint.h" +#include <kernel/init.h> + +uint8_t *_syscall_payload; +uint8_t _syscall_message; + +void main(void *init_message_ptr) +{ + _syscall_payload = init_message_ptr; + _syscall_message = INIT_OBJECT_MESSAGE; + + kputs("Hello, Userland!\n"); + for(;;); +} + +__attribute__((naked)) +void +_start(void) +{ + __asm__ volatile("\ + popq %rdi; \ + jmp main"); +} diff --git a/apps/init/stage1/memory.h b/apps/init/stage1/memory.h new file mode 100644 index 0000000..72db624 --- /dev/null +++ b/apps/init/stage1/memory.h @@ -0,0 +1,6 @@ +#ifndef INIT_STAGE1_MEMORY_H +#define INIT_STAGE1_MEMORY_H 1 + + + +#endif diff --git a/apps/init/stage1/stage1.h b/apps/init/stage1/stage1.h new file mode 100644 index 0000000..d6c3e90 --- /dev/null +++ b/apps/init/stage1/stage1.h @@ -0,0 +1,12 @@ +#ifndef INIT_STAGE1_H +#define INIT_STAGE1_H 1 + +#include <stdint.h> + +extern uint8_t *_syscall_payload; +extern uint8_t _syscall_message; + +void syscall_invoke_noret(uint64_t calltype); +intmax_t syscall_invoke_ret(uint64_t calltype); + +#endif diff --git a/apps/init/stage1/x86_64/syscall.c b/apps/init/stage1/x86_64/syscall.c new file mode 100644 index 0000000..d63be52 --- /dev/null +++ b/apps/init/stage1/x86_64/syscall.c @@ -0,0 +1,19 @@ +#include "stage1/stage1.h" + +void +syscall_invoke_noret(uint64_t calltype) +{ + __asm__ volatile("syscall":: "S"(calltype), "D"(_syscall_message): "memory"); +} + +int64_t +syscall_invoke_ret(uint64_t calltype) +{ + int rax = 0; \ + __asm__ volatile("syscall": "=a"(rax) \ + : "S"(calltype), "D"(_syscall_message) \ + : "memory"); + return rax; + +} + diff --git a/compile_commands.json b/compile_commands.json index 83764f8..aee676c 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -33,12 +33,10 @@ "arguments": [ "/home/jon/prg/jove/tools/bin/x86_64-jove-gcc", "-ffreestanding", - "-mno-sse", "-nostdlib", - "-fno-pie", - "-fno-pic", "-g", "-I/home/jon/prg/jove/sysroot/usr/include", + "-I.", "-c", "main.c", "-o", diff --git a/initrd/files/bin/init b/initrd/files/bin/init Binary files differindex a4ad338..6020cdb 100755 --- a/initrd/files/bin/init +++ b/initrd/files/bin/init diff --git a/kernel b/kernel -Subproject d26eb8b54969e79d933a8e20f2725343cd42dea +Subproject 42a2bdaecaee627247689b3f4ff2828fe3c8dc9 |