summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Source/DriveManager.cxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/Source/DriveManager.cxx
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Source/DriveManager.cxx')
-rw-r--r--Kernel/Source/DriveManager.cxx149
1 files changed, 149 insertions, 0 deletions
diff --git a/Kernel/Source/DriveManager.cxx b/Kernel/Source/DriveManager.cxx
new file mode 100644
index 00000000..c60b2079
--- /dev/null
+++ b/Kernel/Source/DriveManager.cxx
@@ -0,0 +1,149 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#include <KernelKit/DebugOutput.hpp>
+#include <KernelKit/DriveManager.hxx>
+#include <Builtins/ATA/ATA.hxx>
+#include <Builtins/AHCI/AHCI.hxx>
+#include <NewKit/Utils.hpp>
+
+/// @file DriveManager.cxx
+/// @brief Kernel drive manager.
+
+namespace NewOS
+{
+ static UInt16 kATAIO = 0U;
+ static UInt8 kATAMaster = 0U;
+
+ /// @brief reads from an ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_input(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+ pckt->fPacketGood = false;
+
+#ifdef __AHCI__
+ drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize);
+#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
+#endif
+
+ pckt->fPacketGood = true;
+ }
+
+ /// @brief Writes to an ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_output(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+ pckt->fPacketGood = false;
+
+#ifdef __AHCI__
+ drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
+#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
+#endif
+
+ pckt->fPacketGood = true;
+ }
+
+ /// @brief Executes a disk check on the ATA drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt)
+ {
+ if (!pckt)
+ {
+ return;
+ }
+
+ pckt->fPacketGood = false;
+
+#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
+ kATAMaster = true;
+ kATAIO = ATA_PRIMARY_IO;
+
+ MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster));
+#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__)
+
+ pckt->fPacketGood = true;
+ }
+
+/// @brief Gets the drive kind (ATA, SCSI, AHCI...)
+/// @param
+/// @return
+#ifdef __ATA_PIO__
+ const Char* ke_drive_kind(Void)
+ {
+ return "ATA-PIO";
+ }
+#endif
+
+#ifdef __ATA_DMA__
+ const Char* ke_drive_kind(Void)
+ {
+ return "ATA-DMA";
+ }
+#endif
+
+#ifdef __AHCI__
+ const Char* ke_drive_kind(Void)
+ {
+ return "AHCI";
+ }
+#endif
+
+ /// @brief Unimplemented drive.
+ /// @param pckt
+ /// @return
+ Void ke_drv_unimplemented(DriveTrait::DrivePacket* pckt)
+ {
+ }
+
+ /// @brief Makes a new drive.
+ /// @return the new drive.
+ DriveTrait construct_drive() noexcept
+ {
+ DriveTrait trait;
+
+ rt_copy_memory((VoidPtr) "/Mount/Null", trait.fName, rt_string_len("/Mount/Null"));
+ trait.fKind = kInvalidDrive;
+
+ trait.fInput = ke_drv_unimplemented;
+ trait.fOutput = ke_drv_unimplemented;
+ trait.fVerify = ke_drv_unimplemented;
+ trait.fDriveKind = ke_drive_kind;
+
+ return trait;
+ }
+
+ /// @brief Fetches the main drive.
+ /// @return the new drive.
+ DriveTrait construct_main_drive() noexcept
+ {
+ DriveTrait trait;
+
+ rt_copy_memory((VoidPtr) "/Mount/MainDisk/", trait.fName, rt_string_len("/Mount/MainDisk/"));
+ trait.fKind = kMassStorage | kEPMDrive;
+
+ trait.fInput = ke_drv_input;
+ trait.fOutput = ke_drv_output;
+ trait.fVerify = ke_drv_check_disk;
+ trait.fDriveKind = ke_drive_kind;
+
+ return trait;
+ }
+} // namespace NewOS