Rename SYS_version to SYS_getversion
This commit is contained in:
parent
c6b044acab
commit
8e6741ebd6
7
Makefile
7
Makefile
@ -5,14 +5,15 @@ AR := x86_64-luna-ar
|
|||||||
LD := x86_64-luna-ld
|
LD := x86_64-luna-ld
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
tools/sync-libc.sh
|
||||||
@$(MAKE) -C kernel build
|
@$(MAKE) -C kernel build
|
||||||
@$(MAKE) -C apps build
|
|
||||||
@$(MAKE) -C libs build
|
@$(MAKE) -C libs build
|
||||||
|
@$(MAKE) -C apps build
|
||||||
|
|
||||||
clean: initrd-clean
|
clean: initrd-clean
|
||||||
@$(MAKE) -C kernel clean
|
@$(MAKE) -C kernel clean
|
||||||
@$(MAKE) -C apps clean
|
|
||||||
@$(MAKE) -C libs clean
|
@$(MAKE) -C libs clean
|
||||||
|
@$(MAKE) -C apps clean
|
||||||
|
|
||||||
initrd-clean:
|
initrd-clean:
|
||||||
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso
|
rm -f $(LUNA_ROOT)/initrd/boot/moon.elf $(LUNA_ROOT)/Luna.iso
|
||||||
@ -20,5 +21,5 @@ initrd-clean:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
@$(MAKE) -C kernel install
|
@$(MAKE) -C kernel install
|
||||||
@$(MAKE) -C apps install
|
|
||||||
@$(MAKE) -C libs install
|
@$(MAKE) -C libs install
|
||||||
|
@$(MAKE) -C apps install
|
@ -1,22 +1,16 @@
|
|||||||
APPS := init
|
APPS := init
|
||||||
|
|
||||||
APPS_DIR := $(LUNA_ROOT)/apps
|
APPS_DIR := $(LUNA_ROOT)/apps
|
||||||
APPS_OBJ := $(APPS_DIR)/lib
|
APPS_SRC := $(APPS_DIR)/src
|
||||||
APPS_BIN := $(APPS_DIR)/bin
|
APPS_BIN := $(APPS_DIR)/bin
|
||||||
|
|
||||||
REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))
|
REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))
|
||||||
|
|
||||||
ASMFLAGS := -felf64
|
CFLAGS := -Wall -Wextra -Werror -mgeneral-regs-only -Os
|
||||||
|
|
||||||
LDFLAGS := -nostdlib
|
$(APPS_BIN)/%: $(APPS_SRC)/%.c
|
||||||
|
|
||||||
$(APPS_OBJ)/%.o: $(APPS_DIR)/%.asm
|
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(ASM) $(ASMFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(APPS_BIN)/%: $(APPS_OBJ)/%.o
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
$(LD) $(APP_LDFLAGS) -o $@ $^
|
|
||||||
|
|
||||||
build: $(REAL_APPS)
|
build: $(REAL_APPS)
|
||||||
|
|
||||||
@ -25,5 +19,4 @@ install: $(REAL_APPS)
|
|||||||
cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
|
cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(APPS_OBJ)/*
|
|
||||||
rm -f $(APPS_BIN)/*
|
rm -f $(APPS_BIN)/*
|
@ -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
|
|
39
apps/src/init.c
Normal file
39
apps/src/init.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
@ -8,7 +8,7 @@
|
|||||||
#define SYS_write 3
|
#define SYS_write 3
|
||||||
#define SYS_paint 4
|
#define SYS_paint 4
|
||||||
#define SYS_rand 5
|
#define SYS_rand 5
|
||||||
#define SYS_version 6
|
#define SYS_getversion 6
|
||||||
#define SYS_gettid 7
|
#define SYS_gettid 7
|
||||||
|
|
||||||
namespace Syscall
|
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_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_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_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);
|
void sys_gettid(Context* context);
|
@ -21,7 +21,7 @@ void Syscall::entry(Context* context)
|
|||||||
break;
|
break;
|
||||||
case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->rdx, context->r10, context->r8); 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_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;
|
case SYS_gettid: sys_gettid(context); break;
|
||||||
default: context->rax = -1; break;
|
default: context->rax = -1; break;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "interrupts/Context.h"
|
#include "interrupts/Context.h"
|
||||||
#include "std/stdio.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());
|
context->rax = snprintf(buffer, max, "moon %s", moon_version());
|
||||||
}
|
}
|
@ -7,7 +7,7 @@
|
|||||||
#define SYS_write 3
|
#define SYS_write 3
|
||||||
#define SYS_paint 4
|
#define SYS_paint 4
|
||||||
#define SYS_rand 5
|
#define SYS_rand 5
|
||||||
#define SYS_version 6
|
#define SYS_getversion 6
|
||||||
#define SYS_gettid 7
|
#define SYS_gettid 7
|
||||||
|
|
||||||
#ifndef __want_syscalls
|
#ifndef __want_syscalls
|
||||||
|
@ -35,7 +35,7 @@ extern "C"
|
|||||||
case SYS_rand: result = __luna_syscall0(number); break;
|
case SYS_rand: result = __luna_syscall0(number); break;
|
||||||
case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break;
|
case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break;
|
||||||
case SYS_write:
|
case SYS_write:
|
||||||
case SYS_version: {
|
case SYS_getversion: {
|
||||||
arg arg0 = va_arg(ap, arg);
|
arg arg0 = va_arg(ap, arg);
|
||||||
arg arg1 = va_arg(ap, arg);
|
arg arg1 = va_arg(ap, arg);
|
||||||
result = __luna_syscall2(number, arg0, arg1);
|
result = __luna_syscall2(number, arg0, arg1);
|
||||||
|
Loading…
Reference in New Issue
Block a user