mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-30 08:17:58 +00:00
Updated driver API code
This commit is contained in:
parent
1fc03516eb
commit
ce13f5ea82
@ -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 = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user