diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 17:07:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-04 17:07:33 +0100 |
| commit | 9fe3b6e1e2447a11644307e83df2b109b24fe0d1 (patch) | |
| tree | d6eafa0dee897572554d4519b1a9cd878591254c /Private | |
| parent | a3d92ea68a74ef3cc3d3c9a34540754869e4d014 (diff) | |
HCR-11: Support for EFI GOP and SFP.
- SFP stands for Simple Filesystem Protocol, it's always reading through
the ESP.
- Add GOP for UI code.
- Did also patch kernel Virtual Memory code.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/EFIKit/Api.hxx | 7 | ||||
| -rw-r--r-- | Private/EFIKit/EFI.hxx | 11 | ||||
| -rw-r--r-- | Private/EFIKit/Handover.hxx | 4 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.cpp | 4 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.hpp | 14 | ||||
| -rw-r--r-- | Private/HALKit/PowerPC/HalHardware.cxx | 2 | ||||
| -rw-r--r-- | Private/KernelKit/DebugOutput.hpp | 6 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 31 | ||||
| -rw-r--r-- | Private/NewBoot/Source/Entrypoint.cxx | 36 | ||||
| -rw-r--r-- | Private/NewBoot/Source/FileReader.cxx | 71 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx | 10 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm | 8 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 3 | ||||
| -rw-r--r-- | Private/Source/NewFS.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/RuntimeMain.cxx | 8 |
15 files changed, 103 insertions, 114 deletions
diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx index 0d4b14cb..a96eb603 100644 --- a/Private/EFIKit/Api.hxx +++ b/Private/EFIKit/Api.hxx @@ -19,12 +19,7 @@ namespace EFI { /** @brief Stop Execution of program. */ -inline Void Stop() noexcept { - while (true) { - rt_cli(); - rt_halt(); - } -} +Void Stop() noexcept; /** @brief Exit EFI API to let the OS load correctly. diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index f0c87a62..7b034f7c 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -518,7 +518,7 @@ typedef struct EfiSimpleTextOutputProtocol { VoidPtr Mode; } EfiSimpleTextOutputProtocol; -typedef UInt64 EfiStatusType; +typedef UInt32 EfiStatusType; typedef UInt64(EFI_API *EfiOpenVolume)(struct EfiSimpleFilesystemProtocol *, struct EfiFileProtocol **); @@ -603,10 +603,11 @@ enum { struct EfiFileProtocol final { UInt64 Revision; - EfiStatusType (*Open)(struct EfiFileProtocol *, struct EfiFileProtocol **, - EfiCharType *, UInt64, UInt64); + EfiStatusType (*Open)(struct EfiFileProtocol *This, + struct EfiFileProtocol **Out, EfiCharType *CharType, + UInt64 OpenMode, UInt64 Attrib); - EfiStatusType (*Close)(struct EfiFileProtocol *); + EfiStatusType (*Close)(struct EfiFileProtocol *This); EfiStatusType (*Delete)(struct EfiFileProtocol *This); @@ -659,7 +660,7 @@ struct EfiFileInfo final { EfiTime EditTime; UInt64 Attribute; // Do not touch that, it's EFI specific. - WideChar FileName[255]; + WideChar FileName[1]; }; #define EFI_FILE_PROTOCOL_REVISION 0x00010000 diff --git a/Private/EFIKit/Handover.hxx b/Private/EFIKit/Handover.hxx index 07a3bc51..a8248296 100644 --- a/Private/EFIKit/Handover.hxx +++ b/Private/EFIKit/Handover.hxx @@ -24,9 +24,9 @@ /* useful macros */ -#define kHandoverMagic 0xBAD55 +#define kHandoverMagic 0xBADCC -#define kBaseHandoverStruct 0x80000000 +#define kHandoverStartKernel 0xFFFF800000000000 #define kHandoverStructSz sizeof(HEL::HandoverHeader) namespace HCore::HEL { diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 6d6e4ba5..d94d994d 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -54,8 +54,8 @@ auto hal_create_page(Boolean rw, Boolean user) -> UIntPtr { return reinterpret_cast<UIntPtr>(new_pte); } -UIntPtr& hal_get_page_ptr() noexcept { return kPagePtr; } +UIntPtr& hal_page_base() noexcept { return kPagePtr; } -void hal_set_page_ptr(const UIntPtr& newPagePtr) noexcept { kPagePtr = newPagePtr; } +void hal_page_base(const UIntPtr& newPagePtr) noexcept { kPagePtr = newPagePtr; } } // namespace HAL } // namespace HCore diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index 711dc27d..367cc26e 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -12,11 +12,11 @@ #include <NewKit/Defines.hpp> #ifndef PTE_MAX -#define PTE_MAX (512) +#define PTE_MAX (0x200) #endif //! PTE_MAX #ifndef PTE_ALIGN -#define PTE_ALIGN (4096) +#define PTE_ALIGN (0x1000) #endif //! PTE_ALIGN extern "C" void flush_tlb(HCore::UIntPtr VirtualAddr); @@ -41,8 +41,12 @@ struct PageTable64 { bool ExecDisable : 1; }; -PageTable64 *hal_alloc_page(SizeT sz, Boolean rw, Boolean user); -UIntPtr& hal_get_page_ptr() noexcept; -void hal_set_page_ptr(const UIntPtr& newPagePtr) noexcept; +struct PageDirectory64 final { + PageTable64 ALIGN(PTE_ALIGN) Pte[PTE_MAX]; +}; + +PageTable64* hal_alloc_page(SizeT sz, Boolean rw, Boolean user); +UIntPtr& hal_page_base() noexcept; +void hal_page_base(const UIntPtr& newPagePtr) noexcept; UIntPtr hal_create_page(Boolean rw, Boolean user); } // namespace HCore::HAL diff --git a/Private/HALKit/PowerPC/HalHardware.cxx b/Private/HALKit/PowerPC/HalHardware.cxx index 550d3747..89b1a6ae 100644 --- a/Private/HALKit/PowerPC/HalHardware.cxx +++ b/Private/HALKit/PowerPC/HalHardware.cxx @@ -33,7 +33,7 @@ void rt_hang_thread(HAL::StackFrame* stack) {} // @brief main HAL entrypoint void ke_init_hal() {} -void ke_com_print(const char* bytes) { +void ke_com_print(const Char* bytes) { if (!bytes) return; SizeT index = 0; diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index 875884ba..dd34df8e 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -15,10 +15,10 @@ namespace HCore { // @brief Emulates a VT100 terminal. -class TerminalDevice final : public DeviceInterface<const char *> { +class TerminalDevice final : public DeviceInterface<const Char *> { public: - TerminalDevice(void (*print)(const char *), void (*get)(const char *)) - : DeviceInterface<const char *>(print, get) {} + TerminalDevice(void (*print)(const Char *), void (*get)(const Char *)) + : DeviceInterface<const Char *>(print, get) {} virtual ~TerminalDevice() {} diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 05780c53..61ad81f2 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); ~BFileReader(); - HCore::VoidPtr Fetch(EfiHandlePtr ImageHandle, SizeT &Sz); + Void Fetch(EfiHandlePtr ImageHandle); enum { kOperationOkay, @@ -76,6 +76,7 @@ class BFileReader final { }; Int32 &Error() { return mErrorCode; } + VoidPtr Blob() { return mBlob; } public: BFileReader &operator=(const BFileReader &) = default; @@ -86,7 +87,6 @@ class BFileReader final { VoidPtr mBlob{nullptr}; CharacterType mPath[kPathLen]; BTextWriter mWriter; - BDeviceATA mDevice; bool mCached{false}; }; @@ -136,6 +136,10 @@ inline UInt32 In32(UInt16 port) { return value; } +extern "C" VoidPtr __cr3(); + +#endif // __EFI_x86_64__ + /***********************************************************************************/ /// Framebuffer. /***********************************************************************************/ @@ -148,4 +152,25 @@ const UInt32 kRgbBlue = 0x00FF0000; const UInt32 kRgbBlack = 0x00000000; const UInt32 kRgbWhite = 0x00FFFFFF; -#endif // __EFI_x86_64__ +/** QT GOP. */ +inline EfiGraphicsOutputProtocol *kGop; + +/** +@brief Init the QuickTemplate GUI framework. +*/ +inline Void InitQT() noexcept { + EfiGUID gopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); + kGop = nullptr; + + extern EfiBootServices *BS; + + BS->LocateProtocol(&gopGuid, nullptr, (VoidPtr *)&kGop); + + for (int w = 0; w < kGop->Mode->Info->VerticalResolution; ++w) { + for (int h = 0; h < kGop->Mode->Info->HorizontalResolution; ++h) { + *((UInt32 *)(kGop->Mode->FrameBufferBase + + 4 * kGop->Mode->Info->PixelsPerScanLine * w + 4 * h)) = + RGB(10, 10, 10); + } + } +} diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx index 7026da4d..bdcfab4d 100644 --- a/Private/NewBoot/Source/Entrypoint.cxx +++ b/Private/NewBoot/Source/Entrypoint.cxx @@ -1,10 +1,10 @@ /* - * ======================================================== + * ======================================================== * * NewBoot * Copyright Mahrouss Logic, all rights reserved. * - * ======================================================== + * ======================================================== */ #define __BOOTLOADER__ 1 @@ -14,25 +14,10 @@ #include <KernelKit/PE.hpp> #include <NewKit/Ref.hpp> -STATIC Void InitGfx() noexcept { - EfiGUID gopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID); - EfiGraphicsOutputProtocol* gop = nullptr; - - BS->LocateProtocol(&gopGuid, nullptr, (void**)&gop); - - for (int w = 0; w < gop->Mode->Info->VerticalResolution; ++w) { - for (int h = 0; h < gop->Mode->Info->HorizontalResolution; ++h) { - *((UInt32*)(gop->Mode->FrameBufferBase + - 4 * gop->Mode->Info->PixelsPerScanLine * w + 4 * h)) = - RGB(10, 10, 10); - } - } -} - EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { InitEFI(SystemTable); - InitGfx(); + InitQT(); BTextWriter writer; @@ -44,21 +29,14 @@ EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle, .WriteString(SystemTable->FirmwareVendor) .WriteString(L"\r\n"); - UInt64 mapKey = 0; - BFileReader img(L"\\EFI\\BOOT\\HCOREKRNL.EXE"); + img.Fetch(ImageHandle); - SizeT imageSz = 0; - - PEImagePtr blob = (PEImagePtr)img.Fetch(ImageHandle, imageSz); - - if (!blob) - EFI::RaiseHardError(L"HCoreLdr_NoSuchKernel", - L"Couldn't find HCoreKrnl.exe!"); + VoidPtr blob = img.Blob(); - writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n"); + UInt64 MapKey = 0; - EFI::ExitBootServices(mapKey, ImageHandle); + EFI::ExitBootServices(MapKey, ImageHandle); EFI::Stop(); return kEfiOk; diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx index 8602114f..a66f2c71 100644 --- a/Private/NewBoot/Source/FileReader.cxx +++ b/Private/NewBoot/Source/FileReader.cxx @@ -14,9 +14,7 @@ #include <BootKit/BootKit.hxx> #include <EFIKit/Api.hxx> - -#include "EFIKit/EFI.hxx" -#include "NewKit/Defines.hpp" +#include <EFIKit/Handover.hxx> //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -50,7 +48,7 @@ BFileReader::~BFileReader() { @brief this reads all of the buffer. @param ImageHandle used internally. */ -HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) { +Void BFileReader::Fetch(EfiHandlePtr ImageHandle) { mWriter.WriteString(L"HCoreLdr: Fetch-File: ") .WriteString(mPath) .WriteString(L"\r\n"); @@ -75,7 +73,7 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol") .WriteString(L"\r\n"); this->mErrorCode = kNotSupported; - return nullptr; + return; } /// Start doing disk I/O @@ -84,7 +82,7 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Volume") .WriteString(L"\r\n"); this->mErrorCode = kNotSupported; - return nullptr; + return; } /// Open kernel. @@ -97,14 +95,14 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) { .WriteString(mPath) .WriteString(L"\r\n"); this->mErrorCode = kNotSupported; - return nullptr; + return; } if (kernelFile->Revision < EFI_FILE_PROTOCOL_REVISION2) { mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: Invalid-Revision: ") .WriteString(mPath) .WriteString(L"\r\n"); - return nullptr; + return; } /// File FAT info. @@ -120,64 +118,31 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) { .WriteString(mPath) .WriteString(L"\r\n"); this->mErrorCode = kNotSupported; - return nullptr; + return; } mWriter.WriteString(L"HCoreLdr: Fetch-Info: In-Progress...") .WriteString(L"\r\n"); - VoidPtr blob = nullptr; + VoidPtr blob = (VoidPtr)kHandoverStartKernel; mWriter.WriteString(L"HCoreLdr: Fetch-Info: OK...").WriteString(L"\r\n"); - UInt32* sz = nullptr; - - if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&sz) != - kEfiOk) { - mWriter - .WriteString( - L"HCoreLdr: Fetch: Failed to call AllocatePool " - L"correctly!") - .WriteString(L"\r\n"); - - kernelFile->Close(kernelFile); - - return nullptr; - } - - *sz = info.FileSize; - imageSz = *sz; + UInt32 sz = info.FileSize; - if (BS->AllocatePool(EfiLoaderData, *sz, (VoidPtr*)&blob) != kEfiOk) { - mWriter - .WriteString( - L"HCoreLdr: Fetch: Failed to call AllocatePool " - L"correctly!") - .WriteString(L"\r\n"); - - kernelFile->Close(kernelFile); - - return nullptr; - } + BSetMem((CharacterType*)blob, 0, sz); - BSetMem((CharacterType*)blob, 0, *sz); - - mWriter.WriteString(L"HCoreLdr: Fetch-File: In-Progress...") - .WriteString(info.FileName) - .WriteString(L"\r\n"); - - auto resultEfiRead = kernelFile->Read(kernelFile, sz, blob); + auto resultEfiRead = kernelFile->Read(kernelFile, &sz, blob); kernelFile->Close(kernelFile); - if (resultEfiRead == kEfiOk) - mWriter.WriteString(L"HCoreLdr: Fetch-File: OK").WriteString(L"\r\n"); - else - return nullptr; + if (resultEfiRead != kEfiOk) return; + + mCached = true; + mErrorCode = kOperationOkay; - this->mCached = true; - this->mErrorCode = kOperationOkay; + mBlob = blob; - this->mBlob = blob; + // We are done! - return blob; + mWriter.WriteString(L"HCoreLdr: Fetch: OK.").WriteString(L"\r\n"); } diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx index 20dd3125..5a4a2445 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx @@ -31,3 +31,13 @@ extern "C" void rt_std() { asm volatile("std"); } /// @brief Stack Checker, leave empty. extern "C" void ___chkstk_ms(void) {} + +namespace EFI { +Void Stop() noexcept { + while (true) { + rt_cli(); + rt_halt(); + } +} + +} // namespace EFI diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm b/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm new file mode 100644 index 00000000..46928cf7 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm @@ -0,0 +1,8 @@ +bits 64 +global __cr3 + +section .text + +__cr3: + mov rax, cr3 + ret diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 05d6a9ab..cf6bb579 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -17,6 +17,7 @@ invalid-recipe: .PHONY: bootloader-amd64 bootloader-amd64: $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx + $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm $(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCOREKRNL.EXE @@ -28,7 +29,7 @@ make-disk: .PHONY: run-efi-debug run-efi-debug: wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -d int + qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio .PHONY: clean clean: diff --git a/Private/Source/NewFS.cxx b/Private/Source/NewFS.cxx index 2cb4fae9..64c13e11 100644 --- a/Private/Source/NewFS.cxx +++ b/Private/Source/NewFS.cxx @@ -43,7 +43,9 @@ NodePtr NewFilesystemManager::CreateAlias(const char* path) { } const char* NewFilesystemHelper::Root() { return kFilesystemRoot; } + const char* NewFilesystemHelper::UpDir() { return kFilesystemUpDir; } + const char NewFilesystemHelper::Separator() { return kFilesystemSeparator; } } // namespace HCore diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx index e042fb82..e26ce13a 100644 --- a/Private/Source/RuntimeMain.cxx +++ b/Private/Source/RuntimeMain.cxx @@ -17,16 +17,16 @@ extern "C" void RuntimeMain( HCore::HEL::HandoverInformationHeader* HandoverHeader) { - HCore::ke_init_heap(); - HCore::ke_init_ke_heap(); - kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = HandoverHeader->f_VirtualStart; kKernelPhysicalSize = HandoverHeader->f_VirtualSize; kKernelPhysicalStart = HandoverHeader->f_VirtualStart; - HCore::HAL::hal_set_page_ptr((HCore::UIntPtr)kKernelVirtualStart); + HCore::HAL::hal_page_base((HCore::UIntPtr)kKernelVirtualStart); + + HCore::ke_init_ke_heap(); + HCore::ke_init_heap(); MUST_PASS(HCore::ke_init_hal()); |
