From e723038ba97bb84726f16ce5a6258d78262d90d7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 6 May 2024 07:55:10 +0200 Subject: 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 --- Meta/Kernel.svg | 36 ------------------------------- Private/CRT/__mpcc_defines.hxx | 9 ++++++++ Private/CRT/__mpcc_exception.hxx | 46 ++++++++++++++++++++++++++++++++++++++++ Private/CRT/__mpcc_malloc.hxx | 29 +++++++++++++++++++++++++ Private/NewKit/Macros.hpp | 4 ---- Private/Source/Utils.cxx | 25 ++++++++++++++++++++++ Private/makefile | 6 ++++-- ReadMe.md | 1 - 8 files changed, 113 insertions(+), 43 deletions(-) delete mode 100644 Meta/Kernel.svg create mode 100644 Private/CRT/__mpcc_exception.hxx create mode 100644 Private/CRT/__mpcc_malloc.hxx diff --git a/Meta/Kernel.svg b/Meta/Kernel.svg deleted file mode 100644 index fdfd1e73..00000000 --- a/Meta/Kernel.svg +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 +#include + +#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 + +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 + +namespace stdx +{ +/// @brief allocate a new class. +/// @tparam KindClass the class type to allocate. +template +inline NewOS::VoidPtr allocate(Args&&... args) +{ + return new KindClass(NewOS::forward(args)...); +} + +/// @brief free a class. +/// @tparam KindClass the class type to allocate. +template +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), ) diff --git a/ReadMe.md b/ReadMe.md index c169c960..8046b066 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,5 +1,4 @@
-

NewOS

-- cgit v1.2.3