Few improvements on AHCI driver

This commit is contained in:
Alex 2022-11-11 19:57:31 +02:00
parent cc1b6d517f
commit 0bdb2f9ca7
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -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<uint8_t *>(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<uint8_t *>(KAPI->Memory.RequestPage(1));
Ports[PortCount] = new Port(portType, &ABAR->Ports[i], PortCount);
PortCount++;
}
else