summaryrefslogtreecommitdiffhomepage
path: root/dev/ZBA/Sources
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-04 12:56:23 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-04 12:56:23 +0200
commita0a90c80e5dd17df8f609aebc253b4bf9147f90f (patch)
tree459f98ea125db490e887bd85b38fd9165a9491b4 /dev/ZBA/Sources
parentcc9ce57cac59bd443e2319e3b8f427172b93f7da (diff)
Created a new branch for the overhaul project.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZBA/Sources')
-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.cxx77
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx8
-rw-r--r--dev/ZBA/Sources/Thread.cxx2
4 files changed, 52 insertions, 41 deletions
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..55f10ea2 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.
@@ -186,17 +188,45 @@ 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(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk)
+ ;
- while (BS->AllocatePool(EfiLoaderData, kHandoverHeapSz, &handoverHdrPtr->f_HeapStart) != kEfiOk)
+ auto extended_heap = (VoidPtr)((UIntPtr)handoverHdrPtr->f_BitMapStart + kHandoverHeapSz);
+
+ while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &extended_heap) != kEfiOk)
;
handoverHdrPtr->f_VirtualSize =
Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS;
+ handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST;
+
+ BFileReader readerSysChk(L"syschk.sys", ImageHandle);
+ readerSysChk.ReadAll(0);
+
+ Boot::BThread* loaderSysChk = nullptr;
+
+ // ------------------------------------------ //
+ // If we succeed in reading the blob, then execute it.
+ // ------------------------------------------ //
+
+ if (readerSysChk.Blob())
+ {
+ loaderSysChk = new Boot::BThread(readerSysChk.Blob());
+ loaderSysChk->SetName("System Check SYS.");
+ }
+
+ loaderSysChk->Start(handoverHdrPtr);
+
+ // nullify these fields, to avoid being reused later.
+
+ handoverHdrPtr->f_FirmwareCustomTables[0] = nullptr;
+ handoverHdrPtr->f_FirmwareCustomTables[1] = nullptr;
+
handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
handoverHdrPtr->f_Magic = kHandoverMagic;
@@ -213,6 +243,12 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
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;
@@ -226,37 +262,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
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;
-
- BFileReader readerSysChk(L"syschk.sys", ImageHandle);
- readerSysChk.ReadAll(0);
-
- Boot::BThread* loaderSysChk = nullptr;
-
- // ------------------------------------------ //
- // If we succeed in reading the blob, then execute it.
- // ------------------------------------------ //
-
- if (readerSysChk.Blob())
- {
- loaderSysChk = new Boot::BThread(readerSysChk.Blob());
- loaderSysChk->SetName("64-bit System Check DLL.");
- }
-
- loaderSysChk->Start(handoverHdrPtr);
-
- // nullify these fields, to avoid being reused later.
-
- handoverHdrPtr->f_FirmwareCustomTables[0] = nullptr;
- handoverHdrPtr->f_FirmwareCustomTables[1] = nullptr;
-
BFileReader readerKernel(L"newoskrnl.exe", ImageHandle);
readerKernel.ReadAll(0);
@@ -270,7 +275,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();
}
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
index 467f4303..65ea3d89 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx
@@ -25,7 +25,7 @@
*/
BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str)
{
-#ifdef __DEBUG__
+#ifdef __DEBUG_OUTPUT__
if (!str || *str == 0)
return *this;
@@ -57,7 +57,7 @@ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str)
/// @param str the input string.
BTextWriter& BTextWriter::Write(const Char* str)
{
-#ifdef __DEBUG__
+#ifdef __DEBUG_OUTPUT__
if (!str || *str == 0)
return *this;
@@ -87,7 +87,7 @@ BTextWriter& BTextWriter::Write(const Char* str)
BTextWriter& BTextWriter::Write(const UChar* str)
{
-#ifdef __DEBUG__
+#ifdef __DEBUG_OUTPUT__
if (!str || *str == 0)
return *this;
@@ -120,7 +120,7 @@ BTextWriter& BTextWriter::Write(const UChar* str)
*/
BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c)
{
-#ifdef __DEBUG__
+#ifdef __DEBUG_OUTPUT__
EfiCharType str[2];
str[0] = c;
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()