diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-09 00:42:44 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-09 00:42:44 +0200 |
| commit | af8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch) | |
| tree | 96d42a10945fc03df022389aef54708383c1d616 /Kernel/CRT | |
| parent | a874e9cc98df994178d55996943fe81799c61d2f (diff) | |
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/CRT')
| -rw-r--r-- | Kernel/CRT/__mpcc_alloca.hxx | 15 | ||||
| -rw-r--r-- | Kernel/CRT/__mpcc_defines.hxx | 98 | ||||
| -rw-r--r-- | Kernel/CRT/__mpcc_exception.hxx | 39 | ||||
| -rw-r--r-- | Kernel/CRT/__mpcc_malloc.hxx | 30 |
4 files changed, 182 insertions, 0 deletions
diff --git a/Kernel/CRT/__mpcc_alloca.hxx b/Kernel/CRT/__mpcc_alloca.hxx new file mode 100644 index 00000000..f15e059b --- /dev/null +++ b/Kernel/CRT/__mpcc_alloca.hxx @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +inline void* __mpcc_alloca_gcc(size_type sz) +{ + return __builtin_alloca(sz); +} diff --git a/Kernel/CRT/__mpcc_defines.hxx b/Kernel/CRT/__mpcc_defines.hxx new file mode 100644 index 00000000..169dac8c --- /dev/null +++ b/Kernel/CRT/__mpcc_defines.hxx @@ -0,0 +1,98 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef __MPCC_DEF__ +#define __MPCC_DEF__ + +#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/__mpcc_alloca.hxx> +#define __mpcc_alloca(sz) __mpcc_alloca_gcc(sz) +#elif defined(__MPCC__) + +#define __alloca(sz) __mpcc_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/__mpcc_exception.hxx> +#include <CRT/__mpcc_malloc.hxx> + +#endif // ifdef __STD_CXX__ + +#endif /* __MPCC_DEF__ */ diff --git a/Kernel/CRT/__mpcc_exception.hxx b/Kernel/CRT/__mpcc_exception.hxx new file mode 100644 index 00000000..08af0762 --- /dev/null +++ b/Kernel/CRT/__mpcc_exception.hxx @@ -0,0 +1,39 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include <KernelKit/DebugOutput.hpp> + +/// @brief Standard C++ namespace +namespace std +{ +#ifdef __x86_64__ +#ifdef __KERNEL__ + inline void __throw_general(void) + { + __asm__("int $0xD"); + } +#else + inline void __throw_general(void) + { + __exit(33); + } +#endif +#else + inline void __throw_general(void) + { + __exit(33); + } +#endif // if __x86_64__ + + inline void __throw_domain_error(const char* error) + { + NewOS::kcout << "MPCC C++: Domain error: " << error << "\r"; + __throw_general(); + CANT_REACH(); // prevent from continuing. + } +} // namespace std diff --git a/Kernel/CRT/__mpcc_malloc.hxx b/Kernel/CRT/__mpcc_malloc.hxx new file mode 100644 index 00000000..d4d18327 --- /dev/null +++ b/Kernel/CRT/__mpcc_malloc.hxx @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.hpp> + +namespace stdx +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + inline NewOS::VoidPtr allocate(Args&&... args) + { + return new KindClass(NewOS::forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + inline NewOS::Void release(KindClass ptr) + { + if (!ptr) + return; + delete ptr; + } +} // namespace stdx |
