From f719c5e4d825b11c510408612e3bdcd0f23a76c3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Jan 2024 09:27:19 +0100 Subject: MPT: add Detail.hxx for MPT's API. Signed-off-by: Amlal El Mahrouss --- newBoot/Source/MPT/API.cxx | 22 ++++------------- newBoot/Source/MPT/Detail.hxx | 52 +++++++++++++++++++++++++++++++++++++++++ newBoot/Source/MPT/FileType.hxx | 8 +++---- 3 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 newBoot/Source/MPT/Detail.hxx (limited to 'newBoot/Source') diff --git a/newBoot/Source/MPT/API.cxx b/newBoot/Source/MPT/API.cxx index b76ac645..3b003cda 100644 --- a/newBoot/Source/MPT/API.cxx +++ b/newBoot/Source/MPT/API.cxx @@ -8,6 +8,7 @@ */ #include "API.hxx" +#include "Detail.hxx" struct Files32FileHdr final { @@ -45,21 +46,6 @@ struct Files32FileGroup final Files32FileGroup* fNext{ nullptr }; } kRootGroup = nullptr; -extern "C" Assert(bool expr); -extern "C" void* AllocPtr(long sz); - -namespace detail -{ - template - Cls* new_class() - { - Cls* cls = (Cls*)AllocPtr(sizeof(Cls)); - *cls = Cls(); - - return cls; - } -} - /* @brief external inits */ extern "C" int init_ata_mpt(void); extern "C" int init_mpt(void); @@ -69,10 +55,10 @@ namespace mpt bool filesystem_init(void) noexcept { kRootGroup = detail::new_class(); - Assert(kRootGroup != nullptr); - Assert(init_ata_mpt() == 1); - Assert(init_mpt() == 1); + assert(kRootGroup != nullptr); + assert(init_ata_mpt() == detail::okay); + assert(init_mpt() == detail::okay); return true; } diff --git a/newBoot/Source/MPT/Detail.hxx b/newBoot/Source/MPT/Detail.hxx new file mode 100644 index 00000000..efde463b --- /dev/null +++ b/newBoot/Source/MPT/Detail.hxx @@ -0,0 +1,52 @@ +/* +* ======================================================== +* +* newBoot +* Copyright Mahrouss Logic, all rights reserved. +* +* ======================================================== +*/ + +#pragma once + +namespace detail +{ + inline void assert_expr(bool expr, const char* str_expr) const + { + if (!expr) + { + detail::panic("assertion failed!", str_expr); + detail::hang(); + } + } + + 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; + } + + enum + { + okay = 1, + failed = 0, + }; +} + +#ifdef assert +# undef assert +# define assert(expr) detail::assert_expr(expr, #expr) +#endif // ifdef assert + + diff --git a/newBoot/Source/MPT/FileType.hxx b/newBoot/Source/MPT/FileType.hxx index 26beb114..818d8197 100644 --- a/newBoot/Source/MPT/FileType.hxx +++ b/newBoot/Source/MPT/FileType.hxx @@ -19,10 +19,10 @@ template class FileType { public: - hCore::SizeT DiskId{ 0 }; - hCore::VoidPtr DiskSpace{ nullptr }; - hCore::SizeT DiskSize{ 0 }; - hCore::Int32 DiskError{ 0 }; + 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); } -- cgit v1.2.3