diff --git a/Makefile b/Makefile index b324cb2f..994d06e0 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,15 @@ AR := x86_64-luna-ar LD := x86_64-luna-ld build: + tools/sync-libc.sh @$(MAKE) -C kernel build - @$(MAKE) -C apps build @$(MAKE) -C libs build + @$(MAKE) -C apps build clean: initrd-clean @$(MAKE) -C kernel clean - @$(MAKE) -C apps clean @$(MAKE) -C libs clean + @$(MAKE) -C apps clean initrd-clean: rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso @@ -20,5 +21,5 @@ initrd-clean: install: @$(MAKE) -C kernel install - @$(MAKE) -C apps install - @$(MAKE) -C libs install \ No newline at end of file + @$(MAKE) -C libs install + @$(MAKE) -C apps install \ No newline at end of file diff --git a/apps/Makefile b/apps/Makefile index e9722b8c..61df706d 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,22 +1,16 @@ APPS := init APPS_DIR := $(LUNA_ROOT)/apps -APPS_OBJ := $(APPS_DIR)/lib +APPS_SRC := $(APPS_DIR)/src APPS_BIN := $(APPS_DIR)/bin REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS)) -ASMFLAGS := -felf64 +CFLAGS := -Wall -Wextra -Werror -mgeneral-regs-only -Os -LDFLAGS := -nostdlib - -$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm +$(APPS_BIN)/%: $(APPS_SRC)/%.c @mkdir -p $(@D) - $(ASM) $(ASMFLAGS) -o $@ $^ - -$(APPS_BIN)/%: $(APPS_OBJ)/%.o - @mkdir -p $(@D) - $(LD) $(APP_LDFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ build: $(REAL_APPS) @@ -25,5 +19,4 @@ install: $(REAL_APPS) cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin clean: - rm -f $(APPS_OBJ)/* rm -f $(APPS_BIN)/* \ No newline at end of file diff --git a/apps/init.asm b/apps/init.asm deleted file mode 100644 index d44fcc99..00000000 --- a/apps/init.asm +++ /dev/null @@ -1,95 +0,0 @@ -section .text -global _start -_start: - call gettid - cmp rax, 0 - jne .continue ; shenanigans: init is tid 0 (which is normally reserved for the idle task) - mov rdi, shenanigans_label - call print - jmp .end -.continue: - mov rdi, welcome_label - call print - call next_line - mov rdi, 1000 - call sleep - mov rdi, version_label - call print - call get_version - mov rdi, uname - call print - call next_line - call next_line - mov rdi, 2000 - call sleep - mov rdi, end_label - call print -.end: - call exit - -gettid: - mov rax, 7 - int 42h - ret - -sleep: - mov rax, 2 - int 42h - ret - -strlen: - push rbx - push rcx - mov rbx, rdi - xor al, al - mov rcx, 0xffffffff - repne scasb - sub rdi, rbx - mov rax, rdi - pop rcx - pop rbx - dec rax - ret - -print: ; string: rdi - push rdi - call strlen - mov rsi, rax - mov rax, 3 - pop rdi - int 42h - ret - -next_line: - mov rdi, newline - mov rsi, 1 - mov rax, 3 - int 42h - ret - -exit: - mov rax, 0 - int 42h - -get_version: - mov rdi, uname - mov rsi, 40 - mov rax, 6 - int 42h - ret - -section .rodata -version_label: - db "Your kernel version is ", 0 -welcome_label: - db "Welcome to Luna!", 0xA, 0 -end_label: - db "Press any key to restart.", 0xA, 0 -shenanigans_label: - db "SHENANIGANS: init is tid 0 (reserved for the idle task)", 0xA, 0 -newline: - db 0xA - -section .bss -uname: - resb 40 \ No newline at end of file diff --git a/apps/src/init.c b/apps/src/init.c new file mode 100644 index 00000000..553750cb --- /dev/null +++ b/apps/src/init.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +static void print(const char* message) +{ + syscall(SYS_write, message, strlen(message)); +} + +#define println(message) print(message "\n") + +int main() +{ + if (syscall(SYS_gettid) == 0) // why are we the idle task? + { + println("SHENANIGANS! init is tid 0 (which is reserved for the idle task)"); + abort(); + } + + println("Welcome to Luna from a C init!"); + println(""); + + syscall(SYS_sleep, 1000); + + print("Your kernel version is "); + + char version[40]; + syscall(SYS_getversion, version, sizeof(version)); + + print(version); + println("\n"); + + syscall(SYS_sleep, 2000); + + println("Press any key to restart."); + + return 0; +} diff --git a/kernel/include/sys/Syscall.h b/kernel/include/sys/Syscall.h index dcbd18d9..2d3bad59 100644 --- a/kernel/include/sys/Syscall.h +++ b/kernel/include/sys/Syscall.h @@ -8,7 +8,7 @@ #define SYS_write 3 #define SYS_paint 4 #define SYS_rand 5 -#define SYS_version 6 +#define SYS_getversion 6 #define SYS_gettid 7 namespace Syscall @@ -22,5 +22,5 @@ void sys_sleep(Context* context, uint64_t ms); void sys_write(Context* context, const char* addr, size_t size); void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col); void sys_rand(Context* context); -void sys_version(Context* context, char* buffer, size_t max); +void sys_getversion(Context* context, char* buffer, size_t max); void sys_gettid(Context* context); \ No newline at end of file diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index e71504b1..7059a1c0 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -21,7 +21,7 @@ void Syscall::entry(Context* context) break; case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->rdx, context->r10, context->r8); break; case SYS_rand: sys_rand(context); break; - case SYS_version: sys_version(context, (char*)context->rdi, context->rsi); break; + case SYS_getversion: sys_getversion(context, (char*)context->rdi, context->rsi); break; case SYS_gettid: sys_gettid(context); break; default: context->rax = -1; break; } diff --git a/kernel/src/sys/version.cpp b/kernel/src/sys/version.cpp index b5b21f8a..62a53c1c 100644 --- a/kernel/src/sys/version.cpp +++ b/kernel/src/sys/version.cpp @@ -2,7 +2,7 @@ #include "interrupts/Context.h" #include "std/stdio.h" -void sys_version(Context* context, char* buffer, size_t max) +void sys_getversion(Context* context, char* buffer, size_t max) { context->rax = snprintf(buffer, max, "moon %s", moon_version()); } \ No newline at end of file diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index fae8482c..07977c44 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -7,7 +7,7 @@ #define SYS_write 3 #define SYS_paint 4 #define SYS_rand 5 -#define SYS_version 6 +#define SYS_getversion 6 #define SYS_gettid 7 #ifndef __want_syscalls diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index cf7417b6..6660c91d 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -35,7 +35,7 @@ extern "C" case SYS_rand: result = __luna_syscall0(number); break; case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break; case SYS_write: - case SYS_version: { + case SYS_getversion: { arg arg0 = va_arg(ap, arg); arg arg1 = va_arg(ap, arg); result = __luna_syscall2(number, arg0, arg1);