From 040bb34290c9a4305e13637e002060411e5a8385 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 19 Aug 2022 23:36:29 +0200 Subject: include: make camellia/syscalls.h compatible with assembly --- Makefile | 2 +- src/shared/include/camellia/syscalls.h | 47 +++++++++++++++++----------------- src/user/lib/elfload.S | 20 +++++++++++++++ src/user/lib/elfload.s | 17 ------------ 4 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 src/user/lib/elfload.S delete mode 100644 src/user/lib/elfload.s diff --git a/Makefile b/Makefile index 102c00d..dd4cdbd 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ out/obj/%.s.o: src/%.s out/obj/%.S.o: src/%.S @mkdir -p $(@D) - @$(CC) -c $^ -o $@ + @$(CC) $(CFLAGS) -c $^ -o $@ out/obj/shared/%.c.o: src/shared/%.c @mkdir -p $(@D) diff --git a/src/shared/include/camellia/syscalls.h b/src/shared/include/camellia/syscalls.h index dfc964f..04dfba5 100644 --- a/src/shared/include/camellia/syscalls.h +++ b/src/shared/include/camellia/syscalls.h @@ -1,35 +1,34 @@ #pragma once -#include -#include -enum { - // idc about stable syscall numbers just yet - _SYSCALL_EXIT, - _SYSCALL_AWAIT, - _SYSCALL_FORK, +#define _SYSCALL_EXIT 0 +#define _SYSCALL_AWAIT 1 +#define _SYSCALL_FORK 2 + +#define _SYSCALL_OPEN 3 +#define _SYSCALL_MOUNT 4 +#define _SYSCALL_DUP 5 - _SYSCALL_OPEN, - _SYSCALL_MOUNT, - _SYSCALL_DUP, +#define _SYSCALL_READ 6 +#define _SYSCALL_WRITE 7 +#define _SYSCALL_GETSIZE 8 +#define _SYSCALL_REMOVE 9 +#define _SYSCALL_CLOSE 10 - _SYSCALL_READ, - _SYSCALL_WRITE, - _SYSCALL_GETSIZE, - _SYSCALL_REMOVE, - _SYSCALL_CLOSE, +#define _SYSCALL_FS_WAIT 11 +#define _SYSCALL_FS_RESPOND 12 - _SYSCALL_FS_WAIT, - _SYSCALL_FS_RESPOND, +#define _SYSCALL_MEMFLAG 13 +#define _SYSCALL_PIPE 14 - _SYSCALL_MEMFLAG, - _SYSCALL_PIPE, +#define _SYSCALL_SLEEP 15 - _SYSCALL_SLEEP, +#define _SYSCALL_EXECBUF 100 - _SYSCALL_EXECBUF = 100, +#define _SYSCALL_DEBUG_KLOG 101 - _SYSCALL_DEBUG_KLOG, -}; +#ifndef ASM_FILE +#include +#include long _syscall(long, long, long, long, long, long); @@ -83,3 +82,5 @@ void _syscall_sleep(long ms); long _syscall_execbuf(void __user *buf, size_t len); void _syscall_debug_klog(const void __user *buf, size_t len); + +#endif diff --git a/src/user/lib/elfload.S b/src/user/lib/elfload.S new file mode 100644 index 0000000..0f15c06 --- /dev/null +++ b/src/user/lib/elfload.S @@ -0,0 +1,20 @@ +#define ASM_FILE 1 +#include + +.section .text +.global _freejmp_chstack +.type _freejmp_chstack, @function +// void _freejmp_chstack(void *entry, void *low, size_t len, char **argv, char **envp, void *stack); +_freejmp_chstack: + mov %r9, %rsp + jmp _freejmp + +.section .text +.global execbuf_chstack +.type execbuf_chstack, @function +// _Noreturn void execbuf_chstack(void *stack, void __user *buf, size_t len); +execbuf_chstack: + mov %rdi, %rsp + mov $_SYSCALL_EXECBUF, %rdi + syscall + hlt // if execbuf failed we might as well crash diff --git a/src/user/lib/elfload.s b/src/user/lib/elfload.s deleted file mode 100644 index faab85f..0000000 --- a/src/user/lib/elfload.s +++ /dev/null @@ -1,17 +0,0 @@ -.section .text -.global _freejmp_chstack -.type _freejmp_chstack, @function -// void _freejmp_chstack(void *entry, void *low, size_t len, char **argv, char **envp, void *stack); -_freejmp_chstack: - mov %r9, %rsp - jmp _freejmp - -.section .text -.global execbuf_chstack -.type execbuf_chstack, @function -// _Noreturn void execbuf_chstack(void *stack, void __user *buf, size_t len); -execbuf_chstack: - mov %rdi, %rsp - mov $100, %rdi - syscall - jmp 0 // if execbuf failed we might as well crash -- cgit v1.2.3