From 5339d016c07bf717ee388f4feb73544087324af0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 6 Jan 2024 09:14:11 +0100 Subject: git: port from mercurial repo. Signed-off-by: Amlal El Mahrouss --- Source/Storage/ATA.cxx | 99 ++++++++++++++++++++++++++++++++++++++++++++++ Source/Storage/NVME.cxx | 18 +++++++++ Source/Storage/Storage.cxx | 12 ++++++ 3 files changed, 129 insertions(+) create mode 100644 Source/Storage/ATA.cxx create mode 100644 Source/Storage/NVME.cxx create mode 100644 Source/Storage/Storage.cxx (limited to 'Source/Storage') diff --git a/Source/Storage/ATA.cxx b/Source/Storage/ATA.cxx new file mode 100644 index 00000000..5a53d78d --- /dev/null +++ b/Source/Storage/ATA.cxx @@ -0,0 +1,99 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include +#include + +//! @brief Driver for ATA, listens to a specific address for data to come. +//! mapped by NewFirmware. + +#define kATAError 2 + +namespace hCore +{ + Ref kPrdt = nullptr; + + bool set_prdt_struct(Ref& refCtrl) + { + if (!kPrdt) + { + kPrdt = refCtrl; + kcout << "[set_prdt_struct] PRDT is set."; + + return true; + } + + kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n"; + return false; + } + + enum + { + k28BitRead = 0xC8, + k48BitRead = 0x25, + k28BitWrite = 0xCA, + k48BitWrite = 0x35, + }; + + const char* ata_read_28(ULong lba) + { + static char buffer[512]; + + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + + packet[0] = k28BitRead; + packet[1] = (UIntPtr)&buffer; + packet[2] = lba; + + rt_wait_for_io(); + + return buffer; + } + + const char* ata_read_48(ULong lba) + { + static char buffer[512]; + + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + + packet[0] = k48BitRead; + packet[1] = (UIntPtr)&buffer; + packet[4] = lba; + + rt_wait_for_io(); + + return buffer; + } + + Int32 ata_write_48(ULong lba, const char *text) + { + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + + packet[0] = k48BitWrite; + packet[1] = (UIntPtr)&text; + packet[2] = lba; + + rt_wait_for_io(); + + return packet[1] == 2 ? kATAError : 0; + } + + Int32 ata_write_28(ULong lba, const char *text) + { + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + + packet[0] = k28BitWrite; + packet[1] = (UIntPtr)&text; + packet[2] = lba; + + rt_wait_for_io(); + + return packet[1] == 2 ? kATAError : 0; + } +} // namespace hCore diff --git a/Source/Storage/NVME.cxx b/Source/Storage/NVME.cxx new file mode 100644 index 00000000..20fbd84d --- /dev/null +++ b/Source/Storage/NVME.cxx @@ -0,0 +1,18 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +namespace hCore +{ + const char *NVMEDevice::Name() const + { + return ("NVMEDevice"); + } +} // namespace hCore diff --git a/Source/Storage/Storage.cxx b/Source/Storage/Storage.cxx new file mode 100644 index 00000000..f6732599 --- /dev/null +++ b/Source/Storage/Storage.cxx @@ -0,0 +1,12 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include + +const OSScsiPacket kCDRomPacketTemplate = { 0x43, 0, 1, 0, 0, 0, 0, 12, 0x40, 0, 0 }; -- cgit v1.2.3