diff options
Diffstat (limited to 'zap/source')
-rw-r--r-- | zap/source/amd64/bs/trap.s | 4 | ||||
-rw-r--r-- | zap/source/amd64/sys/syscall.s | 27 | ||||
-rw-r--r-- | zap/source/any/bs/trap.c | 2 | ||||
-rw-r--r-- | zap/source/any/math/abs.cc | 13 | ||||
-rw-r--r-- | zap/source/any/math/divmod.cc | 12 | ||||
-rw-r--r-- | zap/source/any/mem/cp.c | 2 | ||||
-rw-r--r-- | zap/source/any/str/fmt.cc | 4 | ||||
-rw-r--r-- | zap/source/any/str/fmtlen.cc | 6 | ||||
-rw-r--r-- | zap/source/any/str/numdig.hh | 2 | ||||
-rw-r--r-- | zap/source/any/sys/syscall.c | 11 | ||||
-rw-r--r-- | zap/source/arm/sys/syscall.s | 32 | ||||
-rw-r--r-- | zap/source/arm64/sys/syscall.s | 26 | ||||
-rw-r--r-- | zap/source/ia32/sys/syscall.s | 34 |
13 files changed, 159 insertions, 16 deletions
diff --git a/zap/source/amd64/bs/trap.s b/zap/source/amd64/bs/trap.s index 93138e5..19c52a8 100644 --- a/zap/source/amd64/bs/trap.s +++ b/zap/source/amd64/bs/trap.s @@ -4,7 +4,7 @@ .intel_syntax noprefix -.globl zap_priv_trap +.globl zap_trap -zap_priv_trap: +zap_trap: ud2 diff --git a/zap/source/amd64/sys/syscall.s b/zap/source/amd64/sys/syscall.s new file mode 100644 index 0000000..f6a615a --- /dev/null +++ b/zap/source/amd64/sys/syscall.s @@ -0,0 +1,27 @@ +# Copyright 2022-2023 Gabriel Jensen. +# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. + +.globl zap_syscall + +zap_syscall: + # System calls on AMD64 use the following registers: + # rax : System call identifier + # rdi : First parameter + # rsi : Second parameter + # rdx : Third parameter + # r10 : Fourth parameter + # r8 : Fifth parameter + # r9 : Sixth parameter + # eax : Return value + # No registers to save. + movq %rdi,%rax # Move the first parameter (the identifier) to rax. + movq %rsi,%rdi # Move parameters into their designated registers. + movq %rdx,%rsi + movq %rcx,%rdx + movq %r8,%r10 # System calls use r10 instead of rcx. + movq %r9,%r8 + movq 0x8(%rsp),%r9 # Extract the sixth argument from the stack. + syscall # Slime incident + # No need to move the return value. + ret diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c index 552572d..307a7f0 100644 --- a/zap/source/any/bs/trap.c +++ b/zap/source/any/bs/trap.c @@ -6,7 +6,7 @@ #include <zap/bs.h> -void zap_priv_trap(void) { +void zap_trap(void) { #if zap_priv_hasbuiltin(__builtin_trap) __builtin_trap(); #endif diff --git a/zap/source/any/math/abs.cc b/zap/source/any/math/abs.cc new file mode 100644 index 0000000..65e5a22 --- /dev/null +++ b/zap/source/any/math/abs.cc @@ -0,0 +1,13 @@ +/* + Copyright 2022-2023 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +*/ + +#include <zap/math.hh> + +extern "C" { + zap_attr_nthrw float zap_absf( float const val) {return ::zap::abs(val);} + zap_attr_nthrw double zap_absd( double const val) {return ::zap::abs(val);} + zap_attr_nthrw long double zap_absld(long double const val) {return ::zap::abs(val);} +} diff --git a/zap/source/any/math/divmod.cc b/zap/source/any/math/divmod.cc index 77523f8..f117013 100644 --- a/zap/source/any/math/divmod.cc +++ b/zap/source/any/math/divmod.cc @@ -4,12 +4,12 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -#include <zap/math.h> +#include <zap/math.hh> extern "C" { - zap_priv_nothrw auto zap_divmodsc(signed char const num,signed char const den) -> ::zap_pairsc {return ::zap::divmod(num,den).cpair();} - zap_priv_nothrw auto zap_divmods( short const num,short const den) -> ::zap_pairs {return ::zap::divmod(num,den).cpair();} - zap_priv_nothrw auto zap_divmodi( int const num,int const den) -> ::zap_pairi {return ::zap::divmod(num,den).cpair();} - zap_priv_nothrw auto zap_divmodl( long const num,long const den) -> ::zap_pairl {return ::zap::divmod(num,den).cpair();} - zap_priv_nothrw auto zap_divmodll(long long const num,long long const den) -> ::zap_pairll {return ::zap::divmod(num,den).cpair();} + zap_attr_nthrw auto zap_divmodsc(signed char const num,signed char const den) -> ::zap_pairsc {return ::zap::divmod(num,den).cpair();} + zap_attr_nthrw auto zap_divmods( short const num,short const den) -> ::zap_pairs {return ::zap::divmod(num,den).cpair();} + zap_attr_nthrw auto zap_divmodi( int const num,int const den) -> ::zap_pairi {return ::zap::divmod(num,den).cpair();} + zap_attr_nthrw auto zap_divmodl( long const num,long const den) -> ::zap_pairl {return ::zap::divmod(num,den).cpair();} + zap_attr_nthrw auto zap_divmodll(long long const num,long long const den) -> ::zap_pairll {return ::zap::divmod(num,den).cpair();} } diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c index 12c6bfd..f0de644 100644 --- a/zap/source/any/mem/cp.c +++ b/zap/source/any/mem/cp.c @@ -6,7 +6,7 @@ #include <zap/mem.h> -void * zap_cp(void * const zap_priv_restr voiddest,void const * const zap_priv_restr voidsrc,zap_sz const num) { +void * zap_cp(void * const zap_restr voiddest,void const * const zap_restr voidsrc,zap_sz const num) { unsigned char * dest = voiddest; unsigned char const * src = voidsrc; unsigned char * const stop = dest + num; diff --git a/zap/source/any/str/fmt.cc b/zap/source/any/str/fmt.cc index b2c0c75..ff6edb1 100644 --- a/zap/source/any/str/fmt.cc +++ b/zap/source/any/str/fmt.cc @@ -4,13 +4,13 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -#include <zap/str.h> +#include <zap/str.hh> #include "numdig.hh" namespace zap { namespace impl { - template<typename signtyp> zap_priv_inln inline static auto fmt(::zap::i02 * buf,signtyp signval,::zap::i8 const bs,::zap::i8 const rtl) noexcept -> void { + template<typename signtyp> zap_attr_iln inline static auto fmt(::zap::i02 * buf,signtyp signval,::zap::i8 const bs,::zap::i8 const rtl) noexcept -> void { using typ = typename ::zap::usign<signtyp>; char32_t const * digs = U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (bs == 0xCu) digs = U"0123456789\u218A\u218B"; diff --git a/zap/source/any/str/fmtlen.cc b/zap/source/any/str/fmtlen.cc index 866d011..b5e508c 100644 --- a/zap/source/any/str/fmtlen.cc +++ b/zap/source/any/str/fmtlen.cc @@ -4,14 +4,14 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ -#include <zap/math.h> -#include <zap/str.h> +#include <zap/math.hh> +#include <zap/str.hh> #include "numdig.hh" namespace zap { namespace impl { - template<typename typ> zap_priv_inln inline static auto fmtlen(typ val,::zap::i8 const bs) noexcept -> ::zap::i8 { + template<typename typ> zap_attr_iln inline static auto fmtlen(typ val,::zap::i8 const bs) noexcept -> ::zap::i8 { ::zap::i8 len = 0x0u; if (val < 0x0) { val = static_cast<typ>(::zap::abs(val)); diff --git a/zap/source/any/str/numdig.hh b/zap/source/any/str/numdig.hh index 65756b9..ea36f0b 100644 --- a/zap/source/any/str/numdig.hh +++ b/zap/source/any/str/numdig.hh @@ -2,7 +2,7 @@ namespace zap { namespace impl { - template<typename typ> zap_priv_inln inline static auto numdig(typ fmtval,::zap::i8 const bs) noexcept -> ::zap::i8 { + template<typename typ> zap_attr_iln inline static auto numdig(typ fmtval,::zap::i8 const bs) noexcept -> ::zap::i8 { ::zap::i8 len = 0x0u; if (fmtval == typ {0x0}) return 0x1u; for (typ val = fmtval;val > 0x0;val /= static_cast<typ>(bs)) ++len; diff --git a/zap/source/any/sys/syscall.c b/zap/source/any/sys/syscall.c new file mode 100644 index 0000000..46d1074 --- /dev/null +++ b/zap/source/any/sys/syscall.c @@ -0,0 +1,11 @@ +/* + Copyright 2022-2023 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +*/ + +#include <zap/str.h> + +void zap_syscall(unsigned long,...) { + zap_trap(); // Unsupported. +} diff --git a/zap/source/arm/sys/syscall.s b/zap/source/arm/sys/syscall.s new file mode 100644 index 0000000..c4f8d40 --- /dev/null +++ b/zap/source/arm/sys/syscall.s @@ -0,0 +1,32 @@ +@ Copyright 2022-2023 Gabriel Jensen. +@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. + +.syntax unified + +.arm + +.globl zap_syscall + +zap_syscall: + @ System calls on ARM EABI use the following registers: + @ r0 : System call identifier + @ r1 : First parameter + @ r2 : Second parameter + @ r3 : Third parameter + @ r4 : Fourth parameter + @ r5 : Fifth parameter + @ r6 : Sixth parameter + @ r0 : Return value + push {r4-r5,r7,lr} @ Remember that the parameters are now further up the stack. + mov r7,r0 @ Move the identifier. + mov r0,r1 @ Place parameters. + mov r1,r2 + mov r2,r3 + ldr r3,[sp,0x10] @ Get the remaining parameters from the stack. + ldr r4,[sp,0x14] + ldr r5,[sp,0x18] + svc 0x0 @ Divinity + pop {r4-r5,r7} @ Restore the registers. + pop {r0} + bx r0 diff --git a/zap/source/arm64/sys/syscall.s b/zap/source/arm64/sys/syscall.s new file mode 100644 index 0000000..df4817d --- /dev/null +++ b/zap/source/arm64/sys/syscall.s @@ -0,0 +1,26 @@ +// Copyright 2022-2023 Gabriel Jensen. +// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +// If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. + +.globl zap_syscall + +zap_syscall: + // System calls on ARM64 use the following registers: + // x0 : System call identifier + // x1 : First parameter + // x2 : Second parameter + // x3 : Third parameter + // x4 : Fourth parameter + // x5 : Fifth parameter + // x6 : Sixth parameter + // x0 : Return value + mov x8,x0 // Move the first parameter (the identifier) to x8. + mov x0,x1 // Shift all of the other parameters to the left. + mov x1,x2 + mov x2,x3 + mov x3,x4 + mov x4,x5 + mov x5,x6 + svc 0x0 // Zephyr + // No need to move the return value (already in x0). + ret diff --git a/zap/source/ia32/sys/syscall.s b/zap/source/ia32/sys/syscall.s new file mode 100644 index 0000000..c99cd2b --- /dev/null +++ b/zap/source/ia32/sys/syscall.s @@ -0,0 +1,34 @@ +# Copyright 2022-2023 Gabriel Jensen. +# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. + +.globl zap_syscall + +zap_syscall: + # System calls on IA-32 use the following registers: + # eax : System call identifier + # ebx : First parameter + # ecx : Second parameter + # edx : Third parameter + # esi : Fourth parameter + # edi : Fifth parameter + # ebp : Sixth parameter + # eax : Return value + pushl %ebx # Remember to save the registers. + pushl %esi + pushl %edi + pushl %ebp # Remember that the provided paramters are now further up the stack. + movl 0x14(%esp),%eax # Move the first parameter (the identifier) to eax. + movl 0x18(%esp),%ebx # Move the remaining parameters into their designated registers. This will read "out of bounds" memory if the number of passed parameters is less than six, but this shouldn't matter as long as the data isn't being used, which it won't be as long as the expected ammount of parameters have been passed. + movl 0x1C(%esp),%ecx + movl 0x20(%esp),%edx + movl 0x24(%esp),%esi + movl 0x28(%esp),%edi + movl 0x2C(%esp),%ebp + int $0x80 # Flying city + popl %ebp # Restore the registers. + popl %edi + popl %esi + popl %ebx + # No need to move the return value. + ret |