summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-04-22 08:37:14 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-04-22 08:37:14 +0000
commit09e1c9738bc5dce28a6e181ebc585f0dea01f109 (patch)
tree2df231f8601402147514572120f762c69bf5c84a /Private/NewBoot/Source
parent41cc598c501ee190385c041b2149eae228b24741 (diff)
parent76c0c6b21532aee82df5bd62cd886bc63d933899 (diff)
Merged in MHR-5 (pull request #1)
MHR-5
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/BootloaderRsrc.rsrc4
-rw-r--r--Private/NewBoot/Source/CDROM/.NEWDEV2
-rw-r--r--Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep0
-rw-r--r--Private/NewBoot/Source/CDROM/SplashScreen.fmt6
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx14
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx119
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx58
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx182
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx33
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx19
-rw-r--r--Private/NewBoot/Source/HEL/POWER/.gitkeep (renamed from Private/NewBoot/Source/CDROM/.gitkeep)0
-rw-r--r--Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S34
-rw-r--r--Private/NewBoot/Source/HEL/POWER/BootEPM.cxx (renamed from Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx)10
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/.gitkeep0
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S22
-rw-r--r--Private/NewBoot/Source/makefile35
16 files changed, 275 insertions, 263 deletions
diff --git a/Private/NewBoot/Source/BootloaderRsrc.rsrc b/Private/NewBoot/Source/BootloaderRsrc.rsrc
index f77a4079..e8d89e9a 100644
--- a/Private/NewBoot/Source/BootloaderRsrc.rsrc
+++ b/Private/NewBoot/Source/BootloaderRsrc.rsrc
@@ -1,6 +1,6 @@
#include "../../CompilerKit/Version.hxx"
-1 ICON "../../Root/Boot/boot-logo.ico"
+1 ICON "../../Root/Boot/Icons/boot-logo.ico"
1 VERSIONINFO
FILEVERSION 1,0,0,0
@@ -11,7 +11,7 @@ BEGIN
BLOCK "080904E4"
BEGIN
VALUE "CompanyName", "Mahrouss-Logic"
- VALUE "FileDescription", "NewOS multi-platform bootloader."
+ VALUE "FileDescription", "New OS multi-platform bootloader."
VALUE "FileVersion", BOOTLOADER_VERSION
VALUE "InternalName", "NewBoot"
VALUE "LegalCopyright", "Copyright Mahrouss-Logic, all rights reserved."
diff --git a/Private/NewBoot/Source/CDROM/.NEWDEV b/Private/NewBoot/Source/CDROM/.NEWDEV
deleted file mode 100644
index d5d2badf..00000000
--- a/Private/NewBoot/Source/CDROM/.NEWDEV
+++ /dev/null
@@ -1,2 +0,0 @@
-[POWER_MANAGEMENT]
-ENFORCE_ACPI=YES \ No newline at end of file
diff --git a/Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep b/Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep
deleted file mode 100644
index e69de29b..00000000
--- a/Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep
+++ /dev/null
diff --git a/Private/NewBoot/Source/CDROM/SplashScreen.fmt b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
new file mode 100644
index 00000000..e47a66a6
--- /dev/null
+++ b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
@@ -0,0 +1,6 @@
+Welcome to NeWS
+
+Brought to you by:
+* MicroKernel, Bootloader: Amlal EL Mahrouss.
+
+Copyright Mahrouss-Logic, all rights reserved.
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
index 2a2852fb..4e41ba2e 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
@@ -72,7 +72,7 @@ ATAInit_Retry:
if (statRdy & ATA_SR_ERR) {
writer.Write(
- L"NewOS: ATA: Select error, not an IDE based hard-drive.\r\n");
+ L"New Boot: ATA: Select error, not an IDE based hard-drive.\r\n");
return false;
}
@@ -108,21 +108,21 @@ ATAInit_Retry:
/* differentiate ATA, ATAPI, SATA and SATAPI */
if (cl == 0x14 && ch == 0xEB) {
- writer.Write(L"NewOS: PATAPI drive detected.\r\n");
+ writer.Write(L"New Boot: PATAPI drive detected.\r\n");
kATADeviceType = kATADevicePATA_PI;
}
if (cl == 0x69 && ch == 0x96) {
- writer.Write(L"NewOS: SATAPI drive detected.\r\n");
+ writer.Write(L"New Boot: SATAPI drive detected.\r\n");
kATADeviceType = kATADeviceSATA_PI;
}
if (cl == 0x0 && ch == 0x0) {
- writer.Write(L"NewOS: PATA drive detected.\r\n");
+ writer.Write(L"New Boot: PATA drive detected.\r\n");
kATADeviceType = kATADevicePATA;
}
if (cl == 0x3c && ch == 0xc3) {
- writer.Write(L"NewOS: SATA drive detected.\r\n");
+ writer.Write(L"New Boot: SATA drive detected.\r\n");
kATADeviceType = kATADeviceSATA;
}
@@ -159,7 +159,7 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
++IndexOff;
while ((In8(ATA_COMMAND(IO))) & ATA_SR_BSY) boot_ata_wait_io(IO);
-
+
byte = In16(IO + ATA_REG_DATA);
Buf[IndexOff] = byte;
}
@@ -213,7 +213,7 @@ BootDeviceATA::BootDeviceATA() noexcept {
BTextWriter writer;
- writer.Write(L"NewOS: Drive is OnLine.\r\n");
+ writer.Write(L"New Boot: Drive is OnLine.\r\n");
}
}
/**
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
deleted file mode 100644
index 0d678dc1..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -------------------------------------------
-
- Copyright Mahrouss Logic
-
-------------------------------------------- */
-
-#include <BootKit/BootKit.hxx>
-#include <FSKit/NewFS.hxx>
-
-#define kEPMSectorSize kATASectorSize
-#define kEPMSwapSize MIB(16)
-#define kEPMGPTStartLba (30)
-
-// {310E1FC7-2060-425D-BE7B-75A37CC679BC}
-STATIC const BlockGUID kEPMGuid = {
- 0x310e1fc7,
- 0x2060,
- 0x425d,
- {0xbe, 0x7b, 0x75, 0xa3, 0x7c, 0xc6, 0x79, 0xbc}};
-
-/// @brief Write epm partition to disk.
-/// @param namePart partition name
-/// @param namePartLength length of name
-/// @param bootDev disk interface.
-/// @return
-EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength,
- BootDevice* bootDev) {
- if (namePartLength > kEPMNameLength || !namePart) return No;
- if (!bootDev) return No;
-
- bootDev->Leak().mBase = kEPMGPTStartLba;
- bootDev->Leak().mSize = kEPMSectorSize;
-
- Char buf[kEPMSectorSize] = {0};
-
- bootDev->Read(buf, 1);
-
- BTextWriter writer;
-
- writer.Write(L"NewOS: Checking for a EPM partition...\r\n");
-
- for (SizeT index = 0; index < kEPMMagicLength; ++index) {
- if (buf[index] != kEPMMagic[index]) {
- writer.Write(L"NewOS: Writing a EPM partition...\r\n");
-
- BootBlockType* bootBlock = (BootBlockType*)buf;
-
- bootBlock->Version = kEPMRevision;
- bootBlock->NumBlocks = 2;
-
- for (SizeT i = 0; i < kEPMNameLength; ++i) {
- bootBlock->Magic[i] = kEPMMagic[i];
- }
-
- for (SizeT i = 0; i < namePartLength; ++i) {
- bootBlock->Name[i] = namePart[i];
- }
-
- bootBlock->LbaStart =
- sizeof(BootBlockType) + (sizeof(PartitionBlockType) * kEPMMaxBlks);
-
- bootBlock->SectorSz = kEPMSectorSize;
-
- bootBlock->Uuid = kEPMGuid;
-
- PartitionBlock* partBlock = (PartitionBlock*)(buf + sizeof(BootBlock));
-
- const char* fsName = "NewFS";
- int fsNameLength = 6;
-
- for (SizeT i = 0; i < fsNameLength; ++i) {
- partBlock->Fs[i] = fsName[i];
- }
-
- partBlock->Version = kEPMNewOS;
-
- const char* partNameSystem = "System HD";
- int partNameLength = 10;
-
- for (SizeT i = 0; i < partNameLength; ++i) {
- partBlock->Name[i] = partNameSystem[i];
- }
-
- partBlock->SectorSz = kEPMSectorSize;
- partBlock->LbaStart = kEPMStartPartitionBlk + kEPMSwapSize;
- partBlock->Version = kNewFSVersionInteger;
- partBlock->Kind = kNewFSPartitionTypeStandard;
- partBlock->LbaEnd = 0UL; ///! grows on the disk.
-
- PartitionBlock* swapBlock = (PartitionBlock*)(buf + sizeof(BootBlock) + sizeof(PartitionBlock));
-
- for (SizeT i = 0; i < fsNameLength; ++i) {
- swapBlock->Fs[i] = fsName[i];
- }
-
- swapBlock->Version = kEPMNewOS;
-
- const char *partNameSwap = "Swap HD";
- partNameLength = 8;
-
- for (SizeT i = 0; i < partNameLength; ++i) {
- swapBlock->Name[i] = partNameSwap[i];
- }
-
- swapBlock->SectorSz = kEPMSectorSize;
- swapBlock->LbaStart = kEPMStartPartitionBlk;
- swapBlock->Version = kNewFSVersionInteger;
- swapBlock->Kind = kNewFSPartitionTypePage;
- swapBlock->LbaEnd = kEPMSwapSize; /// 4 MIB swap partition.
-
- bootDev->Write(buf, 1);
-
- return No;
- }
- }
-
- writer.Write(L"NewOS: Partition found, everything's OK.\r\n");
- return Yes;
-} \ No newline at end of file
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
index b31f37de..3a445d61 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
@@ -3,7 +3,7 @@
Copyright Mahrouss Logic
File: FileReader.cxx
- Purpose: NewBoot FileReader,
+ Purpose: New Boot FileReader,
Read complete file and store it in a buffer.
------------------------------------------- */
@@ -25,7 +25,8 @@
/***
@brief File Reader constructor.
*/
-BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandle) {
+BFileReader::BFileReader(const CharacterTypeUTF16* path,
+ EfiHandlePtr ImageHandle) {
if (path != nullptr) {
SizeT index = 0UL;
for (; path[index] != L'\0'; ++index) {
@@ -46,12 +47,12 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandl
EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID);
if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) {
- mWriter.Write(L"NewOS: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n");
+ mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n");
this->mErrorCode = kNotSupported;
}
if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) {
- mWriter.Write(L"NewOS: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n");
+ mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n");
this->mErrorCode = kNotSupported;
return;
}
@@ -59,7 +60,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandl
/// Start doing disk I/O
if (efp->OpenVolume(efp, &rootFs) != kEfiOk) {
- mWriter.Write(L"NewOS: Fetch-Protocol: No-Such-Volume").Write(L"\r\n");
+ mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r\n");
this->mErrorCode = kNotSupported;
return;
}
@@ -68,7 +69,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandl
if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) !=
kEfiOk) {
- mWriter.Write(L"NewOS: Fetch-Protocol: No-Such-Path: ")
+ mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ")
.Write(mPath)
.Write(L"\r\n");
this->mErrorCode = kNotSupported;
@@ -88,24 +89,19 @@ BFileReader::~BFileReader() {
this->mFile = nullptr;
}
- if (this->mBlob)
- BS->FreePool(mBlob);
+ if (this->mBlob) BS->FreePool(mBlob);
BSetMem(this->mPath, 0, kPathLen);
}
/**
@brief this reads all of the buffer.
- @param ImageHandle used internally.
+ @param until read until size is reached.
*/
-Void BFileReader::ReadAll() {
- /// Allocate Handover page.
-
- if (this->mErrorCode != kOperationOkay) return;
-
+Void BFileReader::ReadAll(SizeT until, SizeT chunk) {
if (mBlob == nullptr) {
- if (auto err = BS->AllocatePool(EfiLoaderCode, mSizeFile,
- (VoidPtr*)&mBlob) != kEfiOk) {
+ if (auto err = BS->AllocatePool(EfiLoaderCode, until,
+ (VoidPtr*)&mBlob) != kEfiOk) {
mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r\n");
EFI::RaiseHardError(L"NewBoot_PageError", L"Allocation error.");
}
@@ -113,8 +109,34 @@ Void BFileReader::ReadAll() {
mErrorCode = kNotSupported;
- if (mFile->Read(mFile, &mSizeFile, (VoidPtr)((UIntPtr)mBlob)) != kEfiOk)
- return;
+ UInt64 bufSize = chunk;
+ UInt64 szCnt = 0;
+ UInt64 curSz = 0;
+
+ while (curSz < until) {
+ if (mFile->Read(mFile, &bufSize, (VoidPtr)((UIntPtr)mBlob + curSz)) != kEfiOk) {
+ break;
+ }
+
+ szCnt += bufSize;
+ curSz += bufSize;
+ if (bufSize == 0)
+ break;
+ }
+
+ mSizeFile = curSz;
mErrorCode = kOperationOkay;
}
+
+/// @brief error code getter.
+/// @return the error code.
+Int32& BFileReader::Error() { return mErrorCode; }
+
+/// @brief blob getter.
+/// @return the blob.
+VoidPtr BFileReader::Blob(){ return mBlob; }
+
+/// @breif Size getter.
+/// @return the size of the file.
+UInt64& BFileReader::Size() { return mSizeFile; }
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f5bb3ce8..638fe37a 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -5,52 +5,61 @@
------------------------------------------- */
#include <BootKit/BootKit.hxx>
+#include <BootKit/Rsrc/Driver.rsrc>
+#include <Builtins/Toolbox/Toolbox.hxx>
#include <KernelKit/MSDOS.hpp>
#include <KernelKit/PE.hxx>
#include <NewKit/Ref.hpp>
-#ifdef __x86_64__
-#include <HALKit/AMD64/HalPageAlloc.hpp>
-#else
-#error This CPU is unknown.
-#endif // ifdef __x86_64__
+/** Graphics related. */
-#define kMaxBufSize 256
+STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
+STATIC UInt16 kStride = 0U;
+STATIC EfiGUID kGopGuid;
-/// @brief Bootloader main type.
-typedef void (*bt_main_type)(HEL::HandoverInformationHeader* handoverInfo);
+/**
+ @brief Finds and stores the GOP.
+*/
+
+STATIC Void CheckAndFindFramebuffer() noexcept {
+ kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
+ kGop = nullptr;
+
+ extern EfiBootServices* BS;
+
+ BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop);
+
+ kStride = 4;
+}
+
+/// @brief check the BootDevice if suitable.
+STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) {
+ if (ataDev.Leak().mErr) return false;
+ return true;
+}
/// @brief Main EFI entrypoint.
/// @param ImageHandle Handle of this image.
/// @param SystemTable The system table of it.
/// @return
-EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
- EfiSystemTable* SystemTable) {
- InitEFI(SystemTable); // Init the EFI library.
- InitGOP(); // Init the GOP.
+EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
+ EfiSystemTable* SystemTable) {
+ InitEFI(SystemTable); ///! Init the EFI library.
+ CheckAndFindFramebuffer(); ///! Init the GOP.
BTextWriter writer;
+
/// Splash screen stuff
- writer.Write(L"Mahrouss-Logic (R) NewOS: ").Write(BVersionString::Shared());
+ writer.Write(L"Mahrouss-Logic (R) New Boot: ")
+ .Write(BVersionString::Shared());
- writer.Write(L"\r\nNewOS: Firmware Vendor: ")
+ writer.Write(L"\r\nNewBoot: Firmware Vendor: ")
.Write(SystemTable->FirmwareVendor)
.Write(L"\r\n");
BootDeviceATA ataDev;
- Boolean isEpmFound = No;
-
- /// if ATA drive is initialized and EFI vendor supports an EPM scheme.
- /// @EDK tells our OS that it supports EPM scheme as well.
- if (ataDev) {
- Char namePart[kEPMNameLength] = {"NewBoot"};
- /// tries to read an EPM block, or writes one if it fails.
- isEpmFound = boot_write_epm_partition(namePart, kEPMNameLength, &ataDev);
- } else {
- writer.Write(L"NewOS: This computer can't work with NewOS.\r\n");
- return kEfiFail;
- }
+ Boolean isGptFound = No;
UInt32 MapKey = 0;
UInt32* SizePtr = nullptr;
@@ -60,7 +69,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
kEfiOk) {
- EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
+ EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!");
}
/****
@@ -73,23 +82,31 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
(VoidPtr*)&Descriptor) != kEfiOk) {
- EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
+ EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!");
}
- /****
- *
- * Get machine memory map.
- *
- */
+ HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
- while (BS->GetMemoryMap(SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
- kEfiOk)
- ;
+ for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
+ ++indexVT) {
+ volatile Char* vendorTable = reinterpret_cast<volatile Char*>(
+ SystemTable->ConfigurationTable[indexVT].VendorTable);
- HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
+ if (vendorTable[0] == 'R' && vendorTable[1] == 'S' &&
+ vendorTable[2] == 'D' && vendorTable[3] == ' ' &&
+ vendorTable[4] == 'P' && vendorTable[5] == 'T' &&
+ vendorTable[6] == 'R' && vendorTable[7] == ' ') {
+ handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
- BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
- (VoidPtr*)&handoverHdrPtr);
+ break;
+ }
+ }
+
+ handoverHdrPtr->f_Magic = kHandoverMagic;
+ handoverHdrPtr->f_Version = kHandoverVersion;
+
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase;
handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution;
@@ -98,58 +115,77 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
- handoverHdrPtr->f_PhysicalStart =
- reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
- handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages;
+ ///! Finally draw bootloader screen.
- handoverHdrPtr->f_VirtualStart =
- reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
+ auto kHandoverHeader = handoverHdrPtr;
- handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
+ ToolboxInitRsrc();
- handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+ ToolboxDrawZone(RGB(FF, FF, FF), handoverHdrPtr->f_GOP.f_Height,
+ handoverHdrPtr->f_GOP.f_Width, 0, 0);
- BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
- handoverHdrPtr->f_FirmwareVendorLen);
+ ToolboxClearRsrc();
-#ifdef __DEBUG__
- writer.Write(L"NewOS: Fetching ACPI's 'RSD PTR'...").Write(L"\r\n");
-#endif
+ ToolboxDrawRsrc(Driver, DRIVER_HEIGHT, DRIVER_WIDTH,
+ (handoverHdrPtr->f_GOP.f_Width - DRIVER_HEIGHT) / 2,
+ (handoverHdrPtr->f_GOP.f_Height - DRIVER_HEIGHT) / 2);
- for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
- ++indexVT) {
- volatile Char* vendorTable = reinterpret_cast<volatile Char*>(
- SystemTable->ConfigurationTable[indexVT].VendorTable);
+ ToolboxClearRsrc();
- if (vendorTable[0] == 'R' && vendorTable[1] == 'S' &&
- vendorTable[2] == 'D' && vendorTable[3] == ' ' &&
- vendorTable[4] == 'P' && vendorTable[5] == 'T' &&
- vendorTable[6] == 'R' && vendorTable[7] == ' ') {
- handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
+ BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
+ (VoidPtr*)&handoverHdrPtr);
-#ifdef __DEBUG__
- writer.Write(L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
- .Write(L"\r\n");
-#endif
+ handoverHdrPtr->f_PhysicalStart = 0;
+ handoverHdrPtr->f_PhysicalSize = 0;
- break;
- }
+ EfiPhysicalAddress* whereAddress =
+ reinterpret_cast<EfiPhysicalAddress*>(kBootVirtualAddress);
+
+ BS->AllocatePages(EfiAllocateType::AllocateAnyPages,
+ EfiMemoryType::EfiConventionalMemory, 1, whereAddress);
+
+ handoverHdrPtr->f_VirtualStart = reinterpret_cast<voidPtr>(whereAddress);
+
+ handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
+ BFileReader reader(L"SplashScreen.fmt", ImageHandle);
+ reader.ReadAll(512, 16);
+
+ Char* buf = (Char*)reader.Blob();
+
+ for (SizeT i = 0; i < reader.Size(); ++i) {
+ if (buf[i] != '\n' && buf[i] != '\r') {
+ if (buf[i] == '*') {
+ writer.WriteCharacter('\t');
+ } else {
+ writer.WriteCharacter(buf[i]);
+ }
+ } else
+ writer.Write(L"\r\n");
}
- if (!isEpmFound) {
- writer.Write(L"NewOS: No partition found for NewOS. (HCR-1000)\r\n");
+ BFileReader kernelFile(L"NewKernel.exe", ImageHandle);
+ kernelFile.ReadAll(KIB(512), 4096);
+
+ ExecOptionalHeaderPtr headerKind = (ExecOptionalHeaderPtr)rt_find_exec_header((DosHeaderPtr)kernelFile.Blob());
+
+ if (!headerKind) {
+ EFI::RaiseHardError(L"Bad-Exec", L"New Boot can't recognize this executable.");
}
- handoverHdrPtr->f_Magic = kHandoverMagic;
- handoverHdrPtr->f_Version = kHandoverVersion;
+ BootMainKind main = (BootMainKind)nullptr;
- writer.Write(L"Running NewOS...\r\n");
+ if (!main) {
+ EFI::RaiseHardError(L"Bad-Exec", L"New Boot can't recognize this executable.");
+ }
EFI::ExitBootServices(MapKey, ImageHandle);
- /// TODO: Read catalog and read NewKernel.exe
+ main(handoverHdrPtr);
EFI::Stop();
- return kEfiFail;
+ CANT_REACH();
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
index 00f7bdd8..d0da09b7 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
@@ -15,3 +15,36 @@ EXTERN_C void rt_sti() { asm volatile("sti"); }
EXTERN_C void rt_cld() { asm volatile("cld"); }
EXTERN_C void rt_std() { asm volatile("std"); }
+
+EXTERN_C void Out8(UInt16 port, UInt8 value) {
+ asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+EXTERN_C void Out16(UInt16 port, UInt16 value) {
+ asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+EXTERN_C void Out32(UInt16 port, UInt32 value) {
+ asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+EXTERN_C UInt8 In8(UInt16 port) {
+ UInt8 value;
+ asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+EXTERN_C UInt16 In16(UInt16 port) {
+ UInt16 value;
+ asm volatile("inw %%dx, %%ax" : "=a"(value) : "d"(port));
+
+ return value;
+}
+
+EXTERN_C UInt32 In32(UInt16 port) {
+ UInt32 value;
+ asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
index 7ccc37aa..2ebde023 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
@@ -21,23 +21,27 @@
@brief puts wrapper over EFI ConOut.
*/
BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) {
- if (*str == 0 || !str) return *this;
+#ifdef __DEBUG__
+ if (!str || *str == 0) return *this;
ST->ConOut->OutputString(ST->ConOut, str);
+#endif // ifdef __DEBUG__
return *this;
}
BTextWriter &BTextWriter::Write(const UChar *str) {
- if (*str == 0 || !str) return *this;
+#ifdef __DEBUG__
+ if (!str || *str == 0) return *this;
CharacterTypeUTF16 strTmp[2];
strTmp[1] = 0;
-
+
for (size_t i = 0; str[i] != 0; i++) {
strTmp[0] = str[i];
ST->ConOut->OutputString(ST->ConOut, strTmp);
}
+#endif // ifdef __DEBUG__
return *this;
}
@@ -46,22 +50,29 @@ BTextWriter &BTextWriter::Write(const UChar *str) {
@brief putc wrapper over EFI ConOut.
*/
BTextWriter &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;
}
BTextWriter &BTextWriter::Write(const Long &x) {
+#ifdef __DEBUG__
this->Write(L"0x");
this->_Write(x);
+#endif // ifdef __DEBUG__
+
return *this;
}
BTextWriter &BTextWriter::_Write(const Long &x) {
+#ifdef __DEBUG__
int y = x / 16;
int h = x % 16;
@@ -78,5 +89,7 @@ BTextWriter &BTextWriter::_Write(const Long &x) {
const char NUMBERS[17] = "0123456789ABCDEF";
this->WriteCharacter(NUMBERS[h]);
+#endif // ifdef __DEBUG__
+
return *this;
}
diff --git a/Private/NewBoot/Source/CDROM/.gitkeep b/Private/NewBoot/Source/HEL/POWER/.gitkeep
index e69de29b..e69de29b 100644
--- a/Private/NewBoot/Source/CDROM/.gitkeep
+++ b/Private/NewBoot/Source/HEL/POWER/.gitkeep
diff --git a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S b/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S
new file mode 100644
index 00000000..c611467d
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S
@@ -0,0 +1,34 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+.section .boot_hdr
+.align 4
+
+/* NewBoot boot header begin */
+
+boot_hdr_mag:
+ .ascii "LX"
+boot_hdr_name:
+ // it has to match ten bytes.
+ .asciz "NewBoot\0\0\0"
+boot_hdr_ver:
+ .word 0x104
+boot_hdr_proc:
+ .long bootloader_start
+
+/* NewOS boot header end */
+
+.extern bootloader_main
+.extern bootloader_stack
+
+.globl bootloader_start
+bootloader_start:
+ mflr 4 /* real address of .Laddr */
+ lwz 0,(bootloader_stack-bootloader_start)(4) /* stack address location */
+ mr 1,0 /* use user defined stack */
+
+ bl bootloader_main
+ blr
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx b/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx
index f088d73c..72276ef9 100644
--- a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx
@@ -21,7 +21,7 @@ STATIC const BlockGUID kEPMGuid = {
/// @param namePart partition name
/// @param namePartLength length of name
/// @param bootDev disk interface.
-/// @return
+/// @return
EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength,
BootDevice* bootDev) {
if (namePartLength > kEPMNameLength || !namePart) return No;
@@ -36,11 +36,11 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
BTextWriter writer;
- writer.Write(L"NewOS: Checking for a EPM partition...\r\n");
+ writer.Write(L"NewBoot: Checking for an EPM partition...\r\n");
for (SizeT index = 0; index < kEPMMagicLength; ++index) {
if (buf[index] != kEPMMagic[index]) {
- writer.Write(L"NewOS: Writing a EPM partition...\r\n");
+ writer.Write(L"NewBoot: Writing an EPM partition...\r\n");
BootBlockType* bootBlock = (BootBlockType*)buf;
@@ -113,6 +113,6 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
}
}
- writer.Write(L"NewOS: Partition found, everything's OK.\r\n");
+ writer.Write(L"NewBoot: Partition found, everything's OK.\r\n");
return Yes;
-} \ No newline at end of file
+}
diff --git a/Private/NewBoot/Source/HEL/PowerPC/.gitkeep b/Private/NewBoot/Source/HEL/PowerPC/.gitkeep
deleted file mode 100644
index e69de29b..00000000
--- a/Private/NewBoot/Source/HEL/PowerPC/.gitkeep
+++ /dev/null
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
deleted file mode 100644
index 0b3cd493..00000000
--- a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -------------------------------------------
-
- Copyright Mahrouss Logic
-
-------------------------------------------- */
-
-.section .init
-.align 4
-
-/* NewOS kernel header begin */
-
-boot_hdr_mag:
- .ascii "LX"
-boot_hdr_name:
- // it has to match ten bytes.
- .asciz "NewBoot\0\0\0"
-boot_hdr_ver:
- .word 0x104
-boot_hdr_proc:
- .long bootloader_start
-
-/* NewOS kernel header end */ \ No newline at end of file
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 4016e3a8..197eb91b 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -1,5 +1,5 @@
##################################################
-# (C) Mahrouss Logic, all rights reserved.
+# (C) Mahrouss Logic, all rights reserved.
# This is the bootloader makefile.
##################################################
@@ -20,12 +20,11 @@ endif
IMG=epm.img
IMG_2=epm-slave.img
-EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int -hdd epm-slave.img
+EMU_FLAGS=-net none -smp 4 -m 8G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int -hdd epm-slave.img
-LD_FLAGS=-e efi_main --subsystem=10
-
-OBJ=$(wildcard *.o) $(wildcard HEL/AMD64/*.obj)
+LD_FLAGS=-e Main --subsystem=10
+OBJ=*.o
REM=rm
REM_FLAG=-f
@@ -35,14 +34,25 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KE
.PHONY: invalid-recipe
invalid-recipe:
- @echo "invalid-recipe: Use make bootloader-<arch> all instead."
+ @echo "invalid-recipe: Use make bootloader-<arch> instead."
+
+KERNEL_OBJ=kernel.bin
+DD=dd
+IMG_CREATE=qemu-img
+MAX_KERNEL_SIZE=1024K
+BOOT_LOADER=NewBoot.exe
+KERNEL=NewKernel.exe
.PHONY: all
all: compile-amd64
- $(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe
- $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI
- $(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI
- $(COPY) NewBoot.exe ../../Root/Boot/NewBoot.exe
+ mkdir -p CDROM/EFI/BOOT
+ $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(KERNEL_OBJ)
+ $(IMG_CREATE) create -f raw $(BOOT_LOADER) $(MAX_KERNEL_SIZE)
+ $(DD) if=$(KERNEL_OBJ) of=$(BOOT_LOADER) bs=1 seek=0 conv=notrunc
+ $(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/BOOTX64.EFI
+ $(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/NEWBOOT.EFI
+ $(COPY) $(BOOT_LOADER) ../../Root/Boot/$(BOOT_LOADER)
+ $(COPY) ../../$(KERNEL) CDROM/$(KERNEL)
ifneq ($(DEBUG_SUPPORT), )
DEBUG = -D__DEBUG__
@@ -68,12 +78,13 @@ download-edk:
.PHONY: clean
clean:
- $(REM) $(REM_FLAG) $(OBJ) NewBoot.exe NewKernel.exe OVMF.fd
+ $(REM) $(REM_FLAG) $(OBJ) NewBoot.exe NewKernel.exe OVMF.fd $(IMG) $(IMG_2)
.PHONY: help
help:
@echo "=== HELP ==="
- @echo "epm-img: Format a disk using the Explicit Partition Map/GPT."
+ @echo "epm-img: Format a disk using the Explicit Partition Map."
+ @echo "gpt-img: Format a disk using the Explicit Partition Map."
@echo "clean: clean bootloader."
@echo "bootloader-amd64: Build bootloader. (PC AMD64)"
@echo "run-efi-amd64: Run bootloader. (PC AMD64)"