summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-16 14:00:12 +0000
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-16 14:00:12 +0000
commit82f0a2da77af7d79e53f5e65e46c527c1fe92765 (patch)
tree319ef7dd933367d64911c0ed9a53f91565002b00
parent544d0cadfc371bcfb54d9f7ec15464bc6a79af21 (diff)
parent4c7aebf1b8964b99b89a25da0965b30fe6c7e6b3 (diff)
Merge branch 'HCR-18' into 'trunk'
HCR-18: First commit, bringing HCoreKrnl.exe into memory. See merge request mahrouss-logic/micro-kernel!6
-rw-r--r--Private/EFIKit/Api.hxx8
-rw-r--r--Private/EFIKit/EFI.hxx9
-rw-r--r--Private/EFIKit/Handover.hxx8
-rw-r--r--Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp4
-rw-r--r--Private/HALKit/AMD64/HalDebugOutput.cxx2
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.hpp18
-rw-r--r--Private/HALKit/PowerPC/HalHardware.cxx4
-rw-r--r--Private/KernelKit/MSDOS.hpp2
-rw-r--r--Private/KernelKit/ProcessManager.hpp12
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx7
-rw-r--r--Private/NewBoot/Source/FileReader.cxx2
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx98
-rw-r--r--Private/NewKit/Json.hpp2
-rw-r--r--Private/NewKit/Macros.hpp4
-rw-r--r--Private/NewKit/Utils.hpp35
-rw-r--r--Private/Source/Network/IP.cpp2
-rw-r--r--Private/Source/PEFSharedObjectRT.cxx23
-rw-r--r--Private/Source/ProcessManager.cxx43
-rw-r--r--Private/Source/String.cxx46
-rw-r--r--Private/Source/URL.cxx10
-rw-r--r--Private/Source/UserHeap.cxx8
-rw-r--r--Private/Source/Utils.cxx14
-rw-r--r--Private/Source/compile_flags.txt1
-rw-r--r--Private/makefile2
-rw-r--r--ReadMe.md2
25 files changed, 229 insertions, 137 deletions
diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx
index 7338235a..d2cb73f8 100644
--- a/Private/EFIKit/Api.hxx
+++ b/Private/EFIKit/Api.hxx
@@ -30,11 +30,7 @@ Bascially frees everything we have in the EFI side.
inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept {
if (!ST) return;
- /// The MapKey may be invalid.
- /// If so, then hang the computer.
- if (ST->BootServices->ExitBootServices(ImageHandle, MapKey) != kEfiOk) {
- EFI::Stop();
- }
+ ST->BootServices->ExitBootServices(ImageHandle, MapKey);
}
enum {
@@ -85,4 +81,6 @@ inline void InitEFI(EfiSystemTable *SystemTable) noexcept {
#endif // ifdef __BOOTLOADER__
+#define kHCoreSubsystem 17
+
#endif /* ifndef __EFI_API__ */
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index dfaf68eb..f2810c8c 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -416,6 +416,11 @@ typedef UInt64(EFI_API *EfiAllocatePages)(EfiAllocateType AllocType,
typedef UInt64(EFI_API *EfiFreePages)(EfiPhysicalAddress *Memory, UInt32 Pages);
+typedef UInt64(EFI_API *EfiGetMemoryMap)(UInt32 *MapSize,
+ EfiMemoryDescriptor *DescPtr,
+ UInt32 *MapKey, UInt32 *DescSize,
+ UInt32 *DescVersion);
+
/**
* @brief GUID type, something you can also find in CFKit.
*/
@@ -459,7 +464,7 @@ typedef struct EfiBootServices {
UIntPtr RestoreTPL;
EfiAllocatePages AllocatePages;
EfiFreePages FreePages;
- UIntPtr GetMemoryMap;
+ EfiGetMemoryMap GetMemoryMap;
EfiAllocatePool AllocatePool;
EfiFreePool FreePool;
UIntPtr CreateEvent;
@@ -720,4 +725,6 @@ struct EfiFileInfo final {
#define EFI_FILE_PROTOCOL_REVISION2 0x00020000
#define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
+#define EFI_EXTRA_DESCRIPTOR_SIZE 8
+
#endif // ifndef __EFI__
diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx
index eb79e934..840af2ec 100644
--- a/Private/EFIKit/Handover.hxx
+++ b/Private/EFIKit/Handover.hxx
@@ -61,22 +61,22 @@ typedef struct HandoverHeader final {
} __attribute__((packed)) HandoverHeader, *HandoverHeaderPtr;
struct HandoverInformationHeader {
- HandoverHeaderPtr f_Header;
+ HandoverHeader f_Header;
voidPtr f_VirtualStart;
SizeT f_VirtualSize;
voidPtr f_PhysicalStart;
SizeT f_PhysicalSize;
- Char f_FirmwareVendorName[32];
+ WideChar f_FirmwareVendorName[32];
SizeT f_FirmwareVendorLen;
voidPtr f_RsdPtr;
voidPtr f_SmBIOS;
voidPtr f_RTC;
voidPtr f_GOP;
- voidPtr f_GOPSize;
+ SizeT f_GOPSize;
};
/**
@brief Handover Jump Proc
*/
-typedef UInt64 (*HandoverProc)(HandoverInformationHeader* pHandover);
+typedef void (*HandoverProc)(HandoverInformationHeader* pHandover);
} // namespace HCore::HEL
diff --git a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
index 1e53140f..73c995c4 100644
--- a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
+++ b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
@@ -96,8 +96,8 @@ static Madt kApicMadtList[256];
Madt* system_find_core(Madt* madt) {
madt = madt + sizeof(Madt);
- if (string_compare(madt->fMag, kApicSignature,
- string_length(kApicSignature)) == 0)
+ if (rt_string_cmp(madt->fMag, kApicSignature,
+ rt_string_len(kApicSignature)) == 0)
return madt;
return nullptr;
diff --git a/Private/HALKit/AMD64/HalDebugOutput.cxx b/Private/HALKit/AMD64/HalDebugOutput.cxx
index ac16cf70..ba8770fe 100644
--- a/Private/HALKit/AMD64/HalDebugOutput.cxx
+++ b/Private/HALKit/AMD64/HalDebugOutput.cxx
@@ -60,7 +60,7 @@ void ke_io_print(const char *bytes) {
Detail::kState = kStateTransmit;
SizeT index = 0;
- SizeT len = string_length(bytes, 256);
+ SizeT len = rt_string_len(bytes, 256);
while (index < len) {
HAL::Out8(Detail::PORT, bytes[index]);
diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp
index d6912318..9ca2c580 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.hpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.hpp
@@ -17,13 +17,17 @@
#include <NewKit/Defines.hpp>
-#ifndef PTE_MAX
-#define PTE_MAX (0x200)
-#endif //! PTE_MAX
+#ifndef kPTEMax
+#define kPTEMax (0x200)
+#endif //! kPTEMax
-#ifndef PTE_ALIGN
-#define PTE_ALIGN (0x1000)
-#endif //! PTE_ALIGN
+#ifndef kPTEAlign
+#define kPTEAlign (0x1000)
+#endif //! kPTEAlign
+
+#ifndef kPTESize
+#define kPTESize (0x1000)
+#endif // !kPTESize
extern "C" void flush_tlb(HCore::UIntPtr VirtualAddr);
extern "C" void write_cr3(HCore::UIntPtr pde);
@@ -68,7 +72,7 @@ inline UInt8 control_register_cast(ControlRegisterBits reg) {
} // namespace Detail
struct PageDirectory64 final {
- PageTable64 ALIGN(PTE_ALIGN) Pte[PTE_MAX];
+ PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax];
};
PageTable64* hal_alloc_page(SizeT sz, Boolean rw, Boolean user);
diff --git a/Private/HALKit/PowerPC/HalHardware.cxx b/Private/HALKit/PowerPC/HalHardware.cxx
index 89b1a6ae..a5f11449 100644
--- a/Private/HALKit/PowerPC/HalHardware.cxx
+++ b/Private/HALKit/PowerPC/HalHardware.cxx
@@ -13,7 +13,7 @@
extern "C" void flush_tlb() {}
extern "C" void rt_wait_for_io() {}
-extern "C" HCore::HAL::StackFrame* rt_get_current_context() {}
+extern "C" HCore::HAL::StackFrame* rt_get_current_context() { return nullptr; }
namespace HCore {
namespace HAL {
@@ -37,7 +37,7 @@ void ke_com_print(const Char* bytes) {
if (!bytes) return;
SizeT index = 0;
- SizeT len = string_length(bytes, 256);
+ SizeT len = rt_string_len(bytes, 256);
while (index < len) {
// TODO
diff --git a/Private/KernelKit/MSDOS.hpp b/Private/KernelKit/MSDOS.hpp
index 2276f3cb..1adf6082 100644
--- a/Private/KernelKit/MSDOS.hpp
+++ b/Private/KernelKit/MSDOS.hpp
@@ -48,7 +48,7 @@ namespace HCore {
inline auto rt_find_exec_header(DosHeaderPtr ptrDos) -> VoidPtr {
if (!ptrDos) return nullptr;
if (ptrDos->eMagic[0] != kMagMz0) return nullptr;
- if (ptrDos->eMagic[0] != kMagMz1) return nullptr;
+ if (ptrDos->eMagic[1] != kMagMz1) return nullptr;
return (VoidPtr)(&ptrDos->eLfanew + 1);
}
diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp
index e6d86959..543b3007 100644
--- a/Private/KernelKit/ProcessManager.hpp
+++ b/Private/KernelKit/ProcessManager.hpp
@@ -130,17 +130,25 @@ class Process final {
ProcessStatus Status;
// Memory, images.
- HeapPtr PoolCursor{nullptr};
+ HeapPtr HeapCursor{nullptr};
ImagePtr Image{nullptr};
- HeapPtr Pool{nullptr};
+ HeapPtr HeapPtr{nullptr};
// memory usage
SizeT UsedMemory{0};
SizeT FreeMemory{0};
+ enum {
+ ExecutableType,
+ DLLType,
+ DriverType,
+ TypeCount,
+ };
+
ProcessTime PTime;
PID ProcessId{-1};
Int32 Ring{3};
+ Int32 Kind{0};
public:
//! @brief boolean operator, check status.
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 0c747643..dcb8daf4 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -64,7 +64,7 @@ class BFileReader final {
explicit BFileReader(const CharacterType *path, EfiHandlePtr ImageHandle);
~BFileReader();
- Void Read();
+ Void ReadAll();
enum {
kOperationOkay,
@@ -80,6 +80,11 @@ class BFileReader final {
EfiFileProtocolPtr File() { return mFile; }
UInt64 &Size() { return mSizeFile; }
+ UInt64 &Size(const UInt64 &Sz) {
+ mSizeFile = Sz;
+ return mSizeFile;
+ }
+
public:
BFileReader &operator=(const BFileReader &) = default;
BFileReader(const BFileReader &) = default;
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 5768cae0..d81248ea 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -103,7 +103,7 @@ BFileReader::~BFileReader() {
@brief this reads all of the buffer.
@param ImageHandle used internally.
*/
-Void BFileReader::Read() {
+Void BFileReader::ReadAll() {
/// Allocate Handover page.
if (mBlob == nullptr) {
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index 3c55c06b..38eb0ea8 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -15,7 +15,14 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
-#define kBufferReadSz 2048
+#ifdef __x86_64__
+#include <HALKit/AMD64/HalPageAlloc.hpp>
+#else
+#error Unknown CPU.
+#endif // ifdef __x86_64__
+
+#define kHeadersSz \
+ (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader))
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
@@ -26,36 +33,28 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
#ifndef __DEBUG__
- writer.WriteString(
- L"MahroussLogic (R) HCore Version 1.00 (Release Channel)\r\n");
+ writer.WriteString(L"HCoreLdr: Version 1.00 (Release Channel)\r\n");
#else
- writer.WriteString(
- L"MahroussLogic (R) HCore Version 1.00 (Insiders Channel)\r\n");
+ writer.WriteString(L"HCoreLdr: Version 1.00 (Insiders Channel)\r\n");
#endif
const char strDate[] = __DATE__;
- writer.WriteString(L"Build Date: ");
+ writer.WriteString(L"HCoreLdr: Build date: ");
- for (auto& ch : strDate) {
- writer.WriteCharacter(ch);
- }
+ for (auto& ch : strDate) writer.WriteCharacter(ch);
writer.WriteString(L"\r\nHCoreLdr: Firmware Vendor: ")
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
- writer.WriteString(L"HCoreLdr: Reading: ")
- .WriteString(L"HCOREKRNL.EXE")
- .WriteString(L"\r\n");
-
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
- img.Size() = kBufferReadSz;
- img.Read();
+ img.Size(kHeadersSz);
+ img.ReadAll();
if (img.Error() == BFileReader::kOperationOkay) {
BlobType blob = (BlobType)img.Blob();
@@ -66,11 +65,72 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
if (ptrHdr && ptrHdr->mMachine == EFI::Platform() &&
ptrHdr->mMagic == kPeMagic) {
if (ptrHdr->mNumberOfSections > 1) {
- UInt64 MapKey = 0;
+ ExecOptionalHeaderPtr optHdr = reinterpret_cast<ExecOptionalHeaderPtr>(
+ ptrHdr + sizeof(ExecHeader));
+
+ UInt32 MapKey = 0;
+ UInt32* Size;
+ EfiMemoryDescriptor* Descriptor;
+ UInt32 SzDesc = 0;
+ UInt32 RevDesc = 0;
+
+ if (BS->AllocatePool(EfiLoaderData, sizeof(UInt64), (VoidPtr*)&Size) !=
+ kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-BadAlloc",
+ L"The bootloader ran out of memory! Please check your specs.");
+ }
+
+ *Size = sizeof(EfiMemoryDescriptor);
+
+ if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
+ (VoidPtr*)&Descriptor) != kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-BadAlloc",
+ L"The bootloader ran out of memory! Please check your specs.");
+ }
+
+ if (BS->GetMemoryMap(Size, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
+ kEfiOk) {
+ EFI::RaiseHardError(
+ L"HCoreLdr-GetMemoryMap",
+ L"GetMemoryMap returned a value which isn't kEfiOk!");
+ }
+
+ HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
+
+ BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
+ (VoidPtr*)&handoverHdrPtr);
+
+ handoverHdrPtr->f_GOP = (voidPtr)kGop->Mode->FrameBufferBase;
+ handoverHdrPtr->f_GOPSize = kGop->Mode->FrameBufferSize;
+
+ handoverHdrPtr->f_PhysicalStart =
+ reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
+ handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages * kPTESize;
+
+ handoverHdrPtr->f_VirtualStart =
+ reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
+
+ handoverHdrPtr->f_VirtualSize =
+ Descriptor->NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareVendorLen =
+ BStrLen(SystemTable->FirmwareVendor);
+
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName,
+ SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
+
+ writer.WriteString(L"HCoreLdr: Leaving it to kernel...\r\n");
EFI::ExitBootServices(MapKey, ImageHandle);
- // Launch PE app.
+ HCore::HEL::HandoverProc proc =
+ reinterpret_cast<HCore::HEL::HandoverProc>(
+ optHdr->mAddressOfEntryPoint);
+
+ proc(handoverHdrPtr);
EFI::Stop();
@@ -78,9 +138,11 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
} else {
writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0001\r\n");
}
+ } else {
+ writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0002\r\n");
}
} else {
- writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0002\r\n");
+ writer.WriteString(L"HCoreLdr: Error-Code: HLDR-0003\r\n");
}
EFI::Stop();
diff --git a/Private/NewKit/Json.hpp b/Private/NewKit/Json.hpp
index 1c404397..3b201ecc 100644
--- a/Private/NewKit/Json.hpp
+++ b/Private/NewKit/Json.hpp
@@ -44,7 +44,7 @@ class JsonType final {
struct JsonStreamTraits final {
JsonType In(const char *full_array) {
- SizeT len = string_length(full_array);
+ SizeT len = rt_string_len(full_array);
if (full_array[0] == '\"' && full_array[len - 1] == ',' ||
full_array[len - 1] == '\"') {
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 739447b0..ecd2d678 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -89,3 +89,7 @@
#define EXTERN extern
#define STATIC static
+
+#ifndef self
+#define self this
+#endif
diff --git a/Private/NewKit/Utils.hpp b/Private/NewKit/Utils.hpp
index c02e071f..dc3b1434 100644
--- a/Private/NewKit/Utils.hpp
+++ b/Private/NewKit/Utils.hpp
@@ -12,21 +12,20 @@
#include <NewKit/Defines.hpp>
-namespace HCore
-{
- Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len);
- Int rt_move_memory(const voidPtr src, voidPtr dst, Size len);
- voidPtr rt_set_memory(voidPtr dst, Char val, Size len);
- void rt_zero_memory(voidPtr pointer, Size len);
- Int string_compare(const Char *src, const Char *cmp, Size len);
- const Char *alloc_string(const Char *text);
- Size string_length(const Char *str);
- Size string_length(const Char *str, SizeT _len);
- Boolean rt_to_string(Char *buf, Int limit, Int base);
- Boolean is_newln(Char chr);
- Boolean is_space(Char chr);
- Int rt_to_uppercase(Int c);
- Int rt_to_lower(Int c);
- voidPtr rt_string_in_string(const char* in, const char* needle);
- char* rt_string_from_char(char* str, const char chr);
-} // namespace HCore
+namespace HCore {
+Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len);
+Int rt_move_memory(const voidPtr src, voidPtr dst, Size len);
+voidPtr rt_set_memory(voidPtr dst, Char val, Size len);
+void rt_zero_memory(voidPtr pointer, Size len);
+Int rt_string_cmp(const Char *src, const Char *cmp, Size len);
+const Char *alloc_string(const Char *text);
+Size rt_string_len(const Char *str);
+Size rt_string_len(const Char *str, SizeT _len);
+Boolean rt_to_string(Char *buf, Int limit, Int base);
+Boolean is_newln(Char chr);
+Boolean is_space(Char chr);
+Int rt_to_uppercase(Int c);
+Int rt_to_lower(Int c);
+voidPtr rt_string_in_string(const char *in, const char *needle);
+char *rt_string_from_char(char *str, const char chr);
+} // namespace HCore
diff --git a/Private/Source/Network/IP.cpp b/Private/Source/Network/IP.cpp
index 38cd6008..b1b45521 100644
--- a/Private/Source/Network/IP.cpp
+++ b/Private/Source/Network/IP.cpp
@@ -82,7 +82,7 @@ ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) {
bool IPFactory::IpCheckVersion4(const char* ip) {
int cnter = 0;
- for (Size base = 0; base < string_length(ip); ++base) {
+ for (Size base = 0; base < rt_string_len(ip); ++base) {
if (ip[base] == '.') {
cnter = 0;
} else {
diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx
index c6bec404..60a3ea8f 100644
--- a/Private/Source/PEFSharedObjectRT.cxx
+++ b/Private/Source/PEFSharedObjectRT.cxx
@@ -20,6 +20,7 @@
01/02/24: Rework shared library ABI, except a __LibInit and __LibFini
(amlel)
+ 15/02/24: Breaking changes, changed the name of the routines. (amlel)
------------------------------------------- */
@@ -31,14 +32,13 @@ using namespace HCore;
/***********************************************************************************/
/***********************************************************************************/
-/* @brief Allocates a new library. */
+/* @brief Library runtime initializer. */
/***********************************************************************************/
-extern "C" SharedObject *__LibInit() {
- SharedObject *library = hcore_tls_new_class<SharedObject>();
+extern "C" SharedObjectPtr ke_library_init(void) {
+ SharedObjectPtr library = hcore_tls_new_class<SharedObject>();
if (!library) {
- kcout << "__LibInit: Out of Memory!\n";
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
return nullptr;
@@ -47,7 +47,6 @@ extern "C" SharedObject *__LibInit() {
library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());
if (!library->Get()) {
- kcout << "__LibInit: Out of Memory!\n";
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
return nullptr;
@@ -57,34 +56,28 @@ extern "C" SharedObject *__LibInit() {
ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
if (!library->Get()->fImageObject) {
- kcout << "__LibInit: Invalid image!\n";
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
return nullptr;
}
library->Get()->fImageEntrypointOffset =
- library->Load<VoidPtr>(kPefStart, string_length(kPefStart, 0), kPefCode);
-
- kcout << "__LibInit: Task is successful!\n";
+ library->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode);
return library;
}
/***********************************************************************************/
-
-/***********************************************************************************/
-/* @brief Frees the library. */
+/* @brief Ends the library. */
/* @note Please check if the lib got freed! */
/* @param SharedObjectPtr the library to free. */
/***********************************************************************************/
-extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) {
+extern "C" Void ke_library_free(SharedObjectPtr lib, bool *successful) {
MUST_PASS(successful);
// sanity check (will also trigger a bug check)
if (lib == nullptr) {
- kcout << "__LibFini: Invalid image!\n";
*successful = false;
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}
@@ -94,8 +87,6 @@ extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) {
lib = nullptr;
- kcout << "__LibFini: Task is successful!\n";
-
*successful = true;
}
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index 82b07c42..ccf037ae 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -18,6 +18,8 @@
#include <NewKit/KernelHeap.hpp>
#include <NewKit/String.hpp>
+#include "NewKit/RuntimeCheck.hpp"
+
///! bugs = 0
/***********************************************************************************/
@@ -54,10 +56,9 @@ void Process::Wake(const bool should_wakeup) {
VoidPtr Process::New(const SizeT &sz) {
if (this->FreeMemory < 1) return nullptr;
- // RAM allocation
- if (this->PoolCursor) {
- VoidPtr ptr = this->PoolCursor;
- this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor + (sizeof(sz)));
+ if (this->HeapCursor) {
+ VoidPtr ptr = this->HeapCursor;
+ this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz)));
++this->UsedMemory;
--this->FreeMemory;
@@ -86,13 +87,13 @@ bool rt_in_pool_region(VoidPtr pool_ptr, VoidPtr pool, const SizeT &sz) {
/* @brief free pointer from usage. */
Boolean Process::Delete(VoidPtr ptr, const SizeT &sz) {
- if (sz < 1 || this->PoolCursor == this->Pool) return false;
+ if (sz < 1 || this->HeapCursor == this->HeapPtr) return false;
// also check for the amount of allocations we've done so far.
if (this->UsedMemory < 1) return false;
- if (rt_in_pool_region(ptr, this->PoolCursor, this->UsedMemory)) {
- this->PoolCursor = (VoidPtr)((UIntPtr)this->PoolCursor - (sizeof(sz)));
+ if (rt_in_pool_region(ptr, this->HeapCursor, this->UsedMemory)) {
+ this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor - (sizeof(sz)));
rt_zero_memory(ptr, sz);
++this->FreeMemory;
@@ -131,14 +132,13 @@ void Process::Exit(Int32 exit_code) {
kExitCode = exit_code;
- if (this->Ring != (Int32)ProcessSelector::kRingDriver &&
- this->Ring != (Int32)ProcessSelector::kRingKernel) {
- if (this->Pool) ke_free_heap(this->Pool);
+ if (this->Ring != (Int32)ProcessSelector::kRingDriver) {
+ if (this->HeapPtr) ke_free_heap(this->HeapPtr);
- this->Pool = nullptr;
- this->PoolCursor = nullptr;
+ this->HeapPtr = nullptr;
+ this->HeapCursor = nullptr;
- this->FreeMemory = kPoolMaxSz;
+ this->FreeMemory = 0UL; // TODO: fill available heap.
this->UsedMemory = 0UL;
}
@@ -155,11 +155,13 @@ void Process::Exit(Int32 exit_code) {
bool ProcessManager::Add(Ref<Process> &process) {
if (!process) return false;
+ if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return false;
+
kcout << "ProcessManager::Add(Ref<Process>& process)\r\n";
- process.Leak().Pool = ke_new_heap(kPoolUser | kPoolRw);
+ process.Leak().HeapPtr = ke_new_heap(kPoolUser | kPoolRw);
process.Leak().ProcessId = this->m_Headers.Count();
- process.Leak().PoolCursor = process.Leak().Pool;
+ process.Leak().HeapCursor = process.Leak().HeapPtr;
process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame *>(
ke_new_ke_heap(sizeof(HAL::StackFrame), true, false));
@@ -172,6 +174,17 @@ bool ProcessManager::Add(Ref<Process> &process) {
this->m_Headers.Add(process);
+ if (!imageStart && process.Leak().Kind == Process::ExecutableType) {
+ process.Leak().Crash();
+ }
+
+ if (!imageStart && process.Leak().Kind == Process::DriverType) {
+ if (process.Leak().Ring == 3)
+ process.Leak().Crash();
+ else
+ ke_stop(RUNTIME_CHECK_PROCESS);
+ }
+
return true;
}
diff --git a/Private/Source/String.cxx b/Private/Source/String.cxx
index 045545cd..0e1b7f41 100644
--- a/Private/Source/String.cxx
+++ b/Private/Source/String.cxx
@@ -15,7 +15,7 @@ Char *StringView::Data() { return m_Data; }
const Char *StringView::CData() { return m_Data; }
-Size StringView::Length() const { return string_length(m_Data); }
+Size StringView::Length() const { return rt_string_len(m_Data); }
bool StringView::operator==(const StringView &rhs) const {
if (rhs.Length() != this->Length()) return false;
@@ -28,9 +28,9 @@ bool StringView::operator==(const StringView &rhs) const {
}
bool StringView::operator==(const Char *rhs) const {
- if (string_length(rhs) != this->Length()) return false;
+ if (rt_string_len(rhs) != this->Length()) return false;
- for (Size index = 0; index < string_length(rhs); ++index) {
+ for (Size index = 0; index < rt_string_len(rhs); ++index) {
if (rhs[index] != m_Data[index]) return false;
}
@@ -48,9 +48,9 @@ bool StringView::operator!=(const StringView &rhs) const {
}
bool StringView::operator!=(const Char *rhs) const {
- if (string_length(rhs) != this->Length()) return false;
+ if (rt_string_len(rhs) != this->Length()) return false;
- for (Size index = 0; index < string_length(rhs); ++index) {
+ for (Size index = 0; index < rt_string_len(rhs); ++index) {
if (rhs[index] == m_Data[index]) return false;
}
@@ -60,7 +60,7 @@ bool StringView::operator!=(const Char *rhs) const {
ErrorOr<StringView> StringBuilder::Construct(const Char *data) {
if (!data || *data == 0) return {};
- StringView view(string_length(data));
+ StringView view(rt_string_len(data));
rt_copy_memory(reinterpret_cast<voidPtr>(const_cast<Char *>(data)),
reinterpret_cast<voidPtr>(view.Data()), view.Length());
@@ -71,7 +71,7 @@ ErrorOr<StringView> StringBuilder::Construct(const Char *data) {
const char *StringBuilder::FromInt(const char *fmt, int i) {
if (!fmt) return ("-1");
- char *ret = (char *)__alloca(sizeof(char) * 8 + string_length(fmt));
+ char *ret = (char *)__alloca(sizeof(char) * 8 + rt_string_len(fmt));
if (!ret) return ("-1");
@@ -81,8 +81,8 @@ const char *StringBuilder::FromInt(const char *fmt, int i) {
return ("-1");
}
- const auto fmt_len = string_length(fmt);
- const auto res_len = string_length(result);
+ const auto fmt_len = rt_string_len(fmt);
+ const auto res_len = rt_string_len(result);
for (Size idx = 0; idx < fmt_len; ++idx) {
if (fmt[idx] == '%') {
@@ -106,12 +106,12 @@ const char *StringBuilder::FromBool(const char *fmt, bool i) {
if (!fmt) return ("?");
const char *boolean_expr = i ? "true" : "false";
- char *ret = (char *)__alloca((sizeof(char) * i) ? 4 : 5 + string_length(fmt));
+ char *ret = (char *)__alloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt));
if (!ret) return ("?");
- const auto fmt_len = string_length(fmt);
- const auto res_len = string_length(boolean_expr);
+ const auto fmt_len = rt_string_len(fmt);
+ const auto res_len = rt_string_len(boolean_expr);
for (Size idx = 0; idx < fmt_len; ++idx) {
if (fmt[idx] == '%') {
@@ -132,9 +132,9 @@ const char *StringBuilder::FromBool(const char *fmt, bool i) {
}
bool StringBuilder::Equals(const char *lhs, const char *rhs) {
- if (string_length(rhs) != string_length(lhs)) return false;
+ if (rt_string_len(rhs) != rt_string_len(lhs)) return false;
- for (Size index = 0; index < string_length(rhs); ++index) {
+ for (Size index = 0; index < rt_string_len(rhs); ++index) {
if (rhs[index] != lhs[index]) return false;
}
@@ -145,14 +145,14 @@ const char *StringBuilder::Format(const char *fmt, const char *fmt2) {
if (!fmt || !fmt2) return ("?");
char *ret =
- (char *)alloca(sizeof(char) * string_length(fmt2) + string_length(fmt2));
+ (char *)alloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt2));
if (!ret) return ("?");
- for (Size idx = 0; idx < string_length(fmt); ++idx) {
+ for (Size idx = 0; idx < rt_string_len(fmt); ++idx) {
if (fmt[idx] == '%') {
Size result_cnt = idx;
- for (Size y_idx = 0; y_idx < string_length(fmt2); ++y_idx) {
+ for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx) {
ret[result_cnt] = fmt2[y_idx];
++result_cnt;
}
@@ -167,27 +167,27 @@ const char *StringBuilder::Format(const char *fmt, const char *fmt2) {
}
static void string_append(char *lhs, char *rhs, int cur) {
- if (lhs && rhs && cur < string_length(lhs)) {
- SizeT sz_rhs = string_length(rhs);
+ if (lhs && rhs && cur < rt_string_len(lhs)) {
+ SizeT sz_rhs = rt_string_len(rhs);
rt_copy_memory(rhs, lhs + cur, sz_rhs);
}
}
StringView &StringView::operator+=(const Char *rhs) {
- if (string_length(rhs) > string_length(this->m_Data)) return *this;
+ if (rt_string_len(rhs) > rt_string_len(this->m_Data)) return *this;
string_append(this->m_Data, const_cast<char *>(rhs), this->m_Cur);
- this->m_Cur += string_length(rhs);
+ this->m_Cur += rt_string_len(rhs);
return *this;
}
StringView &StringView::operator+=(const StringView &rhs) {
- if (string_length(rhs.m_Data) > string_length(this->m_Data)) return *this;
+ if (rt_string_len(rhs.m_Data) > rt_string_len(this->m_Data)) return *this;
string_append(this->m_Data, const_cast<char *>(rhs.m_Data), this->m_Cur);
- this->m_Cur += string_length(const_cast<char *>(rhs.m_Data));
+ this->m_Cur += rt_string_len(const_cast<char *>(rhs.m_Data));
return *this;
}
diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx
index ab289a66..e471c0c1 100644
--- a/Private/Source/URL.cxx
+++ b/Private/Source/URL.cxx
@@ -32,19 +32,19 @@ constexpr const int kProtosCount = 8;
constexpr const int kRangeSz = 4096;
static ErrorOr<StringView> url_extract_location(const char *url) {
- if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
+ if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz)
return ErrorOr<StringView>{-1};
- StringView view(string_length(url));
+ StringView view(rt_string_len(url));
SizeT i = 0;
bool scheme_found = false;
- for (; i < string_length(url); ++i) {
+ for (; i < rt_string_len(url); ++i) {
if (!scheme_found) {
for (int y = 0; kProtosCount; ++y) {
if (rt_string_in_string(view.CData(), kURLProtocols[y])) {
- i += string_length(kURLProtocols[y]) + kUrlOutSz;
+ i += rt_string_len(kURLProtocols[y]) + kUrlOutSz;
scheme_found = true;
break;
@@ -59,7 +59,7 @@ static ErrorOr<StringView> url_extract_location(const char *url) {
}
static ErrorOr<StringView> url_extract_protocol(const char *url) {
- if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
+ if (!url || *url == 0 || rt_string_len(url, kRangeSz) > kRangeSz)
return ErrorOr<StringView>{-1};
ErrorOr<StringView> view{-1};
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
index 5b086111..d3d60f6b 100644
--- a/Private/Source/UserHeap.cxx
+++ b/Private/Source/UserHeap.cxx
@@ -46,7 +46,7 @@ Boolean HeapManager::s_PoolsAreEnabled = true;
Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool;
STATIC VoidPtr ke_find_unused_heap(Int flags);
-STATIC void ke_free_heap_internal(VoidPtr vaddr);
+STATIC Void ke_free_heap_internal(VoidPtr vaddr);
STATIC VoidPtr ke_make_heap(VoidPtr vaddr, Int flags);
STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr);
@@ -75,7 +75,7 @@ STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) {
HeapHeader* poolHdr = reinterpret_cast<HeapHeader*>(virtualAddress);
if (!poolHdr->Free) {
- kcout << "[ke_make_heap] poolHdr->Free, Pool already exists\n";
+ kcout << "[ke_make_heap] poolHdr->Free, HeapPtr already exists\n";
return nullptr;
}
@@ -92,7 +92,7 @@ STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) {
return nullptr;
}
-STATIC void ke_free_heap_internal(VoidPtr virtualAddress) {
+STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) {
HeapHeader* poolHdr = reinterpret_cast<HeapHeader*>(
reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader));
@@ -115,7 +115,7 @@ STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr) {
if (HeapManager::The()[index]) {
// ErrorOr<>::operator Boolean
/// if (address matches)
- /// -> Free Pool.
+ /// -> Free heap.
if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() ==
(UIntPtr)ptr) {
HeapManager::Leak().Leak().FreePage(
diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx
index 6072ccd3..01975192 100644
--- a/Private/Source/Utils.cxx
+++ b/Private/Source/Utils.cxx
@@ -10,7 +10,7 @@
#include <NewKit/Utils.hpp>
namespace HCore {
-Int string_compare(const Char *src, const Char *cmp, Size size) {
+Int rt_string_cmp(const Char *src, const Char *cmp, Size size) {
Int32 counter = 0;
for (Size index = 0; index < size; ++index) {
@@ -24,7 +24,7 @@ void rt_zero_memory(voidPtr pointer, Size len) {
rt_set_memory(pointer, 0, len);
}
-Size string_length(const Char *str, SizeT _len) {
+Size rt_string_len(const Char *str, SizeT _len) {
if (*str == '\0') return 0;
Size len{0};
@@ -39,7 +39,7 @@ Size string_length(const Char *str, SizeT _len) {
return len;
}
-Size string_length(const Char *str) {
+Size rt_string_len(const Char *str) {
if (*str == '\0') return 0;
Size len{0};
@@ -98,12 +98,12 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) {
const Char *alloc_string(const Char *text) {
if (!text) return nullptr;
- const Char *string = new Char[string_length(text)];
+ const Char *string = new Char[rt_string_len(text)];
if (!string) return nullptr;
voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char *>(text));
voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char *>(string));
- rt_copy_memory(vText, vStr, string_length(text));
+ rt_copy_memory(vText, vStr, rt_string_len(text));
return string;
}
@@ -144,8 +144,8 @@ Boolean is_space(Char chr) { return chr == ' '; }
Boolean is_newln(Char chr) { return chr == '\n'; }
voidPtr rt_string_in_string(const char *in, const char *needle) {
- for (size_t i = 0; i < string_length(in); ++i) {
- if (string_compare(in + i, needle, string_length(needle)) == 0)
+ for (size_t i = 0; i < rt_string_len(in); ++i) {
+ if (rt_string_cmp(in + i, needle, rt_string_len(needle)) == 0)
return reinterpret_cast<voidPtr>(const_cast<char *>(in + i));
}
diff --git a/Private/Source/compile_flags.txt b/Private/Source/compile_flags.txt
index 1b0ad789..b2809811 100644
--- a/Private/Source/compile_flags.txt
+++ b/Private/Source/compile_flags.txt
@@ -3,3 +3,4 @@
-std=c++20
-I../
-I$(HOME)/
+-D__USE_NEWFS__
diff --git a/Private/makefile b/Private/makefile
index 8ea6e7f3..1296117b 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -8,7 +8,7 @@ LD = x86_64-w64-mingw32-ld
CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__USE_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./ -I$(HOME)/
ASM = nasm
ASMFLAGS = -f win64
-LDFLAGS = -e Main -shared --subsystem=10
+LDFLAGS = -e Main -shared --subsystem=17
LDOBJ = $(wildcard Obj/*.obj)
# This file is the kernel, responsible of task management, memory, drivers and more.
diff --git a/ReadMe.md b/ReadMe.md
index 3549c26e..201e6406 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -17,7 +17,7 @@ git clone git@github.com:Mahrouss-Logic/h-core.git
And execute:
```
-make all
+make h-core-<cpu>-<hardware>
```
You'd also need The SDK and MinGW, to build and link the components. For Tools look at `Public/Tools`