From fcccf780db4cdc23858c108c6cde1d08360ee88f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 3 Feb 2024 14:52:52 +0100 Subject: Kernel: Got stuck at the way I do things, trying another approach see hcore ticket HCR-11 in Jira. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/Entrypoint.cxx | 53 +++++++ Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx | 74 +++++----- Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx | 120 --------------- .../Source/HEL/AMD64/AMD64-CoreSync-ATA.asm | 24 +++ Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx | 50 ------- Private/NewBoot/Source/ImageReader.cxx | 70 +++++++++ Private/NewBoot/Source/String.cxx | 88 +++++++++++ Private/NewBoot/Source/Utils.cxx | 162 +-------------------- Private/NewBoot/Source/makefile | 5 +- 9 files changed, 277 insertions(+), 369 deletions(-) create mode 100644 Private/NewBoot/Source/Entrypoint.cxx delete mode 100644 Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx create mode 100644 Private/NewBoot/Source/HEL/AMD64/AMD64-CoreSync-ATA.asm delete mode 100644 Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx create mode 100644 Private/NewBoot/Source/ImageReader.cxx create mode 100644 Private/NewBoot/Source/String.cxx (limited to 'Private/NewBoot/Source') diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx new file mode 100644 index 00000000..6a778143 --- /dev/null +++ b/Private/NewBoot/Source/Entrypoint.cxx @@ -0,0 +1,53 @@ +/* + * ======================================================== + * + * NewBoot + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#define __BOOTLOADER__ 1 + +#include +#include +#include +#include + +// don't remove EfiGUID, it will call initializer_list! + +EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, + EfiSystemTable* SystemTable) { + InitEFI(SystemTable); + + BTextWriter writer; + + writer.WriteString(L"HCoreLdr: Firmware: ") + .WriteString(SystemTable->FirmwareVendor) + .WriteString(L"\r\n"); + + UInt64 mapKey = 0; + + BImageReader img(L"HCoreKrnl.exe"); + + SizeT sz = 0UL; + PEImagePtr blob = (PEImagePtr)img.Fetch(sz); + + if (!blob || sz < 1) + EFI::RaiseHardError(L"HCoreLdr_NoSuchKernel", + L"Couldn't find HCoreKrnl.exe!"); + + ExecHeaderPtr headerPtr = (ExecHeaderPtr)blob; + + if (blob[0] == kMagMz0 && blob[1] == kMagMz1) { + writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n"); + /// Load Image here + } else { + EFI::RaiseHardError(L"HCoreLdr_NotPE", L"Not a PE file! Aborting..."); + } + + EFI::Stop(); + EFI::ExitBootServices(mapKey, ImageHandle); + + return kEfiOk; +} diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx index c289bcf5..d6b6e0a9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx @@ -23,6 +23,8 @@ /// bugs: 0 +extern "C" Void ATAWaitForIO(Void); + static Boolean kATADetected = false; static Int32 kATADeviceType = kATADeviceCount; @@ -67,19 +69,19 @@ Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive, UInt16& OutBus, /* differentiate ATA, ATAPI, SATA and SATAPI */ if (cl == 0x14 && ch == 0xEB) { - writer.WriteString(L"HCoreLdr: PATAPI drive detected.\r\n"); + writer.WriteString(L"HCoreLdr: PATAPI: drive detected.\r\n"); kATADeviceType = kATADevicePATA_PI; } if (cl == 0x69 && ch == 0x96) { - writer.WriteString(L"HCoreLdr: SATAPI drive detected.\r\n"); + writer.WriteString(L"HCoreLdr: SATAPI: drive detected.\r\n"); kATADeviceType = kATADeviceSATA_PI; } if (cl == 0 && ch == 0) { - writer.WriteString(L"HCoreLdr: PATA drive detected.\r\n"); + writer.WriteString(L"HCoreLdr: PATA: drive detected.\r\n"); kATADeviceType = kATADevicePATA; } if (cl == 0x3c && ch == 0xc3) { - writer.WriteString(L"HCoreLdr: SATA drive detected.\r\n"); + writer.WriteString(L"HCoreLdr: SATA: drive detected.\r\n"); kATADeviceType = kATADeviceSATA; } @@ -95,52 +97,50 @@ void ATAWait(UInt16 IO) { void ATAPoll(UInt16 IO) { ATAWait(IO); } -Void ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master, CharacterType* Buf, +Void ATAReadLba(UInt32 Lba, UInt8 IO, Boolean Master, CharacterType* Buf, SizeT Offset) { - UInt16 IO = Bus; + rt_cli(); + ATAWaitForIO(); - ATASelect(IO + ATA_REG_HDDEVSEL, - (Master ? ATA_MASTER : ATA_SLAVE) | Lba >> 24 & 0xF); + Lba &= 0x00FFFFFF; - ATASelect(IO + 1, 0); + UInt8 Command = (Master ? 0xE0 : 0xF0); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + Out8(IO + ATA_REG_HDDEVSEL, Command | ((Lba >> 24))); + Out8(IO + ATA_REG_SEC_COUNT0, 0x1); Out8(IO + ATA_REG_LBA0, (UInt8)Lba); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); + Out8(IO + ATA_REG_LBA1, (UInt8)Lba >> 8); + Out8(IO + ATA_REG_LBA2, (UInt8)Lba >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - ATAPoll(IO); - - Buf[Offset] = In16(IO + ATA_REG_DATA); + Buf[Offset] = In16(IO); - ATAWait(IO); + ATAWaitForIO(); + rt_sti(); } -Void ATAWriteLba(UInt32 Lba, UInt8 Bus, Boolean Master, wchar_t* Buf, +Void ATAWriteLba(UInt32 Lba, UInt8 IO, Boolean Master, wchar_t* Buf, SizeT Offset) { - UInt16 IO = Bus; - - ATASelect(IO + ATA_REG_HDDEVSEL, - (Master ? ATA_MASTER : ATA_SLAVE) | Lba >> 24 & 0xF); + rt_cli(); + ATAWaitForIO(); + Lba &= 0x00FFFFFF; - ATASelect(IO + 1, 0); + UInt8 Command = (Master ? 0xE0 : 0xF0); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + Out8(IO + ATA_REG_HDDEVSEL, Command | ((Lba >> 24))); + Out8(IO + ATA_REG_SEC_COUNT0, 0x1); Out8(IO + ATA_REG_LBA0, (UInt8)Lba); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); + Out8(IO + ATA_REG_LBA1, (UInt8)Lba >> 8); + Out8(IO + ATA_REG_LBA2, (UInt8)Lba >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - ATAPoll(IO); - - Out16(IO + ATA_REG_DATA, Buf[Offset]); - - ATAWait(IO); + Out16(IO, Buf[Offset]); + ATAWaitForIO(); + rt_sti(); } Boolean ATAIsDetected(Void) { return kATADetected; } @@ -171,7 +171,7 @@ BATADevice::BATADevice() noexcept { kATADetected = true; BTextWriter writer; - writer.WriteString(L"BATADevice::BATADevice: OnLine\r\n"); + writer.WriteString(L"HCoreLdr: Driver: OnLine.\r\n"); } } @@ -180,12 +180,12 @@ BATADevice::BATADevice() noexcept { @param Sz Sector size @param Buf buffer */ -BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { +BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& SectorSz) { if (!ATAIsDetected()) return *this; - if (!Buf || Sz < 1) return *this; + if (!Buf || SectorSz > kATASectorSz || SectorSz < 1) return *this; - for (SizeT i = 0UL; i < Sz; ++i) { + for (SizeT i = 0UL; i < SectorSz; ++i) { ATAReadLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, Buf, i); } @@ -198,14 +198,14 @@ BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { @param Sz Sector size @param Buf buffer */ -BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& Sz) { +BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& SectorSz) { if (!ATAIsDetected()) return *this; - if (!Buf || Sz < 1) return *this; + if (!Buf || SectorSz > kATASectorSz || SectorSz < 1) return *this; SizeT Off = 0UL; - for (SizeT i = 0UL; i < Sz; ++i) { + for (SizeT i = 0UL; i < SectorSz; ++i) { ATAWriteLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, Buf, Off); diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx deleted file mode 100644 index 8db6ae16..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx +++ /dev/null @@ -1,120 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include - -/// bugs 0 - -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src, - const HCore::SizeT len) { - if (!dest || !src) return 0; - - SizeT index = 0UL; - for (; index < len; ++index) { - dest[index] = src[index]; - } - - return index; -} - -HCore::SizeT BStrLen(const CharacterType *ptr) { - if (!ptr) return 0; - - HCore::SizeT cnt = 0; - - while (*ptr != (CharacterType)0) { - ++ptr; - ++cnt; - } - - return cnt; -} - -HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte, - const HCore::SizeT len) { - if (!src) return 0; - - HCore::SizeT cnt = 0UL; - - while (*src != 0) { - if (cnt > len) break; - - *src = byte; - ++src; - - ++cnt; - } - - return cnt; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -/** -@brief puts wrapper over EFI. -*/ -BTextWriter &BTextWriter::WriteString(const CharacterType *str) { - if (*str == 0 || !str) return *this; - - ST->ConOut->OutputString(ST->ConOut, str); - - return *this; -} - -/** -@brief putc wrapper over EFI. -*/ -BTextWriter &BTextWriter::WriteCharacter(CharacterType c) { - EfiCharType str[2]; - str[0] = c; - str[1] = 0; - ST->ConOut->OutputString(ST->ConOut, str); - - return *this; -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*** - @brief File Reader constructor. -*/ -BImageReader::BImageReader(const CharacterType *path) { - if (path != nullptr) { - SizeT index = 0UL; - for (; path[index] != L'\0'; ++index) { - mPath[index] = path[index]; - } - - mPath[index] = 0; - } -} - -/** -@brief this reads all of the buffer. -@param size, new buffer size. -*/ -HCore::VoidPtr BImageReader::Fetch(SizeT &size) { - BTextWriter writer; - writer.WriteString(L"*** BImageReader::Fetch: Fetching... ") - .WriteString(mPath) - .WriteString(L" *** \r\n"); - - EfiLoadImageProtocol *proto = nullptr; - EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); - - if (BS->LocateProtocol(&guidImg, nullptr, (VoidPtr *)&proto) == kEfiOk) { - } - - return nullptr; -} diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-CoreSync-ATA.asm b/Private/NewBoot/Source/HEL/AMD64/AMD64-CoreSync-ATA.asm new file mode 100644 index 00000000..6ad07a59 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-CoreSync-ATA.asm @@ -0,0 +1,24 @@ +[bits 64] + + +section .text +global ATAWaitForIO + +ATAWaitForIO: + push ax + push dx + + xor ax, ax + mov dx, 01F7h + +ATAWaitForIO_Loop: + in al, dx + and al, 0C0h + cmp al, 040h + jne ATAWaitForIO_Loop + +ATAWaitForIO_End: + pop dx + pop ax + + ret diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx deleted file mode 100644 index c2631a6f..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#define __BOOTLOADER__ 1 - -#include -#include -#include - -// don't remove EfiGUID, it will call initializer_list! - -EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, - EfiSystemTable* SystemTable) { - InitEFI(SystemTable); - - BTextWriter writer; - - writer.WriteString(L"HCoreLdr: Firmware: ") - .WriteString(SystemTable->FirmwareVendor) - .WriteString(L"\r\n"); - - UInt64 mapKey = 0; - - BImageReader img(L"HCoreKrnl.exe"); - - SizeT sz = 0UL; - PEImagePtr blob = (PEImagePtr)img.Fetch(sz); - - if (!blob || sz < 1) - KeRuntimeStop(L"HCoreLdr_NoSuchKernel", L"Couldn't find HCoreKrnl.exe!"); - - ExecHeaderPtr headerPtr = (ExecHeaderPtr)blob; - - if (blob[0] == kMagMz0 && blob[1] == kMagMz1) { - writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n"); - /// Load Image here - } else { - KeRuntimeStop(L"HCoreLdr_NotPE", L"Not a PE file! Aborting..."); - } - - EFI::Stop(); - - return kEfiOk; -} diff --git a/Private/NewBoot/Source/ImageReader.cxx b/Private/NewBoot/Source/ImageReader.cxx new file mode 100644 index 00000000..b714c21f --- /dev/null +++ b/Private/NewBoot/Source/ImageReader.cxx @@ -0,0 +1,70 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: String.cxx + Purpose: NewBoot string library + + Revision History: + + + +------------------------------------------- */ + +#include +#include +#include + +#include "NewKit/Defines.hpp" + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// +// @brief BImageReader class +// +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +/*** + @brief File Reader constructor. +*/ +BImageReader::BImageReader(const CharacterType *path) { + if (path != nullptr) { + SizeT index = 0UL; + for (; path[index] != L'\0'; ++index) { + mPath[index] = path[index]; + } + + mPath[index] = 0; + } +} + +/** + @brief this reads all of the buffer. + @param size, new buffer size. +*/ +HCore::VoidPtr BImageReader::Fetch(SizeT &size) { + mWriter.WriteString(L"HCoreLdr: Fetch-Image: ") + .WriteString(mPath) + .WriteString(L"\r\n"); + + CharacterType bootBlockBytes[kATASectorSz] = {0}; + + mDevice.Leak().mBase = kNewFSAddressAsLba; + mDevice.Leak().mMaster = true; + + mDevice.Read(bootBlockBytes, kATASectorSz); + + NewBootBlock *bootBlock = (NewBootBlock *)bootBlockBytes; + + for (SizeT index = 0UL; index < kNewFSIdentLen; ++index) { + if (bootBlock->Ident[index] != kNewFSIdent[index]) { + mWriter.WriteString(L"HCoreLdr: NewFS: Not found.\r\n"); + return nullptr; + } + } + + /// get file catalog with mPath inside it. + + return nullptr; +} diff --git a/Private/NewBoot/Source/String.cxx b/Private/NewBoot/Source/String.cxx new file mode 100644 index 00000000..a2d19f1f --- /dev/null +++ b/Private/NewBoot/Source/String.cxx @@ -0,0 +1,88 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: String.cxx + Purpose: NewBoot string library + + Revision History: + + + +------------------------------------------- */ + +#include +#include +#include + +/// bugs 0 + +///////////////////////////////////////////////////////////////////////////////////////////////////////// + +HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src, + const HCore::SizeT len) { + if (!dest || !src) return 0; + + SizeT index = 0UL; + for (; index < len; ++index) { + dest[index] = src[index]; + } + + return index; +} + +HCore::SizeT BStrLen(const CharacterType *ptr) { + if (!ptr) return 0; + + HCore::SizeT cnt = 0; + + while (*ptr != (CharacterType)0) { + ++ptr; + ++cnt; + } + + return cnt; +} + +HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte, + const HCore::SizeT len) { + if (!src) return 0; + + HCore::SizeT cnt = 0UL; + + while (*src != 0) { + if (cnt > len) break; + + *src = byte; + ++src; + + ++cnt; + } + + return cnt; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** +@brief puts wrapper over EFI. +*/ +BTextWriter &BTextWriter::WriteString(const CharacterType *str) { + if (*str == 0 || !str) return *this; + + ST->ConOut->OutputString(ST->ConOut, str); + + return *this; +} + +/** +@brief putc wrapper over EFI. +*/ +BTextWriter &BTextWriter::WriteCharacter(CharacterType c) { + EfiCharType str[2]; + str[0] = c; + str[1] = 0; + ST->ConOut->OutputString(ST->ConOut, str); + + return *this; +} diff --git a/Private/NewBoot/Source/Utils.cxx b/Private/NewBoot/Source/Utils.cxx index c51a87d6..8d2242cd 100644 --- a/Private/NewBoot/Source/Utils.cxx +++ b/Private/NewBoot/Source/Utils.cxx @@ -11,164 +11,4 @@ #include #include -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// @brief External EFI code for completeness. -// -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace Detail { -const EfiDevicePathProtocol mUefiDevicePathLibEndDevicePath = { - END_DEVICE_PATH_TYPE, - END_ENTIRE_DEVICE_PATH_SUBTYPE, - {sizeof(EfiDevicePathProtocol), 0}}; - -EfiDevicePathProtocol *UefiDevicePathLibAppendDevicePath( - const EfiDevicePathProtocol *FirstDevicePath, - const EfiDevicePathProtocol *SecondDevicePath) { - SizeT Size; - SizeT Size1; - SizeT Size2; - EfiDevicePathProtocol *NewDevicePath; - EfiDevicePathProtocol *DevicePath2; - - // - // If there's only 1 path, just duplicate it. - // - if (FirstDevicePath == nullptr) { - return DuplicateDevicePath((SecondDevicePath != nullptr) - ? SecondDevicePath - : &mUefiDevicePathLibEndDevicePath); - } - - if (SecondDevicePath == nullptr) { - return DuplicateDevicePath(FirstDevicePath); - } - - if (!IsDevicePathValid(FirstDevicePath, 0) || - !IsDevicePathValid(SecondDevicePath, 0)) { - return nullptr; - } - - // - // Allocate space for the combined device path. It only has one end node of - // length EFI_DEVICE_PATH_PROTOCOL. - // - Size1 = GetDevicePathSize(FirstDevicePath); - Size2 = GetDevicePathSize(SecondDevicePath); - Size = Size1 + Size2 - sizeof(EfiDevicePathProtocol); - - BS->AllocatePool(EfiLoaderData, Size, (VoidPtr *)&NewDevicePath); - - if (NewDevicePath != NULL) { - BCopyMem((CharacterType *)NewDevicePath, (CharacterType *)FirstDevicePath, - Size1); - // - // Over write FirstDevicePath EndNode and do the copy - // - DevicePath2 = - (EfiDevicePathProtocol *)((Char *)NewDevicePath + - (Size1 - sizeof(EfiDevicePathProtocol))); - BCopyMem((CharacterType *)DevicePath2, (CharacterType *)SecondDevicePath, - Size2); - } - - return NewDevicePath; -} - -EfiDevicePathProtocol *AppendDevicePath( - EfiDevicePathProtocol *FirstDevicePath, - EfiDevicePathProtocol *SecondDevicePath) { - return UefiDevicePathLibAppendDevicePath(FirstDevicePath, SecondDevicePath); -} - -EfiDevicePathProtocol *EFI_API DevicePathFromHandle(EfiHandlePtr Handle) { - EfiDevicePathProtocol *DevicePath; - UInt64 Status; - - EfiGUID guid = EfiGUID(EFI_DEVICE_PATH_PROTOCOL_GUID); - - Status = BS->HandleProtocol(Handle, &guid, (VoidPtr *)&DevicePath); - if (Status != kEfiOk) { - DevicePath = nullptr; - } - - return DevicePath; -} - -UInt16 ReadUnaligned16(UInt16 *Buffer) { - // ASSERT (Buffer != NULL); - return *Buffer; -} - -UInt16 WriteUnaligned16(UInt16 *Buffer, UInt16 Value) { - // ASSERT (Buffer != NULL); - - return *Buffer = Value; -} - -UInt16 EFI_API SetDevicePathNodeLength(Void *Node, UInt32 Length) { - // ASSERT(Node != nullptr); - // ASSERT((Length >= sizeof(EfiDevicePathProtocol)) && (Length < KIB(64))); - return WriteUnaligned16( - (UInt16 *)&((EfiDevicePathProtocol *)(Node))->Length[0], - (UInt16)(Length)); -} - -Void EFI_API SetDevicePathEndNode(Void *Node) { - // ASSERT(Node != NULL); - BCopyMem((CharacterType *)Node, - (CharacterType *)&mUefiDevicePathLibEndDevicePath, - sizeof(mUefiDevicePathLibEndDevicePath)); -} - -UInt32 EFI_API DevicePathNodeLength(const Void *Node) { - // ASSERT(Node != NULL); - return ReadUnaligned16( - (UInt16 *)&((EfiDevicePathProtocol *)(Node))->Length[0]); -} - -EfiDevicePathProtocol *EFI_API NextDevicePathNode(Void *Node) { - // ASSERT (Node != NULL); - return (EfiDevicePathProtocol *)((UInt8 *)(Node) + - DevicePathNodeLength(Node)); -} - -EfiDevicePathProtocol *EFI_API FileDevicePath(EfiHandlePtr Device, - CharacterType *FileName) { - SizeT Size; - EfiFileDevicePathProtocol *FilePath; - EfiDevicePathProtocol *DevicePath; - EfiDevicePathProtocol *FileDevicePath; - - DevicePath = nullptr; - - Size = BStrLen(FileName); - BS->AllocatePool( - EfiLoaderData, - Size + sizeof(EfiFileDevicePathProtocol) + sizeof(EfiDevicePathProtocol), - (VoidPtr *)&FileDevicePath); - - if (FileDevicePath != nullptr) { - FilePath = (EfiFileDevicePathProtocol *)FileDevicePath; - FilePath->Proto.Type = kEFIMediaDevicePath; - FilePath->Proto.SubType = kEFIMediaDevicePath; - - BCopyMem(FilePath->Path, FileName, Size); - - SetDevicePathNodeLength(&FilePath->Proto, - Size + sizeof(EfiFileDevicePathProtocol)); - - SetDevicePathEndNode(NextDevicePathNode(&FilePath->Proto)); - - if (Device != nullptr) { - DevicePath = DevicePathFromHandle(Device); - } - - DevicePath = AppendDevicePath(DevicePath, FileDevicePath); - BS->FreePool(FileDevicePath); - } - - return DevicePath; -} -} // namespace Detail +/// @brief EFI API diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 04b39516..eb836632 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -5,7 +5,9 @@ CC_GNU=x86_64-w64-mingw32-g++ LD_GNU=x86_64-w64-mingw32-ld +ASM=nasm +FLAG_ASM=-f win64 FLAG_GNU=-fshort-wchar -fPIC -D__DEBUG__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I../../efiSDK/inc -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/ .PHONY: invalid-recipe @@ -14,8 +16,9 @@ invalid-recipe: .PHONY: bootloader-amd64 bootloader-amd64: + $(ASM) $(FLAG_ASM) HEL/AMD64/AMD64-CoreSync-ATA.asm $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx - $(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe + $(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 -- cgit v1.2.3