From 0bdb2f9ca7cdd4f2424f6439d76ddb35246c6d91 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Nov 2022 19:57:31 +0200 Subject: [PATCH] Few improvements on AHCI driver --- Disk/AHCI/AHCI.cpp | 52 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/Disk/AHCI/AHCI.cpp b/Disk/AHCI/AHCI.cpp index 6b12a1a..07e99d4 100644 --- a/Disk/AHCI/AHCI.cpp +++ b/Disk/AHCI/AHCI.cpp @@ -177,16 +177,60 @@ struct BARData uint64_t MemoryBase; }; +typedef enum +{ + _URC_NO_REASON = 0, + _URC_FOREIGN_EXCEPTION_CAUGHT = 1, + _URC_FATAL_PHASE2_ERROR = 2, + _URC_FATAL_PHASE1_ERROR = 3, + _URC_NORMAL_STOP = 4, + _URC_END_OF_STACK = 5, + _URC_HANDLER_FOUND = 6, + _URC_INSTALL_CONTEXT = 7, + _URC_CONTINUE_UNWIND = 8 +} _Unwind_Reason_Code; + +typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__))); +typedef unsigned _Unwind_Word __attribute__((__mode__(__unwind_word__))); +typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, struct _Unwind_Exception *); + +struct _Unwind_Exception +{ + _Unwind_Exception_Class exception_class; + _Unwind_Exception_Cleanup_Fn exception_cleanup; +#if !defined(__USING_SJLJ_EXCEPTIONS__) && defined(__SEH__) + _Unwind_Word private_[6]; +#else + _Unwind_Word private_1; + _Unwind_Word private_2; +#endif +} __attribute__((__aligned__)); + +extern "C" void _Unwind_Resume(_Unwind_Exception *) { KAPI->Util.DebugPrint(((char *)"_Unwind_Resume" + KAPI->Info.Offset), KAPI->Info.DriverUID); } + void *operator new(size_t Size) { return KAPI->Memory.RequestPage(Size / KAPI->Memory.PageSize + 1); } +void operator delete(void *Ptr) { KAPI->Memory.FreePage(Ptr, 1); } // Potential memory leak +void operator delete(void *Ptr, size_t Size) { KAPI->Memory.FreePage(Ptr, Size / KAPI->Memory.PageSize + 1); } class Port { public: - HBAPort *HBAPortPtr; PortType AHCIPortType; + HBAPort *HBAPortPtr; uint8_t *Buffer; uint8_t PortNumber; + Port(PortType Type, HBAPort *PortPtr, uint8_t PortNumber) + { + this->AHCIPortType = Type; + this->HBAPortPtr = PortPtr; + this->Buffer = static_cast(KAPI->Memory.RequestPage(1)); + KAPI->Util.memset(this->Buffer, 0, KAPI->Memory.PageSize); + this->PortNumber = PortNumber; + } + + ~Port() { KAPI->Memory.FreePage(Buffer, 1); } + void StartCMD() { while (HBAPortPtr->CommandStatus & HBA_PxCMD_CR) @@ -401,11 +445,7 @@ int CallbackHandler(KernelCallback *Data) { // trace("%s drive found at port %d", PortTypeName[portType], i); KAPI->Util.DebugPrint(((char *)"SATA drive found." + KAPI->Info.Offset), KAPI->Info.DriverUID); - Ports[PortCount] = new Port; - Ports[PortCount]->AHCIPortType = portType; - Ports[PortCount]->HBAPortPtr = &ABAR->Ports[i]; - Ports[PortCount]->PortNumber = PortCount; - Ports[PortCount]->Buffer = static_cast(KAPI->Memory.RequestPage(1)); + Ports[PortCount] = new Port(portType, &ABAR->Ports[i], PortCount); PortCount++; } else