diff options
Diffstat (limited to 'dev/kernel')
| -rw-r--r-- | dev/kernel/FirmwareKit/CoreBoot/BootNet.h | 30 | ||||
| -rw-r--r-- | dev/kernel/FirmwareKit/CoreBoot/NetBoot.h | 25 | ||||
| -rw-r--r-- | dev/kernel/FirmwareKit/EFI/EFI.h | 14 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 31 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/DebugOutput.h | 2 |
5 files changed, 53 insertions, 49 deletions
diff --git a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h new file mode 100644 index 00000000..a86ea81a --- /dev/null +++ b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NewKit/Defines.h> + +#define kBootNetINetMagic "NETB" +#define kBootNetINetMagicLength (4) + +#define kBootNetNameLen (256U) + +/// @brief the internet header is used to download updates OTA. +typedef struct BOOTNET_INTERNET_HEADER +{ + Kernel::Char NB1; /// magic char 1 'N' + Kernel::Char NB2; /// magic char 2 'E' + Kernel::Char NB3; /// magic char 3 'T' + Kernel::Char NB4; /// magic char 4 'B' + + Kernel::Char Name[kBootNetNameLen]; /// example: Modjo + Kernel::Int32 Length; /// the patch length. + Kernel::Char Target[kBootNetNameLen]; /// the target file. + Kernel::Boolean ImpliesEEPROM : 1; /// does it imply an EEPROM reprogram? + Kernel::Boolean Preflight : 1; /// is it a preflight packet. + Kernel::Char Data[]; /// non preflight packet has a patch blob for a **PatchTarget** +} ATTRIBUTE(packed) BOOTNET_INTERNET_HEADER; diff --git a/dev/kernel/FirmwareKit/CoreBoot/NetBoot.h b/dev/kernel/FirmwareKit/CoreBoot/NetBoot.h deleted file mode 100644 index b1e9313c..00000000 --- a/dev/kernel/FirmwareKit/CoreBoot/NetBoot.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.h> - -/// @brief the internet header is used to download updates OTA. -typedef struct BOOTNET_INTERNET_HEADER -{ - Kernel::Char NB1; /// magic char 1 'N' - Kernel::Char NB2; /// magic char 2 'E' - Kernel::Char NB3; /// magic char 3 'T' - Kernel::Char NB4; /// magic char 4 'B' - - Kernel::Char PatchName[256U]; /// example: ColdChoco - Kernel::Int32 PatchLength; /// the patch length. - Kernel::Char PatchTarget[256U]; /// the target file. - Kernel::Boolean ImpliesROM; /// does it imply an EEPROM reprogram? - Kernel::Boolean Preflight; /// is it a preflight packet. - Kernel::Char Patch[]; /// non preflight packet has a patch blob for a **PatchTarget** -} BOOTNET_INTERNET_HEADER; diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index 3c3ffa09..1e6de42c 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -201,18 +201,10 @@ typedef enum EfiAllocateType typedef struct EfiMemoryDescriptor { - /// - /// Kind of the memory region. - /// Kind EFI_MEMORY_TYPE is defined in the - /// AllocatePages() function description. - /// + /// @brief Kind of the memory region. UInt32 Kind; - /// - /// Physical address of the first byte in the memory region. PhysicalStart - /// must be aligned on a 4 KiB boundary, and must not be above - /// 0xfffffffffffff000. Kind EFI_PHYSICAL_ADDRESS is defined in the - /// AllocatePages() function description - /// + + /// @brief Physical address of the first byte in the memory region. PhysicalStart EfiPhysicalAddress PhysicalStart; /// /// Virtual address of the first byte in the memory region. diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 38a1742b..7dac018d 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -74,8 +74,10 @@ STATIC Void drv_compute_disk_ahci() noexcept const UInt16 kSzIdent = kib_cast(1); /// Push it to the stack - UInt8 identify_data[kSzIdent] = {0}; + static UInt8 identify_data[kSzIdent] ATTRIBUTE(aligned(4096)) = {0}; + HAL::mm_map_page((void*)mib_cast(1), (void*)mib_cast(1), HAL::kMMFlagsWr); + rt_set_memory(identify_data, 0, kSzIdent); /// Send AHCI command for identification. @@ -140,9 +142,11 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz MUST_PASS(command_header); + constexpr UInt32 kMaxPRDSize = 0x400000; + command_header->Cfl = sizeof(FisRegH2D) / sizeof(UInt32); command_header->Write = Write; - command_header->Prdtl = (UInt16)((size_buffer - 1) / 8); + command_header->Prdtl = (UInt16)((size_buffer + kMaxPRDSize - 1) / kMaxPRDSize); volatile HbaCmdTbl* command_table = (volatile HbaCmdTbl*)((VoidPtr)((UInt64)command_header->Ctba)); @@ -150,18 +154,21 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz MUST_PASS(command_table); - UIntPtr buffer_phys = HAL::hal_get_phys_address(buffer); - - UInt16 prd_i = 0; + UIntPtr buffer_phys = HAL::hal_get_phys_address(buffer); + SizeT bytes_remaining = size_buffer; + SizeT prdt_count = command_header->Prdtl; - for (; prd_i < (command_header->Prdtl - 1); ++prd_i) + for (UInt16 i = 0; i < prdt_count; ++i) { - command_table->Prdt[prd_i].Dbc = ((command_header->Prdtl - 1) / 8); - command_table->Prdt[prd_i].Dba = ((UInt32)(UInt64)buffer_phys); - command_table->Prdt[prd_i].Dbau = (((UInt64)(buffer_phys) >> 32)); - command_table->Prdt[prd_i].Ie = YES; + UInt32 chunk = (bytes_remaining > kMaxPRDSize) ? kMaxPRDSize : bytes_remaining; + + command_table->Prdt[i].Dba = (UInt32)(buffer_phys & 0xFFFFFFFF); + command_table->Prdt[i].Dbau = (UInt32)(buffer_phys >> 32); + command_table->Prdt[i].Dbc = chunk - 1; + command_table->Prdt[i].Ie = 1; - buffer_phys += command_table->Prdt[prd_i].Dbc; + buffer_phys += chunk; + bytes_remaining -= chunk; } volatile FisRegH2D* h2d_fis = (volatile FisRegH2D*)(&command_table->Cfis); @@ -176,7 +183,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz h2d_fis->Lba1 = (lba >> 8) & 0xFF; h2d_fis->Lba2 = (lba >> 16) & 0xFF; - h2d_fis->Device = Identify ? 0U : kSATALBAMode; + h2d_fis->Device = kSATALBAMode; h2d_fis->Lba3 = (lba >> 24) & 0xFF; h2d_fis->Lba4 = (lba >> 32) & 0xFF; diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index cb22ac6b..448e6208 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -208,6 +208,6 @@ namespace Kernel #undef kout #endif // ifdef kout -#define kout Kernel::TerminalDevice::The() << "[NeKernel] *" << __FILE__ << "*: " +#define kout Kernel::TerminalDevice::The() #define kendl Kernel::TerminalDevice::The() << Kernel::end_line() |
