summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-14 18:35:05 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-05-14 18:39:11 +0200
commitf8aaa274535b6541f376090958eedbbba3ba00ba (patch)
tree420a4d41f339ac6e6f083099390dddcf59922cab /dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
parent2b91067c894efde74e96fd9216598a5782699c7b (diff)
feat(kernel): Filesystem fixes, and others.
what? - Add simple generic RTL8139 NIC driver, to be used within a NK device. - Update IVT accordingly. - Comment ARM's AP GIC init function, to tell what it's actually doing. - Cleanup Kernel Main, removed the useless pre_init_scheduler function. - Prepare new FileMgr with HeFileSystemMgr. - Fallback to NeFS when trying to format a fileysstem. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc')
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc42
1 files changed, 29 insertions, 13 deletions
diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
index aec21ee4..dd6b9aea 100644
--- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
@@ -15,6 +15,8 @@
*
*/
+#if 0
+
#include <ArchKit/ArchKit.h>
#include <KernelKit/DriveMgr.h>
#include <StorageKit/ATA.h>
@@ -49,7 +51,7 @@ ATAWaitForIO_Retry2:
return true;
}
-static Void drv_pio_std_select(UInt16 Bus) {
+STATIC Void drv_pio_std_select(UInt16 Bus) {
if (Bus == ATA_PRIMARY_IO)
rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL);
else
@@ -79,15 +81,18 @@ ATAInit_Retry:
OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO;
OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE;
+ drv_pio_std_select(IO);
+
rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
- drv_pio_std_wait_io(IO);
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
+
/// fetch serial info
/// model, speed, number of sectors...
for (SizeT i = 0ul; i < kATADataLen; ++i) {
- kATAIdentifyData[i] = HAL::rt_in16(OutBus + ATA_REG_DATA);
+ kATAIdentifyData[i] = rt_in16(OutBus + ATA_REG_DATA);
}
for (Int32 i = 0; i < 20; i++) {
@@ -99,10 +104,6 @@ ATAInit_Retry:
(Void)(kout << "Drive Model: " << kATADiskModel << kendl);
- // Why? the current disk driver writes whole word instead of a single byte (expected btw) so i'm
- // planning to finish +Next drivers for 0.0.3
- ke_panic(RUNTIME_CHECK_INVALID, "PIO driver is currently being reworked.");
-
return true;
}
@@ -118,16 +119,22 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
- for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
+
+ for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);
- Buf[IndexOff] = HAL::rt_in16(IO + ATA_REG_DATA);
+
+ auto in = rt_in16(IO + ATA_REG_DATA);
+
+ Buf[IndexOff] = in & 0xFF;
+ Buf[IndexOff + 1] = (in >> 8) & 0xFF;
}
}
@@ -143,16 +150,23 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
- for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) {
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
+
+ for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);
- rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]);
+
+ UInt8 low = (UInt8)Buf[IndexOff];
+ UInt8 high = (IndexOff + 1 < Size) ? (UInt8)Buf[IndexOff + 1] : 0;
+ UInt16 packed = (high << 8) | low;
+
+ rt_out16(IO + ATA_REG_DATA, packed);
}
}
@@ -261,4 +275,6 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster)
return drv_pio_std_init(Bus, Drive, OutBus, OutMaster);
}
+#endif
+
#endif \ No newline at end of file