summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 11:39:57 +0000
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 11:39:57 +0000
commit05eca8d3061b60eac0a652a4b1e39269a9af79e8 (patch)
treeaef93af31d679cc5e9ee251f937b5554d0d978c1 /Private/NewBoot
parentf08c864e988f6f1f01985910955755220b37ecc8 (diff)
parent167ef193e25aa58e962620558b8e2685cbded476 (diff)
Merge branch 'HCR-9-add-support-for-file-load-hel-amd64' into 'trunk'
Bootloader: Getting it done now. See merge request mahrouss-logic/micro-kernel!4
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/Arch/ATA.hxx5
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx5
-rw-r--r--Private/NewBoot/BootKit/EPM.hxx2
-rw-r--r--Private/NewBoot/BootKit/Protocol.hxx58
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/ATA.cxx)22
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/BootKit.cxx)40
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx)2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx (renamed from Private/NewBoot/Source/HEL/AMD64/Platform.cxx)4
-rw-r--r--Private/NewBoot/Source/makefile1
9 files changed, 55 insertions, 84 deletions
diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/Arch/ATA.hxx
index 5c42237a..4042aaa9 100644
--- a/Private/NewBoot/BootKit/Arch/ATA.hxx
+++ b/Private/NewBoot/BootKit/Arch/ATA.hxx
@@ -127,13 +127,14 @@ class BATADevice final {
};
explicit BATADevice() noexcept;
+ ~BATADevice() = default;
HCORE_COPY_DEFAULT(BATADevice);
struct ATATraits final {
SizeT mBase{1024};
UInt16 mBus{kPrimary};
- Boolean mMaster{false};
+ Boolean mMaster{true};
};
operator bool() { return ATAIsDetected(); }
@@ -154,3 +155,5 @@ enum {
kATADeviceSATA_PI,
kATADeviceCount,
};
+
+#define kATASectorSz 512
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 70519aba..b0dbccd5 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -48,6 +48,8 @@ class BTextWriter final {
BTextWriter(const BTextWriter &) = default;
};
+HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src,
+ const HCore::SizeT len);
HCore::SizeT BStrLen(const CharacterType *ptr);
HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte,
const HCore::SizeT len);
@@ -80,8 +82,7 @@ class BFileReader final {
private:
Int32 mErrorCode{kOperationOkay};
- CharacterType mPath[255];
- BATADevice mDevice;
+ CharacterType mPath[kPathLen];
};
/***********************************************************************************/
diff --git a/Private/NewBoot/BootKit/EPM.hxx b/Private/NewBoot/BootKit/EPM.hxx
index 803d500c..359eed1b 100644
--- a/Private/NewBoot/BootKit/EPM.hxx
+++ b/Private/NewBoot/BootKit/EPM.hxx
@@ -9,4 +9,4 @@
#pragma once
-#include <HALKit/EPM.hxx>
+#include <EFIKit/EPM.hxx>
diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx
index 2f84d0a8..b2725794 100644
--- a/Private/NewBoot/BootKit/Protocol.hxx
+++ b/Private/NewBoot/BootKit/Protocol.hxx
@@ -9,61 +9,5 @@
#pragma once
+#include <EFIKit/BootProtocol.hxx>
#include <EFIKit/EFI.hxx>
-
-/* useful macros */
-
-#define kHandoverMagic 0xBAD55
-
-#define kBaseHandoverStruct 0x80000000
-#define kHandoverStructSz sizeof(HEL::HandoverHeader)
-
-namespace HCore::HEL {
-/**
- @brief the kind of executable we're loading.
-*/
-enum {
- kTypeKernel = 100,
- kTypeKernelDriver = 101,
- kTypeRsrc = 102,
- kTypeCount = 3,
-};
-
-/**
- @brief The executable architecture.
-*/
-
-enum {
- kArchAmd64 = 122,
- kArchCount = 2,
-};
-
-/**
-@brief The first struct that we read when inspecting The executable
-it tells us more about it and IS format independent.
-*/
-struct __attribute__((packed)) HandoverHeader final {
- Int32 f_TargetMagic;
- Int32 f_TargetType;
- Int32 f_TargetArch;
- UIntPtr f_TargetStartAddress;
-};
-
-struct HandoverInformationHeader {
- HandoverHeader* f_Header;
- voidPtr f_VirtualStart;
- SizeT f_VirtualSize;
- voidPtr f_PhysicalStart;
- SizeT f_PhysicalSize;
- Char f_FirmwareVendorName[32];
- SizeT f_FirmwareVendorLen;
- voidPtr f_RsdPtr;
- voidPtr f_SmBIOS;
- voidPtr f_RTC;
-};
-
-/**
- @brief Handover Jump Proc
-*/
-typedef UInt64 (*HandoverProc)(HandoverInformationHeader* pHandover);
-} // namespace HCore::HEL
diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx
index 4f1b3171..c289bcf5 100644
--- a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx
@@ -114,9 +114,7 @@ Void ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master, CharacterType* Buf,
ATAPoll(IO);
- for (SizeT index = 0UL; index < 256; ++index) {
- Buf[index + Offset] = In16(IO + ATA_REG_DATA);
- }
+ Buf[Offset] = In16(IO + ATA_REG_DATA);
ATAWait(IO);
}
@@ -140,13 +138,13 @@ Void ATAWriteLba(UInt32 Lba, UInt8 Bus, Boolean Master, wchar_t* Buf,
ATAPoll(IO);
- for (SizeT index = 0UL; index < 256; ++index) {
- Out16(IO + ATA_REG_DATA, Buf[index + Offset]);
- }
+ Out16(IO + ATA_REG_DATA, Buf[Offset]);
ATAWait(IO);
}
+Boolean ATAIsDetected(Void) { return kATADetected; }
+
/***
*
*
@@ -155,10 +153,8 @@ Void ATAWriteLba(UInt32 Lba, UInt8 Bus, Boolean Master, wchar_t* Buf,
*
*/
-Boolean ATAIsDetected(Void) { return kATADetected; }
-
/**
- * @brief Init ATA driver.
+ * @brief ATA Device constructor.
* @param void none.
*/
BATADevice::BATADevice() noexcept {
@@ -189,13 +185,9 @@ BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) {
if (!Buf || Sz < 1) return *this;
- SizeT Off = 0;
-
for (SizeT i = 0UL; i < Sz; ++i) {
ATAReadLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster,
- Buf, Off);
-
- Off += 512;
+ Buf, i);
}
return *this;
@@ -217,7 +209,7 @@ BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& Sz) {
ATAWriteLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster,
Buf, Off);
- Off += 512;
+ Off += kATASectorSz;
}
return *this;
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
index 99f8d41b..600a8fcc 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
@@ -9,10 +9,27 @@
#include <BootKit/BootKit.hxx>
#include <EFIKit/Api.hxx>
+#include <FSKit/NewFS.hxx>
/// bugs 0
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src,
+ const HCore::SizeT len) {
+ if (!dest || !src) return 0;
+
+ SizeT index = 0UL;
+ for (; index < len; ++index) {
+ dest[index] = src[index];
+ }
+
+ return index;
+}
+
HCore::SizeT BStrLen(const CharacterType *ptr) {
+ if (!ptr) return 0;
+
HCore::SizeT cnt = 0;
while (*ptr != (CharacterType)0) {
@@ -23,12 +40,10 @@ HCore::SizeT BStrLen(const CharacterType *ptr) {
return cnt;
}
-/**
- @biref set memory
-*/
-
HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte,
const HCore::SizeT len) {
+ if (!src) return 0;
+
HCore::SizeT cnt = 0UL;
while (*src != 0) {
@@ -43,9 +58,8 @@ HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte,
return cnt;
}
-/**
-@brief puts wrapper over VGA.
-*/
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
BTextWriter &BTextWriter::WriteString(const CharacterType *str) {
if (*str == 0 || !str) return *this;
@@ -66,6 +80,9 @@ BTextWriter &BTextWriter::WriteCharacter(CharacterType c) {
return *this;
}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
/***
@brief File Reader constructor.
*/
@@ -89,5 +106,14 @@ HCore::VoidPtr BFileReader::ReadAll() {
.WriteString(mPath)
.WriteString(L" *** \r\n");
+ EfiFileDevicePathProtocol loadFile{0};
+ loadFile.LengthData[0] = 0xFF;
+ loadFile.LengthData[1] = 0;
+
+ loadFile.Type = kEFIMediaDevicePath;
+ loadFile.SubType = 0; // from all drives.
+
+ BCopyMem(loadFile.Path, mPath, kPathLen);
+
return nullptr;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx
index 69f235c4..256c7feb 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx
@@ -33,6 +33,8 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
KeRuntimeStop(L"HCoreLdr_NoSuchKernel",
L"Couldn't find HCoreKrnl.exe! Aborting...");
+ writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n");
+
EFI::ExitBootServices(SystemTable, mapKey, ImageHandle);
EFI::Stop();
diff --git a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
index f92de33b..663d4bcb 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
@@ -27,4 +27,6 @@ extern "C" void rt_cld() { asm volatile("cld"); }
extern "C" void rt_std() { asm volatile("std"); }
-extern "C" void ___chkstk_ms(void) { EFI::Stop(); }
+/// @brief Stack check
+
+extern "C" void ___chkstk_ms(void) {}
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 063fa42a..0f679772 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -17,6 +17,7 @@ bootloader-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx
$(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe
cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI
+ cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCoreKrnl.exe
.PHONY: run-efi-debug
run-efi-debug: