diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
| commit | 8719b4570a2d10dd49a0d3a47e24f5c55bdda85e (patch) | |
| tree | ba095740888f3768e08b2ea058b0ea6da2d0403d /dev/crt | |
| parent | 45944b3d2dab04b763fcc6d10164fe8069e60b08 (diff) | |
:boom: A big refactor on the filesystem structure.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/crt')
| -rw-r--r-- | dev/crt/ReadMe.md | 5 | ||||
| -rw-r--r-- | dev/crt/__ndk_alloca.hxx | 18 | ||||
| -rw-r--r-- | dev/crt/__ndk_defines.hxx | 121 | ||||
| -rw-r--r-- | dev/crt/__ndk_exception.hxx | 35 | ||||
| -rw-r--r-- | dev/crt/__ndk_new_delete.hxx | 28 | ||||
| -rw-r--r-- | dev/crt/crt.json | 20 | ||||
| -rw-r--r-- | dev/crt/src/__ndk_runtime.cxx | 12 |
7 files changed, 239 insertions, 0 deletions
diff --git a/dev/crt/ReadMe.md b/dev/crt/ReadMe.md new file mode 100644 index 00000000..c90f5b5f --- /dev/null +++ b/dev/crt/ReadMe.md @@ -0,0 +1,5 @@ +# ZKA C++ RunTime.
+
+This is the public interface of ZKA' C++ RunTime.
+
+###### (c) ZKA Technologies, all rights reserved.
diff --git a/dev/crt/__ndk_alloca.hxx b/dev/crt/__ndk_alloca.hxx new file mode 100644 index 00000000..3c796bf2 --- /dev/null +++ b/dev/crt/__ndk_alloca.hxx @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: __ndk_alloca.hxx + Purpose: Stack allocation functions. + +------------------------------------------- */ + +#pragma once + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +inline ptr_type __ndk_alloca(size_type sz) +{ + return __builtin_alloca(sz); +} diff --git a/dev/crt/__ndk_defines.hxx b/dev/crt/__ndk_defines.hxx new file mode 100644 index 00000000..bea3f67c --- /dev/null +++ b/dev/crt/__ndk_defines.hxx @@ -0,0 +1,121 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __NDK_DEFINES_HXX__ +#define __NDK_DEFINES_HXX__ + +#ifndef __GNUC__ + +typedef __SIZE_TYPE__ size_t; + +#ifdef __LP64__ +typedef long int ssize_t; +#else +typedef int ssize_t; +#endif // __LP64__ + +typedef size_t ptrdiff_t; +typedef size_t uintptr_t; +typedef void* voidptr_t; +typedef void* any_t; +typedef char* caddr_t; + +#ifndef NULL +#define NULL ((voidptr_t)0) +#endif // !null + +#ifdef __GNUC__ +#include <crt/__ndk_alloca.hxx> +#define __ndk_alloca(sz) __ndk_alloca(sz) +#elif defined(__NDK__) + +#define __alloca(sz) __ndk_alloca(sz) +#endif + +#define __deref(ptr) (*(ptr)) + +#ifdef __cplusplus +#define __init_decl() \ + extern "C" \ + { +#define __fini_decl() \ + } \ + ; +#else +#define __init_decl() +#define __fini_decl() +#endif + +#if __has_builtin(__builtin_alloca) +#define alloca(sz) __builtin_alloca(sz) +#ifdef __alloca +#undef __alloca +#endif +#define __alloca alloca +#else +#warning alloca not detected +#endif + +typedef long long off_t; +typedef unsigned long long uoff_t; + +typedef union float_cast { + struct + { + unsigned int mantissa : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + }; + + float f; +} __attribute__((packed)) float_cast_t; + +typedef union double_cast { + struct + { + unsigned long long int mantissa : 52; + unsigned int exponent : 11; + unsigned int sign : 1; + }; + + double f; +} __attribute__((packed)) double_cast_t; + +#endif // ifndef __GNUC__ + +/// Include these helpers as well. + +#ifdef __STD_CXX__ + +#include <crt/__ndk_exception.hxx> +#include <crt/__ndk_malloc.hxx> + +#endif // ifdef __STD_CXX__ + +namespace std +{ + /// @brief Forward object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template <typename Args> + inline Args&& forward(Args& arg) + { + return static_cast<Args&&>(arg); + } + + /// @brief Move object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template <typename Args> + inline Args&& move(Args&& arg) + { + return static_cast<Args&&>(arg); + } +} // namespace std + +#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/crt/__ndk_exception.hxx b/dev/crt/__ndk_exception.hxx new file mode 100644 index 00000000..67735a9d --- /dev/null +++ b/dev/crt/__ndk_exception.hxx @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/__ndk_defines.hxx> + +/// @brief CRT exit, with exit code (!!! exits all threads. !!!) +/// @param code +/// @return +extern "C" int __exit(int code); + +/// @brief Standard C++ namespace +namespace std +{ + inline void __throw_general(void) + { + __exit(33); + } + + inline void __throw_domain_error(const char* error) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + + inline void __throw_bad_array_new_length(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } +} // namespace std diff --git a/dev/crt/__ndk_new_delete.hxx b/dev/crt/__ndk_new_delete.hxx new file mode 100644 index 00000000..fad61aa9 --- /dev/null +++ b/dev/crt/__ndk_new_delete.hxx @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <crt/__ndk_defines.hxx> + +namespace stdx +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline void* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline void release(KindClass ptr) + { + delete ptr; + } +} // namespace stdx diff --git a/dev/crt/crt.json b/dev/crt/crt.json new file mode 100644 index 00000000..dbca05fa --- /dev/null +++ b/dev/crt/crt.json @@ -0,0 +1,20 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "./"], + "sources_path": ["src/*.cxx"], + "output_name": "ndkcrt.dll", + "compiler_flags": [ + "-ffreestanding", + "-shared", + "-fno-rtti", + "-fno-exceptions", + " -Wl,--subsystem=17" + ], + "cpp_macros": [ + "__CRT_AMD64__", + "cCRTVersion=0x0100", + "cEFSVersionHighest=0x0100", + "cEFSVersionLowest=0x0100" + ] +} diff --git a/dev/crt/src/__ndk_runtime.cxx b/dev/crt/src/__ndk_runtime.cxx new file mode 100644 index 00000000..b81963a8 --- /dev/null +++ b/dev/crt/src/__ndk_runtime.cxx @@ -0,0 +1,12 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/__ndk_alloca.hxx>
+#include <crt/__ndk_defines.hxx>
+#include <crt/__ndk_exception.hxx>
+#include <crt/__ndk_new_delete.hxx>
+
+/// @note No sources needed for now.
|
