summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source/MPT
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-27 10:26:31 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-27 10:26:31 +0100
commit70e95128b11dbb535e4679cbacb1cbeaa414c822 (patch)
tree42fd94536a54058a39f0c85be99431c6ad1a0cf8 /Private/NewBoot/Source/MPT
parent44a081a4442181b208c09c6f748124c9d23b61fd (diff)
Kernel: Improving AMD64 HAL, Add TIBInstall.asm, currently Working on
SMPManager and Bootloader. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source/MPT')
-rw-r--r--Private/NewBoot/Source/MPT/.hgkeep0
-rw-r--r--Private/NewBoot/Source/MPT/API.cxx70
-rw-r--r--Private/NewBoot/Source/MPT/API.hxx17
-rw-r--r--Private/NewBoot/Source/MPT/Detail.hxx52
-rw-r--r--Private/NewBoot/Source/MPT/FileType.hxx36
-rw-r--r--Private/NewBoot/Source/MPT/MPT.hxx29
6 files changed, 204 insertions, 0 deletions
diff --git a/Private/NewBoot/Source/MPT/.hgkeep b/Private/NewBoot/Source/MPT/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/.hgkeep
diff --git a/Private/NewBoot/Source/MPT/API.cxx b/Private/NewBoot/Source/MPT/API.cxx
new file mode 100644
index 00000000..8c649024
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/API.cxx
@@ -0,0 +1,70 @@
+/*
+ * ========================================================
+ *
+ * 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<detail::Files32FileGroup>();
+
+ 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
new file mode 100644
index 00000000..2ba9bc74
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/API.hxx
@@ -0,0 +1,17 @@
+/*
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#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
diff --git a/Private/NewBoot/Source/MPT/Detail.hxx b/Private/NewBoot/Source/MPT/Detail.hxx
new file mode 100644
index 00000000..31636b90
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/Detail.hxx
@@ -0,0 +1,52 @@
+/*
+* ========================================================
+*
+* NewBoot
+* Copyright 2024 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 <typename Cls>
+ 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/Private/NewBoot/Source/MPT/FileType.hxx b/Private/NewBoot/Source/MPT/FileType.hxx
new file mode 100644
index 00000000..77408b25
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/FileType.hxx
@@ -0,0 +1,36 @@
+/*
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+// @brief this file purpose is to read/write files.
+
+#include <NewKit/Defines.hpp>
+
+/// \brief File buffer class
+/// \tparam _Manager The disk manager
+template <typename _Manager>
+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
new file mode 100644
index 00000000..c1b9c6a1
--- /dev/null
+++ b/Private/NewBoot/Source/MPT/MPT.hxx
@@ -0,0 +1,29 @@
+/*
+ * ========================================================
+ *
+ * NewBoot
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+// @brief 255 size partition header.
+// we use that to gather information about this hard drive.
+
+struct MasterPartitionTable final
+{
+ char fPartName[32];
+ int fPartType;
+ int fPartSectorSz;
+ int fPartSectorCnt;
+ char fReserved[211];
+};
+
+enum
+{
+ kPartEfi = 0x10,
+ kPartEpm = 0x11,
+ kPartEbr = 0x12,
+}; \ No newline at end of file