From de4af9d8929da048ab714b75d2af23ccebe3f6cb Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 27 Jan 2024 10:53:58 +0100 Subject: Bootloader: Refactor MPT, working on EFI support. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/MPT/API.cxx | 70 --------------------------------- Private/NewBoot/Source/MPT/API.hxx | 12 +++--- Private/NewBoot/Source/MPT/Detail.hxx | 14 +------ Private/NewBoot/Source/MPT/FileType.hxx | 36 ----------------- Private/NewBoot/Source/MPT/MPT.hxx | 7 ++-- Private/NewBoot/Source/Start.cxx | 8 ++++ Private/NewBoot/Source/makefile | 4 +- 7 files changed, 21 insertions(+), 130 deletions(-) delete mode 100644 Private/NewBoot/Source/MPT/API.cxx delete mode 100644 Private/NewBoot/Source/MPT/FileType.hxx diff --git a/Private/NewBoot/Source/MPT/API.cxx b/Private/NewBoot/Source/MPT/API.cxx deleted file mode 100644 index 8c649024..00000000 --- a/Private/NewBoot/Source/MPT/API.cxx +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include "API.hxx" -#include "Detail.hxx" - -#define kFilesR 0x01 /* read-only */ -#define kFilesH 0x02 /* hidden */ -#define kFilesS 0x04 /* system */ -#define kFilesL 0x08 /* volume label */ -#define kFilesD 0x10 /* directory */ -#define kFilesZ 0x20 /* archive */ - -// @brief Array of unused bits. -#define kFilesU { 0x40, 0x80 } - -namespace mpt::detail -{ - struct Files32FileHdr final - { - char Filename[32]; - char Ext[3]; - char Attr; - char Case; - char CreateMs; - unsigned short Create; - unsigned short CreateDate; - unsigned short LastAccess; - unsigned short Timestamp; - unsigned short Datestamp; - unsigned short StartLba; - unsigned int SizeFile; - }; - - struct Files32FileGroup final - { - Files32FileHdr* fHdr{ nullptr }; - - Files32FileGroup* fUpper{ nullptr }; - Files32FileGroup* fLower{ nullptr }; - Files32FileGroup* fPrev{ nullptr }; - Files32FileGroup* fNext{ nullptr }; - }; - - /* @brief external inits */ - extern "C" int init_ata_mpt(void); - extern "C" int init_mpt(void); - - Files32FileGroup* kRootGroup = nullptr; -} - -namespace mpt -{ - bool init_mpt() noexcept - { - detail::kRootGroup = detail::new_class(); - - assert(detail::kRootGroup != nullptr); - assert(detail::init_ata_mpt() == detail::okay); - assert(detail::init_mpt() == detail::okay); - - return true; - } -} \ No newline at end of file diff --git a/Private/NewBoot/Source/MPT/API.hxx b/Private/NewBoot/Source/MPT/API.hxx index 2ba9bc74..83de5365 100644 --- a/Private/NewBoot/Source/MPT/API.hxx +++ b/Private/NewBoot/Source/MPT/API.hxx @@ -9,9 +9,9 @@ #pragma once -namespace mpt -{ - /// initializes the Master Partition Table and the Files32 filesystem. - /// \return status, assert(fail) is also triggered, use filesystem_hook_error if you want to catch it. - bool init_mpt() noexcept; -} \ No newline at end of file +#ifdef __MPT_NEED_ATA_SUPPORT +extern "C" int init_ata_mpt(void); +#endif // __MPT_NEED_ATA_SUPPORT + +#include +#include \ No newline at end of file diff --git a/Private/NewBoot/Source/MPT/Detail.hxx b/Private/NewBoot/Source/MPT/Detail.hxx index 31636b90..002f5595 100644 --- a/Private/NewBoot/Source/MPT/Detail.hxx +++ b/Private/NewBoot/Source/MPT/Detail.hxx @@ -22,19 +22,7 @@ namespace detail inline void hang() const { - while (1) - {} - } - - extern "C" void* new_ptr(long sz); - - template - inline Cls* new_class() - { - Cls* cls = (Cls*)new_ptr(sizeof(Cls)); - *cls = Cls(); - - return cls; + while (1) {} } enum diff --git a/Private/NewBoot/Source/MPT/FileType.hxx b/Private/NewBoot/Source/MPT/FileType.hxx deleted file mode 100644 index 77408b25..00000000 --- a/Private/NewBoot/Source/MPT/FileType.hxx +++ /dev/null @@ -1,36 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -// @brief this file purpose is to read/write files. - -#include - -/// \brief File buffer class -/// \tparam _Manager The disk manager -template -class FileType -{ -public: - hCore::SizeT DiskId{ 0 }; // identification number of the drive. - hCore::VoidPtr DiskSpace{ nullptr }; // the pointer containing the requested disk data. - hCore::SizeT DiskSize{ 0 }; // it's size - hCore::Int32 DiskError{ 0 }; // if it's going well. - - FileType* Read(const char* path) { return _Manager::Read(path); } - FileType* Write(FileType* path) { return _Manager::Write(path); } - - // little sanity test - operator bool() - { - return DiskError != 0 && DiskSize > 0; - } - -}; \ No newline at end of file diff --git a/Private/NewBoot/Source/MPT/MPT.hxx b/Private/NewBoot/Source/MPT/MPT.hxx index c1b9c6a1..9ac79cd1 100644 --- a/Private/NewBoot/Source/MPT/MPT.hxx +++ b/Private/NewBoot/Source/MPT/MPT.hxx @@ -9,8 +9,8 @@ #pragma once -// @brief 255 size partition header. -// we use that to gather information about this hard drive. +/// @brief 255 size partition header. +/// we use that to gather information about this hard drive. struct MasterPartitionTable final { @@ -26,4 +26,5 @@ enum kPartEfi = 0x10, kPartEpm = 0x11, kPartEbr = 0x12, -}; \ No newline at end of file +}; + diff --git a/Private/NewBoot/Source/Start.cxx b/Private/NewBoot/Source/Start.cxx index 223fcc0f..eed20034 100644 --- a/Private/NewBoot/Source/Start.cxx +++ b/Private/NewBoot/Source/Start.cxx @@ -7,11 +7,19 @@ * ======================================================== */ +#define __MPT_NEED_ATA_SUPPORT 1 + #include +#include extern "C" void Main(void) { +#ifdef __DBG__ + BKTextWriter writer; writer.WriteString("Booting Kernel...", kBlack, kWhite, 0, 0); +#endif + + init_ata_mpt(); } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 3273b52f..911cdfef 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -11,8 +11,8 @@ FLAG_GNU=-I../ -I../../../efiSDK/inc -c -ffreestanding -fno-rtti -fno-exceptions .PHONY: arch-amd64 arch-amd64: - $(CC_GNU) $(FLAG_GNU) HEL/AMD64/BootAMD64.cxx *.cxx - $(LD_GNU) *.o -e Main -Ttext 0x000 --oformat binary -o BootloaderStage2.bin + $(CC_GNU) $(FLAG_GNU) -D__DBG__ HEL/AMD64/BootAMD64.cxx *.cxx + $(LD_GNU) *.o -e Main --oformat binary -o BootloaderStage2.bin .PHONY: clean clean: -- cgit v1.2.3