diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-15 11:09:38 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-15 11:09:38 +0100 |
| commit | f323b1049bb581403d903f95224c0476b1812d43 (patch) | |
| tree | c757c75cc476b79a57d39be8b5f20045dc720031 | |
| parent | c6592da1f0461ee7b60fcc5a7f9e852273171b6d (diff) | |
HCR-18
Kernel:
- Add back RuntimeMain jump.
- Update DLL/SO runtime for PEF.
NewBoot:
- Figured out how to load this PE in a reusable way.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
| -rw-r--r-- | Private/HALKit/AMD64/HalStartSequence.asm | 4 | ||||
| -rw-r--r-- | Private/NewBoot/Source/RuntimeMain.cxx | 35 | ||||
| -rw-r--r-- | Private/Source/PEFSharedObjectRT.cxx | 21 |
3 files changed, 21 insertions, 39 deletions
diff --git a/Private/HALKit/AMD64/HalStartSequence.asm b/Private/HALKit/AMD64/HalStartSequence.asm index 1db3b218..c8e0a4e2 100644 --- a/Private/HALKit/AMD64/HalStartSequence.asm +++ b/Private/HALKit/AMD64/HalStartSequence.asm @@ -31,6 +31,10 @@ section .text ;; Just a simple setup, we'd also need to tell some before Main: + push rcx + jmp RuntimeMain + pop rcx +L0: cli hlt jmp $ diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx index 8d649459..4388d8f5 100644 --- a/Private/NewBoot/Source/RuntimeMain.cxx +++ b/Private/NewBoot/Source/RuntimeMain.cxx @@ -7,7 +7,6 @@ * ======================================================== */ -#include "EFIKit/EFI.hxx" #define __BOOTLOADER__ 1 #include <BootKit/BootKit.hxx> @@ -17,16 +16,13 @@ #include <NewKit/Ref.hpp> #ifdef __x86_64__ - #include <HALKit/AMD64/HalPageAlloc.hpp> - #else - #error Unknown CPU. +#endif // ifdef __x86_64__ -#endif - -#define kBufferReadSz 4096 +#define kBufferReadSz \ + (sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader)) EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { @@ -49,9 +45,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, 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) @@ -81,22 +75,13 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, ExecSectionHeaderPtr headers = (ExecSectionHeaderPtr)(&ptrHdr->mCharacteristics + 1); - for (int i = 0u; i < ptrHdr->mNumberOfSections; ++i) { - auto& hdr = headers[i]; + EfiPhysicalAddress base = optHdr->mImageBase + optHdr->mBaseOfData; + BS->AllocatePages(AllocateAddress, EfiLoaderCode, 1, &base); - if (hdr.mName[0] != '.') continue; + UInt64 codeSz = optHdr->mSizeOfCode; + img.File()->Read(img.File(), &codeSz, (VoidPtr)&base); - UInt64 addr = hdr.mVirtualAddress; - - BS->AllocatePages(AllocateAnyPages, EfiLoaderCode, 1, &addr); - - UInt64 pos = (optHdr->mImageBase + optHdr->mBaseOfData) + - hdr.mPointerToRawData; - - img.File()->SetPosition(img.File(), &pos); - img.Size(hdr.mSizeOfRawData); - img.File()->Read(img.File(), &img.Size(), (VoidPtr)addr); - } + // TODO ExecReader class UInt32 MapKey = 0; UInt32* Size = 0; @@ -152,6 +137,8 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, handoverHdrPtr->f_HeapCommitSize = optHdr->mSizeOfHeapCommit; handoverHdrPtr->f_StackCommitSize = optHdr->mSizeOfStackCommit; + writer.WriteString(L"HCoreLdr: Exit...\r\n"); + EFI::ExitBootServices(MapKey, ImageHandle); HCore::HEL::HandoverProc proc = diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx index aceca259..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,7 +56,6 @@ 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; @@ -66,25 +64,20 @@ extern "C" SharedObject *__LibInit() { library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - kcout << "__LibInit: Task is successful!\n"; - 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; } |
