summaryrefslogtreecommitdiffhomepage
path: root/dev/crt
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-10-25 16:52:55 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-10-25 16:52:55 +0200
commitbde40a348877ff33649c5335a9ebe0502a606d7c (patch)
tree0aaf2821c8436afd9ba7f74a28b6e97ae2a795d2 /dev/crt
parent5c319a1b4d08ce784f164aa5d073af71336e1547 (diff)
IMP: Cleanup source code.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/crt')
-rw-r--r--dev/crt/ReadMe.md5
-rw-r--r--dev/crt/alloca.h19
-rw-r--r--dev/crt/base_alloc.h49
-rw-r--r--dev/crt/base_exception.h36
-rw-r--r--dev/crt/crtx64.json20
-rw-r--r--dev/crt/defines.h106
-rw-r--r--dev/crt/exit.h20
-rw-r--r--dev/crt/math.h62
-rw-r--r--dev/crt/src/alloca.cc9
-rw-r--r--dev/crt/src/base_exception.cc9
-rw-r--r--dev/crt/src/hal/x86/base_alloc.cc55
-rw-r--r--dev/crt/src/hal/x86/exit.cc19
12 files changed, 0 insertions, 409 deletions
diff --git a/dev/crt/ReadMe.md b/dev/crt/ReadMe.md
deleted file mode 100644
index 055650b0..00000000
--- a/dev/crt/ReadMe.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# ZKA C++ RunTime Kit.
-
-This is the public interface of ZKA' C++ RunTime.
-
-###### (c) ZKA Web Services Co, all rights reserved.
diff --git a/dev/crt/alloca.h b/dev/crt/alloca.h
deleted file mode 100644
index 35e742d8..00000000
--- a/dev/crt/alloca.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
- File: alloca.h
- Purpose: Stack allocation functions.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <crt/defines.h>
-
-inline ptr_type __rt_alloca(size_type sz)
-{
- return __builtin_alloca(sz);
-}
-
-#define alloca __rt_alloca
diff --git a/dev/crt/base_alloc.h b/dev/crt/base_alloc.h
deleted file mode 100644
index 97826d80..00000000
--- a/dev/crt/base_alloc.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <crt/defines.h>
-
-namespace std::base_alloc
-{
- /// @brief allocate a new class.
- /// @tparam KindClass the class type to allocate.
- template <typename KindClass, typename... Args>
- inline KindClass* allocate(Args&&... args)
- {
- return new KindClass(forward(args)...);
- }
-
- /// @brief allocate a new class.
- /// @note aborts on error.
- /// @tparam KindClass the class type to allocate.
- template <typename KindClass, typename... Args>
- inline KindClass* allocate_nothrow(Args&&... args) noexcept
- {
- return allocate(forward(args)...);
- }
-
- /// @brief free a class.
- /// @tparam KindClass the class type to allocate.
- template <typename KindClass>
- inline void release(KindClass ptr)
- {
- if (!ptr)
- return;
-
- delete ptr;
- }
-
- /// @brief destroy and free a class.
- /// @note aborts on error.
- /// @tparam KindClass the class type to allocate.
- template <typename KindClass>
- inline void release_nothrow(KindClass ptr) noexcept
- {
- release(ptr);
- }
-} // namespace std::base_alloc
diff --git a/dev/crt/base_exception.h b/dev/crt/base_exception.h
deleted file mode 100644
index 3b95f400..00000000
--- a/dev/crt/base_exception.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <crt/defines.h>
-#include <crt/exit.h>
-
-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_alloc(void)
- {
- __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/crtx64.json b/dev/crt/crtx64.json
deleted file mode 100644
index b8e99385..00000000
--- a/dev/crt/crtx64.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "compiler_path": "x86_64-w64-mingw32-g++",
- "compiler_std": "c++20",
- "headers_path": ["../", "./"],
- "sources_path": ["src/*.cc", "src/hal/x86/*.cc"],
- "output_name": "crtx64.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/defines.h b/dev/crt/defines.h
deleted file mode 100644
index f9c85387..00000000
--- a/dev/crt/defines.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#ifndef __TOOLCHAINKIT_DEFINES_H__
-#define __TOOLCHAINKIT_DEFINES_H__
-
-#include <stdint.h>
-#include <stddef.h>
-
-#ifdef __GNUC__
-
-typedef void* ptr_type;
-typedef __SIZE_TYPE__ size_type;
-
-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/alloca.h>
-#elif defined(__TOOLCHAINKIT__)
-#define __alloca(sz) __rt_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
-
-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/base_exception.h>
-#include <crt/base_alloc.h>
-
-#endif // ifdef __STD_CXX__
-
-/// @brief Standard C++ namespace.
-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 /* __TOOLCHAINKIT_DEFINES_H__ */
diff --git a/dev/crt/exit.h b/dev/crt/exit.h
deleted file mode 100644
index 9bf9928f..00000000
--- a/dev/crt/exit.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <crt/defines.h>
-
-extern "C" int exit(int code);
-
-/// @brief Standard C++ namespace
-namespace std
-{
- inline int exit(int code)
- {
- return exit(code);
- }
-} // namespace std
diff --git a/dev/crt/math.h b/dev/crt/math.h
deleted file mode 100644
index fd948d63..00000000
--- a/dev/crt/math.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <crt/defines.h>
-
-/// @file Math.h
-/// @brief Math functions.
-
-#ifdef __ZKA_USE_DOUBLE__
-typedef double real_type;
-#else
-typedef float real_type;
-#endif
-
-namespace std::math
-{
- /// @brief Power function, with Repeat argument.
- template <size_t Exponent>
- inline real_type pow(real_type in)
- {
- if (Exponent == 0)
- return 1; // Any number to the power of 0 is 1.
-
- if (Exponent == 1)
- return in; // Any number to the power of 1 is itself.
-
- size_t cnt = Exponent;
-
- real_type result = 1;
-
- for (auto i = 0; i < cnt; ++i)
- result *= in;
-
- return result;
- }
-
- /// @brief Square of function, with Base template argument.
- /// @param of Base argument to find sqquare of
- template <size_t Base>
- inline real_type sqr(real_type in)
- {
- if (in == 0)
- return 0;
-
- return pow<1 / Base>(in);
- }
-
- /// @brief Linear interpolation equation solver.
- /// @param from where?
- /// @param to to?
- /// @param Updated diff value according to difference.
- inline real_type lerp(real_type to, real_type from, real_type stat)
- {
- real_type diff = (to - from);
- return from + (diff * stat);
- }
-} // namespace std::math
diff --git a/dev/crt/src/alloca.cc b/dev/crt/src/alloca.cc
deleted file mode 100644
index ccee07a7..00000000
--- a/dev/crt/src/alloca.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#include <crt/alloca.h>
-
-/// @note Just here for building.
diff --git a/dev/crt/src/base_exception.cc b/dev/crt/src/base_exception.cc
deleted file mode 100644
index 75699f64..00000000
--- a/dev/crt/src/base_exception.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#include <crt/base_exception.h>
-
-/// @note Just here for building.
diff --git a/dev/crt/src/hal/x86/base_alloc.cc b/dev/crt/src/hal/x86/base_alloc.cc
deleted file mode 100644
index 10690d4b..00000000
--- a/dev/crt/src/hal/x86/base_alloc.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#include <crt/base_alloc.h>
-#include <crt/base_exception.h>
-
-#define kAllocSyscallId "mov $10, %%r9\n\t"
-#define kFreeSyscallId "mov $11, %%r9\n\t"
-
-void* operator new(size_t length)
-{
- void* ptr = nullptr;
-
- // do syscall according to PEF convention.
- asm("mov %0, %%r8\n\t" kAllocSyscallId
- "syscall"
- : "=r"(ptr));
-
- if (!ptr)
- std::__throw_bad_alloc();
-
- return ptr;
-}
-
-void* operator new[](size_t length)
-{
- ptr_type ptr = nullptr;
-
- // do syscall according to PEF convention.
- asm("mov %0, %%r8\n\t" kAllocSyscallId
- "syscall"
- : "=r"(ptr));
-
- if (!ptr)
- std::__throw_bad_alloc();
-
- return ptr;
-}
-
-void operator delete(void* ptr) noexcept
-{
- asm("mov %0, %%r8\n\t" kFreeSyscallId
- "syscall"
- : "=r"(ptr));
-}
-
-void operator delete[](void* ptr) noexcept
-{
- asm("mov %0, %%r8\n\t" kFreeSyscallId
- "syscall"
- : "=r"(ptr));
-}
diff --git a/dev/crt/src/hal/x86/exit.cc b/dev/crt/src/hal/x86/exit.cc
deleted file mode 100644
index 8ee6744b..00000000
--- a/dev/crt/src/hal/x86/exit.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Web Services Co.
-
-------------------------------------------- */
-
-#include <crt/exit.h>
-
-#define kAllocSyscallId "mov $12, %%r9\n\t"
-
-/// @note Just here for building.
-extern "C" int exit(int code)
-{
- asm("mov 0, %%r8\n\t" kAllocSyscallId
- "syscall"
- : "=r"(code));
-
- return 1;
-}