summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/Modules/AHCI/AHCI.h10
-rw-r--r--dev/SCIKit/Macros.h2
-rw-r--r--dev/ZBAKit/amd64-efi.make2
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootATA.cc4
-rw-r--r--dev/ZKAKit/FSKit/NeFS.h12
-rw-r--r--dev/ZKAKit/FirmwareKit/EFI/EFI.h22
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc2
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc6
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc3
-rw-r--r--dev/ZKAKit/HALKit/AMD64/PCI/Device.cc4
-rw-r--r--dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc159
-rw-r--r--dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc4
-rw-r--r--dev/ZKAKit/KernelKit/HardwareThreadScheduler.h2
-rw-r--r--dev/ZKAKit/KernelKit/LoaderInterface.h6
-rw-r--r--dev/ZKAKit/KernelKit/PCI/DMA.h2
-rw-r--r--dev/ZKAKit/KernelKit/UserProcessScheduler.h2
-rw-r--r--dev/ZKAKit/NewKit/Macros.h2
-rw-r--r--dev/ZKAKit/src/BitMapMgr.cc1
-rw-r--r--dev/ZKAKit/src/CodeMgr.cc6
-rw-r--r--dev/ZKAKit/src/DriveMgr.cc1
-rw-r--r--dev/ZKAKit/src/FS/NeFS.cc15
-rw-r--r--dev/ZKAKit/src/HardwareThreadScheduler.cc3
-rw-r--r--dev/ZKAKit/src/PEFCodeMgr.cc10
-rw-r--r--dev/ZKAKit/src/Property.cc2
-rw-r--r--dev/ZKAKit/src/Semaphore.cc3
25 files changed, 157 insertions, 128 deletions
diff --git a/dev/Modules/AHCI/AHCI.h b/dev/Modules/AHCI/AHCI.h
index b6e3e706..82e95b04 100644
--- a/dev/Modules/AHCI/AHCI.h
+++ b/dev/Modules/AHCI/AHCI.h
@@ -2,8 +2,8 @@
Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved.
- File: Defines.h
- Purpose: AHCI header.
+ File: AHCI.h
+ Purpose: AHCI protocol defines.
Revision History:
@@ -359,12 +359,6 @@ Kernel::SizeT drv_get_sector_count();
/// @brief get device size.
Kernel::SizeT drv_get_size();
-/// @brief get sector count.
-Kernel::SizeT drv_get_sector_count();
-
-/// @brief get device size.
-Kernel::SizeT drv_get_size();
-
#endif // ifdef __AHCI__
/* EOF */
diff --git a/dev/SCIKit/Macros.h b/dev/SCIKit/Macros.h
index 2143c4d5..cd49acd0 100644
--- a/dev/SCIKit/Macros.h
+++ b/dev/SCIKit/Macros.h
@@ -44,7 +44,7 @@ typedef char Char;
typedef VoidPtr SCIObject;
typedef SCIObject IOObject;
-typedef IOObject FSObject;
+typedef IOObject FSObject;
typedef SCIObject DLLObject;
typedef SCIObject ThreadObject;
typedef SCIObject SocketObject;
diff --git a/dev/ZBAKit/amd64-efi.make b/dev/ZBAKit/amd64-efi.make
index 1121060f..15739d50 100644
--- a/dev/ZBAKit/amd64-efi.make
+++ b/dev/ZBAKit/amd64-efi.make
@@ -34,7 +34,7 @@ EMU_FLAGS=-net none -smp 1 -m 8G -M q35 \
file=fat:rw:src/Root/,index=2,format=raw \
-drive id=disk_2,file=$(IMG),if=none \
-device ahci,id=ahci \
- -device ide-hd,drive=disk_2,bus=ahci.0 -d int -no-shutdown -no-reboot
+ -device ide-hd,drive=disk_2,bus=ahci.0 -serial stdio -no-shutdown -no-reboot
LD_FLAGS=-e Main --subsystem=10
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootATA.cc b/dev/ZBAKit/src/HEL/AMD64/BootATA.cc
index 353ecd06..99810a30 100644
--- a/dev/ZBAKit/src/HEL/AMD64/BootATA.cc
+++ b/dev/ZBAKit/src/HEL/AMD64/BootATA.cc
@@ -124,7 +124,7 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
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);
@@ -154,7 +154,7 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf,
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);
diff --git a/dev/ZKAKit/FSKit/NeFS.h b/dev/ZKAKit/FSKit/NeFS.h
index e686ab3c..53367940 100644
--- a/dev/ZKAKit/FSKit/NeFS.h
+++ b/dev/ZKAKit/FSKit/NeFS.h
@@ -239,15 +239,15 @@ namespace Kernel
/// @param theFork the fork itself.
/// @return the fork
_Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input NFS_FORK_STRUCT& theFork);
+ _Input NFS_FORK_STRUCT& theFork);
/// @brief Find fork inside New filesystem.
/// @param catalog the catalog.
/// @param name the fork name.
/// @return the fork.
_Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input const Char* name,
- Boolean dataOrRsrc);
+ _Input const Char* name,
+ Boolean dataOrRsrc);
_Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork);
@@ -257,7 +257,7 @@ namespace Kernel
_Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name);
- _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name,
+ _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind);
@@ -267,12 +267,12 @@ namespace Kernel
_Input Bool isRsrcFork,
_Input VoidPtr data,
_Input SizeT sizeOfData,
- _Input const Char* forkName);
+ _Input const Char* forkName);
VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
_Input Bool isRsrcFork,
_Input SizeT dataSz,
- _Input const Char* forkName);
+ _Input const Char* forkName);
bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off);
diff --git a/dev/ZKAKit/FirmwareKit/EFI/EFI.h b/dev/ZKAKit/FirmwareKit/EFI/EFI.h
index 3cf997e3..c227fcd3 100644
--- a/dev/ZKAKit/FirmwareKit/EFI/EFI.h
+++ b/dev/ZKAKit/FirmwareKit/EFI/EFI.h
@@ -50,7 +50,7 @@ typedef UInt64 EfiStatusType;
/// This is like NT's Win32 HANDLE type.
typedef struct EfiHandle
{
-}* EfiHandlePtr;
+} * EfiHandlePtr;
/* UEFI uses wide characters by default. */
typedef WideChar EfiCharType;
@@ -593,7 +593,7 @@ typedef struct EfiSystemTable
{
EfiGUID VendorGUID;
VoidPtr VendorTable;
- }* ConfigurationTable;
+ } * ConfigurationTable;
} EfiSystemTable;
#define kEfiOk 0
@@ -823,11 +823,11 @@ typedef struct _EfiProcessorInformation
typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS)(
IN struct _EfiMpServicesProtocol* Self,
- OUT UInt32* NumberOfProcessors,
- OUT UInt32* NumberOfEnabledProcessors);
+ OUT UInt32* NumberOfProcessors,
+ OUT UInt32* NumberOfEnabledProcessors);
typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_GET_PROCESSOR_INFO)(
- IN struct _EfiMpServicesProtocol* Self,
+ IN struct _EfiMpServicesProtocol* Self,
IN UInt32* ProcessorNumber,
OUT struct _EfiProcessorInformation* NumberOfEnabledProcessors);
@@ -842,8 +842,8 @@ typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_STARTUP_ALL_APS)(
IN Boolean SingleThread,
IN VoidPtr WaitEvent OPTIONAL, // EFI_EVENT first, but unused here.
IN UInt32 TimeoutInMicroSeconds,
- IN Void* ProcedureArgument OPTIONAL,
- OUT UInt32** FailedCpuList OPTIONAL);
+ IN Void* ProcedureArgument OPTIONAL,
+ OUT UInt32** FailedCpuList OPTIONAL);
typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_SWITCH_BSP)(
IN struct _EfiMpServicesProtocol* This,
@@ -856,18 +856,18 @@ typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_STARTUP_THIS_AP)(
IN UInt32 ProcessorNumber,
IN VoidPtr WaitEvent OPTIONAL,
IN UInt32 TimeoutInMicroseconds,
- IN Void* ProcedureArgument OPTIONAL,
- OUT Boolean* Finished OPTIONAL);
+ IN Void* ProcedureArgument OPTIONAL,
+ OUT Boolean* Finished OPTIONAL);
typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_ENABLEDISABLEAP)(
IN struct _EfiMpServicesProtocol* This,
IN UInt32 ProcessorNumber,
IN Boolean EnableAP,
- IN UInt32* HealthFlag OPTIONAL);
+ IN UInt32* HealthFlag OPTIONAL);
typedef EfiStatusType EFI_API (*EFI_MP_SERVICES_WHOAMI)(
IN struct _EfiMpServicesProtocol* This,
- OUT UInt32* ProcessorNumber);
+ OUT UInt32* ProcessorNumber);
typedef struct _EfiMpServicesProtocol
{
diff --git a/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc b/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc
index e25664eb..ff48e8c5 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc
@@ -42,7 +42,7 @@ namespace Kernel
HAL::rt_out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
HAL::rt_out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
HAL::rt_out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if
- // serial returns same byte)
+ // serial returns same byte)
// Check if serial is faulty (i.e: not same byte as sent)
if (HAL::rt_in8(PORT) != 0xAE)
diff --git a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
index c90c3b1a..a426fa48 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc
@@ -14,7 +14,7 @@ namespace Kernel::HAL
namespace Detail
{
STATIC ::Kernel::Detail::AMD64::InterruptDescriptorAMD64
- kInterruptVectorTable[kKernelIdtSize] = { };
+ kInterruptVectorTable[kKernelIdtSize] = {};
STATIC void hal_set_irq_mask(UInt8 irql);
STATIC void hal_clear_irq_mask(UInt8 irql);
@@ -28,8 +28,8 @@ namespace Kernel::HAL
UInt16 cCommonDivisor = kPITFrequency / ticks; // 100 Hz.
- HAL::rt_out8(kPITControlPort, 0x36); // Command to PIT
- HAL::rt_out8(kPITChannel0Port, cCommonDivisor & 0xFF); // Send low byte
+ HAL::rt_out8(kPITControlPort, 0x36); // Command to PIT
+ HAL::rt_out8(kPITChannel0Port, cCommonDivisor & 0xFF); // Send low byte
HAL::rt_out8(kPITChannel0Port, (cCommonDivisor >> 8) & 0xFF); // Send high byte
hal_clear_irq_mask(32);
diff --git a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
index 3c472943..8444b03f 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
@@ -96,7 +96,8 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept
Kernel::rtl_create_process([]() -> void {
while (Yes)
;
- }, process_name);
+ },
+ process_name);
/* Load interrupts and start SMP. */
diff --git a/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc b/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc
index 24966ae3..7b0f64b3 100644
--- a/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc
+++ b/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc
@@ -14,7 +14,7 @@ Kernel::UInt ZKA_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort
(bar & 0xFC);
Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
- target);
+ target);
return Kernel::HAL::rt_in32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
}
@@ -26,7 +26,7 @@ void ZKA_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort de
(bar & ~3);
Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
- target);
+ target);
}
#define PCI_BAR_IO 0x01
diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
index 5123bf9f..d9c9f87f 100644
--- a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
+++ b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
@@ -23,7 +23,7 @@
#ifdef __AHCI__
#define kMaxAhciPoll (100000U)
-#define kCmdOrCtrlCmd 1
+#define kCmdOrCtrlCmd 1
#define kCmdOrCtrlCtrl 0
enum
@@ -34,27 +34,98 @@ enum
};
STATIC Kernel::PCI::Device kAhciDevice;
-STATIC HbaPort* kAhciPort = nullptr;
+STATIC HbaPort* kAhciPort = nullptr;
+STATIC Kernel::Lba kCurrentDiskSectorCount = 0UL;
+
+Kernel::Void drv_calculate_disk_geometry()
+{
+ // Slot is now used, OS uses slot 0, driver must not use slot 0.
+
+ // Prepare command header.
+
+ HbaCmdHeader* cmd_header = (HbaCmdHeader*)(Kernel::UIntPtr)kAhciPort->Clb;
+
+ // Read operation/set entries count.
+
+ Kernel::UInt16 identify_data[256] = {0};
+ Kernel::UInt64 size = 512 - 1; // Adjust size for 512 bytes of data (Dbc should be 511)
+
+ cmd_header->Cfl = sizeof(FisRegH2D) / sizeof(Kernel::UInt32);
+ cmd_header->Prdtl = 1; // 1 PRDT entry
+
+ // Prepare command table.
+ HbaCmdTbl* cmd_tbl = (HbaCmdTbl*)(Kernel::UIntPtr)cmd_header->Ctba;
+
+ // First PRD entry
+ cmd_tbl->PrdtEntries[0].Dba = (Kernel::UInt32)(Kernel::UIntPtr)identify_data;
+ cmd_tbl->PrdtEntries[0].Dbc = size; // Byte count (511 for 512 bytes of data)
+ cmd_tbl->PrdtEntries[0].InterruptBit = 1; // Set interrupt flag
+
+ // 5. Prepare the command FIS (Frame Information Structure)
+ FisRegH2D* cmd_fis = (FisRegH2D*)(cmd_tbl->Cfis);
+ cmd_fis->FisType = kFISTypeRegH2D;
+ cmd_fis->CmdOrCtrl = kCmdOrCtrlCmd; // Command
+ cmd_fis->Command = kAHCICmdIdentify;
+
+ // 6. Issue the command by writing to the port's command issue register (CI)
+ kAhciPort->Ci = 1; // Issue command slot 0
+
+ // Polling loop for command completion
+ while (kAhciPort->Ci)
+ {
+ // Check for errors in the Task File Data register (PxTFD)
+ if (kAhciPort->Tfd & (1 << 0))
+ { // Error bit
+ kcout << "Error in task file, can't get disk geometry." << endl;
+ Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
+ }
+
+ // If the device is busy, wait
+ if (kAhciPort->Tfd & (1 << 7))
+ {
+ kcout << "Device is busy, waiting..." << endl;
+ continue;
+ }
+
+ // If command completes, clear the PxCI register
+ if (kAhciPort->Is & (1 << 30))
+ { // If an interrupt occurred (device ready)
+ kcout << "Command completed successfully." << endl;
+ break;
+ }
+ }
+
+ // Retrieve the max LBA value
+ kCurrentDiskSectorCount = 0UL;
+ kCurrentDiskSectorCount |= identify_data[100];
+ kCurrentDiskSectorCount |= identify_data[101] << 16;
+ kCurrentDiskSectorCount |= identify_data[102] << 32;
+ kCurrentDiskSectorCount |= identify_data[103] << 48;
+
+ kcout << "Max LBA: " << Kernel::number(kCurrentDiskSectorCount) << endl;
+
+ BREAK_POINT();
+}
/// @brief Initializes an AHCI disk.
/// @param PortsImplemented the amount of kAhciPort that have been detected.
-/// @return
+/// @return if the disk was successfully initialized or not.
Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
{
using namespace Kernel;
PCI::Iterator iterator(Types::PciDeviceKind::MassStorageController);
- for (SizeT devIndex = 0; devIndex < ZKA_BUS_COUNT; ++devIndex)
+ for (SizeT device_index = 0; device_index < ZKA_BUS_COUNT; ++device_index)
{
+ kAhciDevice = iterator[device_index].Leak(); // And then leak the reference.
+
// if SATA and then interface is AHCI...
- if (iterator[devIndex].Leak().Subclass() == kSATASubClass &&
- iterator[devIndex].Leak().ProgIf() == kSATAProgIfAHCI)
+ if (kAhciDevice.Subclass() == kSATASubClass &&
+ kAhciDevice.ProgIf() == kSATAProgIfAHCI)
{
- iterator[devIndex].Leak().EnableMmio(0x24); // Enable the memory index_byte/o for this ahci device.
- iterator[devIndex].Leak().BecomeBusMaster(0x24); // Become bus master for this ahci device, so that we can control it.
-
- kAhciDevice = iterator[devIndex].Leak(); // And then leak the reference.
+ kAhciDevice.EnableMmio(0x24); // Enable the memory index_byte/o for this ahci device.
+ kAhciDevice.BecomeBusMaster(0x24); // Become bus master for this ahci device, so that we can control it.
HbaMem* mem_ahci = (HbaMem*)kAhciDevice.Bar(0x24);
@@ -83,10 +154,10 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented)
detected = true;
- mem_ahci->Ghc |= (1 << kAhciGHC_AE);
-
kAhciPort = &mem_ahci->Ports[ahci_index];
+ drv_calculate_disk_geometry();
+
break;
}
}
@@ -109,23 +180,11 @@ Kernel::Boolean drv_std_detected(Kernel::Void)
Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer)
{
- STATIC Kernel::Boolean kSlotIsUsed = No;
-
- Kernel::LockDelegate<kMaxAhciPoll> lock(&kSlotIsUsed);
-
- if (kSlotIsUsed)
- return;
-
// Slot is now used, OS uses slot 0, driver must not use slot 0.
- kSlotIsUsed = Yes;
-
- Kernel::Int64 free_slot = 0L;
-
// Prepare command header.
HbaCmdHeader* cmd_header = (HbaCmdHeader*)(Kernel::UIntPtr)kAhciPort->Clb;
- cmd_header += free_slot;
// Read operation/set entries count.
@@ -140,15 +199,9 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size
Kernel::UInt64 size = size * kAHCISectorSize;
Kernel::Int64 index_byte = 0L;
- for (index_byte = 0; index_byte < (cmd_header->Prdtl - 1); ++index_byte)
- {
- cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
- cmd_tbl->PrdtEntries[index_byte].Dbc = (kib_cast(8)) - 1; // 8KB buffer size
- cmd_tbl->PrdtEntries[index_byte].InterruptBit = 1; // Interrupt on completion
-
- size -= kib_cast(8);
- buffer += kib_cast(4); // Move the buffer pointer forward
- }
+ cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
+ cmd_tbl->PrdtEntries[index_byte].Dbc = size; // 8KB buffer size
+ cmd_tbl->PrdtEntries[index_byte].InterruptBit = 1; // Interrupt on completion
// Last PRDT entry
cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
@@ -176,12 +229,12 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size
cmd_fis->CountHigh = (size >> 8) & 0xFF;
// 6. Issue the command by writing to the port's command issue register (CI)
- kAhciPort->Ci = 1 << free_slot;
+ kAhciPort->Ci = 1;
// 7. Wait for the command to complete (simple spinlock, no need for an object here)
while (Yes)
{
- if (!(kAhciPort->Ci & (1 << free_slot)))
+ if (!(kAhciPort->Ci & 1))
{
break; // Command has completed
}
@@ -189,26 +242,16 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size
{
return; // Error in task file
}
- }
- kSlotIsUsed = No;
+ kcout << Kernel::number((kAhciPort->Ci & 1)) << endl;
+ }
}
Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer)
{
- STATIC Kernel::Boolean kSlotIsUsed = No;
-
- if (kSlotIsUsed)
- return;
-
- kSlotIsUsed = Yes;
-
- Kernel::Int64 free_slot = 0L;
-
// Prepare command header.
HbaCmdHeader* cmd_header = (HbaCmdHeader*)(Kernel::UIntPtr)kAhciPort->Clb;
- cmd_header += free_slot;
// Read operation/set entries count.
@@ -223,15 +266,9 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Siz
Kernel::UInt64 size = size * kAHCISectorSize;
Kernel::Int64 index_byte = 0L;
- for (index_byte = 0; index_byte < (cmd_header->Prdtl - 1); ++index_byte)
- {
- cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
- cmd_tbl->PrdtEntries[index_byte].Dbc = (kib_cast(8)) - 1; // 8KB buffer size
- cmd_tbl->PrdtEntries[index_byte].InterruptBit = 1; // Interrupt on completion
-
- size -= kib_cast(8);
- buffer += kib_cast(4); // Move the buffer pointer forward
- }
+ cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
+ cmd_tbl->PrdtEntries[index_byte].Dbc = size; // 8KB buffer size
+ cmd_tbl->PrdtEntries[index_byte].InterruptBit = 1; // Interrupt on completion
// Last PRDT entry
cmd_tbl->PrdtEntries[index_byte].Dba = (Kernel::UInt32)(Kernel::UIntPtr)buffer;
@@ -259,12 +296,12 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Siz
cmd_fis->CountHigh = (size >> 8) & 0xFF;
// 6. Issue the command by writing to the port's command issue register (CI)
- kAhciPort->Ci = 1 << free_slot;
+ kAhciPort->Ci = 1;
// 7. Wait for the command to complete (simple spinlock, no need for an object here)
while (Yes)
{
- if (!(kAhciPort->Ci & (1 << free_slot)))
+ if (!(kAhciPort->Ci & 1))
{
break; // Command has completed
}
@@ -274,9 +311,9 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Siz
Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED);
return; // Error in task file
}
- }
- kSlotIsUsed = No;
+ kcout << Kernel::number((kAhciPort->Ci & 1)) << endl;
+ }
}
/***
@@ -285,7 +322,7 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Siz
*/
Kernel::SizeT drv_get_sector_count()
{
- return 0;
+ return kCurrentDiskSectorCount;
}
/// @brief Get the drive size.
diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc b/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc
index 19baa6d9..436b76d0 100644
--- a/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc
+++ b/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc
@@ -123,7 +123,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz
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);
@@ -155,7 +155,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS
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);
diff --git a/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h b/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h
index 5d1abff5..1ef08a6e 100644
--- a/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h
+++ b/dev/ZKAKit/KernelKit/HardwareThreadScheduler.h
@@ -105,7 +105,7 @@ namespace Kernel
public:
Ref<HardwareThread*> operator[](const SizeT& idx);
bool operator!() noexcept;
- operator bool() noexcept;
+ operator bool() noexcept;
const Bool IsUser() override
{
diff --git a/dev/ZKAKit/KernelKit/LoaderInterface.h b/dev/ZKAKit/KernelKit/LoaderInterface.h
index 9323aec7..f5a34495 100644
--- a/dev/ZKAKit/KernelKit/LoaderInterface.h
+++ b/dev/ZKAKit/KernelKit/LoaderInterface.h
@@ -25,9 +25,9 @@ namespace Kernel
public:
virtual _Output ErrorOr<VoidPtr> GetBlob() = 0;
- virtual _Output const Char* AsString() = 0;
- virtual _Output const Char* MIME() = 0;
- virtual _Output const Char* Path() = 0;
+ virtual _Output const Char* AsString() = 0;
+ virtual _Output const Char* MIME() = 0;
+ virtual _Output const Char* Path() = 0;
virtual _Output ErrorOr<VoidPtr> FindStart() = 0;
virtual _Output VoidPtr FindSymbol(_Input const Char* name, _Input Int32 kind) = 0;
};
diff --git a/dev/ZKAKit/KernelKit/PCI/DMA.h b/dev/ZKAKit/KernelKit/PCI/DMA.h
index 0ad2c344..b4bbc570 100644
--- a/dev/ZKAKit/KernelKit/PCI/DMA.h
+++ b/dev/ZKAKit/KernelKit/PCI/DMA.h
@@ -52,7 +52,7 @@ namespace Kernel
T* Get(const UIntPtr off = 0);
public:
- operator bool();
+ operator bool();
bool operator!();
public:
diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h
index 865a6477..1a9cce06 100644
--- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h
+++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h
@@ -262,7 +262,7 @@ namespace Kernel
ZKA_COPY_DEFAULT(UserProcessScheduler)
- operator bool();
+ operator bool();
bool operator!();
public:
diff --git a/dev/ZKAKit/NewKit/Macros.h b/dev/ZKAKit/NewKit/Macros.h
index 10afb7b2..8db257be 100644
--- a/dev/ZKAKit/NewKit/Macros.h
+++ b/dev/ZKAKit/NewKit/Macros.h
@@ -11,7 +11,7 @@
#endif
#ifndef kib_cast
-#define kib_cast(X) (Kernel::UInt64)((X) * 1024)
+#define kib_cast(X) (Kernel::UInt64)((X)*1024)
#endif
#ifndef MIB
diff --git a/dev/ZKAKit/src/BitMapMgr.cc b/dev/ZKAKit/src/BitMapMgr.cc
index 0ce298d8..e2dd7dfa 100644
--- a/dev/ZKAKit/src/BitMapMgr.cc
+++ b/dev/ZKAKit/src/BitMapMgr.cc
@@ -170,7 +170,6 @@ namespace Kernel
if (!page_ptr)
return No;
-
Detail::IBitMapAllocator traits;
Bool ret = traits.FreeBitMap(page_ptr);
diff --git a/dev/ZKAKit/src/CodeMgr.cc b/dev/ZKAKit/src/CodeMgr.cc
index 81020775..5f04865f 100644
--- a/dev/ZKAKit/src/CodeMgr.cc
+++ b/dev/ZKAKit/src/CodeMgr.cc
@@ -22,11 +22,11 @@ namespace Kernel
return No;
static UserProcess proc;
-
+
kcout << "Setting-up process data...\r";
- proc.Code = reinterpret_cast<VoidPtr>(main);
- proc.Kind = UserProcess::kExectuableKind;
+ proc.Code = reinterpret_cast<VoidPtr>(main);
+ proc.Kind = UserProcess::kExectuableKind;
proc.StackSize = kib_cast(16);
rt_set_memory(proc.Name, 0, kProcessNameLen);
diff --git a/dev/ZKAKit/src/DriveMgr.cc b/dev/ZKAKit/src/DriveMgr.cc
index d4ffc8d5..38dd1cbb 100644
--- a/dev/ZKAKit/src/DriveMgr.cc
+++ b/dev/ZKAKit/src/DriveMgr.cc
@@ -151,6 +151,7 @@ namespace Kernel
trait.fPacket.fPacketSize = sizeof(_BOOT_BLOCK_STRUCT);
trait.fPacket.fPacketContent = &block_struct;
+ trait.fInit(&trait.fPacket);
io_drv_input(&trait.fPacket);
trait.fKind = kMassStorage;
diff --git a/dev/ZKAKit/src/FS/NeFS.cc b/dev/ZKAKit/src/FS/NeFS.cc
index ff8d94f2..239651da 100644
--- a/dev/ZKAKit/src/FS/NeFS.cc
+++ b/dev/ZKAKit/src/FS/NeFS.cc
@@ -61,7 +61,7 @@ STATIC MountpointInterface kDiskMountpoint;
/// @return the fork
/***********************************************************************************/
_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input NFS_FORK_STRUCT& the_fork)
+ _Input NFS_FORK_STRUCT& the_fork)
{
if (catalog && the_fork.ForkName[0] != 0 &&
the_fork.DataSize <= kNeFSForkDataSz)
@@ -170,8 +170,8 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal
/// @return the fork.
/***********************************************************************************/
_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input const Char* name,
- Boolean isDataFork)
+ _Input const Char* name,
+ Boolean isDataFork)
{
auto drv = kDiskMountpoint.A();
NFS_FORK_STRUCT* the_fork = nullptr;
@@ -236,7 +236,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name)
/// @param kind the catalog kind.
/// @return catalog pointer.
/***********************************************************************************/
-_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
+_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
@@ -936,7 +936,7 @@ Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName)
VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
_Input Bool is_rsrc_fork,
_Input SizeT dataSz,
- _Input const Char* forkName)
+ _Input const Char* forkName)
{
if (!catalog)
{
@@ -1034,16 +1034,13 @@ namespace Kernel::Detail
Boolean fs_init_newfs(Void) noexcept
{
kcout << "Creating drives...\r";
+ kcout << "Constructing A:\r";
kDiskMountpoint.A() = io_construct_main_drive();
kDiskMountpoint.B() = io_construct_drive();
kDiskMountpoint.C() = io_construct_drive();
kDiskMountpoint.D() = io_construct_drive();
- kcout << "Constructing A:\r";
-
- kDiskMountpoint.A().fInit(&kDiskMountpoint.A().fPacket);
-
kcout << "Constructing A: [ OK ]\r";
return true;
diff --git a/dev/ZKAKit/src/HardwareThreadScheduler.cc b/dev/ZKAKit/src/HardwareThreadScheduler.cc
index 5316f53a..7e124c0a 100644
--- a/dev/ZKAKit/src/HardwareThreadScheduler.cc
+++ b/dev/ZKAKit/src/HardwareThreadScheduler.cc
@@ -112,10 +112,9 @@ namespace Kernel
if (!hal_check_stack(frame))
return No;
- this->fStack = frame;
+ this->fStack = frame;
this->fSourcePID = pid;
-
Bool ret = mp_register_process(image, stack_ptr, fStack, this->fSourcePID);
if (ret)
diff --git a/dev/ZKAKit/src/PEFCodeMgr.cc b/dev/ZKAKit/src/PEFCodeMgr.cc
index 7faf728e..33bd659c 100644
--- a/dev/ZKAKit/src/PEFCodeMgr.cc
+++ b/dev/ZKAKit/src/PEFCodeMgr.cc
@@ -255,12 +255,12 @@ namespace Kernel
STATIC UserProcess proc;
- proc.Kind = procKind;
- proc.ExecImg = errOrStart.Leak().Leak();
- proc.ExecImg = exec.GetBlob().Leak().Leak();
- proc.StackSize = *(UIntPtr*)exec.FindSymbol(kPefStackSizeSymbol, kPefData);
+ proc.Kind = procKind;
+ proc.ExecImg = errOrStart.Leak().Leak();
+ proc.ExecImg = exec.GetBlob().Leak().Leak();
+ proc.StackSize = *(UIntPtr*)exec.FindSymbol(kPefStackSizeSymbol, kPefData);
proc.MemoryLimit = *(UIntPtr*)exec.FindSymbol(kPefHeapSizeSymbol, kPefData);
- proc.PTime = 0UL;
+ proc.PTime = 0UL;
rt_set_memory(proc.Name, 0, kProcessNameLen);
diff --git a/dev/ZKAKit/src/Property.cc b/dev/ZKAKit/src/Property.cc
index ae3186bd..6ff430c1 100644
--- a/dev/ZKAKit/src/Property.cc
+++ b/dev/ZKAKit/src/Property.cc
@@ -19,7 +19,7 @@ namespace CFKit
Property::Property() = default;
/***********************************************************************************/
- /// @brief Check if property's name equals to name.
+ /// @brief Check if property's name equals to name.
/// @param name string to check.
/***********************************************************************************/
Bool Property::StringEquals(KString& name)
diff --git a/dev/ZKAKit/src/Semaphore.cc b/dev/ZKAKit/src/Semaphore.cc
index baf7776f..4b69912c 100644
--- a/dev/ZKAKit/src/Semaphore.cc
+++ b/dev/ZKAKit/src/Semaphore.cc
@@ -66,6 +66,7 @@ namespace Kernel
/***********************************************************************************/
Void Semaphore::WaitForProcess() noexcept
{
- while (fLockingProcess);
+ while (fLockingProcess)
+ ;
}
} // namespace Kernel