diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/data/build/user.mk | 3 | ||||
-rw-r--r-- | src/lib/libc/Makefile | 7 | ||||
-rw-r--r-- | src/lib/libc/amd64/include/machine/syscall.h | 109 | ||||
-rw-r--r-- | src/sys/include/compat/unix/syscall.h | 11 | ||||
-rw-r--r-- | src/sys/include/sys/syscall.h | 20 |
6 files changed, 135 insertions, 16 deletions
@@ -6,6 +6,7 @@ /src/sys/target /src/sys/os/amd64 /src/iso_root +/src/lib/libc/include/sys/ *.o *.d *.iso diff --git a/src/data/build/user.mk b/src/data/build/user.mk index dd1eb16..ad6b023 100644 --- a/src/data/build/user.mk +++ b/src/data/build/user.mk @@ -1,2 +1,3 @@ INTERNAL_CFLAGS = -T$(LDSCRIPT) -znoexecstack \ - -L$(LIBC_DIR) -I$(LIBC_DIR)/include/ -pie -no-pie + -L$(LIBC_DIR) -I$(LIBC_DIR)/include/ \ + -I$(LIBC_DIR)/$(TARGET)/include/ -pie -no-pie diff --git a/src/lib/libc/Makefile b/src/lib/libc/Makefile index 3287084..adde835 100644 --- a/src/lib/libc/Makefile +++ b/src/lib/libc/Makefile @@ -2,13 +2,18 @@ OBJ = $(shell find build/ -name "*.o") LIBC_OUT = libc.a .PHONY: all -all: build target +all: build sys target ar rcs $(LIBC_OUT) $(OBJ) .PHONY: target target: cd $(TARGET); make CC=$(CC) LD=$(LD) AS=$(AS) +.PHONY: sys +sys: + mkdir -p include/sys/ + rsync -av ../../sys/include/sys/ include/sys/ + # Create build directory build: mkdir -p $@ diff --git a/src/lib/libc/amd64/include/machine/syscall.h b/src/lib/libc/amd64/include/machine/syscall.h new file mode 100644 index 0000000..d089ba0 --- /dev/null +++ b/src/lib/libc/amd64/include/machine/syscall.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and L5 engineers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_SYSCALL_H_ +#define _MACHINE_SYSCALL_H_ + +#include <sys/syscall.h> +#include <sys/types.h> +#include <sys/cdefs.h> + +typedef __ssize_t scarg_t; + +__always_inline static inline long +syscall0(scarg_t code) +{ + volatile long ret; + __ASMV("int $0x80" : "=a"(ret) : "a"(code)); + return ret; +} + +__always_inline static inline long +syscall1(scarg_t code, scarg_t arg0) +{ + volatile long ret; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0) : "memory"); + return ret; +} + +__always_inline static long inline +syscall2(scarg_t code, scarg_t arg0, scarg_t arg1) +{ + volatile long ret; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0), "S"(arg1) : "memory"); + return ret; +} + +__always_inline static inline long +syscall3(scarg_t code, scarg_t arg0, scarg_t arg1, scarg_t arg2) +{ + volatile long ret; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0), "S"(arg1), "d"(arg2) : "memory"); + return ret; +} + +__always_inline static inline long +syscall4(scarg_t code, scarg_t arg0, scarg_t arg1, scarg_t arg2, scarg_t arg3) +{ + volatile long ret; + register scarg_t _arg3 asm("r10") = arg3; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0), "S"(arg1), "d"(arg2), "r"(_arg3) : "memory"); + return ret; +} + +__always_inline static inline long +syscall5(scarg_t code, scarg_t arg0, scarg_t arg1, scarg_t arg2, scarg_t arg3, scarg_t arg4) +{ + volatile long ret; + register scarg_t _arg3 asm("r10") = arg3; + register scarg_t _arg4 asm("r9") = arg4; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0), "S"(arg1), "d"(arg2), "r"(_arg3), "r"(_arg4) : "memory"); + return ret; +} + +__always_inline static inline long +syscall6(scarg_t code, scarg_t arg0, scarg_t arg1, scarg_t arg2, scarg_t arg3, scarg_t arg4, scarg_t arg5) +{ + volatile long ret; + register scarg_t _arg3 asm("r10") = arg3; + register scarg_t _arg4 asm("r9") = arg4; + register scarg_t _arg5 asm("r8") = arg5; + __ASMV("int $0x80" : "=a"(ret) : "a"(code), "D"(arg0), "S"(arg1), "d"(arg2), "r"(_arg3), "r"(_arg4), "r"(_arg5) : "memory"); + return ret; +} + +#define _SYSCALL_N(a0, a1, a2, a3, a4, a5, a6, name, ...) \ + name + +#define syscall(...) \ +_SYSCALL_N(__VA_ARGS__, syscall6, syscall5, \ + syscall4, syscall3, syscall2, syscall1, \ + syscall0)(__VA_ARGS__) + +#endif /* !_MACHINE_SYSCALL_H_ */ diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index a3e7257..88c86ba 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -35,17 +35,6 @@ #include <sys/syscall.h> /* - * Default syscall numbers - * - * Defines marked as (mandatory) must be implemented - * between latches. - */ -#define SYS_none 0x00 -#define SYS_exit 0x01 -#define SYS_write 0x02 -#define SYS_cross 0x03 /* cross a border (mandatory) */ - -/* * Exit the current process - exit(2) syscall */ scret_t sys_exit(struct syscall_args *scargs); diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index 9d9c765..3f8ab10 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -32,6 +32,23 @@ #include <sys/types.h> #include <sys/limits.h> +#if !defined(_KERNEL) +#include <machine/syscall.h> +#endif /* _!KERNEL */ + +/* + * Default syscall numbers + * + * Defines marked as (mandatory) must be implemented + * between latches. + */ +#define SYS_none 0x00 +#define SYS_exit 0x01 +#define SYS_write 0x02 +#define SYS_cross 0x03 /* cross a border (mandatory) */ + +typedef __ssize_t scret_t; +typedef __ssize_t scarg_t; #if defined(_KERNEL) /* @@ -39,9 +56,6 @@ */ #define SCARG(SCARGS, TYPE, SYSNO) ((TYPE)(SCARGS)->arg[(SYSNO)]) -typedef ssize_t scret_t; -typedef ssize_t scarg_t; - struct syscall_args { scarg_t arg[6]; struct trapframe *tf; |