diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-04-28 15:13:03 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-04-28 15:13:03 +0000 |
| commit | 14f10cc0b35155ddb19ec9069ebb884246e61dcf (patch) | |
| tree | a988617d1c511cf04eb2c2392829a37d82a59e2e /Private/HALKit | |
| parent | db0681412191dcceb5aa99cf31fb8339d6bc4adb (diff) | |
| parent | 346558208d39a036effe3a4ec232fa5df5a3c8e7 (diff) | |
Merged in MHR-18 (pull request #8)
MHR-18: A lot of fixes and improvements, mostly related to disk I/O and kernel stability.
Diffstat (limited to 'Private/HALKit')
| -rw-r--r-- | Private/HALKit/64x0/HalVirtualMemory.cxx | 2 | ||||
| -rw-r--r-- | Private/HALKit/64x0/MBCI/.gitkeep | 0 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalACPIFactoryInterface.cxx | 11 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalControlRegister.s | 8 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMouse.cxx | 7 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.cpp | 36 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalPageAlloc.hpp | 4 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Processor.hpp | 8 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/AHCI.cxx | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/ATA-PIO.cxx | 138 | ||||
| -rw-r--r-- | Private/HALKit/compile_flags.txt | 1 |
12 files changed, 114 insertions, 105 deletions
diff --git a/Private/HALKit/64x0/HalVirtualMemory.cxx b/Private/HALKit/64x0/HalVirtualMemory.cxx index 2ae0f7ac..96202c00 100644 --- a/Private/HALKit/64x0/HalVirtualMemory.cxx +++ b/Private/HALKit/64x0/HalVirtualMemory.cxx @@ -10,5 +10,5 @@ using namespace NewOS; /// @brief Flush system TLB, looks like the POWER version, as it acts the same, no specific instruction for that. -/// @note The 88K MMU should be present in the die. +/// @note The 88K MMU should be present as well. EXTERN_C void hal_flush_tlb() { asm volatile("invltlb"); } diff --git a/Private/HALKit/64x0/MBCI/.gitkeep b/Private/HALKit/64x0/MBCI/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Private/HALKit/64x0/MBCI/.gitkeep diff --git a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx index d18d49cf..91e0eeb6 100644 --- a/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Private/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -22,10 +22,6 @@ void rt_shutdown_acpi_virtualbox(void) { HAL::Out16(0x4004, 0x3400); } ACPIFactoryInterface::ACPIFactoryInterface(voidPtr rsdPtr) : fRsdp(rsdPtr), fEntries(0) { - volatile RSDP *_rsdPtr = reinterpret_cast<volatile RSDP *>(this->fRsdp); - - MUST_PASS(_rsdPtr); - MUST_PASS(_rsdPtr->Revision >= 2); } Void ACPIFactoryInterface::Shutdown() { @@ -60,11 +56,14 @@ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const char *signature) { return ErrorOr<voidPtr>{-4}; } - SDT* xsdt = (SDT*)(rsdPtr->RsdtAddress + rsdPtr->XsdtAddress); + SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); + SizeT num = xsdt->Length + sizeof(SDT) / 8; + this->fEntries = num; + kcout << "ACPI: Number of entries: " << number(num) << endl; - kcout << "ACPI: Address of XSDT: " << number((UIntPtr)xsdt) << endl; + kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; constexpr short ACPI_SIGNATURE_LENGTH = 4; diff --git a/Private/HALKit/AMD64/HalControlRegister.s b/Private/HALKit/AMD64/HalControlRegister.s index 74dda36c..2a649f04 100644 --- a/Private/HALKit/AMD64/HalControlRegister.s +++ b/Private/HALKit/AMD64/HalControlRegister.s @@ -11,10 +11,12 @@ .globl hal_read_cr0 .globl hal_flush_tlb -.section .text +.text hal_flush_tlb: - invlpg (%rcx) + call hal_read_cr3 + mov %rcx, %rax + call hal_write_cr3 ret hal_read_cr3: @@ -36,5 +38,3 @@ hal_write_cr3: hal_write_cr0: movq %cr0, %rdi ret - - diff --git a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 37e8f0cc..5c845812 100644 --- a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -6,7 +6,7 @@ #include <Builtins/ACPI/ACPIFactoryInterface.hxx> #include <HALKit/AMD64/Processor.hpp> -#include "NewKit/KernelCheck.hpp" +#include <NewKit/KernelCheck.hpp> /////////////////////////////////////////////////////////////////////////////////////// diff --git a/Private/HALKit/AMD64/HalKernelMouse.cxx b/Private/HALKit/AMD64/HalKernelMouse.cxx index 468a595f..6321265a 100644 --- a/Private/HALKit/AMD64/HalKernelMouse.cxx +++ b/Private/HALKit/AMD64/HalKernelMouse.cxx @@ -6,6 +6,7 @@ #include <Builtins/PS2/PS2MouseInterface.hxx> #include <Builtins/Toolbox/Toolbox.hxx> +#include <Builtins/Toolbox/Rsrc/Cursor.rsrc> #include <KernelKit/Framebuffer.hpp> #include <NewKit/Defines.hpp> @@ -22,6 +23,8 @@ STATIC NewOS::PS2MouseInterface kMousePS2; STATIC NewOS::Char kMousePacket[4] = {}; STATIC NewOS::Boolean kMousePacketReady = false; +STATIC ToolboxInitRsrc(); + #define kPS2Leftbutton 0b00000001 #define kPS2Middlebutton 0b00000010 #define kPS2Rightbutton 0b00000100 @@ -38,7 +41,7 @@ Void hal_handle_mouse() { switch (kMouseCycle) { case 0: if (kMousePacketReady) break; - if (data & 0b00001000 == 0) break; + if ((data & 0b00001000) == 0) break; kMousePacket[0] = data; kMouseCycle++; break; @@ -149,4 +152,4 @@ EXTERN_C Void _hal_init_mouse() { HAL::Out8(0x21, 0b11111001); HAL::Out8(0xA1, 0b11101111); -}
\ No newline at end of file +} diff --git a/Private/HALKit/AMD64/HalPageAlloc.cpp b/Private/HALKit/AMD64/HalPageAlloc.cpp index 3a8d3047..9ba0ea4d 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.cpp +++ b/Private/HALKit/AMD64/HalPageAlloc.cpp @@ -10,28 +10,31 @@ #include <NewKit/KernelCheck.hpp> STATIC NewOS::Boolean kAllocationInProgress = false; + namespace NewOS { namespace HAL { namespace Detail { struct VirtualMemoryHeader { - Boolean Present : 1; - Boolean ReadWrite : 1; - Boolean User : 1; + UInt32 Magic; + Boolean Present; + Boolean ReadWrite; + Boolean User; + SizeT PageSize; }; struct VirtualMemoryHeaderTraits { /// @brief Get next header. - /// @param current - /// @return + /// @param current + /// @return VirtualMemoryHeader* Next(VirtualMemoryHeader* current) { - return current + sizeof(PTE); + return current + sizeof(PTE) + current->PageSize; } /// @brief Get previous header. - /// @param current - /// @return + /// @param current + /// @return VirtualMemoryHeader* Prev(VirtualMemoryHeader* current) { - return current - sizeof(PTE); + return current - sizeof(PTE) - current->PageSize; } }; } @@ -41,22 +44,27 @@ struct VirtualMemoryHeaderTraits { /// @param rw read/write flag. /// @param user user flag. /// @return the page table of it. -STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user) -> VoidPtr { +STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr { if (kAllocationInProgress) return nullptr; kAllocationInProgress = true; + constexpr auto cVMTMagic = 0xDEEFD00D; + ///! fetch from the start. Detail::VirtualMemoryHeader* vmHeader = reinterpret_cast<Detail::VirtualMemoryHeader*>(kKernelVirtualStart); Detail::VirtualMemoryHeaderTraits traits; - while (vmHeader->Present) { + while (vmHeader->Present && + vmHeader->Magic != cVMTMagic) { vmHeader = traits.Next(vmHeader); } + vmHeader->Magic = cVMTMagic; vmHeader->Present = true; vmHeader->ReadWrite = rw; vmHeader->User = user; + vmHeader->PageSize = size; kAllocationInProgress = false; @@ -67,14 +75,16 @@ STATIC auto hal_try_alloc_new_page(Boolean rw, Boolean user) -> VoidPtr { /// @param rw read/write bit. /// @param user user bit. /// @return -auto hal_alloc_page(Boolean rw, Boolean user) -> VoidPtr { +auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr { /// Wait for a ongoing allocation to complete. while (kAllocationInProgress) { ; } + if (size == 0) ++size; + /// allocate new page. - return hal_try_alloc_new_page(rw, user); + return hal_try_alloc_new_page(rw, user, size); } } // namespace HAL } // namespace NewOS diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp index d23c6e96..94956329 100644 --- a/Private/HALKit/AMD64/HalPageAlloc.hpp +++ b/Private/HALKit/AMD64/HalPageAlloc.hpp @@ -26,7 +26,7 @@ #define kPTESize (0x1000) #endif // !kPTESize -EXTERN_C void hal_flush_tlb(NewOS::UIntPtr pde); +EXTERN_C void hal_flush_tlb(); EXTERN_C void hal_write_cr3(NewOS::UIntPtr pde); EXTERN_C void hal_write_cr0(NewOS::UIntPtr bit); @@ -72,7 +72,7 @@ struct PageDirectory64 final { PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax]; }; -VoidPtr hal_alloc_page(Boolean rw, Boolean user); +VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size); } // namespace NewOS::HAL namespace NewOS { diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index 70452d1d..efe773da 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -16,6 +16,7 @@ #include <NewKit/Array.hpp> #include <NewKit/Defines.hpp> #include <NewKit/Utils.hpp> +#include <FirmwareKit/Handover.hxx> #ifdef kCPUBackendName #undef kCPUBackendName @@ -30,7 +31,7 @@ #define kTrapGate (0xEF) #define kTaskGate (0b10001100) #define kGdtCodeSelector (0x08) -#define kVirtualAddressStartOffset (0x100) +#define kVirtualAddressStartOffset (0x10000000) namespace NewOS { namespace Detail::AMD64 { @@ -183,3 +184,8 @@ EXTERN_C void hal_load_gdt(NewOS::HAL::RegisterGDT ptr); /// @brief Maximum size of the IDT. #define kKernelIdtSize 0x100 #define kKernelInterruptId 0x32 + +inline NewOS::VoidPtr kKernelVirtualStart = (NewOS::VoidPtr)kVirtualAddressStartOffset; +inline NewOS::UIntPtr kKernelVirtualSize = 0UL; + +inline NewOS::VoidPtr kKernelPhysicalStart = nullptr; diff --git a/Private/HALKit/AMD64/Storage/AHCI.cxx b/Private/HALKit/AMD64/Storage/AHCI.cxx index c9db540a..80224d89 100644 --- a/Private/HALKit/AMD64/Storage/AHCI.cxx +++ b/Private/HALKit/AMD64/Storage/AHCI.cxx @@ -36,7 +36,7 @@ NewOS::Boolean drv_std_init(NewOS::UInt16& PortsImplemented) { iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device. kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference. - kcout << "NewKernel: [PCI] Found AHCI controller.\r\n"; + kcout << "New Kernel: [PCI] Found AHCI controller.\r\n"; return true; } diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx index beb113d3..6fe1e29a 100644 --- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -32,21 +32,21 @@ static Int32 kATADeviceType = kATADeviceCount; static Char kATAData[kATADataLen] = {0}; Boolean drv_std_wait_io(UInt16 IO) { - for (int i = 0; i < 4; i++) In8(IO + ATA_REG_STATUS); + for (int i = 0; i < 4; i++) In8(IO + ATA_REG_STATUS); -ATAWaitForIO_Retry: - auto statRdy = In8(IO + ATA_REG_STATUS); + ATAWaitForIO_Retry: + auto statRdy = In8(IO + ATA_REG_STATUS); - if ((statRdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; + if ((statRdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; -ATAWaitForIO_Retry2: - statRdy = In8(IO + ATA_REG_STATUS); + ATAWaitForIO_Retry2: + statRdy = In8(IO + ATA_REG_STATUS); - if (statRdy & ATA_SR_ERR) return false; + if (statRdy & ATA_SR_ERR) return false; - if (!(statRdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; + if (!(statRdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; - return true; + return true; } Void drv_std_select(UInt16 Bus) { @@ -58,98 +58,69 @@ Void drv_std_select(UInt16 Bus) { Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - if (drv_std_detected()) return true; + if (drv_std_detected()) return true; - UInt16 IO = Bus; + UInt16 IO = Bus; - drv_std_select(IO); + drv_std_select(IO); - // Bus init, NEIN bit. - Out8(IO + ATA_REG_NEIN, 1); + // Bus init, NEIN bit. + Out8(IO + ATA_REG_NEIN, 1); - // identify until it's good. + // identify until it's good. ATAInit_Retry: - auto statRdy = In8(IO + ATA_REG_STATUS); - - if (statRdy & ATA_SR_ERR) { - kcout << "New OS: ATA: Select error, not an IDE based hard-drive.\r\n"; - - return false; - } - - if ((statRdy & ATA_SR_BSY)) goto ATAInit_Retry; - - Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - - rt_set_memory(kATAData, 0, kATADataLen); - - /// fetch serial info - /// model, speed, number of sectors... + auto statRdy = In8(IO + ATA_REG_STATUS); - drv_std_wait_io(IO); - - for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = In16(IO + ATA_REG_DATA); - } - - OutBus = Bus; - OutMaster = (OutBus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; + if (statRdy & ATA_SR_ERR) { + return false; + } - Out8(Bus + ATA_REG_HDDEVSEL, 0xA0 | ATA_MASTER << 4); + if ((statRdy & ATA_SR_BSY)) goto ATAInit_Retry; - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); + Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - unsigned cl = In8(Bus + ATA_CYL_LOW); /* get the "signature bytes" */ - unsigned ch = In8(Bus + ATA_CYL_HIGH); + /// fetch serial info + /// model, speed, number of sectors... - /* differentiate ATA, ATAPI, SATA and SATAPI */ - if (cl == 0x14 && ch == 0xEB) { - kcout << "New OS: PATAPI drive detected.\r\n"; - kATADeviceType = kATADevicePATA_PI; - } - if (cl == 0x69 && ch == 0x96) { - kcout << "New OS: SATAPI drive detected.\r\n"; - kATADeviceType = kATADeviceSATA_PI; - } + drv_std_wait_io(IO); - if (cl == 0x0 && ch == 0x0) { - kcout << "New OS: PATA drive detected.\r\n"; - kATADeviceType = kATADevicePATA; - } + for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { + kATAData[indexData] = In16(IO + ATA_REG_DATA); + } - if (cl == 0x3c && ch == 0xc3) { - kcout << "New OS: SATA drive detected.\r\n"; - kATADeviceType = kATADeviceSATA; - } + OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; - Out8(IO + ATA_REG_CONTROL, 0x02); + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - return true; + return true; } Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { UInt8 Command = ((!Master )? 0xE0 : 0xF0); + Lba /= SectorSz; + + drv_std_wait_io(IO); + drv_std_select(IO); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + + Out8(IO + ATA_REG_SEC_COUNT0, 2); Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA4, (Lba) >> 24); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); drv_std_wait_io(IO); for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { - WideChar chr = In16(IO + ATA_REG_DATA); - - Buf[IndexOff] = chr; + drv_std_wait_io(IO); + Buf[IndexOff] = In16(IO + ATA_REG_DATA); + drv_std_wait_io(IO); } } @@ -157,25 +128,44 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { UInt8 Command = ((!Master) ? 0xE0 : 0xF0); + Lba /= SectorSz; + + drv_std_wait_io(IO); + drv_std_select(IO); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + + Out8(IO + ATA_REG_SEC_COUNT0, 2); Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA4, (Lba) >> 24); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); drv_std_wait_io(IO); for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + drv_std_wait_io(IO); Out16(IO + ATA_REG_DATA, Buf[IndexOff]); - + drv_std_wait_io(IO); } } -/// @check is ATA detected? +/// @brief is ATA detected? Boolean drv_std_detected(Void) { return kATADetected; } +/*** + @brief Getter, gets the number of sectors inside the drive. +*/ +NewOS::SizeT drv_std_get_sector_count() { + return (kATAData[61] << 16)| kATAData[60]; +} + +/// @brief Get the drive size. +NewOS::SizeT drv_std_get_drv_size() { + return drv_std_get_sector_count() * kATASectorSize; +} + #endif /* ifdef __ATA_PIO__ */ diff --git a/Private/HALKit/compile_flags.txt b/Private/HALKit/compile_flags.txt index a37ae6bf..26779833 100644 --- a/Private/HALKit/compile_flags.txt +++ b/Private/HALKit/compile_flags.txt @@ -3,3 +3,4 @@ -std=c++20 -I./ -I../ +-D__NEWOS_AMD64__ |
