diff --git a/Core/Driver/DriverAPI.cpp b/Core/Driver/DriverAPI.cpp index cf432d13..5aa0f646 100644 --- a/Core/Driver/DriverAPI.cpp +++ b/Core/Driver/DriverAPI.cpp @@ -7,13 +7,18 @@ #include "../../Fex.hpp" #include "api.hpp" +// show debug messages +// #define DEBUG_DRIVER_API 1 + +#ifdef DEBUG_DRIVER_API +#define drvdbg(m, ...) debug(m, ##__VA_ARGS__) +#else +#define drvdbg(m, ...) +#endif + NewLock(DriverDisplayPrintLock); -void DriverDebugPrint(char *String, unsigned long DriverUID) -{ - SmartLock(DriverDisplayPrintLock); - trace("[%ld] %s", DriverUID, String); -} +void DriverDebugPrint(char *String, unsigned long DriverUID) { trace("[%ld] %s", DriverUID, String); } void DriverDisplayPrint(char *String) { @@ -24,57 +29,60 @@ void DriverDisplayPrint(char *String) void *RequestPage(unsigned long Size) { - SmartLock(DriverDisplayPrintLock); - // debug("Requesting %ld pages from the kernel...", Size); void *ret = KernelAllocator.RequestPages(Size); - // debug("Got %#lx", ret); + drvdbg("Allocated %ld pages (%#lx-%#lx)", Size, (unsigned long)ret, (unsigned long)ret + FROM_PAGES(Size)); return ret; } void FreePage(void *Page, unsigned long Size) { - SmartLock(DriverDisplayPrintLock); - debug("Freeing %ld pages from the address %#lx...", Size, (unsigned long)Page); + drvdbg("Freeing %ld pages (%#lx-%#lx)", Size, (unsigned long)Page, (unsigned long)Page + FROM_PAGES(Size)); KernelAllocator.FreePages(Page, Size); } void MapMemory(void *VirtualAddress, void *PhysicalAddress, unsigned long Flags) { SmartLock(DriverDisplayPrintLock); - debug("Mapping %#lx to %#lx with flags %#lx...", (unsigned long)VirtualAddress, (unsigned long)PhysicalAddress, Flags); + drvdbg("Mapping %#lx to %#lx with flags %#lx...", (unsigned long)VirtualAddress, (unsigned long)PhysicalAddress, Flags); Memory::Virtual().Map(VirtualAddress, PhysicalAddress, Flags); } void UnmapMemory(void *VirtualAddress) { SmartLock(DriverDisplayPrintLock); - debug("Unmapping %#lx...", (unsigned long)VirtualAddress); + drvdbg("Unmapping %#lx...", (unsigned long)VirtualAddress); Memory::Virtual().Unmap(VirtualAddress); } void *Drivermemcpy(void *Destination, void *Source, unsigned long Size) { SmartLock(DriverDisplayPrintLock); - // debug("Copying %ld bytes from %#lx to %#lx...", Size, (unsigned long)Source, (unsigned long)Destination); + drvdbg("Copying %ld bytes from %#lx-%#lx to %#lx-%#lx...", Size, + (unsigned long)Source, (unsigned long)Source + Size, + (unsigned long)Destination, (unsigned long)Destination + Size); return memcpy(Destination, Source, Size); } void *Drivermemset(void *Destination, int Value, unsigned long Size) { SmartLock(DriverDisplayPrintLock); - // debug("Setting %ld bytes from %#lx to %#x...", Size, (unsigned long)Destination, Value); + drvdbg("Setting value %#x at %#lx-%#lx (%ld bytes)...", Value, + (unsigned long)Destination, (unsigned long)Destination + Size, + Size); return memset(Destination, Value, Size); } void DriverNetSend(unsigned int DriverID, unsigned char *Data, unsigned short Size) { // This is useless I guess... - NIManager->DrvSend(DriverID, Data, Size); + if (NIManager) + NIManager->DrvSend(DriverID, Data, Size); } void DriverNetReceive(unsigned int DriverID, unsigned char *Data, unsigned short Size) { - NIManager->DrvReceive(DriverID, Data, Size); + if (NIManager) + NIManager->DrvReceive(DriverID, Data, Size); } void DriverAHCIDiskRead(unsigned int DriverID, unsigned long Sector, unsigned char *Data, unsigned int SectorCount, unsigned char Port) @@ -112,6 +120,25 @@ unsigned int DriverGetHeight() return Display->GetBuffer(0)->Height; } +void DriverSleep(unsigned long Milliseconds) +{ + SmartLock(DriverDisplayPrintLock); + drvdbg("Sleeping for %ld milliseconds...", Milliseconds); + if (TaskManager) + TaskManager->Sleep(Milliseconds); + else + TimeManager->Sleep(Milliseconds); +} + +int Driversprintf(char *Buffer, const char *Format, ...) +{ + va_list args; + va_start(args, Format); + int ret = vsprintf(Buffer, Format, args); + va_end(args); + return ret; +} + KernelAPI KernelAPITemplate = { .Version = { .Major = 0, @@ -136,6 +163,8 @@ KernelAPI KernelAPITemplate = { .DisplayPrint = DriverDisplayPrint, .memcpy = Drivermemcpy, .memset = Drivermemset, + .Sleep = DriverSleep, + .sprintf = Driversprintf, }, .Command = { .Network = {