summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-18 23:10:15 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-18 23:10:15 +0200
commit0ae4062bfe9936cc9fd2c7bb924442480b067d93 (patch)
tree491b3cfc9c751557c37213ff437e56f66d100a4d /Private/NewBoot/Source
parent706c58b9b9fa74c63180f490a1f48652d0408944 (diff)
MHR-5: initial commit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx119
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx119
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx10
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S14
4 files changed, 62 insertions, 200 deletions
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/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f5bb3ce8..a5014f92 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -5,53 +5,41 @@
------------------------------------------- */
#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__
-
#define kMaxBufSize 256
-/// @brief Bootloader main type.
-typedef void (*bt_main_type)(HEL::HandoverInformationHeader* handoverInfo);
+/// @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 efi_main(EfiHandlePtr ImageHandle,
+ EfiSystemTable* SystemTable) {
+ InitEFI(SystemTable); ///! Init the EFI library.
+ InitGOP(); ///! Init the GOP.
BTextWriter writer;
/// Splash screen stuff
- writer.Write(L"Mahrouss-Logic (R) NewOS: ").Write(BVersionString::Shared());
+ writer.Write(L"Mahrouss-Logic (R) NewBoot: ").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;
- }
-
UInt32 MapKey = 0;
UInt32* SizePtr = nullptr;
EfiMemoryDescriptor* Descriptor = nullptr;
@@ -76,46 +64,8 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
}
- /****
- *
- * Get machine memory map.
- *
- */
-
- while (BS->GetMemoryMap(SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
- kEfiOk)
- ;
-
HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
- BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
- (VoidPtr*)&handoverHdrPtr);
-
- handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase;
- handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution;
- handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution;
- handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
- 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;
-
- handoverHdrPtr->f_VirtualStart =
- reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
-
- handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
-
- handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
-
- BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
- handoverHdrPtr->f_FirmwareVendorLen);
-
-#ifdef __DEBUG__
- writer.Write(L"NewOS: Fetching ACPI's 'RSD PTR'...").Write(L"\r\n");
-#endif
-
for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
++indexVT) {
volatile Char* vendorTable = reinterpret_cast<volatile Char*>(
@@ -127,29 +77,48 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
vendorTable[6] == 'R' && vendorTable[7] == ' ') {
handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
-#ifdef __DEBUG__
- writer.Write(L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
- .Write(L"\r\n");
-#endif
+ writer.Write(L"NewBoot: Found RSDP for kernel.\r\n");
break;
}
}
- if (!isEpmFound) {
- writer.Write(L"NewOS: No partition found for NewOS. (HCR-1000)\r\n");
- }
-
handoverHdrPtr->f_Magic = kHandoverMagic;
handoverHdrPtr->f_Version = kHandoverVersion;
- writer.Write(L"Running NewOS...\r\n");
+ 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;
+ handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution;
+ handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
+ handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
+ handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
+
+ BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
+ (VoidPtr*)&handoverHdrPtr);
+
+ handoverHdrPtr->f_PhysicalStart = 0;
+ handoverHdrPtr->f_PhysicalSize = 0;
+
+ 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);
- EFI::ExitBootServices(MapKey, ImageHandle);
+ // EFI::ExitBootServices(MapKey, ImageHandle);
/// TODO: Read catalog and read NewKernel.exe
- EFI::Stop();
+ // EFI::Stop();
- return kEfiFail;
+ CANT_REACH();
}
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
index f088d73c..72276ef9 100644
--- a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/PowerPC/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/BootPowerPC.S b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
index 0b3cd493..53d9d4f2 100644
--- a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
+++ b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
@@ -19,4 +19,16 @@ boot_hdr_ver:
boot_hdr_proc:
.long bootloader_start
-/* NewOS kernel header end */ \ No newline at end of file
+/* NewOS kernel 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