summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-04-26 12:29:13 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-04-26 12:29:13 +0000
commit97eb8462433a831f8a02a08acfc7ca32e794d37d (patch)
treee7cddb857e50a2cca41a5364b4240cd8c6c0ec13 /Private/NewBoot/Source
parentf7a7080d18ac2be758b242c22f020c018b1c4824 (diff)
parent313c303fab092b1c45e615f960826375e7eef093 (diff)
Merged in MHR-16 (pull request #6)
MHR-16 - A lot of features and USA design.
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/CDROM/SplashScreen.fmt7
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx3
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx105
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx8
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootJump.S9
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx88
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx11
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootString.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx8
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx17
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Support.cxx49
-rw-r--r--Private/NewBoot/Source/HEL/POWER/BootEPM.cxx118
-rw-r--r--Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S (renamed from Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S)2
-rw-r--r--Private/NewBoot/Source/makefile28
14 files changed, 215 insertions, 240 deletions
diff --git a/Private/NewBoot/Source/CDROM/SplashScreen.fmt b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
index a3dba676..857c63a1 100644
--- a/Private/NewBoot/Source/CDROM/SplashScreen.fmt
+++ b/Private/NewBoot/Source/CDROM/SplashScreen.fmt
@@ -1,6 +1,7 @@
-Welcome to the NeWS.
+Welcome to NeWS.
-Brought to you by:
-* MicroKernel, Bootloader: Amlal EL Mahrouss.
+Brought to you by: Amlal EL Mahrouss.
+* NewBoot, NewKernel: Amlal EL Mahrouss.
+This copy can boot directly to NewKernel (Unified System).
Copyright Mahrouss-Logic, all rights reserved.
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
index d736ac59..d04a94d3 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
@@ -15,4 +15,7 @@
*
*/
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/HW/SATA.hxx>
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
index 4e41ba2e..8ab7dc20 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
@@ -15,8 +15,9 @@
*
*/
-#include <BootKit/HW/ATA.hxx>
+#include <FirmwareKit/EFI.hxx>
#include <BootKit/BootKit.hxx>
+#include <BootKit/HW/ATA.hxx>
/// bugs: 0
@@ -24,7 +25,7 @@
static Boolean kATADetected = false;
static Int32 kATADeviceType = kATADeviceCount;
-static CharacterTypeUTF8 kATAData[kATADataLen] = {0};
+static UInt16 kATAData[kATADataLen] = {0};
Boolean boot_ata_detected(Void);
@@ -55,7 +56,7 @@ Void boot_ata_select(UInt16 Bus) {
Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus,
UInt8& OutMaster) {
- if (boot_ata_detected()) return false;
+ if (boot_ata_detected()) return true;
BTextWriter writer;
@@ -81,103 +82,60 @@ ATAInit_Retry:
Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
- BSetMem(kATAData, 0, kATADataLen);
-
/// fetch serial info
/// model, speed, number of sectors...
boot_ata_wait_io(IO);
for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) {
- kATAData[indexData] = In16(IO + ATA_REG_DATA);
+ kATAData[indexData] = In8(IO + ATA_REG_DATA);
}
OutBus =
(Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary;
- OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE;
-
- Out8(Bus + ATA_REG_HDDEVSEL, 0xA0 | ATA_MASTER << 4);
-
- In8(Bus + ATA_REG_CONTROL);
- In8(Bus + ATA_REG_CONTROL);
- In8(Bus + ATA_REG_CONTROL);
- In8(Bus + ATA_REG_CONTROL);
-
- unsigned cl = In8(Bus + ATA_CYL_LOW); /* get the "signature bytes" */
- unsigned ch = In8(Bus + ATA_CYL_HIGH);
-
- /* differentiate ATA, ATAPI, SATA and SATAPI */
- if (cl == 0x14 && ch == 0xEB) {
- writer.Write(L"New Boot: PATAPI drive detected.\r\n");
- kATADeviceType = kATADevicePATA_PI;
- }
- if (cl == 0x69 && ch == 0x96) {
- writer.Write(L"New Boot: SATAPI drive detected.\r\n");
- kATADeviceType = kATADeviceSATA_PI;
- }
-
- if (cl == 0x0 && ch == 0x0) {
- writer.Write(L"New Boot: PATA drive detected.\r\n");
- kATADeviceType = kATADevicePATA;
- }
-
- if (cl == 0x3c && ch == 0xc3) {
- writer.Write(L"New Boot: SATA drive detected.\r\n");
- kATADeviceType = kATADeviceSATA;
- }
- Out8(IO + ATA_REG_CONTROL, 0x02);
+ OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE;
return true;
}
Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
SizeT SectorSz, SizeT Size) {
- UInt8 Command = (!Master ? 0xE0 : 0xF0);
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
boot_ata_wait_io(IO);
+ boot_ata_select(IO);
- Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF));
- Out8(IO + ATA_REG_SEC_COUNT0, SectorSz);
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+ Out8(IO + ATA_REG_SEC_COUNT0, 1);
Out8(IO + ATA_REG_LBA0, (Lba));
Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
- Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+ Out8(IO + ATA_REG_LBA4, (Lba) >> 24);
Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
- while ((In8(ATA_COMMAND(IO))) & ATA_SR_BSY) boot_ata_wait_io(IO);
-
- UInt16 byte = In16(IO + ATA_REG_DATA);
- SizeT IndexOff = 0UL;
- Buf[IndexOff] = byte;
-
- while (byte != 0xFF) {
- if (IndexOff > Size) break;
-
- ++IndexOff;
-
- while ((In8(ATA_COMMAND(IO))) & ATA_SR_BSY) boot_ata_wait_io(IO);
-
- byte = In16(IO + ATA_REG_DATA);
- Buf[IndexOff] = byte;
+ for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
+ boot_ata_wait_io(IO);
+ Buf[IndexOff] = In16(IO + ATA_REG_DATA);
}
}
Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
SizeT SectorSz, SizeT Size) {
- UInt8 Command = (!Master ? 0xE0 : 0xF0);
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
boot_ata_wait_io(IO);
+ boot_ata_select(IO);
- Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF));
- Out8(IO + ATA_REG_SEC_COUNT0, SectorSz);
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+ Out8(IO + ATA_REG_SEC_COUNT0, 1);
Out8(IO + ATA_REG_LBA0, (Lba));
Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
- Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+ Out8(IO + ATA_REG_LBA4, (Lba) >> 24);
Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
@@ -203,17 +161,11 @@ Boolean boot_ata_detected(Void) { return kATADetected; }
* @param void none.
*/
BootDeviceATA::BootDeviceATA() noexcept {
- if (boot_ata_detected()) return;
-
if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus,
this->Leak().mMaster) ||
boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus,
this->Leak().mMaster)) {
kATADetected = true;
-
- BTextWriter writer;
-
- writer.Write(L"New Boot: Drive is OnLine.\r\n");
}
}
/**
@@ -236,7 +188,9 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz
if (!Buf || SectorSz < 1) return *this;
- boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster,
+ auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize;
+
+ boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster,
Buf, SectorSz, this->Leak().mSize);
return *this;
@@ -257,7 +211,9 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS
if (!Buf || SectorSz < 1) return *this;
- boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster,
+ auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize;
+
+ boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster,
Buf, SectorSz, this->Leak().mSize);
return *this;
@@ -268,3 +224,14 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS
* @return BootDeviceATA::ATATrait& the drive config.
*/
BootDeviceATA::ATATrait& BootDeviceATA::Leak() { return mTrait; }
+
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+SizeT BootDeviceATA::GetSectorsCount() noexcept {
+ return (kATAData[61] << 16)| kATAData[60];
+}
+
+SizeT BootDeviceATA::GetDiskSize() noexcept {
+ return this->GetSectorsCount() * BootDeviceATA::kSectorSize;
+}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
index 33067380..b2d728ae 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx
@@ -8,6 +8,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
#include <FirmwareKit/Handover.hxx>
#include <cstddef>
@@ -64,7 +66,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
if (efp->OpenVolume(efp, &rootFs) != kEfiOk) {
mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r\n");
- EFI::RaiseHardError(L"NoSuchVolume", L"No Such volume.");
+ EFI::ThrowError(L"NoSuchVolume", L"No Such volume.");
this->mErrorCode = kNotSupported;
return;
}
@@ -76,7 +78,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ")
.Write(mPath)
.Write(L"\r\n");
- EFI::RaiseHardError(L"NoSuchPath", L"No Such file on filesystem.");
+ EFI::ThrowError(L"NoSuchPath", L"No Such file on filesystem.");
this->mErrorCode = kNotSupported;
return;
}
@@ -108,7 +110,7 @@ Void BFileReader::ReadAll(SizeT until, SizeT chunk) {
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.");
+ EFI::ThrowError(L"OutOfMemory", L"Allocation error.");
}
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootJump.S b/Private/NewBoot/Source/HEL/AMD64/BootJump.S
new file mode 100644
index 00000000..af278cc7
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/BootJump.S
@@ -0,0 +1,9 @@
+.global rt_jump_to_address
+.text
+
+.code64
+.intel_syntax noprefix
+
+rt_jump_to_address:
+ jmp rcx
+ ret
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 42852b5d..68762089 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -4,19 +4,31 @@
------------------------------------------- */
-#include <BootKit/BootKit.hxx>
#include <BootKit/Rsrc/NewBoot.rsrc>
#include <Builtins/Toolbox/Toolbox.hxx>
+#include <FirmwareKit/EFI.hxx>
#include <KernelKit/MSDOS.hpp>
#include <KernelKit/PEF.hpp>
+#include <NewKit/Macros.hpp>
+#include <BootKit/BootKit.hxx>
#include <NewKit/Ref.hpp>
+#include <cstring>
+
+/// make the compiler shut up.
+#ifndef kMachineModel
+#define kMachineModel "NeWS HD"
+#endif // !kMachineModel
/** Graphics related. */
+EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH);
+
STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
STATIC UInt16 kStride = 0U;
STATIC EfiGUID kGopGuid;
+EXTERN_C Void rt_jump_to_address(VoidPtr blob);
+
/**
@brief Finds and stores the GOP.
*/
@@ -58,9 +70,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
.Write(SystemTable->FirmwareVendor)
.Write(L"\r\n");
- BootDeviceATA ataDev;
- Boolean isGptFound = No;
-
UInt32 MapKey = 0;
UInt32* SizePtr = nullptr;
EfiMemoryDescriptor* Descriptor = nullptr;
@@ -69,7 +78,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
kEfiOk) {
- EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!");
+ EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!");
}
/****
@@ -82,7 +91,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
(VoidPtr*)&Descriptor) != kEfiOk) {
- EFI::RaiseHardError(L"Bad-Alloc", L"New Boot ran out of memory!");
+ EFI::ThrowError(L"Bad-Alloc", L"New Boot ran out of memory!");
}
HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
@@ -168,41 +177,56 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
}
}
- BFileReader kernelFile(L"NewLoader.exe", ImageHandle);
- kernelFile.ReadAll(MIB(1), 4096);
+ ///
+ /// The following checks for an exisiting partition
+ /// inside the disk, if it doesn't have one,
+ /// format the disk.
+ //
- if (kernelFile.Blob()) {
- PEFContainer* headerKind =
- reinterpret_cast<PEFContainer*>(kernelFile.Blob());
+ BDiskFormatFactory<BootDeviceATA> diskFormatter;
- if (headerKind->Magic[0] == kPefMagic[0] &&
- headerKind->Magic[1] == kPefMagic[1] &&
- headerKind->Magic[2] == kPefMagic[2] &&
- headerKind->Magic[3] == kPefMagic[3] &&
- headerKind->Magic[4] == kPefMagic[4]) {
- if (headerKind->Abi != kPefAbi || headerKind->Cpu != kPefArchAMD64) {
- EFI::RaiseHardError(L"Bad-Architecture",
- L"New Boot can't run this architecture.");
- }
+ if (!diskFormatter) {
+ BDiskFormatFactory<BootDeviceATA>::BFileDescriptor rootDesc{0};
- BootMainKind main = (BootMainKind) nullptr;
+ memcpy(rootDesc.fFileName, "/", strlen("/"));
+ memcpy(rootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork));
- if (!main) {
- EFI::RaiseHardError(L"Bad-Exec",
- L"New Boot can't recognize this executable.");
- }
+ rootDesc.fBlobSz = BootDeviceATA::kSectorSize;
+ rootDesc.fBlob = new Char[rootDesc.fBlobSz];
- EFI::ExitBootServices(MapKey, ImageHandle);
+ memset(rootDesc.fBlob, 0, rootDesc.fBlobSz);
- main(handoverHdrPtr);
+ memcpy(rootDesc.fBlob, kMachineModel " startup disk.",
+ strlen(kMachineModel " startup disk."));
- EFI::Stop();
+ rootDesc.fKind = kNewFSCatalogKindDir;
- CANT_REACH();
- }
+ BDiskFormatFactory<BootDeviceATA>::BFileDescriptor bootDesc{0};
+
+ bootDesc.fKind = kNewFSCatalogKindDir;
+
+ memcpy(bootDesc.fFileName, "/Boot", strlen("/Boot"));
+ memcpy(bootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork));
+
+ bootDesc.fBlobSz = BootDeviceATA::kSectorSize;
+ bootDesc.fBlob = new Char[rootDesc.fBlobSz];
+
+ memset(bootDesc.fBlob, 0, bootDesc.fBlobSz);
+
+ memcpy(bootDesc.fBlob, kMachineModel " startup folder.",
+ strlen(kMachineModel " startup folder."));
+
+ rootDesc.fNext = &bootDesc;
+ rootDesc.fNext->fPrev = &rootDesc;
+
+ diskFormatter.Format(kMachineModel, &rootDesc, 2);
}
- EFI::RaiseHardError(L"Invalid-PEF-Executable", L"PEF executable expected. Got something else.");
+ EFI::ExitBootServices(MapKey, ImageHandle);
+
+ hal_init_platform(kHandoverHeader);
+
+ 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 d0da09b7..2ac90dd8 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
@@ -4,7 +4,12 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
+#include "HALKit/AMD64/Processor.hpp"
+
+#if 0
EXTERN_C void rt_hlt() { asm volatile("hlt"); }
@@ -48,3 +53,9 @@ EXTERN_C UInt32 In32(UInt16 port) {
return value;
}
+
+#else
+
+void rt_hlt() { NewOS::HAL::rt_halt(); }
+
+#endif // 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
index 1c6b528e..ef0e4744 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx
@@ -11,6 +11,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
/// bugs 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
index 2ebde023..fc91a02a 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx
@@ -11,6 +11,8 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
/// BUGS: 0
@@ -30,7 +32,7 @@ BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) {
return *this;
}
-BTextWriter &BTextWriter::Write(const UChar *str) {
+BTextWriter &BTextWriter::Write(const Char *str) {
#ifdef __DEBUG__
if (!str || *str == 0) return *this;
@@ -73,8 +75,8 @@ BTextWriter &BTextWriter::Write(const Long &x) {
BTextWriter &BTextWriter::_Write(const Long &x) {
#ifdef __DEBUG__
- int y = x / 16;
- int h = x % 16;
+ UInt64 y = (x > 0 ? x : -x) / 16;
+ UInt64 h = (x > 0 ? x : -x) % 16;
if (y) this->_Write(y);
diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
index 1bb2d9ca..909ccca6 100644
--- a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
@@ -4,9 +4,13 @@
------------------------------------------- */
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
#include <BootKit/BootKit.hxx>
#include <cstddef> /* Since we're using GCC for this EFI program. */
+#if 0
+
/// @brief Allocates a new object.
/// @param sz the size.
/// @return
@@ -18,6 +22,17 @@ void* operator new(size_t sz)
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)
@@ -32,3 +47,5 @@ void operator delete(void* buf, size_t size)
{
BS->FreePool(buf);
}
+
+#endif // Inactive
diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
new file mode 100644
index 00000000..a8e2c275
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx
@@ -0,0 +1,49 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <FirmwareKit/EFI/EFI.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <BootKit/Vendor/Support.hxx>
+
+#if 0
+
+/// @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) {
+ SetMem(dst, byte, len);
+ 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) {
+ CopyMem(dst, src, len);
+ return dst;
+}
+
+/// @brief strlen definition in C++.
+EXTERN_C size_t strlen(const char *whatToCheck) {
+ if (!whatToCheck || *whatToCheck == 0) return 0;
+
+ SizeT len = 0;
+
+ while (whatToCheck[len] != 0) {
+ ++len;
+ }
+
+ return len;
+}
+
+/// @brief somthing specific to the microsoft ABI, regarding checking the stack.
+EXTERN_C void ___chkstk_ms(void) {}
+
+#endif
diff --git a/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx b/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx
deleted file mode 100644
index 72276ef9..00000000
--- a/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx
+++ /dev/null
@@ -1,118 +0,0 @@
-/* -------------------------------------------
-
- Copyright Mahrouss Logic
-
-------------------------------------------- */
-
-#include <BootKit/BootKit.hxx>
-#include <FSKit/NewFS.hxx>
-
-#define kEPMSectorSize (1024U)
-#define kEPMSwapSize MIB(16)
-
-// {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 = kEPMStartPartitionBlk;
- bootDev->Leak().mSize = kEPMSectorSize;
-
- Char buf[kEPMSectorSize] = {0};
-
- bootDev->Read(buf, 1);
-
- BTextWriter writer;
-
- 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"NewBoot: Writing an 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));
-
- char* fsName = "NewFS";
- int fsNameLength = 6;
-
- for (SizeT i = 0; i < fsNameLength; ++i) {
- partBlock->Fs[i] = fsName[i];
- }
-
- partBlock->Version = kEPMNewOS;
-
- char* partName = "System HD";
- int partNameLength = 10;
-
- for (SizeT i = 0; i < partNameLength; ++i) {
- partBlock->Name[i] = partName[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;
-
- partName = "Swap HD";
- partNameLength = 8;
-
- for (SizeT i = 0; i < partNameLength; ++i) {
- swapBlock->Name[i] = partName[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"NewBoot: Partition found, everything's OK.\r\n");
- return Yes;
-}
diff --git a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S b/Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S
index c611467d..41fc6ae2 100644
--- a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S
+++ b/Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S
@@ -10,7 +10,7 @@
/* NewBoot boot header begin */
boot_hdr_mag:
- .ascii "LX"
+ .ascii "CB"
boot_hdr_name:
// it has to match ten bytes.
.asciz "NewBoot\0\0\0"
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 2f9e3756..8306f844 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -18,13 +18,17 @@ else
EMU=qemu-system-x86_64
endif
+ifeq ($(NEWS_MODEL), )
+NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\""
+endif
+
IMG=epm.img
IMG_2=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 Main --subsystem=10
-OBJ=*.o
+OBJ=*.o ../../Objects/*.obj
REM=rm
REM_FLAG=-f
@@ -36,7 +40,7 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__
invalid-recipe:
@echo "invalid-recipe: Use make bootloader-<arch> instead."
-KERNEL_OBJ=kernel.bin
+KERNEL_OBJ=boot.bin
DD=dd
IMG_CREATE=qemu-img
MAX_KERNEL_SIZE=1024K
@@ -46,12 +50,9 @@ KERNEL=NewKernel.exe
.PHONY: all
all: compile-amd64
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
+ $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(BOOT_LOADER)
$(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/BOOTX64.EFI
$(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/NEWBOOT.EFI
- $(COPY) $(BOOT_LOADER) ../../Root/Boot/$(BOOT_LOADER)
ifneq ($(DEBUG_SUPPORT), )
DEBUG = -D__DEBUG__
@@ -59,8 +60,8 @@ endif
.PHONY: compile-amd64
compile-amd64:
- $(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o
- $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard *.cxx)
+ # $(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o
+ $(CC_GNU) $(NEWOS_MODEL) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx)
.PHONY: run-efi-amd64
run-efi-amd64:
@@ -68,16 +69,21 @@ run-efi-amd64:
.PHONY: epm-img
epm-img:
- qemu-img create -f raw $(IMG) 256M
- qemu-img create -f raw $(IMG_2) 512M
+ qemu-img create -f qcow2 $(IMG) 512M
+ qemu-img create -f qcow2 $(IMG_2) 512M
.PHONY: download-edk
download-edk:
$(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
+BINS=*.bin
+EXECUTABLES=NewBoot.exe NewKernel.exe OVMF.fd
+
+TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES)
+
.PHONY: clean
clean:
- $(REM) $(REM_FLAG) $(OBJ) NewBoot.exe NewKernel.exe OVMF.fd $(IMG) $(IMG_2)
+ $(REM) $(TARGETS)
.PHONY: help
help: