summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-04 07:56:52 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-04 07:56:52 +0200
commit216b2f35b38b582a930948fca76c272e424c9d96 (patch)
treecfeed5605e4d6d86ee9e8eaebb28f8389edd1f50 /dev
parent9aef4d0ad473901d8f4a4f1405a2f8df0b725a71 (diff)
kernel, storage: important patches done to AHCI, PIO, PagingMgr, and DMA.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/boot/amd64-desktop.make2
-rw-r--r--dev/boot/src/BootThread.cc18
-rw-r--r--dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc2
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc12
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc10
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc24
6 files changed, 34 insertions, 34 deletions
diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make
index b0f81a39..6e796752 100644
--- a/dev/boot/amd64-desktop.make
+++ b/dev/boot/amd64-desktop.make
@@ -119,7 +119,7 @@ run-efi-amd64-ahci:
.PHONY: run-efi-amd64-ata-pio
run-efi-amd64-ata-pio:
- $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S
+ $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -d int
.PHONY: run-efi-amd64-ata-dma
run-efi-amd64-ata-dma:
diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc
index aac3c931..ee70812f 100644
--- a/dev/boot/src/BootThread.cc
+++ b/dev/boot/src/BootThread.cc
@@ -73,23 +73,18 @@ namespace Boot
writer.Write("BootZ: Minor Subsystem Ver: ").Write(opt_header_ptr->MinorSubsystemVersion).Write("\r");
writer.Write("BootZ: Magic: ").Write(header_ptr->Signature).Write("\r");
- constexpr auto cPageSize = 512;
-
EfiPhysicalAddress loadStartAddress = opt_header_ptr->ImageBase;
loadStartAddress += opt_header_ptr->BaseOfData;
writer.Write("BootZ: Image base: ").Write(loadStartAddress).Write("\r");
- auto numPages = opt_header_ptr->SizeOfImage / cPageSize;
- BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress);
-
fStack = new UInt8[mib_cast(16)];
LDR_SECTION_HEADER_PTR sectPtr = (LDR_SECTION_HEADER_PTR)(((Char*)opt_header_ptr) + header_ptr->SizeOfOptionalHeader);
- constexpr auto sectionForCode = ".text";
- constexpr auto sectionForNewLdr = ".ldr";
- constexpr auto sectionForBSS = ".bss";
+ constexpr auto sectionForCode = ".text";
+ constexpr auto sectionForBootZ = ".ldr";
+ constexpr auto sectionForBSS = ".bss";
for (SizeT sectIndex = 0; sectIndex < numSecs; ++sectIndex)
{
@@ -114,7 +109,7 @@ namespace Boot
fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + opt_header_ptr->AddressOfEntryPoint);
writer.Write("BootZ: Executable entry address: ").Write((UIntPtr)fStartAddress).Write("\r");
}
- else if (StrCmp(sectionForNewLdr, sect->Name) == 0)
+ else if (StrCmp(sectionForBootZ, sect->Name) == 0)
{
struct HANDOVER_INFORMATION_STUB
{
@@ -159,8 +154,9 @@ namespace Boot
// ========================================= //
fStartAddress = nullptr;
+
writer.Write("BootZ: PEF executable detected, won't load it.\r");
- writer.Write("BootZ: note: PEF executables aren't loadable by default.\r");
+ writer.Write("BootZ: note: PEF executables aren't supported for now.\r");
}
else
{
@@ -187,7 +183,7 @@ namespace Boot
if (own_stack)
{
- UInt8* aligned_stack = &fStack[mib_cast(16)];
+ UInt8* aligned_stack = &fStack[mib_cast(16) - 1];
aligned_stack = (UInt8*)((UIntPtr)aligned_stack & ~0xF);
rt_jump_to_address(fStartAddress, fHandover, aligned_stack);
diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc
index 63796393..6a9a89b7 100644
--- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc
+++ b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc
@@ -91,7 +91,7 @@ namespace Kernel::HAL
// Lastly, grab the pte entry.
NE_PDE* pde_struct = reinterpret_cast<NE_PDE*>(pt_base);
- return pde_struct->fEntries[pt_index]->PhysicalAddress;
+ return pde_struct->fEntries[pt_entry]->PhysicalAddress;
}
/***********************************************************************************/
diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
index 21d95b5d..f74db6c0 100644
--- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc
@@ -15,6 +15,7 @@
*
*/
+#include "NewKit/Defines.h"
#include <KernelKit/DeviceMgr.h>
#include <KernelKit/DriveMgr.h>
#include <KernelKit/ProcessScheduler.h>
@@ -71,13 +72,13 @@ STATIC Void drv_compute_disk_ahci() noexcept
kSATASectorCount = 0UL;
/// Normally 512 bytes, but add an additional 512 bytes to make 1 KIB.
- const UInt16 kSzIdent = kib_cast(1);
+ const UInt16 kSzIdent = 256;
/// Push it to the stack
- UInt8* identify_data ATTRIBUTE(aligned(4096)) = new UInt8[kSzIdent];
+ UInt16* identify_data ATTRIBUTE(aligned(4096)) = new UInt16[kSzIdent];
/// Send AHCI command for identification.
- drv_std_input_output_ahci<NO, YES, YES>(0, identify_data, kAHCISectorSize, kSzIdent);
+ drv_std_input_output_ahci<NO, YES, YES>(0, (UInt8*)identify_data, kAHCISectorSize, kSzIdent);
/// Extract 48-bit LBA.
@@ -90,6 +91,9 @@ STATIC Void drv_compute_disk_ahci() noexcept
kSATASectorCount = (identify_data[61] << 16) | identify_data[60];
else
kSATASectorCount = lba48_sectors;
+
+ delete[] identify_data;
+ identify_data = nullptr;
}
/// @brief Finds a command slot for a HBA port.
@@ -140,8 +144,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz
/// Offset to specific command slot.
command_header += slot;
+ /// check for command header.
MUST_PASS(command_header);
+ /// 4kb per PRD.
constexpr const UInt32 kMaxPRDSize = kib_cast(4);
command_header->Cfl = sizeof(FisRegH2D) / sizeof(UInt32);
diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
index 5aabf144..f04d25eb 100644
--- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc
@@ -28,11 +28,11 @@ using namespace Kernel::HAL;
/// BUGS: 0
-STATIC Boolean kATADetected = false;
-STATIC Int32 kATADeviceType = kATADeviceCount;
-STATIC Char kATAData[kATADataLen] = {0};
+STATIC Boolean kATADetected = false;
+STATIC Int32 kATADeviceType = kATADeviceCount;
+STATIC UInt16 kATAIdentifyData[kATADataLen] = {0};
STATIC Kernel::PCI::Device kATADevice;
-STATIC Char kCurrentDiskModel[50] = {"GENERIC DMA"};
+STATIC Char kATADiskModel[50] = {"GENERIC DMA"};
Boolean drv_std_wait_io(UInt16 IO)
{
@@ -198,7 +198,7 @@ Boolean drv_std_detected(Void)
/***********************************************************************************/
Kernel::SizeT drv_get_sector_count()
{
- return (kATAData[61] << 16) | kATAData[60];
+ return (kATAIdentifyData[61] << 16) | kATAIdentifyData[60];
}
/***********************************************************************************/
diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
index aa3b50c4..fc608e94 100644
--- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
@@ -25,12 +25,12 @@ using namespace Kernel::HAL;
/// BUGS: 0
-#define kATADataLen 512
+#define kATADataLen 256
-STATIC Boolean kATADetected = false;
-STATIC Int32 kATADeviceType = kATADeviceCount;
-STATIC Char kATAData[kATADataLen] = {0};
-STATIC Char kCurrentDiskModel[50] = {"GENERIC PIO"};
+STATIC Boolean kATADetected = false;
+STATIC Int32 kATADeviceType = kATADeviceCount;
+STATIC UInt16 kATAIdentifyData[kATADataLen] = {0};
+STATIC Char kATADiskModel[50] = {"GENERIC PIO"};
static Boolean drv_pio_std_wait_io(UInt16 IO)
{
@@ -96,20 +96,18 @@ ATAInit_Retry:
for (SizeT i = 0ul; i < kATADataLen; ++i)
{
- kATAData[i] = HAL::rt_in16(OutBus + ATA_REG_DATA);
+ kATAIdentifyData[i] = HAL::rt_in16(OutBus + ATA_REG_DATA);
}
for (Int32 i = 0; i < 20; i++)
{
- kCurrentDiskModel[i * 2] = kATAData[27 + i] >> 8;
- kCurrentDiskModel[i * 2 + 1] = kATAData[27 + i + 1] & 0xFF;
+ kATADiskModel[i * 2] = (kATAIdentifyData[27 + i] >> 8) & 0xFF;
+ kATADiskModel[i * 2 + 1] = kATAIdentifyData[27 + i] & 0xFF;
}
- kCurrentDiskModel[40] = '\0';
+ kATADiskModel[40] = '\0';
- kout << "Detect: /dev/ata0" << kendl;
-
- kout << "Drive Model: " << kCurrentDiskModel << kendl;
+ kout << "Drive Model: " << kATADiskModel << kendl;
return true;
}
@@ -179,7 +177,7 @@ Boolean drv_pio_std_detected(Void)
*/
SizeT drv_pio_get_sector_count()
{
- return (kATAData[61] << 16) | kATAData[60];
+ return (kATAIdentifyData[61] << 16) | kATAIdentifyData[60];
}
/// @brief Get the drive size.