summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-02-11 09:44:20 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-02-11 09:44:20 +0100
commit624a451284d5971cf9b57113314b3ae4e167bed0 (patch)
tree9d280f65e697006fd3b7f6fdd8b7c690ca7ceeda /dev/Kernel
parent8525590776eda00ee944f2501f75a8fe7577d9eb (diff)
ADD: necessary patches to the PCI subsystem and SATA.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel')
-rw-r--r--dev/Kernel/HALKit/AMD64/HalDebugOutput.cc8
-rw-r--r--dev/Kernel/HALKit/AMD64/PCI/Device.cc72
-rw-r--r--dev/Kernel/HALKit/AMD64/PCI/Iterator.cc4
-rw-r--r--dev/Kernel/HALKit/AMD64/Storage/SATA.cc2
-rw-r--r--dev/Kernel/KernelKit/PCI/Device.h3
-rw-r--r--dev/Kernel/src/FS/NeFS.cc2
6 files changed, 65 insertions, 26 deletions
diff --git a/dev/Kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/Kernel/HALKit/AMD64/HalDebugOutput.cc
index cb8aef59..a95b444e 100644
--- a/dev/Kernel/HALKit/AMD64/HalDebugOutput.cc
+++ b/dev/Kernel/HALKit/AMD64/HalDebugOutput.cc
@@ -122,7 +122,13 @@ namespace Kernel
if (y > kHandoverHeader->f_GOP.f_Height)
{
y = kFontSizeY;
- FB::fb_clear_video();
+
+ fb_init();
+
+ FBDrawInRegion(fb_get_clear_clr(), FB::UIAccessibilty::Height(), FB::UIAccessibilty::Width(),
+ 0, 0);
+
+ fb_clear();
}
++index;
diff --git a/dev/Kernel/HALKit/AMD64/PCI/Device.cc b/dev/Kernel/HALKit/AMD64/PCI/Device.cc
index 66575de1..02d94163 100644
--- a/dev/Kernel/HALKit/AMD64/PCI/Device.cc
+++ b/dev/Kernel/HALKit/AMD64/PCI/Device.cc
@@ -16,6 +16,8 @@ Kernel::UInt NE_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort
Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
target);
+ Kernel::HAL::rt_wait_400ns();
+
return Kernel::HAL::rt_in32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
}
@@ -23,10 +25,12 @@ void NE_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
- (bar & ~3);
+ (bar & 0xFC);
Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
target);
+
+ Kernel::HAL::rt_wait_400ns();
}
#define PCI_BAR_IO 0x01
@@ -45,38 +49,52 @@ namespace Kernel::PCI
UInt Device::Read(UInt bar, Size sz)
{
- NE_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
+ // Ensure aligned access by masking to 4-byte boundary
+ NE_PCISetCfgTarget(bar & 0xFC, fBus, fDevice, fFunction);
+
+ // Read 4 bytes and shift out the correct value
+ UInt data = HAL::rt_in32((UShort)PciConfigKind::ConfigData);
if (sz == 4)
- return HAL::rt_in32((UShort)PciConfigKind::ConfigData + (bar & 3));
+ return data;
if (sz == 2)
- return HAL::rt_in16((UShort)PciConfigKind::ConfigData + (bar & 3));
+ return (data >> ((bar & 2) * 8)) & 0xFFFF;
if (sz == 1)
- return HAL::rt_in8((UShort)PciConfigKind::ConfigData + (bar & 3));
+ return (data >> ((bar & 3) * 8)) & 0xFF;
- return 0xFFFF;
+ return (UShort)PciConfigKind::Invalid;
}
void Device::Write(UInt bar, UIntPtr data, Size sz)
{
- NE_PCISetCfgTarget(bar, fBus, fDevice, fFunction);
+ NE_PCISetCfgTarget(bar & 0xFC, fBus, fDevice, fFunction);
if (sz == 4)
- HAL::rt_out32((UShort)PciConfigKind::ConfigData + (fBar & 3), (UInt)data);
- if (sz == 2)
- HAL::rt_out16((UShort)PciConfigKind::ConfigData + (fBar & 3), (UShort)data);
- if (sz == 1)
- HAL::rt_out8((UShort)PciConfigKind::ConfigData + (fBar & 3), (UChar)data);
+ HAL::rt_out32((UShort)PciConfigKind::ConfigData, (UInt)data);
+ else if (sz == 2)
+ {
+ UInt temp = HAL::rt_in32((UShort)PciConfigKind::ConfigData);
+ temp &= ~(0xFFFF << ((bar & 2) * 8));
+ temp |= (data & 0xFFFF) << ((bar & 2) * 8);
+ HAL::rt_out32((UShort)PciConfigKind::ConfigData, temp);
+ }
+ else if (sz == 1)
+ {
+ UInt temp = HAL::rt_in32((UShort)PciConfigKind::ConfigData);
+ temp &= ~(0xFF << ((bar & 3) * 8));
+ temp |= (data & 0xFF) << ((bar & 3) * 8);
+ HAL::rt_out32((UShort)PciConfigKind::ConfigData, temp);
+ }
}
UShort Device::DeviceId()
{
- return (UShort)(NE_PCIReadRaw(0x0 >> 16, fBus, fDevice, fFunction));
+ return (UShort)(NE_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
}
UShort Device::VendorId()
{
- return (UShort)(NE_PCIReadRaw(0x0, fBus, fDevice, fFunction) >> 16);
+ return (UShort)(NE_PCIReadRaw(0x0, fBus, fDevice, fFunction) & 0xFFFF);
}
UShort Device::InterfaceId()
@@ -106,20 +124,34 @@ namespace Kernel::PCI
void Device::EnableMmio(UInt32 bar_in)
{
- bool enable = Read(bar_in, sizeof(UShort)) | (1 << 1);
- Write(bar_in, enable, sizeof(UShort));
+ UInt32 enable = Read((UShort)PciConfigKind::CommandReg, sizeof(UInt32));
+ enable |= (1 << 1);
+
+ Write((UShort)PciConfigKind::CommandReg, enable, sizeof(UInt32));
}
void Device::BecomeBusMaster(UInt32 bar_in)
{
- bool enable = Read(bar_in, sizeof(UShort)) | (1 << 2);
- Write(bar_in, enable, sizeof(UShort));
+ UInt32 enable = Read((UShort)PciConfigKind::CommandReg, sizeof(UInt32));
+ enable |= (1 << 2);
+
+ Write((UShort)PciConfigKind::CommandReg, enable, sizeof(UInt32));
}
UIntPtr Device::Bar(UInt32 bar_in)
{
- UInt32 bar = NE_PCIReadRaw(bar_in, fBus, fDevice, fFunction);
- return bar;
+ UInt32 bar = NE_PCIReadRaw(bar_in & 0xFC, fBus, fDevice, fFunction);
+
+ if (bar & PCI_BAR_IO)
+ return bar & ~0x03;
+
+ if (bar & PCI_BAR_64)
+ {
+ UInt32 high = NE_PCIReadRaw((bar_in + 4) & 0xFC, fBus, fDevice, fFunction);
+ return ((UIntPtr)high << 32) | (bar & ~0x0F);
+ }
+
+ return bar & ~0x0F;
}
UShort Device::Vendor()
diff --git a/dev/Kernel/HALKit/AMD64/PCI/Iterator.cc b/dev/Kernel/HALKit/AMD64/PCI/Iterator.cc
index 9ceb71f4..de5564dd 100644
--- a/dev/Kernel/HALKit/AMD64/PCI/Iterator.cc
+++ b/dev/Kernel/HALKit/AMD64/PCI/Iterator.cc
@@ -17,9 +17,7 @@ namespace Kernel::PCI
{
for (int function = 0; function < NE_FUNCTION_COUNT; ++function)
{
- auto bar = 0x00;
-
- Device dev(bus, device, function, bar);
+ Device dev(bus, device, function, 0x00);
if (dev.Class() == (UChar)type)
{
diff --git a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc
index 56afa303..3cb00e85 100644
--- a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc
+++ b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc
@@ -91,6 +91,8 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
HbaMem* mem_ahci = (HbaMem*)kPCIDevice.Bar(kSATABar5);
+ kout << hex_number((UIntPtr)mem_ahci) << endl;
+
Kernel::UInt32 ports_implemented = mem_ahci->Pi;
Kernel::UInt16 ahci_index = 0;
diff --git a/dev/Kernel/KernelKit/PCI/Device.h b/dev/Kernel/KernelKit/PCI/Device.h
index c6fb10fc..7af2381d 100644
--- a/dev/Kernel/KernelKit/PCI/Device.h
+++ b/dev/Kernel/KernelKit/PCI/Device.h
@@ -13,7 +13,8 @@ namespace Kernel::PCI
{
ConfigAddress = 0xCF8,
ConfigData = 0xCFC,
- Invalid = 0xFFF
+ CommandReg = 0x0004,
+ Invalid = 0xFFFF,
};
class Device final
diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc
index 529bacbe..bde2daa0 100644
--- a/dev/Kernel/src/FS/NeFS.cc
+++ b/dev/Kernel/src/FS/NeFS.cc
@@ -783,7 +783,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char*
NEFS_CATALOG_STRUCT temporary_catalog{};
kNeFSSearchThroughCatalogList:
- while (drive.fPacket.fPacketGood || !drive.fPacket.fPacketReadOnly)
+ while (drive.fPacket.fPacketGood)
{
drive.fPacket.fPacketLba = start_catalog_lba;
drive.fPacket.fPacketContent = &temporary_catalog;