From b1f19b23148e895d8e0e235af328a9b36f556a40 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 13:33:35 +0200 Subject: dev, kernel, ahci: AHCI related fixes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 9 ++++--- dev/kernel/HALKit/AMD64/Processor.h | 1 + dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 33 ++++++++++++++----------- 3 files changed, 25 insertions(+), 18 deletions(-) (limited to 'dev/kernel/HALKit') diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc index 16fe843a..c6c24be1 100644 --- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc @@ -143,13 +143,14 @@ namespace Kernel::HAL pte->Wr = !!(flags & kMMFlagsWr); pte->User = !!(flags & kMMFlagsUser); pte->Nx = !!(flags & kMMFlagsNX); - pte->Pcd = !(flags & kMMFlagsPCD); - pte->PhysicalAddress = (UIntPtr)(physical_address); - - mmi_page_status(pte); + pte->Pcd = !!(flags & kMMFlagsPCD); + pte->Pwt = !!(flags & kMMFlagsPwt); + pte->PhysicalAddress = ((UIntPtr)(physical_address)); hal_invl_tlb(virtual_address); + mmi_page_status(pte); + return kErrorSuccess; } } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index f2e9c2ea..13819f3e 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -74,6 +74,7 @@ namespace Kernel::HAL kMMFlagsUser = 1 << 3, kMMFlagsNX = 1 << 4, kMMFlagsPCD = 1 << 5, + kMMFlagsPwt = 1 << 6, kMMFlagsCount = 4, }; diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 08fd02ab..3955dd78 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -74,10 +74,10 @@ STATIC Void drv_compute_disk_ahci() noexcept const UInt16 kSzIdent = 512; /// Push it to the stack - UInt16* identify_data = new UInt16[kSzIdent]; + UInt8* identify_data = new UInt8[kSzIdent]; /// Send AHCI command for identification. - drv_std_input_output_ahci(0, (UInt8*)identify_data, kAHCISectorSize, kSzIdent); + drv_std_input_output_ahci(0, identify_data, kAHCISectorSize, kSzIdent); /// Extract 48-bit LBA. UInt64 lba48_sectors = 0; @@ -91,7 +91,16 @@ STATIC Void drv_compute_disk_ahci() noexcept else kSATASectorCount = lba48_sectors; - (Void)(kout << "Device: " << kCurrentDiskModel << kendl); + for (Int32 i = 0; i < 20; i++) + { + kCurrentDiskModel[i * 2] = (identify_data[27 + i] >> 8) & 0xFF; + kCurrentDiskModel[i * 2 + 1] = identify_data[27 + i] & 0xFF; + } + + kCurrentDiskModel[40] = '\0'; + + (Void)(kout << "SATA Sector Count: " << hex_number(kSATASectorCount) << kendl); + (Void)(kout << "SATA Disk Model: " << kCurrentDiskModel << kendl); delete[] identify_data; identify_data = nullptr; @@ -102,17 +111,15 @@ STATIC Void drv_compute_disk_ahci() noexcept /// @return The slot, or ~0. STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept { - UInt32 slots = (port->Sact | port->Ci); + UInt32 slots = port->Sact | port->Ci; - for (Int32 i = 0; i < kSATAPortCnt; ++i) + for (Int32 i = 0; i < kSATAPortCnt; ++i) // AHCI supports up to 32 slots { - if ((slots & 1) == 0) + if ((slots & (1U << i)) == 0) return i; - - slots >>= 1; } - return ~0; + return -1; // no free slot found } /// @brief Send an AHCI command, according to the template parameters. @@ -159,8 +166,6 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz auto ctba_phys = ((UInt64)command_header->Ctbau << 32) | command_header->Ctba; auto command_table = reinterpret_cast(ctba_phys); - rt_set_memory((HbaCmdTbl*)command_table, 0, sizeof(HbaCmdTbl) + (command_header->Prdtl - 1) * sizeof(HbaPrdtEntry)); - MUST_PASS(command_table); UIntPtr buffer_phys = HAL::hal_get_phys_address(buffer); @@ -278,12 +283,12 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) if (kSATADev.Subclass() == kSATASubClass && kSATADev.ProgIf() == kSATAProgIfAHCI) { - HbaMem* mem_ahci = (HbaMem*)kSATADev.Bar(kSATABar5); - kSATADev.EnableMmio(); kSATADev.BecomeBusMaster(); - HAL::mm_map_page((VoidPtr)mem_ahci, (VoidPtr)mem_ahci, HAL::kMMFlagsPresent | HAL::kMMFlagsWr | HAL::kMMFlagsPCD); + HbaMem* mem_ahci = (HbaMem*)kSATADev.Bar(kSATABar5); + + HAL::mm_map_page((VoidPtr)mem_ahci, (VoidPtr)mem_ahci, HAL::kMMFlagsPresent | HAL::kMMFlagsWr | HAL::kMMFlagsPCD | HAL::kMMFlagsPwt); UInt32 ports_implemented = mem_ahci->Pi; UInt16 ahci_index = 0; -- cgit v1.2.3 From 78b14fac0eb63614c1d091f68170f5fd5d3bb9d5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 18:15:43 +0200 Subject: dev, kernel: Working on a 0.0.1e (for Errata) Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 1 - dev/kernel/src/Gfx/FBDeviceInterface.cc | 7 +-- dev/modules/CoreGfx/CoreWindow.h | 85 -------------------------------- 3 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 dev/modules/CoreGfx/CoreWindow.h (limited to 'dev/kernel/HALKit') diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 7f3d4137..ce8c1245 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index c2eb2ca7..b3b52934 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -36,7 +36,7 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) pckt->fY > kHandoverHeader->f_GOP.f_Height) return *this; - FBDrawInRegion(pckt->fColor, pckt->fHeight, pckt->fWidth, pckt->fY, pckt->fX); + this->fOut(this, pckt); return *this; } @@ -53,10 +53,7 @@ FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) pckt->fY > kHandoverHeader->f_GOP.f_Height) return *this; - pckt->fColor = *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + - 4 * kHandoverHeader->f_GOP.f_PixelPerLine * - pckt->fX + - 4 * pckt->fY))); + this->fIn(this, pckt); return *this; } diff --git a/dev/modules/CoreGfx/CoreWindow.h b/dev/modules/CoreGfx/CoreWindow.h deleted file mode 100644 index b1581f65..00000000 --- a/dev/modules/CoreGfx/CoreWindow.h +++ /dev/null @@ -1,85 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -/// @note this file is experimental and not used yet. -/// @file CoreWindow.h -/// @brief Core window drawing functions. - -#pragma once - -#include -#include - -namespace UI -{ - struct UIRect final - { - Kernel::UInt32 x, y, height, width; - }; - - inline void draw_beveled_rect(const UIRect& rect, Kernel::UInt32 topLeftColor, Kernel::UInt32 bottomRightColor) - { - // Top edge - FBDrawInRegion(topLeftColor, rect.height, 1, rect.y, rect.x); - // Left edge - FBDrawInRegion(topLeftColor, 1, rect.width, rect.y, rect.x); - - // Bottom edge - FBDrawInRegion(bottomRightColor, rect.height, 1, rect.y + rect.width - 1, rect.x); - // Right edge - FBDrawInRegion(bottomRightColor, 1, rect.width, rect.y, rect.x + rect.height - 1); - } - - inline void draw_close_button(Kernel::UInt32 x, Kernel::UInt32 y) - { - const Kernel::UInt32 border = fb_color(0x00, 0x00, 0x00); - const Kernel::UInt32 fill = fb_color(0xD0, 0xD0, 0xD0); - - // A simple square for close button, 10x10 px - FBDrawInRegion(border, 10, 10, y, x); // Outer border - FBDrawInRegion(fill, 8, 8, y + 1, x + 1); // Inner fill - } - - inline void draw_title_bar(const UIRect& rect, const char* title) - { - const Kernel::Int32 barHeight = 22; - - Kernel::UInt32 lightEdge = fb_color(0xF0, 0xF0, 0xF0); // Light gray top - Kernel::UInt32 darkEdge = fb_color(0x40, 0x40, 0x40); // Shadow - Kernel::UInt32 fillColor = fb_color(0xA0, 0xA0, 0xA0); // Mid-gray - - // Title bar fill - FBDrawInRegion(fillColor, rect.height - 2, barHeight, rect.y + 1, rect.x + 1); - - // Beveled edges (top, left bright; right, bottom dark) - UIRect bevel = {rect.x + 1, rect.y + 1, rect.height - 2, barHeight}; - draw_beveled_rect(bevel, lightEdge, darkEdge); - - // Title text - fb_render_string(title, rect.y + 8, rect.x + 24, fb_color(0x00, 0x00, 0x00)); - - // Close button - draw_close_button(rect.x + 6, rect.y + 6); - } - - inline void draw_window(const UIRect& rect, const Char* title) - { - Kernel::UInt32 windowFill = fb_color(0xC0, 0xC0, 0xC0); // Body color - Kernel::UInt32 borderDark = fb_color(0x60, 0x60, 0x60); - Kernel::UInt32 borderHighlight = fb_color(0xE0, 0xE0, 0xE0); - - // Fill window body (excluding title bar) - const Kernel::Int32 titleBarHeight = 22; - - FBDrawInRegion(windowFill, rect.height - 2, rect.width - titleBarHeight - 1, rect.y + titleBarHeight + 1, rect.x + 1); - - // Full window bevel border - draw_beveled_rect(rect, borderHighlight, borderDark); - - // Title bar - draw_title_bar(rect, title); - } -} \ No newline at end of file -- cgit v1.2.3