From 9700c31e4958856ea9e4fa755a43d196fcf50614 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 20:05:58 +0100 Subject: NewBoot: Add ATA driver for NewFS/EPM. Also added a ATAHelper class. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/BootKit/BootKit.hxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Private/NewBoot/BootKit/BootKit.hxx') diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index cec3bdc2..73bbce37 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -14,6 +14,7 @@ #pragma once +#include #include using namespace HCore; @@ -27,7 +28,7 @@ enum { kSegmentBss = 6, }; -typedef wchar_t CharacterType; +typedef WideChar CharacterType; /** * @brief BootKit Text Writer class @@ -80,6 +81,9 @@ class BFileReader final { private: Int32 mErrorCode{kOperationOkay}; CharacterType mPath[255]; + + private: + ATAHelper mHelper; }; /***********************************************************************************/ -- cgit v1.2.3 From 025593a068bc83f64386325b826179cafd95a03f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 22:29:30 +0100 Subject: Bootloader: Improve PATA support, but will use UEFI SimpleFile to get the kernel image. Signed-off-by: Amlal El Mahrouss --- Private/EFIKit/Api.hxx | 75 ++++++++++++++ Private/EFIKit/EFI.hxx | 4 + Private/EFIKit/EFILib.hxx | 75 -------------- Private/NewBoot/BootKit/Arch/ATA.hxx | 15 +-- Private/NewBoot/BootKit/BootKit.hxx | 39 +++++++- Private/NewBoot/Source/HEL/AMD64/ATA.cxx | 124 ++++++++++-------------- Private/NewBoot/Source/HEL/AMD64/BootKit.cxx | 4 +- Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 6 +- Private/NewBoot/Source/HEL/AMD64/Platform.cxx | 3 +- Private/NewBoot/Source/makefile | 2 +- 10 files changed, 184 insertions(+), 163 deletions(-) create mode 100644 Private/EFIKit/Api.hxx delete mode 100644 Private/EFIKit/EFILib.hxx (limited to 'Private/NewBoot/BootKit/BootKit.hxx') diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx new file mode 100644 index 00000000..b08c2866 --- /dev/null +++ b/Private/EFIKit/Api.hxx @@ -0,0 +1,75 @@ +/* + * ======================================================== + * + * h-core + * Copyright 2024, Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __EFI_LIB__ +#define __EFI_LIB__ + +#include + +inline EfiSystemTable* ST = nullptr; +inline EfiBootServices* BS = nullptr; + +namespace EFI { +/** +@brief Stop Execution of program. +*/ +inline Void Stop() noexcept { + while (true) { + rt_cli(); + rt_halt(); + } +} + +/** +@brief Exit EFI API to let the OS load correctly. +Bascially frees everything we have in the EFI side. +*/ +inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey, + EfiHandlePtr ImageHandle) noexcept { + if (!SystemTable) return; + + SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey); +} +} // namespace EFI + +inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept { + if (!SystemTable) return; + + ST = SystemTable; + BS = ST->BootServices; + + ST->ConOut->ClearScreen(SystemTable->ConOut); + ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow); +} + +inline void KeRuntimeStop(const EfiCharType* ErrorCode, + const EfiCharType* Reason) noexcept { + ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n"); + + ST->ConOut->OutputString(ST->ConOut, L"*** ErrorCode: "); + ST->ConOut->OutputString(ST->ConOut, ErrorCode); + ST->ConOut->OutputString(ST->ConOut, L", Reason: "); + ST->ConOut->OutputString(ST->ConOut, Reason); + ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); + + EFI::Stop(); +} + +enum { + kPartEPM, + kPartGPT, + kPartMBR, + kPartCnt, +}; + +#ifdef __BOOTLOADER__ +#include +#endif // IF TARGET=BOOTLOADER + +#endif /* ifndef __EFI_LIB__ */ diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index bf06c514..529efe65 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -420,4 +420,8 @@ typedef struct EfiIPV6 { #define kEFIYellow (0x01 | 0x02 | 0x04 | 0x08) +#ifdef __x86_64 +#define __EFI_x86_64__ 1 +#endif // __x86_64 + #endif // __EFI__ diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx deleted file mode 100644 index b08c2866..00000000 --- a/Private/EFIKit/EFILib.hxx +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ======================================================== - * - * h-core - * Copyright 2024, Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#ifndef __EFI_LIB__ -#define __EFI_LIB__ - -#include - -inline EfiSystemTable* ST = nullptr; -inline EfiBootServices* BS = nullptr; - -namespace EFI { -/** -@brief Stop Execution of program. -*/ -inline Void Stop() noexcept { - while (true) { - rt_cli(); - rt_halt(); - } -} - -/** -@brief Exit EFI API to let the OS load correctly. -Bascially frees everything we have in the EFI side. -*/ -inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey, - EfiHandlePtr ImageHandle) noexcept { - if (!SystemTable) return; - - SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey); -} -} // namespace EFI - -inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept { - if (!SystemTable) return; - - ST = SystemTable; - BS = ST->BootServices; - - ST->ConOut->ClearScreen(SystemTable->ConOut); - ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow); -} - -inline void KeRuntimeStop(const EfiCharType* ErrorCode, - const EfiCharType* Reason) noexcept { - ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n"); - - ST->ConOut->OutputString(ST->ConOut, L"*** ErrorCode: "); - ST->ConOut->OutputString(ST->ConOut, ErrorCode); - ST->ConOut->OutputString(ST->ConOut, L", Reason: "); - ST->ConOut->OutputString(ST->ConOut, Reason); - ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); - - EFI::Stop(); -} - -enum { - kPartEPM, - kPartGPT, - kPartMBR, - kPartCnt, -}; - -#ifdef __BOOTLOADER__ -#include -#endif // IF TARGET=BOOTLOADER - -#endif /* ifndef __EFI_LIB__ */ diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/Arch/ATA.hxx index 8327f5c8..6e692c3d 100644 --- a/Private/NewBoot/BootKit/Arch/ATA.hxx +++ b/Private/NewBoot/BootKit/Arch/ATA.hxx @@ -95,6 +95,9 @@ using namespace HCore; #define ATA_PRIMARY 0x00 #define ATA_SECONDARY 0x01 +#define ATA_CYL_LOW 4 +#define ATA_CYL_HIGH 5 + // IO Direction #define ATA_READ 0x00 #define ATA_WRITE 0x013 @@ -114,25 +117,25 @@ UInt16 ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master); Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master); Boolean ATAIsDetected(Void); -class ATAHelper final { +class BATADevice final { public: enum { kPrimary = ATA_PRIMARY, kSecondary = ATA_SECONDARY, }; - explicit ATAHelper() noexcept; + explicit BATADevice() noexcept; - HCORE_COPY_DEFAULT(ATAHelper); + HCORE_COPY_DEFAULT(BATADevice); struct ATATraits final { SizeT mBase{1024}; - UInt8 mBus{kPrimary}; + UInt16 mBus{kPrimary}; Boolean mMaster{false}; }; - ATAHelper& Read(WideChar*, const SizeT&); - ATAHelper& Write(WideChar*, const SizeT&); + BATADevice& Read(WideChar*, const SizeT&); + BATADevice& Write(WideChar*, const SizeT&); ATATraits& Traits(); diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 73bbce37..edd8015b 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -83,7 +83,7 @@ class BFileReader final { CharacterType mPath[255]; private: - ATAHelper mHelper; + BATADevice mDevice; }; /***********************************************************************************/ @@ -92,3 +92,40 @@ class BFileReader final { #include #include + +#ifdef __EFI_x86_64__ + +inline void out8(UInt16 port, UInt8 value) { + asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +inline void out16(UInt16 port, UInt16 value) { + asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +inline void out32(UInt16 port, UInt32 value) { + asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); +} + +inline UInt8 in8(UInt16 port) { + UInt8 value = 0UL; + asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +inline UInt16 in16(UInt16 port) { + UInt16 value = 0UL; + asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +inline UInt32 in32(UInt16 port) { + UInt32 value = 0UL; + asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); + + return value; +} + +#endif // __EFI_x86_64__ \ No newline at end of file diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx index 6b45b4af..6d3635bc 100644 --- a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx @@ -10,40 +10,11 @@ #include #include -static Boolean kATADetected = false; - -extern "C" void out8(UInt16 port, UInt8 value) { - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" void out16(UInt16 port, UInt16 value) { - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" void out32(UInt16 port, UInt32 value) { - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" UInt8 in8(UInt16 port) { - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} +/***********************************************************************************/ +/// Provide some useful processor features. +/***********************************************************************************/ -extern "C" UInt16 in16(UInt16 port) { - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -extern "C" UInt32 in32(UInt16 port) { - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} +static Boolean kATADetected = false; void ATASelect(UInt8 Bus, Boolean isMaster) { if (Bus == ATA_PRIMARY) @@ -54,7 +25,8 @@ void ATASelect(UInt8 Bus, Boolean isMaster) { isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL); } -Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive) { +Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive, UInt16& OutBus, + Boolean& OutMaster) { BTextWriter writer; UInt16 IO = (Bus == ATA_PRIMARY) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; @@ -69,33 +41,35 @@ Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive) { out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); UInt8 status = in8(IO + ATA_REG_STATUS); - writer.WriteString(L"HCoreLdr: Init ATA: Checking status...\r\n"); - - if (status) { - while ((status = in8(IO + ATA_REG_STATUS) & ATA_SR_BSY)) - ; - if (status & ATA_REG_ERROR) { + if (status & ATA_SR_ERR) { #ifdef __DEBUG__ - writer.WriteString(L"HCoreLdr: Init ATA: Bad Drive!\r\n"); + writer.WriteString(L"HCoreLdr: Init ATA: Bad Drive!\r\n"); #endif // ifdef __DEBUG__ - return false; - } + return false; + } -#ifdef __DEBUG__ - writer.WriteString(L"HCoreLdr: Init ATA: OnLine!\r\n"); -#endif // ifdef __DEBUG__ + OutBus = (Bus == ATA_PRIMARY) ? BATADevice::kPrimary : BATADevice::kSecondary; + OutMaster = (Bus == ATA_PRIMARY); - kATADetected = true; - return status; - } + char cl = in8(Bus + ATA_CYL_LOW); /* get the "signature bytes" */ + char ch = in8(Bus + ATA_CYL_HIGH); -#ifdef __DEBUG__ - writer.WriteString(L"HCoreLdr: Init ATA: Not detected!\r\n"); -#endif // ifdef __DEBUG__ - return false; + /* differentiate ATA, ATAPI, SATA and SATAPI */ + if (cl == 0x14 && ch == 0xEB) + writer.WriteString(L"HCoreLdr: PATAPI detected.\r\n"); + if (cl == 0x69 && ch == 0x96) + writer.WriteString(L"HCoreLdr: SATAPI detected.\r\n"); + if (cl == 0 && ch == 0) writer.WriteString(L"HCoreLdr: PATA detected.\r\n"); + if (cl == 0x3c && ch == 0xc3) + writer.WriteString(L"HCoreLdr: SATA detected.\r\n"); + + return true; } +/*** @brief + * This polls the ATA drive. + */ void ATAWait(UInt16 IO) { for (int i = 0; i < 4000; i++) in8(IO + ATA_REG_ALT_STATUS); } @@ -106,8 +80,6 @@ UInt16 ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master) { UInt16 IO = Bus; ATASelect(IO, Master ? ATA_MASTER : ATA_SLAVE); - out8(IO + ATA_REG_LBA5, (UInt8)(Lba >> 24) & 0xF); - out8(IO + ATA_REG_SEC_COUNT0, Lba / 512); out8(IO + ATA_REG_LBA0, (UInt8)Lba); @@ -116,21 +88,18 @@ UInt16 ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master) { out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - ATAPoll(IO); + while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); - UInt16 data = in16(IO + ATA_REG_DATA); + auto chr = in8(IO + ATA_REG_DATA); while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); - - return data; + return chr; } Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master) { UInt16 IO = Bus; ATASelect(IO, Master ? ATA_MASTER : ATA_SLAVE); - out8(IO + ATA_REG_LBA5, (UInt8)(Lba >> 24) & 0xF); - out8(IO + ATA_REG_SEC_COUNT0, Lba / 512); out8(IO + ATA_REG_LBA0, (UInt8)Lba); @@ -139,7 +108,7 @@ Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master) { out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); // TODO: support DMA - ATAPoll(IO); + while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); out32(IO + ATA_REG_DATA, Byte); @@ -152,20 +121,27 @@ Boolean ATAIsDetected(Void) { return kATADetected; } * @brief Init ATA driver. * @param void none. */ -ATAHelper::ATAHelper() noexcept { +BATADevice::BATADevice() noexcept { if (ATAIsDetected()) return; - ATAInitDriver(ATA_PRIMARY, true); - ATAInitDriver(ATA_PRIMARY, false); - - ATAInitDriver(ATA_SECONDARY, true); - ATAInitDriver(ATA_SECONDARY, false); + if (ATAInitDriver(ATA_PRIMARY, true, this->Traits().mBus, + this->Traits().mMaster) || + ATAInitDriver(ATA_PRIMARY, false, this->Traits().mBus, + this->Traits().mMaster) || + ATAInitDriver(ATA_SECONDARY, true, this->Traits().mBus, + this->Traits().mMaster) || + ATAInitDriver(ATA_SECONDARY, false, this->Traits().mBus, + this->Traits().mMaster)) { + kATADetected = true; - BTextWriter writer; - writer.WriteString(L"KeInitATA: Init: Done\r\n"); + BTextWriter writer; + writer.WriteString(L"BATADevice::BATADevice: OnLine\r\n"); + } } -ATAHelper& ATAHelper::Read(CharacterType* Buf, const SizeT& Sz) { +BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { + if (!ATAIsDetected()) return *this; + if (!Buf || Sz < 1) return *this; for (SizeT i = 0UL; i < Sz; ++i) { @@ -175,7 +151,9 @@ ATAHelper& ATAHelper::Read(CharacterType* Buf, const SizeT& Sz) { return *this; } -ATAHelper& ATAHelper::Write(CharacterType* Buf, const SizeT& Sz) { +BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& Sz) { + if (!ATAIsDetected()) return *this; + if (!Buf || Sz < 1) return *this; for (SizeT i = 0UL; i < Sz; ++i) { @@ -185,4 +163,4 @@ ATAHelper& ATAHelper::Write(CharacterType* Buf, const SizeT& Sz) { return *this; } -ATAHelper::ATATraits& ATAHelper::Traits() { return mTraits; } +BATADevice::ATATraits& BATADevice::Traits() { return mTraits; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx index 33e69d05..99f8d41b 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootKit.cxx @@ -8,9 +8,7 @@ */ #include -#include - -#include "BootKit/Arch/ATA.hxx" +#include /// bugs 0 diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index e2c96d19..31ec449f 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -11,7 +11,7 @@ #include #include -#include +#include // don't remove EfiGUID, it will call initializer_list! @@ -27,7 +27,9 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, UInt64 mapKey = 0; - BFileReader reader(L"\\MAHROUSS\\Root\\System\\HCoreKrnl.exe\0"); + CharacterType bytes[1024]; + + BFileReader reader(L"\\Root\\System\\HCoreKrnl.exe\0"); auto blob = reader.ReadAll(); if (!blob) diff --git a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx index dbd2b900..f92de33b 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Platform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Platform.cxx @@ -15,8 +15,7 @@ */ #include - -#include "EFIKit/EFILib.hxx" +#include extern "C" void rt_halt() { asm volatile("hlt"); } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index acf5f201..0f679772 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -22,7 +22,7 @@ bootloader-amd64: .PHONY: run-efi-debug run-efi-debug: wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - qemu-system-x86_64 -bios OVMF.fd -net none -drive file=fat:rw:CDROM,format=raw -d int + qemu-system-x86_64 -bios OVMF.fd -drive file=fat:rw:CDROM,format=raw -d int .PHONY: clean clean: -- cgit v1.2.3 From 95a887d120b7955bb02f582339d0536696a4cc79 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 2 Feb 2024 08:37:13 +0100 Subject: Kernel & Bootloader: Improvements and Fix ATA Read and Write problem. Signed-off-by: Amlal El Mahrouss --- Private/HALKit/AMD64/ACPIManagerAMD64.cpp | 6 +- Private/HALKit/AMD64/DebugOutput.cxx | 24 ++-- Private/HALKit/AMD64/DebugPort.cxx | 10 +- Private/HALKit/AMD64/HalProcessor.cpp | 12 +- Private/HALKit/AMD64/PCI/Device.cpp | 18 +-- Private/HALKit/AMD64/Processor.hpp | 12 +- Private/KernelKit/PCI/Express.hpp | 4 +- Private/KernelKit/PCI/IO-Impl-AMD64.inl | 15 ++- Private/NewBoot/BootKit/Arch/ATA.hxx | 18 ++- Private/NewBoot/BootKit/BootKit.hxx | 16 ++- Private/NewBoot/Source/HEL/AMD64/ATA.cxx | 165 ++++++++++++++++-------- Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 2 - 12 files changed, 186 insertions(+), 116 deletions(-) (limited to 'Private/NewBoot/BootKit/BootKit.hxx') diff --git a/Private/HALKit/AMD64/ACPIManagerAMD64.cpp b/Private/HALKit/AMD64/ACPIManagerAMD64.cpp index e0f9b7fd..9bdd368b 100644 --- a/Private/HALKit/AMD64/ACPIManagerAMD64.cpp +++ b/Private/HALKit/AMD64/ACPIManagerAMD64.cpp @@ -59,11 +59,11 @@ bool ACPIManager::Checksum(const char *checksum, SSizeT len) { return chr == 0; } -void rt_shutdown_acpi_qemu_20(void) { HAL::out16(0xb004, 0x2000); } +void rt_shutdown_acpi_qemu_20(void) { HAL::Out16(0xb004, 0x2000); } -void rt_shutdown_acpi_qemu_30_plus(void) { HAL::out16(0x604, 0x2000); } +void rt_shutdown_acpi_qemu_30_plus(void) { HAL::Out16(0x604, 0x2000); } -void rt_shutdown_acpi_virtualbox(void) { HAL::out16(0x4004, 0x3400); } +void rt_shutdown_acpi_virtualbox(void) { HAL::Out16(0x4004, 0x3400); } /// you'll have to parse the MADT otherwise! } // namespace HCore diff --git a/Private/HALKit/AMD64/DebugOutput.cxx b/Private/HALKit/AMD64/DebugOutput.cxx index e23d9dae..ad9fc8c5 100644 --- a/Private/HALKit/AMD64/DebugOutput.cxx +++ b/Private/HALKit/AMD64/DebugOutput.cxx @@ -26,19 +26,19 @@ static int kState = kStateLimbo; bool serial_init() { #ifdef __DEBUG__ - HAL::out8(PORT + 1, 0x00); // Disable all interrupts - HAL::out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - HAL::out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud - HAL::out8(PORT + 1, 0x00); // (hi byte) - HAL::out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit - HAL::out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold - HAL::out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - HAL::out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip - HAL::out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if + HAL::Out8(PORT + 1, 0x00); // Disable all interrupts + HAL::Out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + HAL::Out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + HAL::Out8(PORT + 1, 0x00); // (hi byte) + HAL::Out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + HAL::Out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + HAL::Out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + HAL::Out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip + HAL::Out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if // serial returns same byte) // Check if serial is faulty (i.e: not same byte as sent) - if (HAL::in8(PORT) != 0xAE) { + if (HAL::In8(PORT) != 0xAE) { ke_stop(RUNTIME_CHECK_HANDSHAKE); } @@ -46,7 +46,7 @@ bool serial_init() { // If serial is not faulty set it in normal operation mode // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) - HAL::out8(Detail::PORT + 4, 0x0F); + HAL::Out8(Detail::PORT + 4, 0x0F); #endif return true; @@ -62,7 +62,7 @@ void system_io_print(const char *bytes) { SizeT len = string_length(bytes, 256); while (index < len) { - HAL::out8(Detail::PORT, bytes[index]); + HAL::Out8(Detail::PORT, bytes[index]); ++index; } diff --git a/Private/HALKit/AMD64/DebugPort.cxx b/Private/HALKit/AMD64/DebugPort.cxx index e5138e27..b0f2f6d1 100644 --- a/Private/HALKit/AMD64/DebugPort.cxx +++ b/Private/HALKit/AMD64/DebugPort.cxx @@ -41,19 +41,19 @@ void rt_debug_listen(DebuggerPorts* theHook) noexcept { if (theHook == nullptr) return; for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) { - HAL::out16(theHook->fPort[i], kDebugMag0); + HAL::Out16(theHook->fPort[i], kDebugMag0); HAL::rt_wait_for_io(); - HAL::out16(theHook->fPort[i], kDebugMag1); + HAL::Out16(theHook->fPort[i], kDebugMag1); HAL::rt_wait_for_io(); - HAL::out16(theHook->fPort[i], kDebugMag2); + HAL::Out16(theHook->fPort[i], kDebugMag2); HAL::rt_wait_for_io(); - HAL::out16(theHook->fPort[i], kDebugMag3); + HAL::Out16(theHook->fPort[i], kDebugMag3); HAL::rt_wait_for_io(); - if (HAL::in16(theHook->fPort[i] != kDebugUnboundPort)) theHook->fBoundCnt++; + if (HAL::In16(theHook->fPort[i] != kDebugUnboundPort)) theHook->fBoundCnt++; } } } // namespace HCore diff --git a/Private/HALKit/AMD64/HalProcessor.cpp b/Private/HALKit/AMD64/HalProcessor.cpp index afdb29b1..80efed3a 100644 --- a/Private/HALKit/AMD64/HalProcessor.cpp +++ b/Private/HALKit/AMD64/HalProcessor.cpp @@ -15,33 +15,33 @@ */ namespace HCore::HAL { -void out8(UInt16 port, UInt8 value) { +void Out8(UInt16 port, UInt8 value) { asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); } -void out16(UInt16 port, UInt16 value) { +void Out16(UInt16 port, UInt16 value) { asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); } -void out32(UInt16 port, UInt32 value) { +void Out32(UInt16 port, UInt32 value) { asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); } -UInt8 in8(UInt16 port) { +UInt8 In8(UInt16 port) { UInt8 value = 0UL; asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); return value; } -UInt16 in16(UInt16 port) { +UInt16 In16(UInt16 port) { UInt16 value = 0UL; asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); return value; } -UInt32 in32(UInt16 port) { +UInt32 In32(UInt16 port) { UInt32 value = 0UL; asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); diff --git a/Private/HALKit/AMD64/PCI/Device.cpp b/Private/HALKit/AMD64/PCI/Device.cpp index 9fdcda43..815043c9 100644 --- a/Private/HALKit/AMD64/PCI/Device.cpp +++ b/Private/HALKit/AMD64/PCI/Device.cpp @@ -16,10 +16,10 @@ HCore::UInt LumiaPCIReadRaw(HCore::UInt bar, HCore::UShort bus, ((HCore::UInt)dev << 11) | ((HCore::UInt)fun << 8) | (bar & 0xFC); - HCore::HAL::out32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigAddress, + HCore::HAL::Out32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigAddress, target); - return HCore::HAL::in32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigData); + return HCore::HAL::In32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigData); } void LumiaPCISetCfgTarget(HCore::UInt bar, HCore::UShort bus, HCore::UShort dev, @@ -28,7 +28,7 @@ void LumiaPCISetCfgTarget(HCore::UInt bar, HCore::UShort bus, HCore::UShort dev, ((HCore::UInt)dev << 11) | ((HCore::UInt)fun << 8) | (bar & ~3); - HCore::HAL::out32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigAddress, + HCore::HAL::Out32((HCore::UShort)HCore::PCI::PciConfigKind::ConfigAddress, target); } @@ -42,10 +42,10 @@ UInt Device::Read(UInt bar, Size sz) { LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); if (sz == 4) - return HAL::in32((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + return HAL::In32((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); if (sz == 2) - return HAL::in16((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); - if (sz == 1) return HAL::in8((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + return HAL::In16((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); + if (sz == 1) return HAL::In8((UShort)PciConfigKind::ConfigData + (m_Bar & 3)); return 0xFFFF; } @@ -54,11 +54,11 @@ void Device::Write(UInt bar, UIntPtr data, Size sz) { LumiaPCISetCfgTarget(bar, m_Bus, m_Device, m_Function); if (sz == 4) - HAL::out32((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UInt)data); + HAL::Out32((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UInt)data); if (sz == 2) - HAL::out16((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UShort)data); + HAL::Out16((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UShort)data); if (sz == 1) - HAL::out8((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UChar)data); + HAL::Out8((UShort)PciConfigKind::ConfigData + (m_Bar & 3), (UChar)data); } UShort Device::DeviceId() { diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index 9b73216b..883d1910 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -17,13 +17,13 @@ #define IsLevelTriggered(flag) (flag & 8) namespace HCore::HAL { -extern "C" UChar in8(UInt16 port); -extern "C" UShort in16(UInt16 port); -extern "C" UInt in32(UInt16 port); +extern "C" UChar In8(UInt16 port); +extern "C" UShort In16(UInt16 port); +extern "C" UInt In32(UInt16 port); -extern "C" void out16(UShort port, UShort byte); -extern "C" void out8(UShort port, UChar byte); -extern "C" void out32(UShort port, UInt byte); +extern "C" void Out16(UShort port, UShort byte); +extern "C" void Out8(UShort port, UChar byte); +extern "C" void Out32(UShort port, UInt byte); extern "C" void rt_wait_for_io(); extern "C" void rt_halt(); diff --git a/Private/KernelKit/PCI/Express.hpp b/Private/KernelKit/PCI/Express.hpp index 45676c23..8b46fbeb 100644 --- a/Private/KernelKit/PCI/Express.hpp +++ b/Private/KernelKit/PCI/Express.hpp @@ -9,4 +9,6 @@ #pragma once -#include \ No newline at end of file +#include + +#define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/Private/KernelKit/PCI/IO-Impl-AMD64.inl b/Private/KernelKit/PCI/IO-Impl-AMD64.inl index c5247d13..f720f2b6 100644 --- a/Private/KernelKit/PCI/IO-Impl-AMD64.inl +++ b/Private/KernelKit/PCI/IO-Impl-AMD64.inl @@ -7,7 +7,8 @@ Revision History: - 30/01/24: Added file (amlel) + 30/01/24: Add file. (amlel) + 02/02/24: Update I/O routines. (amlel) ------------------------------------------- */ @@ -17,11 +18,11 @@ template T IOArray::In(SizeT index) { switch (sizeof(T)) { case 4: - return HAL::in32(m_Ports[index].Leak()); + return HAL::In32(m_Ports[index].Leak()); case 2: - return HAL::in16(m_Ports[index].Leak()); + return HAL::In16(m_Ports[index].Leak()); case 1: - return HAL::in8(m_Ports[index].Leak()); + return HAL::In8(m_Ports[index].Leak()); default: return 0xFFFF; } @@ -33,11 +34,11 @@ void IOArray::Out(SizeT index, T value) { switch (sizeof(T)) { #ifdef __x86_64__ case 4: - HAL::out32(m_Ports[index].Leak(), value); + HAL::Out32(m_Ports[index].Leak(), value); case 2: - HAL::out16(m_Ports[index].Leak(), value); + HAL::Out16(m_Ports[index].Leak(), value); case 1: - HAL::out8(m_Ports[index].Leak(), value); + HAL::Out8(m_Ports[index].Leak(), value); #endif default: break; diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/Arch/ATA.hxx index 6e692c3d..db92e290 100644 --- a/Private/NewBoot/BootKit/Arch/ATA.hxx +++ b/Private/NewBoot/BootKit/Arch/ATA.hxx @@ -113,8 +113,10 @@ using namespace HCore; Boolean ATAInitDriver(UInt8 Bus, UInt8 Drv); Void ATAWait(UInt16 IO); -UInt16 ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master); -Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master); +Void ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master, wchar_t* Buf, + SizeT Offset); +Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master, + wchar_t* Buf, SizeT Offset); Boolean ATAIsDetected(Void); class BATADevice final { @@ -134,11 +136,21 @@ class BATADevice final { Boolean mMaster{false}; }; + operator bool() { return ATAIsDetected(); } + BATADevice& Read(WideChar*, const SizeT&); BATADevice& Write(WideChar*, const SizeT&); - ATATraits& Traits(); + ATATraits& Leak(); private: ATATraits mTraits; }; + +enum { + kATADevicePATA, + kATADeviceSATA, + kATADevicePATA_PI, + kATADeviceSATA_PI, + kATADeviceCount, +}; diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index edd8015b..2b57ec56 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -93,35 +93,39 @@ class BFileReader final { #include #include +/***********************************************************************************/ +/// Provide some useful processor features. +/***********************************************************************************/ + #ifdef __EFI_x86_64__ -inline void out8(UInt16 port, UInt8 value) { +inline void Out8(UInt16 port, UInt8 value) { asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); } -inline void out16(UInt16 port, UInt16 value) { +inline void Out16(UInt16 port, UInt16 value) { asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); } -inline void out32(UInt16 port, UInt32 value) { +inline void Out32(UInt16 port, UInt32 value) { asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); } -inline UInt8 in8(UInt16 port) { +inline UInt8 In8(UInt16 port) { UInt8 value = 0UL; asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); return value; } -inline UInt16 in16(UInt16 port) { +inline UInt16 In16(UInt16 port) { UInt16 value = 0UL; asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); return value; } -inline UInt32 in32(UInt16 port) { +inline UInt32 In32(UInt16 port) { UInt32 value = 0UL; asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx index 0f8d9170..fb11f409 100644 --- a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx @@ -7,21 +7,31 @@ * ======================================================== */ +/** + * @file ATA.cxx + * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com) + * @brief ATA driver. + * @version 0.1 + * @date 2024-02-02 + * + * @copyright Copyright (c) 2024 + * + */ + #include #include -/***********************************************************************************/ -/// Provide some useful processor features. -/***********************************************************************************/ +/// bugs: 0 static Boolean kATADetected = false; +static Int32 kATADeviceType = kATADeviceCount; void ATASelect(UInt8 Bus, Boolean isMaster) { if (Bus == ATA_PRIMARY) - out8(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, + Out8(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL); else - out8(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, + Out8(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL); } @@ -33,14 +43,14 @@ Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive, UInt16& OutBus, ATASelect(Bus, Drive); - out8(IO + ATA_REG_SEC_COUNT0, 0); - out8(IO + ATA_REG_LBA0, 0); - out8(IO + ATA_REG_LBA1, 0); - out8(IO + ATA_REG_LBA2, 0); + Out8(IO + ATA_REG_SEC_COUNT0, 0); + Out8(IO + ATA_REG_LBA0, 0); + Out8(IO + ATA_REG_LBA1, 0); + Out8(IO + ATA_REG_LBA2, 0); - out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - UInt8 status = in8(IO + ATA_REG_STATUS); + UInt8 status = In8(IO + ATA_REG_STATUS); if (status & ATA_SR_ERR) { #ifdef __DEBUG__ @@ -52,17 +62,26 @@ Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive, UInt16& OutBus, OutBus = (Bus == ATA_PRIMARY) ? BATADevice::kPrimary : BATADevice::kSecondary; OutMaster = (Bus == ATA_PRIMARY); - unsigned cl = in16(Bus + ATA_CYL_LOW); /* get the "signature bytes" */ - unsigned ch = in16(Bus + ATA_CYL_HIGH); + unsigned cl = In16(Bus + ATA_CYL_LOW); /* get the "signature bytes" */ + unsigned ch = In16(Bus + ATA_CYL_HIGH); /* differentiate ATA, ATAPI, SATA and SATAPI */ - if (cl == 0x14 && ch == 0xEB) - writer.WriteString(L"HCoreLdr: PATAPI detected.\r\n"); - if (cl == 0x69 && ch == 0x96) - writer.WriteString(L"HCoreLdr: SATAPI detected.\r\n"); - if (cl == 0 && ch == 0) writer.WriteString(L"HCoreLdr: PATA detected.\r\n"); - if (cl == 0x3c && ch == 0xc3) - writer.WriteString(L"HCoreLdr: SATA detected.\r\n"); + if (cl == 0x14 && ch == 0xEB) { + writer.WriteString(L"HCoreLdr: PATAPI drive detected.\r\n"); + kATADeviceType = kATADevicePATA_PI; + } + if (cl == 0x69 && ch == 0x96) { + writer.WriteString(L"HCoreLdr: SATAPI drive detected.\r\n"); + kATADeviceType = kATADeviceSATA_PI; + } + if (cl == 0 && ch == 0) { + writer.WriteString(L"HCoreLdr: PATA drive detected.\r\n"); + kATADeviceType = kATADevicePATA; + } + if (cl == 0x3c && ch == 0xc3) { + writer.WriteString(L"HCoreLdr: SATA drive detected.\r\n"); + kATADeviceType = kATADeviceSATA; + } return true; } @@ -71,50 +90,71 @@ Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive, UInt16& OutBus, * This polls the ATA drive. */ void ATAWait(UInt16 IO) { - for (int i = 0; i < 4000; i++) in8(IO + ATA_REG_ALT_STATUS); + for (int i = 0; i < 4000; i++) In8(IO + ATA_REG_ALT_STATUS); } void ATAPoll(UInt16 IO) { ATAWait(IO); } -UInt16 ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master) { +Void ATAReadLba(UInt32 Lba, UInt8 Bus, Boolean Master, CharacterType* Buf, + SizeT Offset) { UInt16 IO = Bus; - ATASelect(IO, Master ? ATA_MASTER : ATA_SLAVE); - out8(IO + ATA_REG_SEC_COUNT0, Lba / 512); + ATASelect(IO + ATA_REG_HDDEVSEL, + (Master ? ATA_MASTER : ATA_SLAVE) | Lba >> 24 & 0xF); + + ATASelect(IO + 1, 0); - out8(IO + ATA_REG_LBA0, (UInt8)Lba); - out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); - out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); + Out8(IO + ATA_REG_SEC_COUNT0, 1); - out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); + Out8(IO + ATA_REG_LBA0, (UInt8)Lba); + Out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); + Out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); - while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - auto chr = in8(IO + ATA_REG_DATA); + ATAPoll(IO); + + for (SizeT index = 0UL; index < 256; ++index) { + Buf[index + Offset] = In16(IO + ATA_REG_DATA); + } - while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); - return chr; + ATAWait(IO); } -Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master) { +Void ATAWriteLba(UInt16 Byte, UInt32 Lba, UInt8 Bus, Boolean Master, + wchar_t* Buf, SizeT Offset) { UInt16 IO = Bus; - ATASelect(IO, Master ? ATA_MASTER : ATA_SLAVE); - out8(IO + ATA_REG_SEC_COUNT0, Lba / 512); + ATASelect(IO + ATA_REG_HDDEVSEL, + (Master ? ATA_MASTER : ATA_SLAVE) | Lba >> 24 & 0xF); - out8(IO + ATA_REG_LBA0, (UInt8)Lba); - out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); - out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); + ATASelect(IO + 1, 0); - out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); // TODO: support DMA + Out8(IO + ATA_REG_SEC_COUNT0, 1); - while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); + Out8(IO + ATA_REG_LBA0, (UInt8)Lba); + Out8(IO + ATA_REG_LBA1, (UInt8)(Lba >> 8)); + Out8(IO + ATA_REG_LBA2, (UInt8)(Lba >> 16)); - out32(IO + ATA_REG_DATA, Byte); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); + + ATAPoll(IO); + + for (SizeT index = 0UL; index < 256; ++index) { + Out16(IO + ATA_REG_DATA, Buf[index + Offset]); + } - while ((in8(ATA_COMMAND(IO))) & 0x88) ATAWait(IO); + ATAWait(IO); } +/*** + * + * + * ATA Device class. + * + * + */ + Boolean ATAIsDetected(Void) { return kATADetected; } /** @@ -124,14 +164,14 @@ Boolean ATAIsDetected(Void) { return kATADetected; } BATADevice::BATADevice() noexcept { if (ATAIsDetected()) return; - if (ATAInitDriver(ATA_PRIMARY, true, this->Traits().mBus, - this->Traits().mMaster) || - ATAInitDriver(ATA_PRIMARY, false, this->Traits().mBus, - this->Traits().mMaster) || - ATAInitDriver(ATA_SECONDARY, true, this->Traits().mBus, - this->Traits().mMaster) || - ATAInitDriver(ATA_SECONDARY, false, this->Traits().mBus, - this->Traits().mMaster)) { + if (ATAInitDriver(ATA_PRIMARY, true, this->Leak().mBus, + this->Leak().mMaster) || + ATAInitDriver(ATA_PRIMARY, false, this->Leak().mBus, + this->Leak().mMaster) || + ATAInitDriver(ATA_SECONDARY, true, this->Leak().mBus, + this->Leak().mMaster) || + ATAInitDriver(ATA_SECONDARY, false, this->Leak().mBus, + this->Leak().mMaster)) { kATADetected = true; BTextWriter writer; @@ -144,10 +184,14 @@ BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { if (!Buf || Sz < 1) return *this; - for (SizeT i = 0UL; i < Sz; ++i) { - Buf[i] = ATAReadLba(this->Traits().mBase + i, this->Traits().mBus, - this->Traits().mMaster); + SizeT Off = 0; + + for (SizeT i = 0UL; i < (Sz / 512); ++i) { + ATAReadLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, + Buf, Off); + Off += 256; } + return *this; } @@ -156,11 +200,20 @@ BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& Sz) { if (!Buf || Sz < 1) return *this; + SizeT Off = 0UL; + for (SizeT i = 0UL; i < Sz; ++i) { - ATAWriteLba(Buf[i], this->Traits().mBase + i, this->Traits().mBus, - this->Traits().mMaster); + ATAWriteLba(Buf[i], this->Leak().mBase + i, this->Leak().mBus, + this->Leak().mMaster, Buf, Off); + + Off += 256; } + return *this; } -BATADevice::ATATraits& BATADevice::Traits() { return mTraits; } +/** + * @brief ATA Config getter. + * @return BATADevice::ATATraits& the drive config. + */ +BATADevice::ATATraits& BATADevice::Leak() { return mTraits; } diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index 31ec449f..841a1f40 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -27,8 +27,6 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle, UInt64 mapKey = 0; - CharacterType bytes[1024]; - BFileReader reader(L"\\Root\\System\\HCoreKrnl.exe\0"); auto blob = reader.ReadAll(); -- cgit v1.2.3 From 28939d40c856aed0b56fe5a4d1d68a906099d745 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 2 Feb 2024 09:07:33 +0100 Subject: NewBoot: Add documentation to ATA driver. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/BootKit/BootKit.hxx | 2 +- Private/NewBoot/Source/HEL/AMD64/ATA.cxx | 10 ++++++++++ Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'Private/NewBoot/BootKit/BootKit.hxx') diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 2b57ec56..90ef5156 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -132,4 +132,4 @@ inline UInt32 In32(UInt16 port) { return value; } -#endif // __EFI_x86_64__ \ No newline at end of file +#endif // __EFI_x86_64__ diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx index 80dffa02..4f1b3171 100644 --- a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx @@ -179,6 +179,11 @@ BATADevice::BATADevice() noexcept { } } +/** + @brief Read Buf from disk + @param Sz Sector size + @param Buf buffer +*/ BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { if (!ATAIsDetected()) return *this; @@ -196,6 +201,11 @@ BATADevice& BATADevice::Read(CharacterType* Buf, const SizeT& Sz) { return *this; } +/** + @brief Write Buf into disk + @param Sz Sector size + @param Buf buffer +*/ BATADevice& BATADevice::Write(CharacterType* Buf, const SizeT& Sz) { if (!ATAIsDetected()) return *this; diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx index 841a1f40..69f235c4 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx @@ -9,7 +9,6 @@ #define __BOOTLOADER__ 1 -#include #include #include -- cgit v1.2.3 From c8b5a4cc2981c4fd8987b7f048380a13d80981fd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 2 Feb 2024 10:09:27 +0100 Subject: See below. - Pack NewFS data structures. - Add README.TXT in /Drivers/ - Move /Internals/Tools in just /Tools. Signed-off-by: Amlal El Mahrouss --- Drivers/README.TXT | 15 +++++++++++++++ Internal/.gitkeep | 0 Internal/Tools/.gitkeep | 0 Internal/Tools/NewFSPartTool.cxx | 26 -------------------------- Private/FSKit/NewFS.hxx | 8 ++++---- Private/NewBoot/BootKit/BootKit.hxx | 2 -- Tools/.gitkeep | 0 Tools/PartTool.cxx | 27 +++++++++++++++++++++++++++ 8 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 Drivers/README.TXT delete mode 100644 Internal/.gitkeep delete mode 100644 Internal/Tools/.gitkeep delete mode 100644 Internal/Tools/NewFSPartTool.cxx create mode 100644 Tools/.gitkeep create mode 100644 Tools/PartTool.cxx (limited to 'Private/NewBoot/BootKit/BootKit.hxx') diff --git a/Drivers/README.TXT b/Drivers/README.TXT new file mode 100644 index 00000000..d26f409b --- /dev/null +++ b/Drivers/README.TXT @@ -0,0 +1,15 @@ +========================== +Basic Device Drivers (BDD) +========================== + +1 - Build them +2 - Place them inside Private/Root +3 - And continue your build. + + +==================== +What are these? +==================== + +These are HCore device drivers. +Running in Ring-3. To let the driver restart in case of a crash. diff --git a/Internal/.gitkeep b/Internal/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Internal/Tools/.gitkeep b/Internal/Tools/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Internal/Tools/NewFSPartTool.cxx b/Internal/Tools/NewFSPartTool.cxx deleted file mode 100644 index 41bdd392..00000000 --- a/Internal/Tools/NewFSPartTool.cxx +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - - File: MakeNewFS.cpp - Purpose: Partition a drive with a NewFS/EPM filesystem in it. - - Revision History: - - 31/01/24: Added file (amlel) - -------------------------------------------- */ - -/***********************************************************************************/ -/// @file MakeNewFS.cxx -/// @brief NewFS partition program. -/***********************************************************************************/ - -#include - -int main() { - std::cout - << "NewFSPartTool: Make a NewFS partition image from a directory!\n" - << "Copyright Mahrouss Logic, all rights reserved. (INTERNAL TOOL)\n"; - return 0; -} diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 022100cb..75f4e554 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -30,7 +30,7 @@ enum { kUnknowmn = 0xFF, // unknown device or unsupported (floppy) }; -struct NewBootBlock final { +struct PACKED NewBootBlock final { HCore::Char Ident[kIdentLen]; HCore::Char Shell[kNameLen]; @@ -56,7 +56,7 @@ struct NewBootBlock final { #define kKindDirectory 2 #define kKindSymlink 3 -struct NewCatalog final { +struct PACKED NewCatalog final { HCore::Char Name[kNameLen]; HCore::Int32 Flags; @@ -66,7 +66,7 @@ struct NewCatalog final { HCore::Lba LastFork; }; -struct NewFork { +struct PACKED NewFork final { HCore::Int32 Flags; HCore::Int32 Kind; @@ -90,7 +90,7 @@ struct NewFork { #define kConfigLen 64 #define kPartLen 32 -struct NewPartitionBlock final { +struct PACKED NewPartitionBlock final { HCore::Char PartitionName[kPartLen]; HCore::Char JsonPath[kConfigLen]; diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 90ef5156..70519aba 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -81,8 +81,6 @@ class BFileReader final { private: Int32 mErrorCode{kOperationOkay}; CharacterType mPath[255]; - - private: BATADevice mDevice; }; diff --git a/Tools/.gitkeep b/Tools/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Tools/PartTool.cxx b/Tools/PartTool.cxx new file mode 100644 index 00000000..df40ae3c --- /dev/null +++ b/Tools/PartTool.cxx @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: MakeNewFS.cpp + Purpose: Partition a drive with a NewFS/EPM filesystem in it. + + Revision History: + + 31/01/24: Added file (amlel) + +------------------------------------------- */ + +/***********************************************************************************/ +/// @file MakeNewFS.cxx +/// @brief NewFS partition program. +/***********************************************************************************/ + +#include + +int main() { + std::cout + << "PartTool: build a NewFS partition image from a directory!\n" + << "Copyright Mahrouss Logic, all rights reserved. (INTERNAL TOOL)\n"; + + return 0; +} -- cgit v1.2.3