From c7b637d7b68d9b7e271e70a5a5cc0c4fcf9172de Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 12 Oct 2024 19:20:29 +0200 Subject: IMP: Porting stack to AARCH64. - Bootloader and kernel were made to be ported to mulitple platforms. - Some part of the stack have to be written specifically for the platform though. Signed-off-by: Amlal El Mahrouss --- dev/zba/src/BootFileReader.cxx | 203 +++++++++++++++++++++++++++++++ dev/zba/src/BootString.cxx | 92 ++++++++++++++ dev/zba/src/BootSupport.cxx | 80 ++++++++++++ dev/zba/src/BootTextWriter.cxx | 169 +++++++++++++++++++++++++ dev/zba/src/HEL/AMD64/BootFileReader.cxx | 203 ------------------------------- dev/zba/src/HEL/AMD64/BootMain.cxx | 50 ++++---- dev/zba/src/HEL/AMD64/BootPlatform.cxx | 3 +- dev/zba/src/HEL/AMD64/BootString.cxx | 92 -------------- dev/zba/src/HEL/AMD64/BootTextWriter.cxx | 169 ------------------------- dev/zba/src/HEL/AMD64/New+Delete.cxx | 62 ---------- dev/zba/src/HEL/AMD64/Support.cxx | 82 ------------- dev/zba/src/HEL/ARM64/BootMain.cxx | 20 +++ dev/zba/src/HEL/ARM64/BootPlatform.cxx | 40 ++++++ dev/zba/src/New+Delete.cxx | 60 +++++++++ dev/zba/src/Thread.cxx | 10 -- 15 files changed, 692 insertions(+), 643 deletions(-) create mode 100644 dev/zba/src/BootFileReader.cxx create mode 100644 dev/zba/src/BootString.cxx create mode 100644 dev/zba/src/BootSupport.cxx create mode 100644 dev/zba/src/BootTextWriter.cxx delete mode 100644 dev/zba/src/HEL/AMD64/BootFileReader.cxx delete mode 100644 dev/zba/src/HEL/AMD64/BootString.cxx delete mode 100644 dev/zba/src/HEL/AMD64/BootTextWriter.cxx delete mode 100644 dev/zba/src/HEL/AMD64/New+Delete.cxx delete mode 100644 dev/zba/src/HEL/AMD64/Support.cxx create mode 100644 dev/zba/src/HEL/ARM64/BootMain.cxx create mode 100644 dev/zba/src/HEL/ARM64/BootPlatform.cxx create mode 100644 dev/zba/src/New+Delete.cxx (limited to 'dev/zba/src') diff --git a/dev/zba/src/BootFileReader.cxx b/dev/zba/src/BootFileReader.cxx new file mode 100644 index 00000000..e81ba3fb --- /dev/null +++ b/dev/zba/src/BootFileReader.cxx @@ -0,0 +1,203 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: FileReader.cxx + Purpose: New Boot FileReader, + Read complete file and store it in a buffer. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include + +/// @file BootFileReader +/// @brief Bootloader File reader. +/// BUGS: 0 + +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// +/// +/// @name BFileReader class +/// @brief Reads the file as a blob. +/// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*** + @brief File Reader constructor. +*/ +Boot::BFileReader::BFileReader(const CharacterTypeUTF16* path, + EfiHandlePtr ImageHandle) +{ + if (path != nullptr) + { + SizeT index = 0UL; + for (; path[index] != L'\0'; ++index) + { + mPath[index] = path[index]; + } + + mPath[index] = 0; + } + + /// Load protocols with their GUIDs. + + EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID); + + EfiSimpleFilesystemProtocol* efp = nullptr; + + EfiLoadImageProtocol* img = nullptr; + EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); + + if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) + { + mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r"); + this->mErrorCode = kNotSupported; + } + + if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) + { + mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r"); + this->mErrorCode = kNotSupported; + return; + } + + /// Start doing disk I/O + + if (efp->OpenVolume(efp, &mRootFs) != kEfiOk) + { + mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Volume").Write(L"\r"); + this->mErrorCode = kNotSupported; + return; + } + + EfiFileProtocol* KernelFile = nullptr; + + if (mRootFs->Open(mRootFs, &KernelFile, mPath, kEFIFileRead, kEFIReadOnly) != + kEfiOk) + { + mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Path: ") + .Write(mPath) + .Write(L"\r"); + this->mErrorCode = kNotSupported; + + CGDrawString("NEWOSLDR: PLEASE RECOVER YOUR MINKRNL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + + mRootFs->Close(mRootFs); + + return; + } + + mSizeFile = 0; + mFile = KernelFile; + mErrorCode = kOperationOkay; +} + +Boot::BFileReader::~BFileReader() +{ + if (this->mFile) + { + this->mFile->Close(this->mFile); + this->mFile = nullptr; + } + + if (this->mRootFs) + { + this->mRootFs->Close(this->mRootFs); + this->mRootFs = nullptr; + } + + if (this->mBlob) + { + BS->FreePool(this->mBlob); + this->mBlob = nullptr; + } + + BSetMem(this->mPath, 0, kPathLen); +} + +/** + @brief Reads all of the file into a buffer. + @param **readUntil** size of file + @param **chunkToRead** chunk to read each time. +*/ +Void Boot::BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress) +{ + if (mBlob == nullptr) + { + EfiFileInfo newPtrInfo; + UInt32 szInfo = 0; + + EfiGUID cFileInfoGUID = EFI_FILE_INFO_GUID; + + if (mFile->GetInfo(mFile, &cFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk) + { + if (newPtrInfo.FileSize < readUntil) + readUntil = newPtrInfo.FileSize; + else if (readUntil < 1) + readUntil = newPtrInfo.FileSize; + + mWriter.Write(L"NEWOSLDR: Physical size: ").Write(readUntil).Write("\r"); + } + + if (!outAddress) + { + if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*)&mBlob) != + kEfiOk) + { + mWriter.Write(L"*** error: ").Write(err).Write(L" ***\r"); + EFI::ThrowError(L"OutOfMemory", L"Out of memory."); + } + } + else + { + mBlob = (VoidPtr)outAddress; + } + } + + mErrorCode = kNotSupported; + + UInt64 bufSize = chunkToRead; + UInt64 szCnt = 0UL; + + while (szCnt < readUntil) + { + auto res = mFile->Read(mFile, &bufSize, (VoidPtr)(&((Char*)mBlob)[szCnt])); + + szCnt += bufSize; + + if (res == kBufferTooSmall) + { + bufSize = chunkToRead; + } + } + + mSizeFile = szCnt; + mErrorCode = kOperationOkay; +} + +/// @brief error code getter. +/// @return the error code. +Int32& Boot::BFileReader::Error() +{ + return mErrorCode; +} + +/// @brief blob getter. +/// @return the blob. +VoidPtr Boot::BFileReader::Blob() +{ + return mBlob; +} + +/// @breif Size getter. +/// @return the size of the file. +UInt64& Boot::BFileReader::Size() +{ + return mSizeFile; +} diff --git a/dev/zba/src/BootString.cxx b/dev/zba/src/BootString.cxx new file mode 100644 index 00000000..1c109b80 --- /dev/null +++ b/dev/zba/src/BootString.cxx @@ -0,0 +1,92 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: String.cxx + Purpose: NewBoot string library + + Revision History: + + + +------------------------------------------- */ + +#include +#include +#include + +/// BUGS: 0 + +///////////////////////////////////////////////////////////////////////////////////////////////////////// + +Kernel::SizeT Boot::BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len) +{ + if (!dest || !src) + return 0; + + SizeT index = 0UL; + for (; index < len; ++index) + { + dest[index] = src[index]; + } + + return index; +} + +Kernel::SizeT Boot::BStrLen(const CharacterTypeUTF16* ptr) +{ + if (!ptr) + return 0; + + Kernel::SizeT cnt = 0; + + while (*ptr != (CharacterTypeUTF16)0) + { + ++ptr; + ++cnt; + } + + return cnt; +} + +Kernel::SizeT Boot::BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len) +{ + if (!src) + return 0; + + Kernel::SizeT cnt = 0UL; + + while (*src != 0) + { + if (cnt > len) + break; + + *src = byte; + ++src; + + ++cnt; + } + + return cnt; +} + +Kernel::SizeT Boot::BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len) +{ + if (!src) + return 0; + + Kernel::SizeT cnt = 0UL; + + while (*src != 0) + { + if (cnt > len) + break; + + *src = byte; + ++src; + + ++cnt; + } + + return cnt; +} diff --git a/dev/zba/src/BootSupport.cxx b/dev/zba/src/BootSupport.cxx new file mode 100644 index 00000000..bab53c2c --- /dev/null +++ b/dev/zba/src/BootSupport.cxx @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __STANDALONE__ + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. +EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = byte; + } + + return dst; +} + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len) +{ + for (size_t i = 0UL; i < len; ++i) + { + ((int*)dst)[i] = ((int*)src)[i]; + } + + return dst; +} + +/// @brief strlen definition in C++. +EXTERN_C size_t strlen(const char* whatToCheck) +{ + SizeT len = 0; + + while (whatToCheck[len] != 0) + { + ++len; + } + + return len; +} + +/// @brief strcmp definition in C++. +EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) +{ + if (!whatToCheck || *whatToCheck == 0) + return 0; + + SizeT len = 0; + + while (whatToCheck[len] == whatToCheckRight[len]) + { + if (whatToCheck[len] == 0) + return 0; + + ++len; + } + + return len; +} + +/// @brief something specific to the Microsoft's ABI, When the stack grows too big. +EXTERN_C void ___chkstk_ms(void) {} + +#endif diff --git a/dev/zba/src/BootTextWriter.cxx b/dev/zba/src/BootTextWriter.cxx new file mode 100644 index 00000000..b0679715 --- /dev/null +++ b/dev/zba/src/BootTextWriter.cxx @@ -0,0 +1,169 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: String.cxx + Purpose: NewBoot string library + + Revision History: + + + +------------------------------------------- */ + +#include +#include +#include +#include + +/// BUGS: 0 + +///////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** +@brief puts wrapper over EFI ConOut. +*/ +Boot::BTextWriter& Boot::BTextWriter::Write(const CharacterTypeUTF16* str) +{ +#ifdef __DEBUG__ + if (!str || *str == 0) + return *this; + + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) + { + if (str[i] == '\r') + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + else + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } +#endif // ifdef __DEBUG__ + + return *this; +} + +/// @brief UTF-8 equivalent of Write (UTF-16). +/// @param str the input string. +Boot::BTextWriter& Boot::BTextWriter::Write(const Char* str) +{ +#ifdef __DEBUG__ + if (!str || *str == 0) + return *this; + + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) + { + if (str[i] == '\r') + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + else + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } +#endif // ifdef __DEBUG__ + + return *this; +} + +Boot::BTextWriter& Boot::BTextWriter::Write(const UChar* str) +{ +#ifdef __DEBUG__ + if (!str || *str == 0) + return *this; + + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) + { + if (str[i] == '\r') + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + else + { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } +#endif // ifdef __DEBUG__ + + return *this; +} + +/** +@brief putc wrapper over EFI ConOut. +*/ +Boot::BTextWriter& Boot::BTextWriter::WriteCharacter(CharacterTypeUTF16 c) +{ +#ifdef __DEBUG__ + EfiCharType str[2]; + + str[0] = c; + str[1] = 0; + ST->ConOut->OutputString(ST->ConOut, str); +#endif // ifdef __DEBUG__ + + return *this; +} + +Boot::BTextWriter& Boot::BTextWriter::Write(const Long& x) +{ +#ifdef __DEBUG__ + this->_Write(x); + this->Write("h"); +#endif // ifdef __DEBUG__ + + return *this; +} + +Boot::BTextWriter& Boot::BTextWriter::_Write(const Long& x) +{ +#ifdef __DEBUG__ + UInt64 y = (x > 0 ? x : -x) / 16; + UInt64 h = (x > 0 ? x : -x) % 16; + + if (y) + this->_Write(y); + + /* fail if the hex number is not base-16 */ + if (h > 16) + { + this->WriteCharacter('?'); + return *this; + } + + if (y < 0) + y = -y; + + const char cNumbers[] = "0123456789ABCDEF"; + + this->WriteCharacter(cNumbers[h]); +#endif // ifdef __DEBUG__ + + return *this; +} diff --git a/dev/zba/src/HEL/AMD64/BootFileReader.cxx b/dev/zba/src/HEL/AMD64/BootFileReader.cxx deleted file mode 100644 index e81ba3fb..00000000 --- a/dev/zba/src/HEL/AMD64/BootFileReader.cxx +++ /dev/null @@ -1,203 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: FileReader.cxx - Purpose: New Boot FileReader, - Read complete file and store it in a buffer. - -------------------------------------------- */ - -#include -#include -#include -#include -#include -#include - -/// @file BootFileReader -/// @brief Bootloader File reader. -/// BUGS: 0 - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// -/// -/// @name BFileReader class -/// @brief Reads the file as a blob. -/// -/// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*** - @brief File Reader constructor. -*/ -Boot::BFileReader::BFileReader(const CharacterTypeUTF16* path, - EfiHandlePtr ImageHandle) -{ - if (path != nullptr) - { - SizeT index = 0UL; - for (; path[index] != L'\0'; ++index) - { - mPath[index] = path[index]; - } - - mPath[index] = 0; - } - - /// Load protocols with their GUIDs. - - EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID); - - EfiSimpleFilesystemProtocol* efp = nullptr; - - EfiLoadImageProtocol* img = nullptr; - EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); - - if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) - { - mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r"); - this->mErrorCode = kNotSupported; - } - - if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) - { - mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r"); - this->mErrorCode = kNotSupported; - return; - } - - /// Start doing disk I/O - - if (efp->OpenVolume(efp, &mRootFs) != kEfiOk) - { - mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Volume").Write(L"\r"); - this->mErrorCode = kNotSupported; - return; - } - - EfiFileProtocol* KernelFile = nullptr; - - if (mRootFs->Open(mRootFs, &KernelFile, mPath, kEFIFileRead, kEFIReadOnly) != - kEfiOk) - { - mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Path: ") - .Write(mPath) - .Write(L"\r"); - this->mErrorCode = kNotSupported; - - CGDrawString("NEWOSLDR: PLEASE RECOVER YOUR MINKRNL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); - - mRootFs->Close(mRootFs); - - return; - } - - mSizeFile = 0; - mFile = KernelFile; - mErrorCode = kOperationOkay; -} - -Boot::BFileReader::~BFileReader() -{ - if (this->mFile) - { - this->mFile->Close(this->mFile); - this->mFile = nullptr; - } - - if (this->mRootFs) - { - this->mRootFs->Close(this->mRootFs); - this->mRootFs = nullptr; - } - - if (this->mBlob) - { - BS->FreePool(this->mBlob); - this->mBlob = nullptr; - } - - BSetMem(this->mPath, 0, kPathLen); -} - -/** - @brief Reads all of the file into a buffer. - @param **readUntil** size of file - @param **chunkToRead** chunk to read each time. -*/ -Void Boot::BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress) -{ - if (mBlob == nullptr) - { - EfiFileInfo newPtrInfo; - UInt32 szInfo = 0; - - EfiGUID cFileInfoGUID = EFI_FILE_INFO_GUID; - - if (mFile->GetInfo(mFile, &cFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk) - { - if (newPtrInfo.FileSize < readUntil) - readUntil = newPtrInfo.FileSize; - else if (readUntil < 1) - readUntil = newPtrInfo.FileSize; - - mWriter.Write(L"NEWOSLDR: Physical size: ").Write(readUntil).Write("\r"); - } - - if (!outAddress) - { - if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*)&mBlob) != - kEfiOk) - { - mWriter.Write(L"*** error: ").Write(err).Write(L" ***\r"); - EFI::ThrowError(L"OutOfMemory", L"Out of memory."); - } - } - else - { - mBlob = (VoidPtr)outAddress; - } - } - - mErrorCode = kNotSupported; - - UInt64 bufSize = chunkToRead; - UInt64 szCnt = 0UL; - - while (szCnt < readUntil) - { - auto res = mFile->Read(mFile, &bufSize, (VoidPtr)(&((Char*)mBlob)[szCnt])); - - szCnt += bufSize; - - if (res == kBufferTooSmall) - { - bufSize = chunkToRead; - } - } - - mSizeFile = szCnt; - mErrorCode = kOperationOkay; -} - -/// @brief error code getter. -/// @return the error code. -Int32& Boot::BFileReader::Error() -{ - return mErrorCode; -} - -/// @brief blob getter. -/// @return the blob. -VoidPtr Boot::BFileReader::Blob() -{ - return mBlob; -} - -/// @breif Size getter. -/// @return the size of the file. -UInt64& Boot::BFileReader::Size() -{ - return mSizeFile; -} diff --git a/dev/zba/src/HEL/AMD64/BootMain.cxx b/dev/zba/src/HEL/AMD64/BootMain.cxx index 8f8c45d1..3c5e80a3 100644 --- a/dev/zba/src/HEL/AMD64/BootMain.cxx +++ b/dev/zba/src/HEL/AMD64/BootMain.cxx @@ -5,11 +5,9 @@ ------------------------------------------- */ #include -#include #include #include #include -#include #include #include #include @@ -17,7 +15,6 @@ #include #include #include -#include // make the compiler shut up. #ifndef kMachineModel @@ -71,14 +68,6 @@ STATIC Void InitVideoFB() noexcept } } -/// @brief check the BootDevice if suitable. -STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) -{ - if (ataDev.Leak().mErr) - return false; - return true; -} - EXTERN_C VoidPtr boot_read_cr3(); EXTERN_C Void boot_write_cr3(VoidPtr new_cr3); @@ -88,21 +77,23 @@ EXTERN EfiBootServices* BS; /// @param ImageHandle Handle of this image. /// @param SystemTable The system table of it. /// @return nothing, never returns. -EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, +EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { InitEFI(SystemTable); ///! Init the EFI library. - InitVideoFB(); ///! Init the GOP. - - UInt32 MapKey = 0; - UInt32 SizePtr = sizeof(EfiMemoryDescriptor); - EfiMemoryDescriptor* Descriptor = nullptr; - UInt32 SzDesc = sizeof(EfiMemoryDescriptor); - UInt32 RevDesc = 0; HEL::HANDOVER_INFO_HEADER* handover_hdr = new HEL::HANDOVER_INFO_HEADER(); + UInt32 map_key = 0; + UInt32 size_struct_ptr = sizeof(EfiMemoryDescriptor); + EfiMemoryDescriptor* struct_ptr = nullptr; + UInt32 sz_desc = sizeof(EfiMemoryDescriptor); + UInt32 rev_desc = 0; + +#ifdef __ZKA_USE_FB__ + InitVideoFB(); ///! Init the GOP. + for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries; ++indexVT) { @@ -130,6 +121,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handover_hdr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine; handover_hdr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; handover_hdr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; +#endif // __ZKA_USE_FB__ // ------------------------------------------- // // Grab MP services, extended to runtime. // @@ -144,17 +136,21 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, kHandoverHeader = handover_hdr; +#ifdef __ZKA_USE_FB__ CGInit(); CGDrawInRegion(CGColor(0xFF, 0x3A, 0x3A), handover_hdr->f_GOP.f_Height, handover_hdr->f_GOP.f_Width, 0, 0); CGFini(); +#endif // __ZKA_USE_FB__ UInt32 cnt_enabled = 0; UInt32 cnt_disabled = 0; mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled); +#ifdef __ZKA_USE_FB__ CGDrawString("NEWOSLDR (C) ZKA TECHNOLOGIES.", 10, 10, RGB(0xFF, 0xFF, 0xFF)); CGDrawString((cnt_enabled > 1) ? "MULTIPLE PROCESSORS DETECTED." : "SINGLE PROCESSOR DETECTED.", 20, 10, RGB(0xFF, 0xFF, 0xFF)); +#endif // __ZKA_USE_FB__ handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; // Fill handover header now. @@ -180,10 +176,10 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, rt_reset_hardware(); } - BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc); + BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); - Descriptor = new EfiMemoryDescriptor[SzDesc]; - BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc); + struct_ptr = new EfiMemoryDescriptor[sz_desc]; + BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); auto cDefaultMemoryMap = 0; // Grab any usable entries. @@ -193,7 +189,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, SizeT lookIndex = 0UL; - for (; Descriptor[lookIndex].Kind != EfiMemoryType::EfiConventionalMemory; ++lookIndex) + for (; struct_ptr[lookIndex].Kind != EfiMemoryType::EfiConventionalMemory; ++lookIndex) { ZKA_UNUSED(0); } @@ -274,7 +270,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, } else { +#ifdef __ZKA_USE_FB__ CGDrawString("NEWOSLDR: PLEASE RECOVER YOUR MINKRNL IMAGE.", 30, 10, RGB(0xFF, 0xFF, 0xFF)); +#endif // __ZKA_USE_FB__ } Boot::BFileReader chimeWav(L"zka\\startup.wav", ImageHandle); @@ -300,13 +298,17 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, } else { +#ifdef __ZKA_USE_FB__ CGDrawString("NEWOSLDR: ONE OR MORE SYSTEM COMPONENTS ARE MISSING, PLEASE REFORMAT THE OS.", 30, 10, RGB(0xFF, 0xFF, 0xFF)); +#endif // __ZKA_USE_FB__ } - EFI::ExitBootServices(MapKey, ImageHandle); + EFI::ExitBootServices(map_key, ImageHandle); +#ifdef __ZKA_USE_FB__ CGDrawInRegion(CGColor(0xFF, 0x3A, 0x3A), handover_hdr->f_GOP.f_Height, handover_hdr->f_GOP.f_Width, 0, 0); CGFini(); +#endif // __ZKA_USE_FB__ // ---------------------------------------------------- // // Finally load Kernel, and the cr3 to it. diff --git a/dev/zba/src/HEL/AMD64/BootPlatform.cxx b/dev/zba/src/HEL/AMD64/BootPlatform.cxx index 31566a95..ff863a57 100644 --- a/dev/zba/src/HEL/AMD64/BootPlatform.cxx +++ b/dev/zba/src/HEL/AMD64/BootPlatform.cxx @@ -1,3 +1,4 @@ + /* ------------------------------------------- Copyright ZKA Technologies. @@ -102,4 +103,4 @@ void rt_hlt() Kernel::HAL::rt_halt(); } -#endif // 0 +#endif // __STANDALONE__ diff --git a/dev/zba/src/HEL/AMD64/BootString.cxx b/dev/zba/src/HEL/AMD64/BootString.cxx deleted file mode 100644 index 1c109b80..00000000 --- a/dev/zba/src/HEL/AMD64/BootString.cxx +++ /dev/null @@ -1,92 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: String.cxx - Purpose: NewBoot string library - - Revision History: - - - -------------------------------------------- */ - -#include -#include -#include - -/// BUGS: 0 - -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -Kernel::SizeT Boot::BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len) -{ - if (!dest || !src) - return 0; - - SizeT index = 0UL; - for (; index < len; ++index) - { - dest[index] = src[index]; - } - - return index; -} - -Kernel::SizeT Boot::BStrLen(const CharacterTypeUTF16* ptr) -{ - if (!ptr) - return 0; - - Kernel::SizeT cnt = 0; - - while (*ptr != (CharacterTypeUTF16)0) - { - ++ptr; - ++cnt; - } - - return cnt; -} - -Kernel::SizeT Boot::BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len) -{ - if (!src) - return 0; - - Kernel::SizeT cnt = 0UL; - - while (*src != 0) - { - if (cnt > len) - break; - - *src = byte; - ++src; - - ++cnt; - } - - return cnt; -} - -Kernel::SizeT Boot::BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len) -{ - if (!src) - return 0; - - Kernel::SizeT cnt = 0UL; - - while (*src != 0) - { - if (cnt > len) - break; - - *src = byte; - ++src; - - ++cnt; - } - - return cnt; -} diff --git a/dev/zba/src/HEL/AMD64/BootTextWriter.cxx b/dev/zba/src/HEL/AMD64/BootTextWriter.cxx deleted file mode 100644 index b0679715..00000000 --- a/dev/zba/src/HEL/AMD64/BootTextWriter.cxx +++ /dev/null @@ -1,169 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: String.cxx - Purpose: NewBoot string library - - Revision History: - - - -------------------------------------------- */ - -#include -#include -#include -#include - -/// BUGS: 0 - -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** -@brief puts wrapper over EFI ConOut. -*/ -Boot::BTextWriter& Boot::BTextWriter::Write(const CharacterTypeUTF16* str) -{ -#ifdef __DEBUG__ - if (!str || *str == 0) - return *this; - - CharacterTypeUTF16 strTmp[2]; - strTmp[1] = 0; - - for (size_t i = 0; str[i] != 0; i++) - { - if (str[i] == '\r') - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - - strTmp[0] = '\n'; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - else - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - } -#endif // ifdef __DEBUG__ - - return *this; -} - -/// @brief UTF-8 equivalent of Write (UTF-16). -/// @param str the input string. -Boot::BTextWriter& Boot::BTextWriter::Write(const Char* str) -{ -#ifdef __DEBUG__ - if (!str || *str == 0) - return *this; - - CharacterTypeUTF16 strTmp[2]; - strTmp[1] = 0; - - for (size_t i = 0; str[i] != 0; i++) - { - if (str[i] == '\r') - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - - strTmp[0] = '\n'; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - else - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - } -#endif // ifdef __DEBUG__ - - return *this; -} - -Boot::BTextWriter& Boot::BTextWriter::Write(const UChar* str) -{ -#ifdef __DEBUG__ - if (!str || *str == 0) - return *this; - - CharacterTypeUTF16 strTmp[2]; - strTmp[1] = 0; - - for (size_t i = 0; str[i] != 0; i++) - { - if (str[i] == '\r') - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - - strTmp[0] = '\n'; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - else - { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); - } - } -#endif // ifdef __DEBUG__ - - return *this; -} - -/** -@brief putc wrapper over EFI ConOut. -*/ -Boot::BTextWriter& Boot::BTextWriter::WriteCharacter(CharacterTypeUTF16 c) -{ -#ifdef __DEBUG__ - EfiCharType str[2]; - - str[0] = c; - str[1] = 0; - ST->ConOut->OutputString(ST->ConOut, str); -#endif // ifdef __DEBUG__ - - return *this; -} - -Boot::BTextWriter& Boot::BTextWriter::Write(const Long& x) -{ -#ifdef __DEBUG__ - this->_Write(x); - this->Write("h"); -#endif // ifdef __DEBUG__ - - return *this; -} - -Boot::BTextWriter& Boot::BTextWriter::_Write(const Long& x) -{ -#ifdef __DEBUG__ - UInt64 y = (x > 0 ? x : -x) / 16; - UInt64 h = (x > 0 ? x : -x) % 16; - - if (y) - this->_Write(y); - - /* fail if the hex number is not base-16 */ - if (h > 16) - { - this->WriteCharacter('?'); - return *this; - } - - if (y < 0) - y = -y; - - const char cNumbers[] = "0123456789ABCDEF"; - - this->WriteCharacter(cNumbers[h]); -#endif // ifdef __DEBUG__ - - return *this; -} diff --git a/dev/zba/src/HEL/AMD64/New+Delete.cxx b/dev/zba/src/HEL/AMD64/New+Delete.cxx deleted file mode 100644 index 4a308f94..00000000 --- a/dev/zba/src/HEL/AMD64/New+Delete.cxx +++ /dev/null @@ -1,62 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include - -#ifdef __STANDALONE__ -#include /* Since we're using GCC for this EFI program. */ - -EXTERN EfiBootServices* BS; - -/// @brief Allocates a new object. -/// @param sz the size. -/// @return -void* operator new(size_t sz) -{ - void* buf = nullptr; - - while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall) - BS->FreePool(buf); - - return buf; -} - -/// @brief Allocates a new object. -/// @param sz the size. -/// @return -void* operator new[](size_t sz) -{ - void* buf = nullptr; - BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); - - return buf; -} - -/// @brief Deletes the object. -/// @param buf the object. -void operator delete(void* buf) -{ - BS->FreePool(buf); -} - -/// @brief Deletes the object. -/// @param buf the object. -void operator delete[](void* buf) -{ - BS->FreePool(buf); -} - -/// @brief Deletes the object (array specific). -/// @param buf the object. -/// @param size it's size. -void operator delete(void* buf, size_t size) -{ - BS->FreePool(buf); -} - -#endif // __STANDALONE__ diff --git a/dev/zba/src/HEL/AMD64/Support.cxx b/dev/zba/src/HEL/AMD64/Support.cxx deleted file mode 100644 index aa93318b..00000000 --- a/dev/zba/src/HEL/AMD64/Support.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include - -#ifdef __STANDALONE__ - -/// @brief memset definition in C++. -/// @param dst destination pointer. -/// @param byte value to fill in. -/// @param len length of of src. -EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) -{ - for (size_t i = 0UL; i < len; ++i) - { - ((int*)dst)[i] = byte; - } - - return dst; -} - -/// @brief memcpy definition in C++. -/// @param dst destination pointer. -/// @param src source pointer. -/// @param len length of of src. -EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len) -{ - for (size_t i = 0UL; i < len; ++i) - { - ((int*)dst)[i] = ((int*)src)[i]; - } - - return dst; -} - -/// @brief strlen definition in C++. -EXTERN_C size_t strlen(const char* whatToCheck) -{ - SizeT len = 0; - - while (whatToCheck[len] != 0) - { - ++len; - } - - return len; -} - -/// @brief strcmp definition in C++. -EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) -{ - if (!whatToCheck || *whatToCheck == 0) - return 0; - - SizeT len = 0; - - while (whatToCheck[len] == whatToCheckRight[len]) - { - if (whatToCheck[len] == 0) - return 0; - - ++len; - } - - return len; -} - -/// @brief somthing specific to the Microsoft's ABI, When the stack grows too big. -EXTERN_C void ___chkstk_ms(void) -{ -} - -#endif diff --git a/dev/zba/src/HEL/ARM64/BootMain.cxx b/dev/zba/src/HEL/ARM64/BootMain.cxx new file mode 100644 index 00000000..ff26b14c --- /dev/null +++ b/dev/zba/src/HEL/ARM64/BootMain.cxx @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include + +EXTERN EfiBootServices* BS; + +/// @brief Main EFI entrypoint. +/// @param ImageHandle Handle of this image. +/// @param SystemTable The system table of it. +/// @return nothing, never returns. +EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, + EfiSystemTable* SystemTable) +{ + + return 0; +} diff --git a/dev/zba/src/HEL/ARM64/BootPlatform.cxx b/dev/zba/src/HEL/ARM64/BootPlatform.cxx new file mode 100644 index 00000000..fba4b61c --- /dev/null +++ b/dev/zba/src/HEL/ARM64/BootPlatform.cxx @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include + +#ifdef __STANDALONE__ + +using namespace Boot; + +EXTERN_C void rt_hlt() +{ + while (Yes); +} + +EXTERN_C void rt_cli() +{ + +} + +EXTERN_C void rt_sti() +{ + +} + +EXTERN_C void rt_cld() +{ + +} + +EXTERN_C void rt_std() +{ + +} + +#endif // __STANDALONE__ diff --git a/dev/zba/src/New+Delete.cxx b/dev/zba/src/New+Delete.cxx new file mode 100644 index 00000000..7240875a --- /dev/null +++ b/dev/zba/src/New+Delete.cxx @@ -0,0 +1,60 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include + +#ifdef __STANDALONE__ +EXTERN EfiBootServices* BS; + +/// @brief Allocates a new object. +/// @param sz the size. +/// @return +void* operator new(size_t sz) +{ + void* buf = nullptr; + + while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall) + BS->FreePool(buf); + + return buf; +} + +/// @brief Allocates a new object. +/// @param sz the size. +/// @return +void* operator new[](size_t sz) +{ + void* buf = nullptr; + BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); + + return buf; +} + +/// @brief Deletes the object. +/// @param buf the object. +void operator delete(void* buf) +{ + BS->FreePool(buf); +} + +/// @brief Deletes the object. +/// @param buf the object. +void operator delete[](void* buf) +{ + BS->FreePool(buf); +} + +/// @brief Deletes the object (array specific). +/// @param buf the object. +/// @param size it's size. +void operator delete(void* buf, size_t size) +{ + BS->FreePool(buf); +} + +#endif // __STANDALONE__ diff --git a/dev/zba/src/Thread.cxx b/dev/zba/src/Thread.cxx index b19894a9..2383d675 100644 --- a/dev/zba/src/Thread.cxx +++ b/dev/zba/src/Thread.cxx @@ -15,14 +15,6 @@ #include #include -EXTERN_C -{ -#include - - Void - rt_jump_to_address(VoidPtr start, VoidPtr handover); -} - // External boot services symbol. EXTERN EfiBootServices* BS; @@ -161,8 +153,6 @@ namespace Boot err_fn(handover); } - rt_jump_to_address(fStartAddress, handover); - reinterpret_cast(fStartAddress)(handover); } -- cgit v1.2.3