diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 20:24:42 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 20:24:42 +0100 |
| commit | 954285b6c9553a047d0789707ad520c84099e74a (patch) | |
| tree | 2057016a60f38d6df7e9ffe3fc836be3a39cdf06 | |
| parent | 5d0bf1cb68c6eb6eb59f1f82fcccfc3e21bf3f9f (diff) | |
EPM: NewBoot: Implement EPM scheme for HCore.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | Private/FirmwareKit/EPM.hxx | 13 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx | 54 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 5 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Thread.hxx | 3 |
5 files changed, 74 insertions, 3 deletions
diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx index 1bf90aba..ae0a4a54 100644 --- a/Private/FirmwareKit/EPM.hxx +++ b/Private/FirmwareKit/EPM.hxx @@ -13,20 +13,27 @@ #include <NewKit/Defines.hpp> -#define kEPMUUIDLength 37 #define kEPMNameLength 32 #define kEPMFilesystemLength 16 -#define kEPMMagicLength 4 +#define kEPMMagicLength 5 /* The first 512 > x > 1024 bytes of a disk contains this headers. */ +/// @brief EPM GUID block. +typedef struct BlockGUID { + UInt32 Data1; + UInt16 Data2; + UInt16 Data3; + UInt8 Data4[8]; +} BlockGUID; + /** * @brief The EPM bootloader block. */ struct PACKED BootBlock { HCore::Char Magic[kEPMMagicLength]; HCore::Char Name[kEPMNameLength]; - HCore::Char Uuid[kEPMUUIDLength]; + BlockGUID Uuid; HCore::Int32 Version; HCore::Int64 NumBlocks; HCore::Int64 SectorSz; diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 7a393e2a..bad13d85 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -204,3 +204,5 @@ class BVersionString final { public: static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; } }; + +Void boot_try_write_partition_map(const Char* namePart, SizeT namePartLength, BDeviceATA* ataInterface); diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx index a4edfa57..6d2998f3 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx @@ -5,3 +5,57 @@ ------------------------------------------- */ #include <BootKit/BootKit.hxx> + +// {310E1FC7-2060-425D-BE7B-75A37CC679BC} +STATIC const BlockGUID kEPMGuid = { + 0x310e1fc7, + 0x2060, + 0x425d, + {0xbe, 0x7b, 0x75, 0xa3, 0x7c, 0xc6, 0x79, 0xbc}}; + +Void boot_try_write_partition_map(const Char* namePart, SizeT namePartLength, + BDeviceATA* ataInterface) { + if (namePartLength > kEPMNameLength || !namePart) return; + if (!ataInterface) return; + + ataInterface->Leak().mBase = kEPMStartPartition; + ataInterface->Leak().mSize = 512; + + Char buf[512] = {0}; + + ataInterface->Read(buf, 1); + + BTextWriter writer; + + writer.Write(L"NewBoot: Reading EPM boot block..\r\n"); + + for (SizeT i = 0; i < kEPMMagicLength; i++) { + if (buf[i] != kEPMMagic[i]) { + writer.Write(L"NewBoot: Writing EPM boot block..\r\n"); + + BootBlockType* bootBlock = (BootBlockType*)buf; + + bootBlock->Version = kEPMHCore; + bootBlock->NumBlocks = kEPMMaxBlks; + + 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->SectorStart = + sizeof(BootBlockType) + (sizeof(PartitionBlockType) * kEPMMaxBlks); + + bootBlock->SectorSz = kATASectorSize; + + bootBlock->Uuid = kEPMGuid; + + ataInterface->Write(buf, 1); + + return; + } + } +}
\ 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 a3f82275..b4e7b56d 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -27,6 +27,11 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, InitGOP(); // Quick Toolkit for UI BTextWriter writer; + BDeviceATA ataDrv; + + Char namePart[kEPMNameLength] = { "NewKernel Standard System" }; + + boot_try_write_partition_map(namePart, kEPMNameLength, &ataDrv); /// Splash screen stuff diff --git a/Public/SDK/System.Core/Headers/Thread.hxx b/Public/SDK/System.Core/Headers/Thread.hxx index 306419b3..ae6ba057 100644 --- a/Public/SDK/System.Core/Headers/Thread.hxx +++ b/Public/SDK/System.Core/Headers/Thread.hxx @@ -46,4 +46,7 @@ BooleanType HcResumeThread(_Input PtrThread ThreadPtr); QWordType HcProcessIdThread(_Input PtrThread ThreadPtr); +/// @brief Main application thread. +CA_EXTERN_C PtrThread kMainThread; + #endif // __THREAD_API__ |
