From 9db58da40cfcb6643412bfae25aefc0cd1077f9d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 27 May 2024 20:45:46 +0200 Subject: MHR-23: Improve project structure, make it better. Signed-off-by: Amlal El Mahrouss --- SDK/Libraries/CoreSystem/Headers/Defines.h | 235 +++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 SDK/Libraries/CoreSystem/Headers/Defines.h (limited to 'SDK/Libraries/CoreSystem/Headers/Defines.h') diff --git a/SDK/Libraries/CoreSystem/Headers/Defines.h b/SDK/Libraries/CoreSystem/Headers/Defines.h new file mode 100644 index 00000000..a7e46234 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Defines.h @@ -0,0 +1,235 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#ifdef CS_MUST_PASS +#undef CS_MUST_PASS +#endif + +#ifdef _DEBUG +#define CS_MUST_PASS(e) \ + { \ + if (!e) \ + { \ + UiAlert("Assertion failed.\nExpression :%s\nFile: %s\nLine: %i", #e, __FILE__, __LINE__) RtAssertTriggerInterrupt() \ + } \ + } +#else +#define CS_MUST_PASS(e) CS_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CS_EXTERN_C extern "C" + +#else + +#define CS_EXTERN_C extern + +#endif + +struct ApplicationInterface; +struct GUID; + +CS_EXTERN_C void RtAssertTriggerInterrupt(void); + +#define CS_STDCALL __attribute__((stdcall)) +#define CS_CDECL __attribute__((cdecl)) +#define CS_MSCALL __attribute__((ms_abi)) + +#define PACKED __attribute__((packed)) + +#define CS_PASCAL CS_STDCALL + +#include + +typedef __UINT8_TYPE__ ByteType; +typedef __UINT16_TYPE__ WordType; +typedef __UINT32_TYPE__ DWordType; +typedef __UINT64_TYPE__ QWordType; +typedef __SIZE_TYPE__ SizeType; + +typedef char CharacterTypeUTF8; +typedef CharacterTypeUTF8* PtrCharacterType; + +typedef void* PtrVoidType; +typedef void VoidType; + +#ifdef __SINGLE_PRECISION__ +typedef float FloatType; +typedef float PositionType; +#else +typedef double FloatType; +typedef double PositionType; +#endif + +typedef __UINTPTR_TYPE__ UIntPtrType; +typedef __INTPTR_TYPE__ IntPtrType; +typedef __UINT64_TYPE__ UInt64Type; +typedef __INT64_TYPE__ Int64Type; +typedef __UINT32_TYPE__ UInt32Type; +typedef __INT32_TYPE__ Int32Type; + +typedef CharacterTypeUTF8 BooleanType; + +#define Yes 1 +#define No 0 + +#define CS_PTR * + +#define CS_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) + +#ifdef __x86_64__ + +#define CS_FAR __far +#define CS_NEAR __near + +#define _M_AMD64 2 +#else + +#define CS_FAR +#define CS_NEAR + +#endif + +#ifdef __aarch64__ +#define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +#define _M_PPC64 4 +#endif + +#ifdef __64x0__ +#define _M_64000 5 +#endif + +#ifdef __riscv__ +#define _M_RISCV 6 +#endif + +#define CS_STATIC static +#define CS_INLINE inline +#define CS_CONST const + +#ifdef __cplusplus +#define CS_CONSTEXPR constexpr +#else +#define CS_CONSTEXPR +#endif // __cplusplus + +enum RtProcessCall +{ + kCallAllocPtr = 1, + kCallFreePtr, + kCallSizePtr, + kCallCheckPtr, + kCallAllocStack, + /// @brief Open a specific handle + /// (can be used as sel to call methods related to it.) + kCallOpenFile, + kCallCloseFile, + kCallOpenDir, + kCallCloseDir, + kCallOpenDevice, + kCallCloseDevice, + kCallCreateWindow, + kCallCloseWindow, + kCallCreateMenu, + kCallCloseMenu, + kCallRandomNumberGenerator, + kCallGetArgsCount, + kCallGetArgsPtr, + kCallFileExists, + kCallDirectoryExists, + kCallSymlinkExists, + kCallDeviceExists, + kCallDriveExists, + /// @brief Number of process calls. + kCallsCount, +}; + +/** + * @brief GUID type, something you can also find in CFKit. + * @author Amlal El Mahrouss + */ +typedef struct GUID +{ + DWordType Data1; + WordType Data2; + WordType Data3; + ByteType Data4[8]; +} GUIDType, *PtrGUIDType; + +/// \brief Application Interface. +/// \author Amlal El Mahrouss +typedef struct ApplicationInterface +{ + VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); + IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); + VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} ApplicationInterface, *ApplicationInterfaceRef; + +#ifdef __cplusplus + +#define CS_COPY_DELETE(KLASS) \ + KLASS& operator=(const KLASS&) = delete; \ + KLASS(const KLASS&) = delete; + +#define CS_COPY_DEFAULT(KLASS) \ + KLASS& operator=(const KLASS&) = default; \ + KLASS(const KLASS&) = default; + +#define CS_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ + KLASS(KLASS&&) = delete; + +#define CS_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ + KLASS(KLASS&&) = default; + +#define app_cast reinterpret_cast + +template +using StrType = CharacterTypeUTF8[N]; + +#else + +#define app_cast (ApplicationInterfaceRef) + +#endif // ifdef C++ + +/// @brief Get app singleton. +/// @param +/// @return +CS_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); + +/// @brief Get argument count +/// @param +/// @return +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); + +/// @brief Get argument pointer. +/// @param +/// @return +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); + +CS_EXTERN_C ApplicationInterfaceRef kSharedApplication; + +typedef CharacterTypeUTF8 StrType255[255]; + +#define True 1 +#define False 0 +#define Bool BooleanType + +#define NullPtr ((PtrVoidType)0) + +#ifndef kInvalidRef +#define kInvalidRef 0 +#endif + +#include -- cgit v1.2.3 From c34c46598c12b04b2877aa7290dd401cc40a29e3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 2 Jun 2024 09:00:18 +0200 Subject: ACPI: even error codes. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 17 ++++++++--------- SDK/Libraries/CoreSystem/Headers/Defines.h | 4 ++-- SDK/Libraries/CoreSystem/Headers/Math.h | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'SDK/Libraries/CoreSystem/Headers/Defines.h') diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index adeeb10d..7bdec117 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -63,17 +63,15 @@ namespace NewOS MUST_PASS(fRsdp); if (!signature) - return ErrorOr{-2}; + return ErrorOr{-1}; if (*signature == 0) - return ErrorOr{-3}; + return ErrorOr{-1}; RSDP* rsdPtr = reinterpret_cast(this->fRsdp); if (rsdPtr->Revision <= 1) - { - return ErrorOr{-4}; - } + return ErrorOr{-1}; /// FIXME RSDT* xsdt = (RSDT*)(rsdPtr->RsdtAddress); @@ -82,15 +80,16 @@ namespace NewOS if (num < 1) { - kcout << "ACPI: No entries." << endl; - return ErrorOr{-6}; + /// stop here, we should have entries... + ke_stop(RUNTIME_CHECK_ACPI); + return ErrorOr{-1}; } this->fEntries = num; kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; kcout << "ACPI: Revision: " << number(xsdt->Revision) << endl; - kcout << "ACPI: XSDT: " << xsdt->Signature << endl; + kcout << "ACPI: Signature: " << xsdt->Signature << endl; kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; const short cAcpiSignatureLength = 4; @@ -111,7 +110,7 @@ namespace NewOS } } - return ErrorOr{nullptr}; + return ErrorOr{-1}; } /*** diff --git a/SDK/Libraries/CoreSystem/Headers/Defines.h b/SDK/Libraries/CoreSystem/Headers/Defines.h index a7e46234..713d6df8 100644 --- a/SDK/Libraries/CoreSystem/Headers/Defines.h +++ b/SDK/Libraries/CoreSystem/Headers/Defines.h @@ -32,6 +32,8 @@ #endif +#include + struct ApplicationInterface; struct GUID; @@ -231,5 +233,3 @@ typedef CharacterTypeUTF8 StrType255[255]; #ifndef kInvalidRef #define kInvalidRef 0 #endif - -#include diff --git a/SDK/Libraries/CoreSystem/Headers/Math.h b/SDK/Libraries/CoreSystem/Headers/Math.h index 0a13e86f..0079803e 100644 --- a/SDK/Libraries/CoreSystem/Headers/Math.h +++ b/SDK/Libraries/CoreSystem/Headers/Math.h @@ -9,7 +9,7 @@ #include /////////////////////////////////////////////////////////////////////// -/// Random functions /// +/// Random number generators functions /// /////////////////////////////////////////////////////////////////////// /// @brief Number generator helper. -- cgit v1.2.3