summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-06 07:55:10 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-06 07:56:54 +0200
commite723038ba97bb84726f16ce5a6258d78262d90d7 (patch)
treece9d0d7d0ef1d886bdc025fef5a50a38eded8132 /Private
parentf95d8bf159d10b5a9521dcaa0bc37aa0e9dfc02b (diff)
MHR-23: See below.
This commit adds 1 function a macro and 2 functions. - __throw_domain_error, which just throws an interrupt. - allocate, which allocates a class. - release, which releases a class. - __STD_CXX__ to tell if we use standard C++. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/CRT/__mpcc_defines.hxx9
-rw-r--r--Private/CRT/__mpcc_exception.hxx46
-rw-r--r--Private/CRT/__mpcc_malloc.hxx29
-rw-r--r--Private/NewKit/Macros.hpp4
-rw-r--r--Private/Source/Utils.cxx25
-rw-r--r--Private/makefile6
6 files changed, 113 insertions, 6 deletions
diff --git a/Private/CRT/__mpcc_defines.hxx b/Private/CRT/__mpcc_defines.hxx
index 3992013c..0e295d25 100644
--- a/Private/CRT/__mpcc_defines.hxx
+++ b/Private/CRT/__mpcc_defines.hxx
@@ -86,4 +86,13 @@ typedef union double_cast {
#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/Private/CRT/__mpcc_exception.hxx b/Private/CRT/__mpcc_exception.hxx
new file mode 100644
index 00000000..a41d1731
--- /dev/null
+++ b/Private/CRT/__mpcc_exception.hxx
@@ -0,0 +1,46 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+/// This file is an implementation of __throw* family of functions.
+
+#include <KernelKit/DebugOutput.hpp>
+
+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.
+ }
+}
+
+EXTERN_C void abort(void)
+{
+ std::__throw_general();
+ CANT_REACH();
+}
diff --git a/Private/CRT/__mpcc_malloc.hxx b/Private/CRT/__mpcc_malloc.hxx
new file mode 100644
index 00000000..35b0ffbc
--- /dev/null
+++ b/Private/CRT/__mpcc_malloc.hxx
@@ -0,0 +1,29 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/KernelHeap.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
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 86060a02..9366fe5c 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -90,10 +90,6 @@
#define CONST const
-#ifndef self
-#define self this
-#endif
-
#define STRINGIFY(X) #X
#define NEWOS_UNUSED(X) ((void)X)
diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx
index 868705bc..b0b3be8d 100644
--- a/Private/Source/Utils.cxx
+++ b/Private/Source/Utils.cxx
@@ -211,18 +211,43 @@ namespace NewOS
}
} // namespace NewOS
+////////////////////////////////////////////////////////////////////////////////////////
+/// Exported C functions
+////////////////////////////////////////////////////////////////////////////////////////
+
+/// @brief memset in C++
EXTERN_C void memset(void* dst, char src, size_t len)
{
NewOS::rt_set_memory(dst, src, len);
}
+/// @brief memcpy in C++
EXTERN_C void memcpy(void* dst, void* src, size_t len)
{
NewOS::rt_copy_memory(src, dst, len);
}
+/// @brief memmove in C++
+EXTERN_C void* memmove(void* dst, void* src, size_t len)
+{
+ NewOS::rt_copy_memory(src, dst, len);
+ return dst;
+}
+
/// @brief strlen definition in C++.
EXTERN_C size_t strlen(const char* whatToCheck)
{
return NewOS::rt_string_len(whatToCheck);
}
+
+/// @brief memcmp in C++
+EXTERN_C NewOS::SizeT memcmp(void* dst, void* src, size_t len)
+{
+ return NewOS::rt_string_cmp((char*)src, (char*)dst, len);
+}
+
+/// @brief strcmp in C++
+EXTERN_C NewOS::SizeT strcmp(char* dst, char* src, size_t len)
+{
+ return NewOS::rt_string_cmp(src, dst, len);
+}
diff --git a/Private/makefile b/Private/makefile
index 6a73c10d..d665c5fe 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -5,8 +5,10 @@
CC = x86_64-w64-mingw32-gcc
LD = x86_64-w64-mingw32-ld
-CCFLAGS = -c -ffreestanding -fPIC -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \
- -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./
+CCFLAGS = -c -fPIC -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \
+ -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./ \
+ -DBLEND2D_NO_STDCXX -DBLEND2D_NO_TLS -DBLEND2D_EMBED
+
ASM = nasm
ifneq ($(ATA_PIO_SUPPORT), )