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/Dist/.gitkeep | 0 SDK/Libraries/.gitkeep | 0 SDK/Libraries/CoreCxxRuntime/.gitkeep | 0 SDK/Libraries/CoreCxxRuntime/Private.xml | 3 + .../CoreCxxRuntime/Sources/New+Delete.cxx | 33 +++ SDK/Libraries/CorePEFRuntime/.gitkeep | 0 SDK/Libraries/CorePEFRuntime/Private.xml | 3 + SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c | 23 ++ SDK/Libraries/CoreSystem/.gitkeep | 0 SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s | 28 +++ SDK/Libraries/CoreSystem/ARM64/.gitkeep | 0 SDK/Libraries/CoreSystem/Headers/Alert.h | 25 +++ SDK/Libraries/CoreSystem/Headers/Defines.h | 235 +++++++++++++++++++++ SDK/Libraries/CoreSystem/Headers/File.h | 52 +++++ SDK/Libraries/CoreSystem/Headers/Heap.h | 39 ++++ SDK/Libraries/CoreSystem/Headers/Hint.h | 20 ++ SDK/Libraries/CoreSystem/Headers/Intl.h | 29 +++ SDK/Libraries/CoreSystem/Headers/Math.h | 27 +++ SDK/Libraries/CoreSystem/Headers/Rsrc.h | 12 ++ SDK/Libraries/CoreSystem/Headers/Thread.h | 47 +++++ SDK/Libraries/CoreSystem/Headers/Transport.h | 48 +++++ SDK/Libraries/CoreSystem/POWER/CoreAssembly.s | 23 ++ SDK/Libraries/CoreSystem/Private.xml | 4 + SDK/Libraries/CoreSystem/RISCV/.gitkeep | 0 SDK/Libraries/CoreSystem/ReadMe.md | 13 ++ SDK/Libraries/CoreSystem/Sources/App.c | 31 +++ SDK/Libraries/CoreSystem/Sources/CRTStartup.c | 12 ++ SDK/Libraries/CoreSystem/Sources/File.c | 58 +++++ SDK/Libraries/CoreSystem/Sources/Heap.c | 54 +++++ SDK/Libraries/CoreSystem/Sources/Math.c | 14 ++ SDK/Libraries/CoreSystem/Sources/Thread.c | 9 + SDK/Libraries/CoreSystem/amd64.mk | 22 ++ SDK/Libraries/CoreSystem/compile_flags.txt | 4 + SDK/Library/.gitkeep | 0 SDK/Library/CoreCxxRuntime/.gitkeep | 0 SDK/Library/CoreCxxRuntime/Private.xml | 3 - SDK/Library/CoreCxxRuntime/Sources/New+Delete.cxx | 33 --- SDK/Library/CorePEFRuntime/.gitkeep | 0 SDK/Library/CorePEFRuntime/Private.xml | 3 - SDK/Library/CorePEFRuntime/Sources/PEFStart.c | 23 -- SDK/Library/CoreSystem/.gitkeep | 0 SDK/Library/CoreSystem/AMD64/CoreAssembly.s | 28 --- SDK/Library/CoreSystem/ARM64/.gitkeep | 0 SDK/Library/CoreSystem/Headers/Alert.h | 25 --- SDK/Library/CoreSystem/Headers/Defines.h | 235 --------------------- SDK/Library/CoreSystem/Headers/File.h | 52 ----- SDK/Library/CoreSystem/Headers/Heap.h | 39 ---- SDK/Library/CoreSystem/Headers/Hint.h | 20 -- SDK/Library/CoreSystem/Headers/Intl.h | 29 --- SDK/Library/CoreSystem/Headers/Math.h | 27 --- SDK/Library/CoreSystem/Headers/Rsrc.h | 12 -- SDK/Library/CoreSystem/Headers/Thread.h | 47 ----- SDK/Library/CoreSystem/Headers/Transport.h | 48 ----- SDK/Library/CoreSystem/POWER/CoreAssembly.s | 23 -- SDK/Library/CoreSystem/Private.xml | 4 - SDK/Library/CoreSystem/RISCV/.gitkeep | 0 SDK/Library/CoreSystem/ReadMe.md | 13 -- SDK/Library/CoreSystem/Sources/App.c | 31 --- SDK/Library/CoreSystem/Sources/CRTStartup.c | 12 -- SDK/Library/CoreSystem/Sources/File.c | 58 ----- SDK/Library/CoreSystem/Sources/Heap.c | 54 ----- SDK/Library/CoreSystem/Sources/Math.c | 14 -- SDK/Library/CoreSystem/Sources/Thread.c | 9 - SDK/Library/CoreSystem/amd64.mk | 22 -- SDK/Library/CoreSystem/compile_flags.txt | 4 - SDK/Tools/.gitkeep | 0 66 files changed, 868 insertions(+), 868 deletions(-) create mode 100644 SDK/Dist/.gitkeep create mode 100644 SDK/Libraries/.gitkeep create mode 100644 SDK/Libraries/CoreCxxRuntime/.gitkeep create mode 100644 SDK/Libraries/CoreCxxRuntime/Private.xml create mode 100644 SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx create mode 100644 SDK/Libraries/CorePEFRuntime/.gitkeep create mode 100644 SDK/Libraries/CorePEFRuntime/Private.xml create mode 100644 SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c create mode 100644 SDK/Libraries/CoreSystem/.gitkeep create mode 100644 SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s create mode 100644 SDK/Libraries/CoreSystem/ARM64/.gitkeep create mode 100644 SDK/Libraries/CoreSystem/Headers/Alert.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Defines.h create mode 100644 SDK/Libraries/CoreSystem/Headers/File.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Heap.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Hint.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Intl.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Math.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Rsrc.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Thread.h create mode 100644 SDK/Libraries/CoreSystem/Headers/Transport.h create mode 100644 SDK/Libraries/CoreSystem/POWER/CoreAssembly.s create mode 100644 SDK/Libraries/CoreSystem/Private.xml create mode 100644 SDK/Libraries/CoreSystem/RISCV/.gitkeep create mode 100644 SDK/Libraries/CoreSystem/ReadMe.md create mode 100644 SDK/Libraries/CoreSystem/Sources/App.c create mode 100644 SDK/Libraries/CoreSystem/Sources/CRTStartup.c create mode 100644 SDK/Libraries/CoreSystem/Sources/File.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Heap.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Math.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Thread.c create mode 100644 SDK/Libraries/CoreSystem/amd64.mk create mode 100644 SDK/Libraries/CoreSystem/compile_flags.txt delete mode 100644 SDK/Library/.gitkeep delete mode 100644 SDK/Library/CoreCxxRuntime/.gitkeep delete mode 100644 SDK/Library/CoreCxxRuntime/Private.xml delete mode 100644 SDK/Library/CoreCxxRuntime/Sources/New+Delete.cxx delete mode 100644 SDK/Library/CorePEFRuntime/.gitkeep delete mode 100644 SDK/Library/CorePEFRuntime/Private.xml delete mode 100644 SDK/Library/CorePEFRuntime/Sources/PEFStart.c delete mode 100644 SDK/Library/CoreSystem/.gitkeep delete mode 100644 SDK/Library/CoreSystem/AMD64/CoreAssembly.s delete mode 100644 SDK/Library/CoreSystem/ARM64/.gitkeep delete mode 100644 SDK/Library/CoreSystem/Headers/Alert.h delete mode 100644 SDK/Library/CoreSystem/Headers/Defines.h delete mode 100644 SDK/Library/CoreSystem/Headers/File.h delete mode 100644 SDK/Library/CoreSystem/Headers/Heap.h delete mode 100644 SDK/Library/CoreSystem/Headers/Hint.h delete mode 100644 SDK/Library/CoreSystem/Headers/Intl.h delete mode 100644 SDK/Library/CoreSystem/Headers/Math.h delete mode 100644 SDK/Library/CoreSystem/Headers/Rsrc.h delete mode 100644 SDK/Library/CoreSystem/Headers/Thread.h delete mode 100644 SDK/Library/CoreSystem/Headers/Transport.h delete mode 100644 SDK/Library/CoreSystem/POWER/CoreAssembly.s delete mode 100644 SDK/Library/CoreSystem/Private.xml delete mode 100644 SDK/Library/CoreSystem/RISCV/.gitkeep delete mode 100644 SDK/Library/CoreSystem/ReadMe.md delete mode 100644 SDK/Library/CoreSystem/Sources/App.c delete mode 100644 SDK/Library/CoreSystem/Sources/CRTStartup.c delete mode 100644 SDK/Library/CoreSystem/Sources/File.c delete mode 100644 SDK/Library/CoreSystem/Sources/Heap.c delete mode 100644 SDK/Library/CoreSystem/Sources/Math.c delete mode 100644 SDK/Library/CoreSystem/Sources/Thread.c delete mode 100644 SDK/Library/CoreSystem/amd64.mk delete mode 100644 SDK/Library/CoreSystem/compile_flags.txt delete mode 100644 SDK/Tools/.gitkeep (limited to 'SDK') diff --git a/SDK/Dist/.gitkeep b/SDK/Dist/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/.gitkeep b/SDK/Libraries/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CoreCxxRuntime/.gitkeep b/SDK/Libraries/CoreCxxRuntime/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CoreCxxRuntime/Private.xml b/SDK/Libraries/CoreCxxRuntime/Private.xml new file mode 100644 index 00000000..7ee426c0 --- /dev/null +++ b/SDK/Libraries/CoreCxxRuntime/Private.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx b/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx new file mode 100644 index 00000000..cc59586f --- /dev/null +++ b/SDK/Libraries/CoreCxxRuntime/Sources/New+Delete.cxx @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +typedef SizeType size_t; + +void* operator new[](size_t sz) +{ + if (sz == 0) + ++sz; + + return RtHeapAllocate(sz, kStandardAllocation); +} + +void* operator new(size_t sz) +{ + if (sz == 0) + ++sz; + + return RtHeapAllocate(sz, kArrayAllocation); +} + +void operator delete[](void* ptr) +{ + if (ptr == nullptr) + return; + + RtHeapFree(ptr); +} \ No newline at end of file diff --git a/SDK/Libraries/CorePEFRuntime/.gitkeep b/SDK/Libraries/CorePEFRuntime/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CorePEFRuntime/Private.xml b/SDK/Libraries/CorePEFRuntime/Private.xml new file mode 100644 index 00000000..7ee426c0 --- /dev/null +++ b/SDK/Libraries/CorePEFRuntime/Private.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c b/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c new file mode 100644 index 00000000..e9a45f09 --- /dev/null +++ b/SDK/Libraries/CorePEFRuntime/Sources/PEFStart.c @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Application entrypoint. +/// @param void +/// @return void +CS_EXTERN_C VoidType AppMain(VoidType); + +/// @brief Process entrypoint. +/// @param void +/// @return void +CS_EXTERN_C VoidType __ImageStart(VoidType) +{ + kSharedApplication = RtGetAppPointer(); + CS_MUST_PASS(kSharedApplication); + + AppMain(); +} diff --git a/SDK/Libraries/CoreSystem/.gitkeep b/SDK/Libraries/CoreSystem/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s b/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s new file mode 100644 index 00000000..5d1484cf --- /dev/null +++ b/SDK/Libraries/CoreSystem/AMD64/CoreAssembly.s @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + + Purpose: AMD64 low level I/O + +------------------------------------------- */ + +.text + +.globl RtGetAppPointer +.globl RtAssertTriggerInterrupt + +/* @brief Application getter */ +/* @throws: ApptError: appartement error. */ +RtGetAppPointer: + mov $0x10, %rcx /* sysGetProcessObject */ + int $0x32 + + /* rax gets saved and returned. */ + ret + +RtAssertTriggerInterrupt: + mov $0x11, %rcx /* sysTerminateCurrentProcess */ + int $0x32 + + ret + diff --git a/SDK/Libraries/CoreSystem/ARM64/.gitkeep b/SDK/Libraries/CoreSystem/ARM64/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CoreSystem/Headers/Alert.h b/SDK/Libraries/CoreSystem/Headers/Alert.h new file mode 100644 index 00000000..7decd4ca --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Alert.h @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/************************************************************* + * + * File: Alert.h + * Purpose: New OS alert dialog. + * Date: 3/26/24 + * + * Copyright SoftwareLabs, all rights reserved. + * + *************************************************************/ + +#pragma once + +#include + +/// @brief Shows an alert box, as provided by the OS. +/// @param fmt The alert formating. +/// @param +/// @return +CS_EXTERN_C VoidType UiAlert(const CharacterTypeUTF8* fmt, ...); 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 diff --git a/SDK/Libraries/CoreSystem/Headers/File.h b/SDK/Libraries/CoreSystem/Headers/File.h new file mode 100644 index 00000000..0013b074 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/File.h @@ -0,0 +1,52 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define kMaxForkNameLength (256U) /* long fork names. */ + +struct _Fork; + +/// @brief Filesystem wrapper. + +typedef QWordType FSRef; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); + +/// @brief Closes the file and flushes it to the said file. +/// @param refCS the filesystem reference. +/// @return +CS_EXTERN_C VoidType CSCloseFile(FSRef refCS); + +/// @brief A fork information header. +typedef struct _Fork +{ + Int32Type forkFlags; + Int32Type forkKind; + CharacterTypeUTF8 forkName[kMaxForkNameLength]; + SizeType forkSize; + CharacterTypeUTF8 forkData[]; +} ForkType, ForkTypePtr; + +typedef ForkType* FSForkRef; + +/// @brief Gets the fork inside a file. +/// @param refCS the filesystem ref +/// @param forkName the fork's name +/// @return the fork data. +CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); + +/// @brief Check if the filesystem path is valid. +/// @return if not return false, or true. +CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); + +/// END OF FILE diff --git a/SDK/Libraries/CoreSystem/Headers/Heap.h b/SDK/Libraries/CoreSystem/Headers/Heap.h new file mode 100644 index 00000000..b2ad6e74 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Heap.h @@ -0,0 +1,39 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +#define cAllocationKindCount (2U) + +enum CsAllocationKind +{ + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; + +/// @brief Allocates a new pointer from process pool. +/// @param sz the size +/// @param flags the allocation flags. +/// @return +CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, + DWordType flags); + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr); + +/// @brief Gets the size of the process' pointer. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr); + +/// @brief Frees the process pointer. +/// @param ptr the pointer to free. +/// @return +CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr); diff --git a/SDK/Libraries/CoreSystem/Headers/Hint.h b/SDK/Libraries/CoreSystem/Headers/Hint.h new file mode 100644 index 00000000..ee14711d --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Hint.h @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#pragma compiler(hint_manifest) + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/SDK/Libraries/CoreSystem/Headers/Intl.h b/SDK/Libraries/CoreSystem/Headers/Intl.h new file mode 100644 index 00000000..b868adca --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Intl.h @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +/// @brief Intlization primitives. + +#include + +typedef UInt64Type IntlRef; + +/// @brief Get app locale. +/// @param name locale name. +/// @return +IntlRef IntlGetLocale(const char* name); + +/// @brief Set app locale. +/// @param intl the locale +/// @return +BooleanType IntlSetLocale(const IntlRef intl); + +/// @brief locale helpers. + +/// @brief translate a string from a locale. +const CharacterTypeUTF8* Intl(const CharacterTypeUTF8* input, + const IntlRef locale); diff --git a/SDK/Libraries/CoreSystem/Headers/Math.h b/SDK/Libraries/CoreSystem/Headers/Math.h new file mode 100644 index 00000000..0a13e86f --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Math.h @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +/////////////////////////////////////////////////////////////////////// +/// Random functions /// +/////////////////////////////////////////////////////////////////////// + +/// @brief Number generator helper. +/// @return Random generated number. +CS_EXTERN_C SizeType MathRand(VoidType); + +/////////////////////////////////////////////////////////////////////// +/// Mathematical functions /// +/////////////////////////////////////////////////////////////////////// + +CS_EXTERN_C FloatType Sqrt(FloatType number); + +CS_EXTERN_C FloatType Cosine(FloatType number); +CS_EXTERN_C FloatType Sine(FloatType number); +CS_EXTERN_C FloatType Tangent(FloatType number); \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Headers/Rsrc.h b/SDK/Libraries/CoreSystem/Headers/Rsrc.h new file mode 100644 index 00000000..7fe52910 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Rsrc.h @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Rsrc.h +/// @brief RXML forks. \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Headers/Thread.h b/SDK/Libraries/CoreSystem/Headers/Thread.h new file mode 100644 index 00000000..15b40df3 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Thread.h @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD__ +#define __THREAD__ + +#include + +#define kThreadErrorExit (-33) + +/// @brief Thread reference. +typedef QWordType ThreadRef; + +/// @brief Main application thread. +CS_EXTERN_C ThreadRef kMainThread; + +typedef VoidType (*ThreadEntrypointKind)(VoidType); + +/// @brief Creates a new thread, and runs the code. +/// @param threadName the thread's name. +/// @param threadStart where to start. +/// @return +CS_EXTERN_C ThreadRef CSThreadCreate(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); + +/// @brief Dispoes the thread, and exits with code kThreadErrorExit +/// @param ref the thread reference. +/// @return nothing. +CS_EXTERN_C VoidType CSThreadRelease(ThreadRef ref); + +/// @brief Waits for the thread to complete. +/// @param ref the thread reference. +/// @return nothing. +CS_EXTERN_C VoidType CSThreadJoin(ThreadRef ref); + +/// @brief Yields the current thread. +/// @param ref the thead reference. +/// @return +CS_EXTERN_C VoidType CSThreadYield(ThreadRef ref); + +#endif // __THREAD__ diff --git a/SDK/Libraries/CoreSystem/Headers/Transport.h b/SDK/Libraries/CoreSystem/Headers/Transport.h new file mode 100644 index 00000000..3f6db3f1 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Headers/Transport.h @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +// +// Created by Amlal on 5/12/24 +// + +#ifndef __TRANSPORT__ +#define __TRANSPORT__ + +/// @file: Transport.h +/// @brief Open Transport Layer, an alternative to berkeley sockets. + +#include + +typedef QWordType TrStreamType; + +/// @brief Opens a new socket +/// @param afType address family +/// @param sockType type of socket +/// @param sockProto socket protocol. +/// @return The STREAMS socket. +/// @note return is const. +CS_EXTERN_C CS_CONST TrStreamType CSOpenSocket(UInt32Type afType, UInt32Type sockType, UInt32Type sockProto); + +/// @brief Close a STREAMS socket. +/// @param streams The streams socket. +/// @return +CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TrStreamType streams); + +/// @brief Get OpenTransport version. +/// @param void +/// @return +CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); + +enum +{ + TrSocketProtoTCP, /// TCP socket + TrSocketProtoUDP, /// UDP socket + TrSocketProtoUN, /// IPC socket + TrSocketProtoRaw, /// Raw socket + TrSocketProtoCount, +}; + +#endif // __TRANSPORT__ \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s b/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s new file mode 100644 index 00000000..e7919f23 --- /dev/null +++ b/SDK/Libraries/CoreSystem/POWER/CoreAssembly.s @@ -0,0 +1,23 @@ +; /* ------------------------------------------- +; +; Copyright SoftwareLabs +; +; Purpose: POWER low level I/O +; +; ------------------------------------------- */ + +/* @brief Application getter */ +/* @throws: ApptError: appartement error. */ +export .code64 RtGetAppPointer: + mflr r3 + stw 0x10, 0(r3) /* sysGetProcessObject */ + sc + + blr + +export .code64 RtAssertTriggerInterrupt: + mflr r3 + stw 0x11, 0(r3) /* sysTerminateCurrentProcess */ + sc + + blr diff --git a/SDK/Libraries/CoreSystem/Private.xml b/SDK/Libraries/CoreSystem/Private.xml new file mode 100644 index 00000000..4be6c388 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Private.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/RISCV/.gitkeep b/SDK/Libraries/CoreSystem/RISCV/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/SDK/Libraries/CoreSystem/ReadMe.md b/SDK/Libraries/CoreSystem/ReadMe.md new file mode 100644 index 00000000..ae5df339 --- /dev/null +++ b/SDK/Libraries/CoreSystem/ReadMe.md @@ -0,0 +1,13 @@ +# CoreSystem +## Core System framework. + +Currently contains: + +- Heap API. +- File API. +- Data API. +- Threading API. + +Needs to have: +- Device API +- Drive API. \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/App.c b/SDK/Libraries/CoreSystem/Sources/App.c new file mode 100644 index 00000000..42ea19c6 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/App.c @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. +ApplicationInterfaceRef kSharedApplication = NullPtr; + +/// @brief Gets the app arguments count. +/// @param void no arguments. +/// @return The number of arguments given to the application. +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param void no arguments. +/// @return +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, + kCallGetArgsPtr); +} diff --git a/SDK/Libraries/CoreSystem/Sources/CRTStartup.c b/SDK/Libraries/CoreSystem/Sources/CRTStartup.c new file mode 100644 index 00000000..1cfad65d --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/CRTStartup.c @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +VoidType __DllMainCRTStartup(VoidType) +{ + kSharedApplication = RtGetAppPointer(); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c new file mode 100644 index 00000000..7547e7f2 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/File.c @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +enum FileOp +{ + kFlushFile, + kReadFork, + kWriteFork, + kOpenFork, + kCloseFork, +}; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, + const CharacterTypeUTF8* rest) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path && CSIsValidPath(path) == Yes); + CS_MUST_PASS(rest); + + return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, + rest); +} + +/// @brief Closes the file and flushes it to the said file. +/// @param refCS the filesystem reference. +/// @return +CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); +} + +/// @brief Check if filesystem path is valid. +/// @param path +/// @return +CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path); + + return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Heap.c b/SDK/Libraries/CoreSystem/Sources/Heap.c new file mode 100644 index 00000000..e7a77ba5 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Heap.c @@ -0,0 +1,54 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +/// @brief Allocate from the user's heap. +/// @param sz size of object. +/// @param flags flags. +/// @return +CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(sz); + CS_MUST_PASS(flags); + + return (PtrVoidType)kSharedApplication->Invoke(kSharedApplication, + kCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param ptr the pointer to free. +CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + + CS_UNREFERENCED_PARAMETER( + kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param ptr the pointer to find. +/// @return the size. +CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + + CS_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to check. +/// @return if it exists +CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); +} diff --git a/SDK/Libraries/CoreSystem/Sources/Math.c b/SDK/Libraries/CoreSystem/Sources/Math.c new file mode 100644 index 00000000..19df42f3 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Math.c @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Number generator helper. +/// @return Random generated number. +CS_EXTERN_C SizeType MathRand(VoidType) +{ + return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Thread.c b/SDK/Libraries/CoreSystem/Sources/Thread.c new file mode 100644 index 00000000..7d00bf9e --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Thread.c @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +ThreadRef kMainThread = 0; diff --git a/SDK/Libraries/CoreSystem/amd64.mk b/SDK/Libraries/CoreSystem/amd64.mk new file mode 100644 index 00000000..e64de90f --- /dev/null +++ b/SDK/Libraries/CoreSystem/amd64.mk @@ -0,0 +1,22 @@ +################################################## +# (C) SoftwareLabs, all rights reserved. +# This is the CoreSystem Makefile. +################################################## + +CC=x86_64-w64-mingw32-gcc +AR=x86_64-w64-mingw32-ar +CCINC=-I./ +CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -e __DllMainCRTStartup -shared +OUTPUT=CoreSystem.lib + +.PHONY: all +all: build-core-amd64 + @echo "[CoreSystem.lib] Build done." + +.PHONY: build-core-amd64 +build-core-amd64: + $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard AMD64/*.s) -o $(OUTPUT) + +.PHONY: clean +clean: + rm -f $(wildcard *.lib) diff --git a/SDK/Libraries/CoreSystem/compile_flags.txt b/SDK/Libraries/CoreSystem/compile_flags.txt new file mode 100644 index 00000000..749a500e --- /dev/null +++ b/SDK/Libraries/CoreSystem/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../../Kernel +-std=c17 diff --git a/SDK/Library/.gitkeep b/SDK/Library/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CoreCxxRuntime/.gitkeep b/SDK/Library/CoreCxxRuntime/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CoreCxxRuntime/Private.xml b/SDK/Library/CoreCxxRuntime/Private.xml deleted file mode 100644 index 7ee426c0..00000000 --- a/SDK/Library/CoreCxxRuntime/Private.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SDK/Library/CoreCxxRuntime/Sources/New+Delete.cxx b/SDK/Library/CoreCxxRuntime/Sources/New+Delete.cxx deleted file mode 100644 index cc59586f..00000000 --- a/SDK/Library/CoreCxxRuntime/Sources/New+Delete.cxx +++ /dev/null @@ -1,33 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -typedef SizeType size_t; - -void* operator new[](size_t sz) -{ - if (sz == 0) - ++sz; - - return RtHeapAllocate(sz, kStandardAllocation); -} - -void* operator new(size_t sz) -{ - if (sz == 0) - ++sz; - - return RtHeapAllocate(sz, kArrayAllocation); -} - -void operator delete[](void* ptr) -{ - if (ptr == nullptr) - return; - - RtHeapFree(ptr); -} \ No newline at end of file diff --git a/SDK/Library/CorePEFRuntime/.gitkeep b/SDK/Library/CorePEFRuntime/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CorePEFRuntime/Private.xml b/SDK/Library/CorePEFRuntime/Private.xml deleted file mode 100644 index 7ee426c0..00000000 --- a/SDK/Library/CorePEFRuntime/Private.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SDK/Library/CorePEFRuntime/Sources/PEFStart.c b/SDK/Library/CorePEFRuntime/Sources/PEFStart.c deleted file mode 100644 index e9a45f09..00000000 --- a/SDK/Library/CorePEFRuntime/Sources/PEFStart.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Application entrypoint. -/// @param void -/// @return void -CS_EXTERN_C VoidType AppMain(VoidType); - -/// @brief Process entrypoint. -/// @param void -/// @return void -CS_EXTERN_C VoidType __ImageStart(VoidType) -{ - kSharedApplication = RtGetAppPointer(); - CS_MUST_PASS(kSharedApplication); - - AppMain(); -} diff --git a/SDK/Library/CoreSystem/.gitkeep b/SDK/Library/CoreSystem/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CoreSystem/AMD64/CoreAssembly.s b/SDK/Library/CoreSystem/AMD64/CoreAssembly.s deleted file mode 100644 index 5d1484cf..00000000 --- a/SDK/Library/CoreSystem/AMD64/CoreAssembly.s +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - - Purpose: AMD64 low level I/O - -------------------------------------------- */ - -.text - -.globl RtGetAppPointer -.globl RtAssertTriggerInterrupt - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -RtGetAppPointer: - mov $0x10, %rcx /* sysGetProcessObject */ - int $0x32 - - /* rax gets saved and returned. */ - ret - -RtAssertTriggerInterrupt: - mov $0x11, %rcx /* sysTerminateCurrentProcess */ - int $0x32 - - ret - diff --git a/SDK/Library/CoreSystem/ARM64/.gitkeep b/SDK/Library/CoreSystem/ARM64/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CoreSystem/Headers/Alert.h b/SDK/Library/CoreSystem/Headers/Alert.h deleted file mode 100644 index 7decd4ca..00000000 --- a/SDK/Library/CoreSystem/Headers/Alert.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -/************************************************************* - * - * File: Alert.h - * Purpose: New OS alert dialog. - * Date: 3/26/24 - * - * Copyright SoftwareLabs, all rights reserved. - * - *************************************************************/ - -#pragma once - -#include - -/// @brief Shows an alert box, as provided by the OS. -/// @param fmt The alert formating. -/// @param -/// @return -CS_EXTERN_C VoidType UiAlert(const CharacterTypeUTF8* fmt, ...); diff --git a/SDK/Library/CoreSystem/Headers/Defines.h b/SDK/Library/CoreSystem/Headers/Defines.h deleted file mode 100644 index a7e46234..00000000 --- a/SDK/Library/CoreSystem/Headers/Defines.h +++ /dev/null @@ -1,235 +0,0 @@ -/* ------------------------------------------- - - 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 diff --git a/SDK/Library/CoreSystem/Headers/File.h b/SDK/Library/CoreSystem/Headers/File.h deleted file mode 100644 index 594b4edb..00000000 --- a/SDK/Library/CoreSystem/Headers/File.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -struct _Fork; - -/// @brief Filesystem wrapper. - -typedef QWordType FSRef; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS); - -#define kMaxForkNameLength (256U) /* long fork names. */ - -/// @brief A fork information header. -typedef struct _Fork -{ - Int32Type forkFlags; - Int32Type forkKind; - CharacterTypeUTF8 forkName[kMaxForkNameLength]; - SizeType forkSize; - CharacterTypeUTF8 forkData[]; -} ForkType, ForkTypePtr; - -typedef ForkType* FSForkRef; - -/// @brief Gets the fork inside a file. -/// @param refCS the filesystem ref -/// @param forkName the fork's name -/// @return the fork data. -CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); - -/// @brief Check if the filesystem path is valid. -/// @return if not return false, or true. -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); - -/// END OF FILE diff --git a/SDK/Library/CoreSystem/Headers/Heap.h b/SDK/Library/CoreSystem/Headers/Heap.h deleted file mode 100644 index b2ad6e74..00000000 --- a/SDK/Library/CoreSystem/Headers/Heap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -#define cAllocationKindCount (2U) - -enum CsAllocationKind -{ - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -/// @brief Allocates a new pointer from process pool. -/// @param sz the size -/// @param flags the allocation flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, - DWordType flags); - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr); - -/// @brief Gets the size of the process' pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr); - -/// @brief Frees the process pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr); diff --git a/SDK/Library/CoreSystem/Headers/Hint.h b/SDK/Library/CoreSystem/Headers/Hint.h deleted file mode 100644 index ee14711d..00000000 --- a/SDK/Library/CoreSystem/Headers/Hint.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/SDK/Library/CoreSystem/Headers/Intl.h b/SDK/Library/CoreSystem/Headers/Intl.h deleted file mode 100644 index b868adca..00000000 --- a/SDK/Library/CoreSystem/Headers/Intl.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -/// @brief Intlization primitives. - -#include - -typedef UInt64Type IntlRef; - -/// @brief Get app locale. -/// @param name locale name. -/// @return -IntlRef IntlGetLocale(const char* name); - -/// @brief Set app locale. -/// @param intl the locale -/// @return -BooleanType IntlSetLocale(const IntlRef intl); - -/// @brief locale helpers. - -/// @brief translate a string from a locale. -const CharacterTypeUTF8* Intl(const CharacterTypeUTF8* input, - const IntlRef locale); diff --git a/SDK/Library/CoreSystem/Headers/Math.h b/SDK/Library/CoreSystem/Headers/Math.h deleted file mode 100644 index 0a13e86f..00000000 --- a/SDK/Library/CoreSystem/Headers/Math.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -/////////////////////////////////////////////////////////////////////// -/// Random functions /// -/////////////////////////////////////////////////////////////////////// - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType); - -/////////////////////////////////////////////////////////////////////// -/// Mathematical functions /// -/////////////////////////////////////////////////////////////////////// - -CS_EXTERN_C FloatType Sqrt(FloatType number); - -CS_EXTERN_C FloatType Cosine(FloatType number); -CS_EXTERN_C FloatType Sine(FloatType number); -CS_EXTERN_C FloatType Tangent(FloatType number); \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Headers/Rsrc.h b/SDK/Library/CoreSystem/Headers/Rsrc.h deleted file mode 100644 index 7fe52910..00000000 --- a/SDK/Library/CoreSystem/Headers/Rsrc.h +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Rsrc.h -/// @brief RXML forks. \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Headers/Thread.h b/SDK/Library/CoreSystem/Headers/Thread.h deleted file mode 100644 index 15b40df3..00000000 --- a/SDK/Library/CoreSystem/Headers/Thread.h +++ /dev/null @@ -1,47 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -// -// Created by Amlal on 3/18/24 -// - -#ifndef __THREAD__ -#define __THREAD__ - -#include - -#define kThreadErrorExit (-33) - -/// @brief Thread reference. -typedef QWordType ThreadRef; - -/// @brief Main application thread. -CS_EXTERN_C ThreadRef kMainThread; - -typedef VoidType (*ThreadEntrypointKind)(VoidType); - -/// @brief Creates a new thread, and runs the code. -/// @param threadName the thread's name. -/// @param threadStart where to start. -/// @return -CS_EXTERN_C ThreadRef CSThreadCreate(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); - -/// @brief Dispoes the thread, and exits with code kThreadErrorExit -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadRelease(ThreadRef ref); - -/// @brief Waits for the thread to complete. -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadJoin(ThreadRef ref); - -/// @brief Yields the current thread. -/// @param ref the thead reference. -/// @return -CS_EXTERN_C VoidType CSThreadYield(ThreadRef ref); - -#endif // __THREAD__ diff --git a/SDK/Library/CoreSystem/Headers/Transport.h b/SDK/Library/CoreSystem/Headers/Transport.h deleted file mode 100644 index 3f6db3f1..00000000 --- a/SDK/Library/CoreSystem/Headers/Transport.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -// -// Created by Amlal on 5/12/24 -// - -#ifndef __TRANSPORT__ -#define __TRANSPORT__ - -/// @file: Transport.h -/// @brief Open Transport Layer, an alternative to berkeley sockets. - -#include - -typedef QWordType TrStreamType; - -/// @brief Opens a new socket -/// @param afType address family -/// @param sockType type of socket -/// @param sockProto socket protocol. -/// @return The STREAMS socket. -/// @note return is const. -CS_EXTERN_C CS_CONST TrStreamType CSOpenSocket(UInt32Type afType, UInt32Type sockType, UInt32Type sockProto); - -/// @brief Close a STREAMS socket. -/// @param streams The streams socket. -/// @return -CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TrStreamType streams); - -/// @brief Get OpenTransport version. -/// @param void -/// @return -CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); - -enum -{ - TrSocketProtoTCP, /// TCP socket - TrSocketProtoUDP, /// UDP socket - TrSocketProtoUN, /// IPC socket - TrSocketProtoRaw, /// Raw socket - TrSocketProtoCount, -}; - -#endif // __TRANSPORT__ \ No newline at end of file diff --git a/SDK/Library/CoreSystem/POWER/CoreAssembly.s b/SDK/Library/CoreSystem/POWER/CoreAssembly.s deleted file mode 100644 index e7919f23..00000000 --- a/SDK/Library/CoreSystem/POWER/CoreAssembly.s +++ /dev/null @@ -1,23 +0,0 @@ -; /* ------------------------------------------- -; -; Copyright SoftwareLabs -; -; Purpose: POWER low level I/O -; -; ------------------------------------------- */ - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -export .code64 RtGetAppPointer: - mflr r3 - stw 0x10, 0(r3) /* sysGetProcessObject */ - sc - - blr - -export .code64 RtAssertTriggerInterrupt: - mflr r3 - stw 0x11, 0(r3) /* sysTerminateCurrentProcess */ - sc - - blr diff --git a/SDK/Library/CoreSystem/Private.xml b/SDK/Library/CoreSystem/Private.xml deleted file mode 100644 index 4be6c388..00000000 --- a/SDK/Library/CoreSystem/Private.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/SDK/Library/CoreSystem/RISCV/.gitkeep b/SDK/Library/CoreSystem/RISCV/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/SDK/Library/CoreSystem/ReadMe.md b/SDK/Library/CoreSystem/ReadMe.md deleted file mode 100644 index ae5df339..00000000 --- a/SDK/Library/CoreSystem/ReadMe.md +++ /dev/null @@ -1,13 +0,0 @@ -# CoreSystem -## Core System framework. - -Currently contains: - -- Heap API. -- File API. -- Data API. -- Threading API. - -Needs to have: -- Device API -- Drive API. \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Sources/App.c b/SDK/Library/CoreSystem/Sources/App.c deleted file mode 100644 index 42ea19c6..00000000 --- a/SDK/Library/CoreSystem/Sources/App.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. -ApplicationInterfaceRef kSharedApplication = NullPtr; - -/// @brief Gets the app arguments count. -/// @param void no arguments. -/// @return The number of arguments given to the application. -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); -} - -/// @brief Gets the app arguments pointer. -/// @param void no arguments. -/// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, - kCallGetArgsPtr); -} diff --git a/SDK/Library/CoreSystem/Sources/CRTStartup.c b/SDK/Library/CoreSystem/Sources/CRTStartup.c deleted file mode 100644 index 1cfad65d..00000000 --- a/SDK/Library/CoreSystem/Sources/CRTStartup.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -VoidType __DllMainCRTStartup(VoidType) -{ - kSharedApplication = RtGetAppPointer(); -} \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Sources/File.c b/SDK/Library/CoreSystem/Sources/File.c deleted file mode 100644 index 7547e7f2..00000000 --- a/SDK/Library/CoreSystem/Sources/File.c +++ /dev/null @@ -1,58 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include -#include - -enum FileOp -{ - kFlushFile, - kReadFork, - kWriteFork, - kOpenFork, - kCloseFork, -}; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, - const CharacterTypeUTF8* rest) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path && CSIsValidPath(path) == Yes); - CS_MUST_PASS(rest); - - return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, - rest); -} - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) -{ - CS_MUST_PASS(kSharedApplication); - - kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); - kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); -} - -/// @brief Check if filesystem path is valid. -/// @param path -/// @return -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path); - - return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); -} \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Sources/Heap.c b/SDK/Library/CoreSystem/Sources/Heap.c deleted file mode 100644 index e7a77ba5..00000000 --- a/SDK/Library/CoreSystem/Sources/Heap.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include -#include - -/// @brief Allocate from the user's heap. -/// @param sz size of object. -/// @param flags flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(sz); - CS_MUST_PASS(flags); - - return (PtrVoidType)kSharedApplication->Invoke(kSharedApplication, - kCallAllocPtr, sz, flags); -} - -/// @brief Free pointer from the user's heap. -/// @param ptr the pointer to free. -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - - CS_UNREFERENCED_PARAMETER( - kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); -} - -/// @brief Get pointer size. -/// @param ptr the pointer to find. -/// @return the size. -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - - CS_MUST_PASS(ptr); - return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); -} - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to check. -/// @return if it exists -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); -} diff --git a/SDK/Library/CoreSystem/Sources/Math.c b/SDK/Library/CoreSystem/Sources/Math.c deleted file mode 100644 index 19df42f3..00000000 --- a/SDK/Library/CoreSystem/Sources/Math.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType) -{ - return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); -} \ No newline at end of file diff --git a/SDK/Library/CoreSystem/Sources/Thread.c b/SDK/Library/CoreSystem/Sources/Thread.c deleted file mode 100644 index 7d00bf9e..00000000 --- a/SDK/Library/CoreSystem/Sources/Thread.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include - -ThreadRef kMainThread = 0; diff --git a/SDK/Library/CoreSystem/amd64.mk b/SDK/Library/CoreSystem/amd64.mk deleted file mode 100644 index e64de90f..00000000 --- a/SDK/Library/CoreSystem/amd64.mk +++ /dev/null @@ -1,22 +0,0 @@ -################################################## -# (C) SoftwareLabs, all rights reserved. -# This is the CoreSystem Makefile. -################################################## - -CC=x86_64-w64-mingw32-gcc -AR=x86_64-w64-mingw32-ar -CCINC=-I./ -CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -e __DllMainCRTStartup -shared -OUTPUT=CoreSystem.lib - -.PHONY: all -all: build-core-amd64 - @echo "[CoreSystem.lib] Build done." - -.PHONY: build-core-amd64 -build-core-amd64: - $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard AMD64/*.s) -o $(OUTPUT) - -.PHONY: clean -clean: - rm -f $(wildcard *.lib) diff --git a/SDK/Library/CoreSystem/compile_flags.txt b/SDK/Library/CoreSystem/compile_flags.txt deleted file mode 100644 index 749a500e..00000000 --- a/SDK/Library/CoreSystem/compile_flags.txt +++ /dev/null @@ -1,4 +0,0 @@ --I./ --I../ --I../../../Kernel --std=c17 diff --git a/SDK/Tools/.gitkeep b/SDK/Tools/.gitkeep deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3 From 5bc5e4de0d4dcfc52c192315ca5c59a066d678d8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 1 Jun 2024 23:59:03 +0200 Subject: MHR-23: Fix ACPI and APIC probe. Signed-off-by: Amlal El Mahrouss --- Kernel/Builtins/ACPI/ACPI.hxx | 2 +- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 18 +++++----- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 42 ++++++---------------- Kernel/HALKit/AMD64/Processor.hpp | 30 ++++++++-------- SDK/Libraries/CoreSystem/Headers/File.h | 5 +++ SDK/Libraries/CoreSystem/Sources/File.c | 13 ++++++- 6 files changed, 54 insertions(+), 56 deletions(-) (limited to 'SDK') diff --git a/Kernel/Builtins/ACPI/ACPI.hxx b/Kernel/Builtins/ACPI/ACPI.hxx index d9bfeaca..430a39f4 100644 --- a/Kernel/Builtins/ACPI/ACPI.hxx +++ b/Kernel/Builtins/ACPI/ACPI.hxx @@ -81,7 +81,7 @@ namespace NewOS UInt32 OemRev; UInt32 CreatorID; UInt32 CreatorRevision; - UInt64 AddressArr[]; + UInt32 AddressArr[]; }; } // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index f92554f8..adeeb10d 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -76,36 +76,38 @@ namespace NewOS } /// FIXME - RSDT* xsdt = (RSDT*)rsdPtr->XsdtAddress; + RSDT* xsdt = (RSDT*)(rsdPtr->RsdtAddress); - if (NewOS::HAL::ke_map_address((PDE*)hal_read_cr3(), rsdPtr->XsdtAddress, (UIntPtr)xsdt, NewOS::HAL::eFlagsRw)) - return ErrorOr{-5}; - - Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt64); + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32); if (num < 1) { + kcout << "ACPI: No entries." << endl; return ErrorOr{-6}; } 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: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; const short cAcpiSignatureLength = 4; for (Size index = 0; index < this->fEntries; ++index) { - SDT* sdt = (SDT*)(xsdt->AddressArr[index]); + SDT& sdt = *(SDT*)xsdt->AddressArr[index]; + + kcout << "ACPI: Revision: " << number(sdt.CreatorID) << endl; for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) { - if (sdt->Signature[signature_index] != signature[signature_index]) + if (sdt.Signature[signature_index] != signature[signature_index]) break; if (signature_index == (cAcpiSignatureLength - 1)) - return ErrorOr(reinterpret_cast(sdt)); + return ErrorOr(reinterpret_cast(&sdt)); } } diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 287b1882..5ab40532 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -137,37 +137,17 @@ namespace NewOS::HAL if (kApicMadt != nullptr) { - auto madt = (SDT*)kApicMadt; - - const UInt8* madt_end = (const UInt8*)madt + madt->Length; - const UInt8* entry_ptr = (const UInt8*)(madt + 1); - - while (entry_ptr < madt_end) - { - const MadtType::MadtAddress* entry_header = (const MadtType::MadtAddress*)entry_ptr; - - switch (entry_header->Flags) - { - case 0: { - const MadtProcessorLocalApic* local_apic = (const MadtProcessorLocalApic*)entry_ptr; - if (local_apic->Flags & 1) - { - // Processor is enabled - kcout << "Processor ID: %d, APIC ID: %d\n" - << number(local_apic->AcpiProcessorId) << number(local_apic->ApicId); - } - break; - } - default: - break; - } - - entry_ptr += entry_header->RecordLen; - } - - while (true) - { - } + MadtType* madt = (MadtType*)kApicMadt; + + constexpr auto cMaxProbableCores = 4; + + for (SizeT i = 0; i < cMaxProbableCores; ++i) + { + if (madt->MadtRecords[i].Flags == 0x01) // if local apic. + { + // then register as a core for scheduler. + } + } } else { diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp index 608a502f..4916d845 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hpp @@ -74,24 +74,27 @@ namespace NewOS::HAL if (!pde->Pte[pml4_index].Present) { pde->Pte[pml4_index].Present = true; - kcout << "PM: It is present now.\r"; + kcout << "PM is present now.\r"; + + pde->Pte[pml4_index].PhysicalAddress = phys_addr; + pde->Pte[pml4_index].Rw = flags & eFlagsRw; + pde->Pte[pml4_index].User = flags & eFlagsUser; + pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + + return 0; } else { - kcout << "PM: It is already present.\r"; - kcout << "Address? " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; - kcout << "User? " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; - kcout << "RW? " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; + kcout << "PM is already present.\r"; - return 1; - } + kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; + kcout << "User: " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; + kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; - pde->Pte[pml4_index].PhysicalAddress = phys_addr; - pde->Pte[pml4_index].Rw = flags & eFlagsRw; - pde->Pte[pml4_index].User = flags & eFlagsUser; - pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + return 1; + } - return 0; + return 0; } /// @brief Map address to PDE. @@ -102,9 +105,6 @@ namespace NewOS::HAL inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) { UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; - UInt16 pdpt_index = (virt_addr >> 30) & 0x1FF; - UInt16 pd_index = (virt_addr >> 21) & 0x1FF; - UInt16 pt_index = (virt_addr >> 12) & 0x1FF; if (pde->Pte[pml4_index].Present) { diff --git a/SDK/Libraries/CoreSystem/Headers/File.h b/SDK/Libraries/CoreSystem/Headers/File.h index 0013b074..cfd9ee30 100644 --- a/SDK/Libraries/CoreSystem/Headers/File.h +++ b/SDK/Libraries/CoreSystem/Headers/File.h @@ -49,4 +49,9 @@ CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); /// @return if not return false, or true. CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); + /// END OF FILE diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c index 7547e7f2..6e0e810a 100644 --- a/SDK/Libraries/CoreSystem/Sources/File.c +++ b/SDK/Libraries/CoreSystem/Sources/File.c @@ -38,10 +38,21 @@ CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) { CS_MUST_PASS(kSharedApplication); - kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); + CSFlushFile(refCS); + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); } +/// @brief Flush file +/// @param refCS the file reference. +/// @return +CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); +} + /// @brief Check if filesystem path is valid. /// @param path /// @return -- 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') 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