summaryrefslogtreecommitdiffhomepage
path: root/dev/ZBA
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-09-05 19:13:02 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-09-05 19:13:02 +0000
commit621e814da6d5005ade8a1fe3f378a363db559cf7 (patch)
tree438f1337c0eb2ae83cf3d409c29848d396be08b2 /dev/ZBA
parentcc9ce57cac59bd443e2319e3b8f427172b93f7da (diff)
parent3b60a1e87ab02a1b72d8bb9f7392780899d5a0d7 (diff)
Merged in major-refactor (pull request #19)
Major refactor
Diffstat (limited to 'dev/ZBA')
-rw-r--r--dev/ZBA/BootKit/BootKit.hxx81
-rw-r--r--dev/ZBA/Modules/NetBoot/build.json2
-rw-r--r--dev/ZBA/Modules/SysChk/Module.cxx2
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootAPI.S (renamed from dev/ZBA/Sources/HEL/AMD64/BootJump.S)6
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootMain.cxx93
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx9
-rw-r--r--dev/ZBA/Sources/Thread.cxx2
-rw-r--r--dev/ZBA/amd64-efi.make4
8 files changed, 88 insertions, 111 deletions
diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx
index 6ac87b82..3f7b0a96 100644
--- a/dev/ZBA/BootKit/BootKit.hxx
+++ b/dev/ZBA/BootKit/BootKit.hxx
@@ -15,10 +15,10 @@
#include <FirmwareKit/EPM.hxx>
#include <CompilerKit/Version.hxx>
-/// include NewFS header and Support header as well.
+/// include NeFS header and Support header as well.
#include <cstring>
-#include <FSKit/NewFS.hxx>
+#include <FSKit/NeFS.hxx>
#include <BootKit/Support.hxx>
/***********************************************************************************/
@@ -193,7 +193,7 @@ public:
/// @brief File entry for **BDiskFormatFactory**.
struct BFileDescriptor final
{
- Char fFileName[kNewFSNodeNameLen];
+ Char fFileName[kNeFSNodeNameLen];
Int32 fKind;
};
@@ -219,7 +219,7 @@ public:
/// @brief check if partition is good.
Bool IsPartitionValid() noexcept
{
- fDiskDev.Leak().mBase = (kNewFSRootCatalogStartAddress);
+ fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress);
fDiskDev.Leak().mSize = BootDev::kSectorSize;
Char buf[BootDev::kSectorSize] = {0};
@@ -230,18 +230,18 @@ public:
BTextWriter writer;
- for (SizeT indexMag = 0UL; indexMag < kNewFSIdentLen; ++indexMag)
+ for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag)
{
- if (blockPart->Ident[indexMag] != kNewFSIdent[indexMag])
+ if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag])
return false;
}
- writer.Write(L"newosldr: Disk size: ").Write(this->fDiskDev.GetDiskSize()).Write(L"\r");
+ writer.Write(L"newosldr: Disk is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r");
if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() ||
blockPart->DiskSize < 1 ||
blockPart->SectorSize != BootDev::kSectorSize ||
- blockPart->Version != kNewFSVersionInteger ||
+ blockPart->Version != kNeFSVersionInteger ||
blockPart->StartCatalog == 0)
{
return false;
@@ -251,7 +251,7 @@ public:
return false;
}
- writer.Write(L"newosldr: Partition name: ").Write(blockPart->PartitionName).Write(L" is healthy.\r");
+ writer.Write(L"newosldr: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r");
return true;
}
@@ -260,7 +260,7 @@ private:
/// @brief Write all of the requested catalogs into the filesystem.
/// @param fileBlobs the blobs.
/// @param blobCount the number of blobs to write.
- /// @param partBlock the NewFS partition block.
+ /// @param partBlock the NeFS partition block.
Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock)
{
BFileDescriptor* blob = fileBlobs;
@@ -269,14 +269,14 @@ private:
NFS_CATALOG_STRUCT catalogKind{0};
- constexpr auto cNewFSCatalogPadding = 4;
+ constexpr auto cNeFSCatalogPadding = 4;
catalogKind.PrevSibling = startLba;
- catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding);
+ catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding);
/// Fill catalog kind.
catalogKind.Kind = blob->fKind;
- catalogKind.Flags = kNewFSFlagCreated;
+ catalogKind.Flags = kNeFSFlagCreated;
--partBlock.FreeCatalog;
--partBlock.FreeSectors;
@@ -316,7 +316,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName,
/// @note A catalog roughly equal to a sector.
- constexpr auto cMinimumDiskSize = 10; // at minimum.
+ constexpr auto cMinimumDiskSize = 4; // at minimum.
/// @note also look at EPM headers, for free part blocks.
@@ -325,70 +325,37 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName,
EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here.");
return false;
}
-
- fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress;
- fDiskDev.Leak().mSize = sectorSz;
-
+
NFS_ROOT_PARTITION_BLOCK partBlock{0};
- fDiskDev.Read((Char*)&partBlock, sizeof(NFS_ROOT_PARTITION_BLOCK));
-
- if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen) == 0 &&
- partBlock.Version != kNewFSVersionInteger)
- {
- if (partBlock.Version != 0)
- {
- BTextWriter writer;
- writer.Write(L"newosldr: Disk partition updated.\r");
-
- partBlock.Version = kNewFSVersionInteger;
-
- fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress;
- fDiskDev.Leak().mSize = sectorSz;
-
- fDiskDev.Write((Char*)&partBlock, sectorSz);
-
- return true;
- }
- }
- else if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen))
- {
- BTextWriter writer;
- writer.Write(L"newosldr: Disk partition error, not a valid one.\r");
-
- // TODO: Find a way to use EFI::Stop.
- while (1)
- ;
- }
-
- CopyMem(partBlock.Ident, kNewFSIdent, kNewFSIdentLen - 1);
+ CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1);
CopyMem(partBlock.PartitionName, partName, strlen(partName));
- partBlock.Version = kNewFSVersionInteger;
+ partBlock.Version = kNeFSVersionInteger;
partBlock.CatalogCount = blobCount;
- partBlock.Kind = kNewFSHardDrive;
+ partBlock.Kind = kNeFSHardDrive;
partBlock.SectorSize = sectorSz;
partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT);
partBlock.SectorCount = fDiskDev.GetSectorsCount();
partBlock.FreeSectors = fDiskDev.GetSectorsCount();
- partBlock.StartCatalog = kNewFSCatalogStartAddress;
+ partBlock.StartCatalog = kNeFSCatalogStartAddress;
partBlock.DiskSize = fDiskDev.GetDiskSize();
- partBlock.Flags = kNewFSPartitionTypeBoot | kNewFSPartitionTypeStandard;
+ partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard;
- fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress;
+ fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress;
fDiskDev.Leak().mSize = sectorSz;
fDiskDev.Write((Char*)&partBlock, sectorSz);
BOOT_BLOCK_STRUCT epmBoot{0};
- constexpr auto cFsName = "NewFS";
+ constexpr auto cFsName = "NeFS";
constexpr auto cBlockName = "ZKA:";
CopyMem(epmBoot.Fs, reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), StrLen(cFsName));
- epmBoot.FsVersion = kNewFSVersionInteger;
- epmBoot.LbaStart = kNewFSRootCatalogStartAddress;
+ epmBoot.FsVersion = kNeFSVersionInteger;
+ epmBoot.LbaStart = kNeFSRootCatalogStartAddress;
epmBoot.SectorSz = partBlock.SectorSize;
epmBoot.NumBlocks = partBlock.CatalogCount;
diff --git a/dev/ZBA/Modules/NetBoot/build.json b/dev/ZBA/Modules/NetBoot/build.json
index 78336241..c24966d9 100644
--- a/dev/ZBA/Modules/NetBoot/build.json
+++ b/dev/ZBA/Modules/NetBoot/build.json
@@ -11,7 +11,7 @@
"-fPIC",
"-fno-rtti",
"-fno-exceptions",
- "-Wl,--subsystem=17,--image-base 0x10000000"
+ "-Wl,--subsystem=17,--image-base,0x1000000"
],
"cpp_macros": [
"__NEWOSKRNL__",
diff --git a/dev/ZBA/Modules/SysChk/Module.cxx b/dev/ZBA/Modules/SysChk/Module.cxx
index 9bc3425c..7bf7fb62 100644
--- a/dev/ZBA/Modules/SysChk/Module.cxx
+++ b/dev/ZBA/Modules/SysChk/Module.cxx
@@ -15,7 +15,7 @@ EXTERN_C Int32 ModuleMain(Kernel::HEL::HandoverInformationHeader* Handover)
cST->ConOut->ClearScreen(cST->ConOut);
- cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: CHECKING FOR VALID NEWFS OR EXT4 PARTITIONS...\r\n");
+ cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: CHECKING FOR VALID NEWFS OR HPFS PARTITIONS...\r\n");
cST->ConOut->OutputString(cST->ConOut, L"SYSCHK: GOOD TO GO!\r\n");
return kEfiOk;
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootJump.S b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S
index d8e09d4e..e391351d 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootJump.S
+++ b/dev/ZBA/Sources/HEL/AMD64/BootAPI.S
@@ -39,3 +39,9 @@ wait_gate2:
mov cr4,rax
reset_wait:
jmp reset_wait
+
+.global write_cr3
+
+write_cr3:
+ mov cr3, rcx
+ ret \ No newline at end of file
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
index 576ada08..9cccc922 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
@@ -79,6 +79,8 @@ STATIC Bool CheckBootDevice(BootDeviceATA& ataDev)
return true;
}
+EXTERN_C Void write_cr3(VoidPtr new_cr3);
+
/// @brief Main EFI entrypoint.
/// @param ImageHandle Handle of this image.
/// @param SystemTable The system table of it.
@@ -152,6 +154,27 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1;
// Fill handover header now.
+ BDiskFormatFactory<BootDeviceATA> checkPart;
+
+ // ---------------------------------------------------- //
+ // The following checks for an exisiting partition
+ // inside the disk, if it doesn't have one,
+ // format the disk.
+ // ---------------------------------------------------- //
+
+ if (!checkPart.IsPartitionValid())
+ {
+ BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root;
+ root.fFileName[0] = kNeFSRoot[0];
+ root.fFileName[1] = 0;
+
+ root.fKind = kNeFSCatalogKindDir;
+
+ checkPart.Format("ZKA (A:)", &root, 1);
+
+ rt_reset_hardware();
+ }
+
BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc);
Descriptor = new EfiMemoryDescriptor[SzDesc];
@@ -186,52 +209,14 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] =
(UIntPtr)Descriptor;
- handoverHdrPtr->f_VirtualStart =
- (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart;
+ handoverHdrPtr->f_BitMapStart = 0;
- handoverHdrPtr->f_HeapStart = 0;
-
- while (BS->AllocatePool(EfiLoaderData, kHandoverHeapSz, &handoverHdrPtr->f_HeapStart) != kEfiOk)
+ while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk)
;
handoverHdrPtr->f_VirtualSize =
Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */
- handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
-
- handoverHdrPtr->f_Magic = kHandoverMagic;
- handoverHdrPtr->f_Version = kHandoverVersion;
-
- // Provide fimware vendor name.
-
- BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
- handoverHdrPtr->f_FirmwareVendorLen);
-
- handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
-
- // Assign to global 'kHandoverHeader'.
-
- BDiskFormatFactory<BootDeviceATA> checkPart;
-
- if (!checkPart.IsPartitionValid())
- {
- BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root;
- root.fFileName[0] = kNewFSRoot[0];
- root.fFileName[1] = 0;
-
- root.fKind = kNewFSCatalogKindDir;
-
- checkPart.Format("ZKA (A:)", &root, 1);
-
- rt_reset_hardware();
- }
-
- // ---------------------------------------------------- //
- // The following checks for an exisiting partition
- // inside the disk, if it doesn't have one,
- // format the disk.
- // ---------------------------------------------------- //
-
handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS;
handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST;
@@ -247,7 +232,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
if (readerSysChk.Blob())
{
loaderSysChk = new Boot::BThread(readerSysChk.Blob());
- loaderSysChk->SetName("64-bit System Check DLL.");
+ loaderSysChk->SetName("System Check SYS.");
}
loaderSysChk->Start(handoverHdrPtr);
@@ -257,6 +242,20 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_FirmwareCustomTables[0] = nullptr;
handoverHdrPtr->f_FirmwareCustomTables[1] = nullptr;
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
+ handoverHdrPtr->f_Magic = kHandoverMagic;
+ handoverHdrPtr->f_Version = kHandoverVersion;
+
+ // Provide fimware vendor name.
+
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
+
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
+ // Assign to global 'kHandoverHeader'.
+
BFileReader readerKernel(L"newoskrnl.exe", ImageHandle);
readerKernel.ReadAll(0);
@@ -270,7 +269,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
if (readerKernel.Blob())
{
loader = new Boot::BThread(readerKernel.Blob());
- loader->SetName("64-bit Kernel DLL.");
+ loader->SetName("64-Bit Kernel EXE.");
handoverHdrPtr->f_KernelImage = readerKernel.Blob();
}
@@ -288,11 +287,17 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
urbanistTTF.ReadAll(0);
if (readerSysDrv.Blob() &&
- chimeWav.Blob())
+ chimeWav.Blob() &&
+ urbanistTTF.Blob())
{
handoverHdrPtr->f_StartupChime = chimeWav.Blob();
- handoverHdrPtr->f_StartupImage = readerKernel.Blob();
+ handoverHdrPtr->f_ChimeSz = chimeWav.Size();
+ handoverHdrPtr->f_StartupImage = readerSysDrv.Blob();
+ handoverHdrPtr->f_StartupSz = readerSysDrv.Size();
+ handoverHdrPtr->f_KernelImage = readerKernel.Blob();
+ handoverHdrPtr->f_KernelSz = readerKernel.Size();
handoverHdrPtr->f_TTFallbackFont = urbanistTTF.Blob();
+ handoverHdrPtr->f_FontSz = urbanistTTF.Size();
}
else
{
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
index 467f4303..d43be468 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
@@ -134,7 +134,6 @@ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c)
BTextWriter& BTextWriter::Write(const Long& x)
{
#ifdef __DEBUG__
- this->Write(L"0x");
this->_Write(x);
#endif // ifdef __DEBUG__
@@ -145,14 +144,14 @@ BTextWriter& BTextWriter::Write(const Long& x)
BTextWriter& BTextWriter::_Write(const Long& x)
{
#ifdef __DEBUG__
- UInt64 y = (x > 0 ? x : -x) / 16;
- UInt64 h = (x > 0 ? x : -x) % 16;
+ UInt64 y = (x > 0 ? x : -x) / 10;
+ UInt64 h = (x > 0 ? x : -x) % 10;
if (y)
this->_Write(y);
/* fail if the hex number is not base-16 */
- if (h > 15)
+ if (h > 10)
{
this->WriteCharacter('?');
return *this;
@@ -161,7 +160,7 @@ BTextWriter& BTextWriter::_Write(const Long& x)
if (y < 0)
y = -y;
- const char cNumbers[17] = "0123456789ABCDEF";
+ const char cNumbers[] = "0123456789";
this->WriteCharacter(cNumbers[h]);
#endif // ifdef __DEBUG__
diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx
index 1ea83618..13b02b92 100644
--- a/dev/ZBA/Sources/Thread.cxx
+++ b/dev/ZBA/Sources/Thread.cxx
@@ -165,7 +165,7 @@ namespace Boot
err_fn(handover);
}
- rt_jump_to_address(fStartAddress, handover);
+ reinterpret_cast<HEL::HandoverProc>(fStartAddress)(handover);
}
const Char* BThread::GetName()
diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make
index d75f2aaf..1f8bf1b1 100644
--- a/dev/ZBA/amd64-efi.make
+++ b/dev/ZBA/amd64-efi.make
@@ -29,14 +29,14 @@ IMG=epm-master-1.img
IMG_2=epm-slave.img
IMG_3=epm-master-2.img
-EMU_FLAGS=-net none -m 8G -M q35 -cpu qemu64 \
+EMU_FLAGS=-net none -m 8G -M q35 \
-bios $(BIOS) -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:Sources/Root/,index=2,format=raw \
-drive id=disk_2,file=$(IMG_2),if=none \
-device ahci,id=ahci \
- -device ide-hd,drive=disk_2,bus=ahci.0 -d int
+ -device ide-hd,drive=disk_2,bus=ahci.0 -serial stdio -no-reboot
LD_FLAGS=-e Main --subsystem=10