mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Move drivers to kernel
This commit is contained in:
@ -22,24 +22,24 @@
|
||||
|
||||
enum DebugLevel
|
||||
{
|
||||
DebugLevelNone = 0,
|
||||
DebugLevelError = 1,
|
||||
DebugLevelWarning = 2,
|
||||
DebugLevelInfo = 3,
|
||||
DebugLevelDebug = 4,
|
||||
DebugLevelTrace = 5,
|
||||
DebugLevelFixme = 6,
|
||||
DebugLevelUbsan = 7
|
||||
DebugLevelNone = 0,
|
||||
DebugLevelError = 1,
|
||||
DebugLevelWarning = 2,
|
||||
DebugLevelInfo = 3,
|
||||
DebugLevelDebug = 4,
|
||||
DebugLevelTrace = 5,
|
||||
DebugLevelFixme = 6,
|
||||
DebugLevelUbsan = 7
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace SysDbg
|
||||
{
|
||||
void Write(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void WriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void LockedWrite(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void LockedWriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void Write(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void WriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void LockedWrite(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
void LockedWriteLine(DebugLevel Level, const char *File, int Line, const char *Function, const char *Format, ...);
|
||||
}
|
||||
|
||||
#define error(Format, ...) SysDbg::WriteLine(DebugLevelError, __FILE__, __LINE__, __FUNCTION__, Format, ##__VA_ARGS__)
|
||||
@ -103,4 +103,6 @@ void SysDbgLockedWriteLine(enum DebugLevel Level, const char *File, int Line, co
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#define stub fixme("stub")
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DEBUGGER_H__
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <ints.hpp>
|
||||
#include <lock.hpp>
|
||||
#include <debug.h>
|
||||
#include <cpu.hpp>
|
||||
#include <pci.hpp>
|
||||
@ -29,114 +30,207 @@
|
||||
|
||||
namespace Driver
|
||||
{
|
||||
enum DriverCode
|
||||
{
|
||||
ERROR,
|
||||
OK,
|
||||
NOT_AVAILABLE,
|
||||
INVALID_FEX_HEADER,
|
||||
INVALID_DRIVER_DATA,
|
||||
NOT_DRIVER,
|
||||
NOT_IMPLEMENTED,
|
||||
DRIVER_RETURNED_ERROR,
|
||||
UNKNOWN_DRIVER_TYPE,
|
||||
PCI_DEVICE_NOT_FOUND,
|
||||
DRIVER_CONFLICT
|
||||
};
|
||||
enum DriverCode
|
||||
{
|
||||
/* This must be the same as in DAPI.hpp DriverReturnCode */
|
||||
ERROR,
|
||||
OK,
|
||||
NOT_IMPLEMENTED,
|
||||
NOT_FOUND,
|
||||
NOT_READY,
|
||||
NOT_AVAILABLE,
|
||||
NOT_AUTHORIZED,
|
||||
NOT_VALID,
|
||||
NOT_ACCEPTED,
|
||||
INVALID_PCI_BAR,
|
||||
INVALID_KERNEL_API,
|
||||
INVALID_MEMORY_ALLOCATION,
|
||||
INVALID_DATA,
|
||||
DEVICE_NOT_SUPPORTED,
|
||||
SYSTEM_NOT_SUPPORTED,
|
||||
KERNEL_API_VERSION_NOT_SUPPORTED,
|
||||
|
||||
class DriverInterruptHook;
|
||||
struct DriverFile
|
||||
{
|
||||
bool Enabled = false;
|
||||
size_t DriverUID = 0;
|
||||
void *Address = nullptr;
|
||||
void *InterruptCallback = nullptr;
|
||||
Memory::MemMgr *MemTrk = nullptr;
|
||||
DriverInterruptHook *InterruptHook[16]{};
|
||||
/* End of driver-only errors */
|
||||
|
||||
bool operator==(const DriverFile &Other) const
|
||||
{
|
||||
return DriverUID == Other.DriverUID;
|
||||
}
|
||||
};
|
||||
INVALID_FEX_HEADER,
|
||||
INVALID_DRIVER_DATA,
|
||||
NOT_DRIVER,
|
||||
DRIVER_RETURNED_ERROR,
|
||||
UNKNOWN_DRIVER_TYPE,
|
||||
UNKNOWN_DRIVER_BIND_TYPE,
|
||||
PCI_DEVICE_NOT_FOUND,
|
||||
DRIVER_CONFLICT
|
||||
};
|
||||
|
||||
class DriverInterruptHook : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
DriverFile Handle;
|
||||
bool Enabled = true;
|
||||
class DriverInterruptHook;
|
||||
struct DriverFile
|
||||
{
|
||||
bool Enabled = false;
|
||||
bool BuiltIn = false;
|
||||
unsigned int DriverUID = 0;
|
||||
void *Address = nullptr;
|
||||
void *ExtendedHeaderAddress = nullptr;
|
||||
void *InterruptCallback = nullptr;
|
||||
Memory::MemMgr *MemTrk = nullptr;
|
||||
DriverInterruptHook *InterruptHook[16]{};
|
||||
|
||||
bool operator==(const DriverFile &Other) const
|
||||
{
|
||||
return DriverUID == Other.DriverUID;
|
||||
}
|
||||
};
|
||||
|
||||
struct BuiltInDriverInfo
|
||||
{
|
||||
int (*EntryPoint)(void *);
|
||||
void *ExtendedHeader;
|
||||
};
|
||||
|
||||
class DriverInterruptHook : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
NewLock(DriverInterruptLock);
|
||||
|
||||
DriverFile Handle;
|
||||
bool Enabled = true;
|
||||
|
||||
#if defined(a64)
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#elif defined(aa64)
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
#endif
|
||||
|
||||
public:
|
||||
void Enable() { Enabled = true; }
|
||||
void Disable() { Enabled = false; }
|
||||
bool IsEnabled() { return Enabled; }
|
||||
DriverInterruptHook(int Interrupt, DriverFile Handle);
|
||||
virtual ~DriverInterruptHook() = default;
|
||||
};
|
||||
public:
|
||||
void Enable() { Enabled = true; }
|
||||
void Disable() { Enabled = false; }
|
||||
bool IsEnabled() { return Enabled; }
|
||||
DriverInterruptHook(int Interrupt, DriverFile Handle);
|
||||
virtual ~DriverInterruptHook() = default;
|
||||
};
|
||||
|
||||
class Driver
|
||||
{
|
||||
private:
|
||||
std::vector<DriverFile> Drivers;
|
||||
unsigned long DriverUIDs = 0;
|
||||
DriverCode CallDriverEntryPoint(void *fex, void *KAPIAddress);
|
||||
class Driver
|
||||
{
|
||||
private:
|
||||
NewLock(DriverInitLock);
|
||||
|
||||
void MapPCIAddresses(PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIGeneric(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIDisplay(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCINetwork(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIStorage(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIFileSystem(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIInput(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode BindPCIAudio(Memory::MemMgr *mem, void *fex, PCI::PCIDeviceHeader *PCIDevice);
|
||||
DriverCode DriverLoadBindPCI(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||
std::vector<DriverFile> Drivers;
|
||||
unsigned int DriverUIDs = 0;
|
||||
/* If BuiltIn is true, the "fex" is the entry point. */
|
||||
DriverCode CallDriverEntryPoint(void *fex, bool BuiltIn = false);
|
||||
|
||||
DriverCode BindInterruptGeneric(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptDisplay(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptNetwork(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptStorage(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptFileSystem(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptInput(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInterruptAudio(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode DriverLoadBindInterrupt(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||
public:
|
||||
/**
|
||||
* @brief Load and bind a driver to a PCI device.
|
||||
*
|
||||
* This function will search for a PCI device with the given VendorID and DeviceID.
|
||||
* If the device is found, the driver will be loaded and bound to the device.
|
||||
*
|
||||
* @param DriverAddress The address of the driver. The file will be copied to a new location.
|
||||
* @param Size The size of the driver.
|
||||
* @param IsBuiltIn If the driver is built-in, the @param DriverAddress will be @see BuiltInDriverInfo and the @param Size will be ignored.
|
||||
* @return DriverCode The result of the operation.
|
||||
*/
|
||||
DriverCode DriverLoadBindPCI(uintptr_t DriverAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
DriverCode BindInputGeneric(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputDisplay(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputNetwork(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputStorage(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputFileSystem(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputInput(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindInputAudio(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode DriverLoadBindInput(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||
/**
|
||||
* @brief Load and bind a driver to an interrupt.
|
||||
*
|
||||
* This function will search for an interrupt with the given IRQ.
|
||||
* If the interrupt is found, the driver will be loaded and bound to the interrupt.
|
||||
*
|
||||
* @param DriverAddress The address of the driver. The file will be copied to a new location.
|
||||
* @param Size The size of the driver.
|
||||
* @param IsBuiltIn If the driver is built-in, the @param DriverAddress will be @see BuiltInDriverInfo and the @param Size will be ignored.
|
||||
* @return DriverCode The result of the operation.
|
||||
*/
|
||||
DriverCode DriverLoadBindInterrupt(uintptr_t DriverAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
DriverCode BindProcessGeneric(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessDisplay(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessNetwork(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessStorage(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessFileSystem(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessInput(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode BindProcessAudio(Memory::MemMgr *mem, void *fex);
|
||||
DriverCode DriverLoadBindProcess(void *DrvExtHdr, uintptr_t DriverAddress, size_t Size, bool IsElf = false);
|
||||
/**
|
||||
* @brief Load and bind a driver to an input device.
|
||||
*
|
||||
* This function will attach the driver to the input device.
|
||||
*
|
||||
* @param DriverAddress The address of the driver. The file will be copied to a new location.
|
||||
* @param Size The size of the driver.
|
||||
* @param IsBuiltIn If the driver is built-in, the @param DriverAddress will be @see BuiltInDriverInfo and the @param Size will be ignored.
|
||||
* @return DriverCode The result of the operation.
|
||||
*/
|
||||
DriverCode DriverLoadBindInput(uintptr_t DriverAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
public:
|
||||
std::vector<DriverFile> GetDrivers() { return Drivers; }
|
||||
void Panic();
|
||||
void UnloadAllDrivers();
|
||||
bool UnloadDriver(unsigned long DUID);
|
||||
int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB);
|
||||
DriverCode LoadDriver(uintptr_t DriverAddress, size_t Size);
|
||||
DriverCode StartDrivers();
|
||||
Driver();
|
||||
~Driver();
|
||||
};
|
||||
/**
|
||||
* @brief Load and bind a driver to a process.
|
||||
*
|
||||
* This function will attach the driver to the process.
|
||||
*
|
||||
* @param DriverAddress The address of the driver. The file will be copied to a new location.
|
||||
* @param Size The size of the driver.
|
||||
* @param IsBuiltIn If the driver is built-in, the @param DriverAddress will be @see BuiltInDriverInfo and the @param Size will be ignored.
|
||||
* @return DriverCode The result of the operation.
|
||||
*/
|
||||
DriverCode DriverLoadBindProcess(uintptr_t DriverAddress, size_t Size, bool IsBuiltIn = false);
|
||||
|
||||
/**
|
||||
* @brief Get the currently loaded drivers.
|
||||
*
|
||||
* This function returns a clone of the drivers vector.
|
||||
* This means that the vector can be modified without affecting the drivers.
|
||||
*
|
||||
* @return std::vector<DriverFile> A clone of the drivers vector.
|
||||
*/
|
||||
std::vector<DriverFile> GetDrivers() { return Drivers; }
|
||||
|
||||
/* Reserved by the kernel */
|
||||
void Panic();
|
||||
|
||||
/**
|
||||
* @brief Unload all drivers.
|
||||
*
|
||||
* This function will unload all drivers.
|
||||
*/
|
||||
void UnloadAllDrivers();
|
||||
|
||||
/**
|
||||
* @brief Unload a driver.
|
||||
*
|
||||
* This function will unload a driver with the given driver unique ID.
|
||||
* It will free the memory and remove the driver from the drivers vector.
|
||||
*
|
||||
* @param DUID The driver unique ID.
|
||||
* @return true If the driver was found and unloaded successfully, false otherwise.
|
||||
*/
|
||||
bool UnloadDriver(unsigned long DUID);
|
||||
|
||||
/**
|
||||
* @brief Send a callback to a driver.
|
||||
*
|
||||
* This function will send a callback to a driver with the given driver unique ID.
|
||||
* This is used to communicate with drivers.
|
||||
*
|
||||
* @param DUID The driver unique ID.
|
||||
* @param KCB The @see KernelCallback structure.
|
||||
* @return int The result of the operation.
|
||||
*/
|
||||
int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB);
|
||||
|
||||
/**
|
||||
* @brief Load a driver.
|
||||
* @param DriverAddress The address of the driver file.
|
||||
* @param Size The size of the driver file.
|
||||
* @return DriverCode The result of the operation.
|
||||
*/
|
||||
DriverCode LoadDriver(uintptr_t DriverAddress, size_t Size);
|
||||
|
||||
/* Reserved by the kernel */
|
||||
void LoadDrivers();
|
||||
|
||||
/* Reserved by the kernel */
|
||||
Driver();
|
||||
|
||||
/* Reserved by the kernel */
|
||||
~Driver();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DRIVER_H__
|
||||
|
668
include/gui.hpp
668
include/gui.hpp
@ -26,383 +26,383 @@
|
||||
|
||||
namespace GraphicalUserInterface
|
||||
{
|
||||
typedef uintptr_t Handle;
|
||||
typedef uintptr_t Handle;
|
||||
|
||||
struct MouseData
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
int64_t Z;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
};
|
||||
struct MouseData
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
int64_t Z;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
};
|
||||
|
||||
struct ScreenBitmap
|
||||
{
|
||||
int64_t Width;
|
||||
int64_t Height;
|
||||
size_t Size;
|
||||
size_t Pitch;
|
||||
uint64_t BitsPerPixel;
|
||||
uint8_t *Data;
|
||||
};
|
||||
struct ScreenBitmap
|
||||
{
|
||||
int64_t Width;
|
||||
int64_t Height;
|
||||
size_t Size;
|
||||
size_t Pitch;
|
||||
uint64_t BitsPerPixel;
|
||||
uint8_t *Data;
|
||||
};
|
||||
|
||||
struct Rect
|
||||
{
|
||||
int64_t Left;
|
||||
int64_t Top;
|
||||
size_t Width;
|
||||
size_t Height;
|
||||
struct Rect
|
||||
{
|
||||
size_t Left;
|
||||
size_t Top;
|
||||
size_t Width;
|
||||
size_t Height;
|
||||
|
||||
bool Contains(int64_t X, int64_t Y)
|
||||
{
|
||||
return (X >= Left && X <= Left + Width && Y >= Top && Y <= Top + Height);
|
||||
}
|
||||
bool Contains(size_t X, size_t Y)
|
||||
{
|
||||
return (X >= Left && X <= Left + Width && Y >= Top && Y <= Top + Height);
|
||||
}
|
||||
|
||||
bool Contains(Rect rect)
|
||||
{
|
||||
return (rect.Left >= Left && rect.Left + rect.Width <= Left + Width && rect.Top >= Top && rect.Top + rect.Height <= Top + Height);
|
||||
}
|
||||
};
|
||||
bool Contains(Rect rect)
|
||||
{
|
||||
return (rect.Left >= Left && rect.Left + rect.Width <= Left + Width && rect.Top >= Top && rect.Top + rect.Height <= Top + Height);
|
||||
}
|
||||
};
|
||||
|
||||
enum CursorType
|
||||
{
|
||||
Visible = 0,
|
||||
Hidden,
|
||||
Arrow,
|
||||
Hand,
|
||||
Wait,
|
||||
IBeam,
|
||||
ResizeHorizontal,
|
||||
ResizeVertical,
|
||||
ResizeDiagonalLeft,
|
||||
ResizeDiagonalRight,
|
||||
ResizeAll,
|
||||
Cross,
|
||||
Help,
|
||||
No,
|
||||
AppStarting,
|
||||
};
|
||||
enum CursorType
|
||||
{
|
||||
Visible = 0,
|
||||
Hidden,
|
||||
Arrow,
|
||||
Hand,
|
||||
Wait,
|
||||
IBeam,
|
||||
ResizeHorizontal,
|
||||
ResizeVertical,
|
||||
ResizeDiagonalLeft,
|
||||
ResizeDiagonalRight,
|
||||
ResizeAll,
|
||||
Cross,
|
||||
Help,
|
||||
No,
|
||||
AppStarting,
|
||||
};
|
||||
|
||||
struct Event
|
||||
{
|
||||
struct
|
||||
{
|
||||
size_t Width;
|
||||
size_t Height;
|
||||
} Resize;
|
||||
struct Event
|
||||
{
|
||||
struct
|
||||
{
|
||||
size_t Width;
|
||||
size_t Height;
|
||||
} Resize;
|
||||
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseDown;
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseDown;
|
||||
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseUp;
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseUp;
|
||||
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseMove;
|
||||
};
|
||||
struct
|
||||
{
|
||||
int64_t X;
|
||||
int64_t Y;
|
||||
bool Left;
|
||||
bool Right;
|
||||
bool Middle;
|
||||
} MouseMove;
|
||||
};
|
||||
|
||||
/*
|
||||
virtual void OnMouseMove(Event *e) {}
|
||||
virtual void OnMouseClick(Event *e) {}
|
||||
virtual void OnMouseDoubleClick(Event *e) {}
|
||||
virtual void OnMouseDown(Event *e) {}
|
||||
virtual void OnMouseUp(Event *e) {}
|
||||
virtual void OnMouseWheel(Event *e) {}
|
||||
virtual void OnMouseEnter(Event *e) {}
|
||||
virtual void OnMouseLeave(Event *e) {}
|
||||
virtual void OnMouseHover(Event *e) {}
|
||||
virtual void OnMouseDrag(Event *e) {}
|
||||
virtual void OnMouseDragStart(Event *e) {}
|
||||
virtual void OnMouseDragEnd(Event *e) {}
|
||||
virtual void OnMouseDragEnter(Event *e) {}
|
||||
virtual void OnMouseDragLeave(Event *e) {}
|
||||
virtual void OnMouseDragHover(Event *e) {}
|
||||
virtual void OnMouseDragDrop(Event *e) {}
|
||||
virtual void OnMouseDragDropEnter(Event *e) {}
|
||||
virtual void OnMouseDragDropLeave(Event *e) {}
|
||||
virtual void OnMouseDragDropHover(Event *e) {}
|
||||
virtual void OnMouseDragDropEnd(Event *e) {}
|
||||
virtual void OnMouseDragDropStart(Event *e) {}
|
||||
virtual void OnMouseDragDropCancel(Event *e) {}
|
||||
virtual void OnMouseDragDropComplete(Event *e) {}
|
||||
virtual void OnMouseDragDropAbort(Event *e) {}
|
||||
/*
|
||||
virtual void OnMouseMove(Event *e) {}
|
||||
virtual void OnMouseClick(Event *e) {}
|
||||
virtual void OnMouseDoubleClick(Event *e) {}
|
||||
virtual void OnMouseDown(Event *e) {}
|
||||
virtual void OnMouseUp(Event *e) {}
|
||||
virtual void OnMouseWheel(Event *e) {}
|
||||
virtual void OnMouseEnter(Event *e) {}
|
||||
virtual void OnMouseLeave(Event *e) {}
|
||||
virtual void OnMouseHover(Event *e) {}
|
||||
virtual void OnMouseDrag(Event *e) {}
|
||||
virtual void OnMouseDragStart(Event *e) {}
|
||||
virtual void OnMouseDragEnd(Event *e) {}
|
||||
virtual void OnMouseDragEnter(Event *e) {}
|
||||
virtual void OnMouseDragLeave(Event *e) {}
|
||||
virtual void OnMouseDragHover(Event *e) {}
|
||||
virtual void OnMouseDragDrop(Event *e) {}
|
||||
virtual void OnMouseDragDropEnter(Event *e) {}
|
||||
virtual void OnMouseDragDropLeave(Event *e) {}
|
||||
virtual void OnMouseDragDropHover(Event *e) {}
|
||||
virtual void OnMouseDragDropEnd(Event *e) {}
|
||||
virtual void OnMouseDragDropStart(Event *e) {}
|
||||
virtual void OnMouseDragDropCancel(Event *e) {}
|
||||
virtual void OnMouseDragDropComplete(Event *e) {}
|
||||
virtual void OnMouseDragDropAbort(Event *e) {}
|
||||
|
||||
virtual void OnKeyDown(Event *e) {}
|
||||
virtual void OnKeyUp(Event *e) {}
|
||||
virtual void OnKeyPress(Event *e) {}
|
||||
virtual void OnKeyDown(Event *e) {}
|
||||
virtual void OnKeyUp(Event *e) {}
|
||||
virtual void OnKeyPress(Event *e) {}
|
||||
|
||||
virtual void OnFocusEnter(Event *e) {}
|
||||
virtual void OnFocusLeave(Event *e) {}
|
||||
virtual void OnFocusHover(Event *e) {}
|
||||
virtual void OnFocusEnter(Event *e) {}
|
||||
virtual void OnFocusLeave(Event *e) {}
|
||||
virtual void OnFocusHover(Event *e) {}
|
||||
|
||||
virtual void OnResize(Event *e) {}
|
||||
virtual void OnMinimize(Event *e) {}
|
||||
virtual void OnMaximize(Event *e) {}
|
||||
virtual void OnMove(Event *e) {}
|
||||
virtual void OnShow(Event *e) {}
|
||||
virtual void OnHide(Event *e) {}
|
||||
virtual void OnClose(Event *e) {}
|
||||
virtual void OnDestroy(Event *e) {}
|
||||
virtual void OnResize(Event *e) {}
|
||||
virtual void OnMinimize(Event *e) {}
|
||||
virtual void OnMaximize(Event *e) {}
|
||||
virtual void OnMove(Event *e) {}
|
||||
virtual void OnShow(Event *e) {}
|
||||
virtual void OnHide(Event *e) {}
|
||||
virtual void OnClose(Event *e) {}
|
||||
virtual void OnDestroy(Event *e) {}
|
||||
|
||||
virtual void OnPaint(Event *e) {}
|
||||
virtual void OnPaintBackground(Event *e) {}
|
||||
virtual void OnPaintForeground(Event *e) {}
|
||||
virtual void OnPaintOverlay(Event *e) {}
|
||||
virtual void OnPaintAll(Event *e) {}
|
||||
virtual void OnPaintChildren(Event *e) {}
|
||||
virtual void OnPaintChildrenBackground(Event *e) {}
|
||||
virtual void OnPaintChildrenForeground(Event *e) {}
|
||||
virtual void OnPaintChildrenBorder(Event *e) {}
|
||||
virtual void OnPaintChildrenShadow(Event *e) {}
|
||||
virtual void OnPaintChildrenOverlay(Event *e) {}
|
||||
virtual void OnPaintChildrenAll(Event *e) {}
|
||||
*/
|
||||
virtual void OnPaint(Event *e) {}
|
||||
virtual void OnPaintBackground(Event *e) {}
|
||||
virtual void OnPaintForeground(Event *e) {}
|
||||
virtual void OnPaintOverlay(Event *e) {}
|
||||
virtual void OnPaintAll(Event *e) {}
|
||||
virtual void OnPaintChildren(Event *e) {}
|
||||
virtual void OnPaintChildrenBackground(Event *e) {}
|
||||
virtual void OnPaintChildrenForeground(Event *e) {}
|
||||
virtual void OnPaintChildrenBorder(Event *e) {}
|
||||
virtual void OnPaintChildrenShadow(Event *e) {}
|
||||
virtual void OnPaintChildrenOverlay(Event *e) {}
|
||||
virtual void OnPaintChildrenAll(Event *e) {}
|
||||
*/
|
||||
|
||||
void SetPixel(ScreenBitmap *Bitmap, int64_t X, int64_t Y, uint32_t Color);
|
||||
void DrawOverBitmap(ScreenBitmap *DestinationBitmap,
|
||||
ScreenBitmap *SourceBitmap,
|
||||
int64_t Top,
|
||||
int64_t Left,
|
||||
bool IgnoreZero = true);
|
||||
void PutRect(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
void PutBorder(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
uint32_t BlendColors(uint32_t c1, uint32_t c2, float t);
|
||||
void PutBorderWithShadow(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
void DrawShadow(ScreenBitmap *Bitmap, Rect rect);
|
||||
void PaintChar(Video::Font *font, ScreenBitmap *Bitmap, char c, uint32_t Color, int64_t *CharCursorX, int64_t *CharCursorY);
|
||||
void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color);
|
||||
void SetPixel(ScreenBitmap *Bitmap, int64_t X, int64_t Y, uint32_t Color);
|
||||
void DrawOverBitmap(ScreenBitmap *DestinationBitmap,
|
||||
ScreenBitmap *SourceBitmap,
|
||||
int64_t Top,
|
||||
int64_t Left,
|
||||
bool IgnoreZero = true);
|
||||
void PutRect(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
void PutBorder(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
uint32_t BlendColors(uint32_t c1, uint32_t c2, float t);
|
||||
void PutBorderWithShadow(ScreenBitmap *Bitmap, Rect rect, uint32_t Color);
|
||||
void DrawShadow(ScreenBitmap *Bitmap, Rect rect);
|
||||
void PaintChar(Video::Font *font, ScreenBitmap *Bitmap, char c, uint32_t Color, int64_t *CharCursorX, int64_t *CharCursorY);
|
||||
void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color);
|
||||
|
||||
class WidgetCollection
|
||||
{
|
||||
private:
|
||||
Memory::MemMgr *mem;
|
||||
ScreenBitmap *Buffer;
|
||||
Video::Font *CurrentFont;
|
||||
void *ParentWindow;
|
||||
bool NeedRedraw;
|
||||
class WidgetCollection
|
||||
{
|
||||
private:
|
||||
Memory::MemMgr *mem;
|
||||
ScreenBitmap *Buffer;
|
||||
Video::Font *CurrentFont;
|
||||
void *ParentWindow;
|
||||
bool NeedRedraw;
|
||||
|
||||
struct HandleMeta
|
||||
{
|
||||
char Type[4];
|
||||
};
|
||||
struct HandleMeta
|
||||
{
|
||||
char Type[4];
|
||||
};
|
||||
|
||||
struct LabelObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
char Text[512];
|
||||
uint32_t Color;
|
||||
int64_t CharCursorX, CharCursorY;
|
||||
};
|
||||
struct LabelObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
char Text[512];
|
||||
uint32_t Color;
|
||||
int64_t CharCursorX, CharCursorY;
|
||||
};
|
||||
|
||||
struct PanelObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
uint32_t Color;
|
||||
uint32_t BorderColor;
|
||||
uint32_t ShadowColor;
|
||||
bool Shadow;
|
||||
};
|
||||
struct PanelObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
uint32_t Color;
|
||||
uint32_t BorderColor;
|
||||
uint32_t ShadowColor;
|
||||
bool Shadow;
|
||||
};
|
||||
|
||||
struct ButtonObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
char Text[512];
|
||||
uint32_t Color;
|
||||
uint32_t HoverColor;
|
||||
uint32_t PressedColor;
|
||||
uint32_t BorderColor;
|
||||
uint32_t ShadowColor;
|
||||
int64_t CharCursorX, CharCursorY;
|
||||
bool Shadow;
|
||||
bool Hover;
|
||||
bool Pressed;
|
||||
uintptr_t OnClick;
|
||||
};
|
||||
struct ButtonObject
|
||||
{
|
||||
HandleMeta Handle;
|
||||
Rect rect;
|
||||
char Text[512];
|
||||
uint32_t Color;
|
||||
uint32_t HoverColor;
|
||||
uint32_t PressedColor;
|
||||
uint32_t BorderColor;
|
||||
uint32_t ShadowColor;
|
||||
int64_t CharCursorX, CharCursorY;
|
||||
bool Shadow;
|
||||
bool Hover;
|
||||
bool Pressed;
|
||||
uintptr_t OnClick;
|
||||
};
|
||||
|
||||
std::vector<LabelObject *> Labels;
|
||||
std::vector<PanelObject *> Panels;
|
||||
std::vector<ButtonObject *> Buttons;
|
||||
std::vector<LabelObject *> Labels;
|
||||
std::vector<PanelObject *> Panels;
|
||||
std::vector<ButtonObject *> Buttons;
|
||||
|
||||
public:
|
||||
void ReplaceFont(Video::Font *NewFont)
|
||||
{
|
||||
delete this->CurrentFont;
|
||||
this->CurrentFont = NewFont;
|
||||
}
|
||||
public:
|
||||
void ReplaceFont(Video::Font *NewFont)
|
||||
{
|
||||
delete this->CurrentFont;
|
||||
this->CurrentFont = NewFont;
|
||||
}
|
||||
|
||||
Handle CreatePanel(Rect rect, uint32_t Color);
|
||||
Handle CreateButton(Rect rect, const char *Text, uintptr_t OnClick = (uintptr_t) nullptr);
|
||||
Handle CreateLabel(Rect rect, const char *Text);
|
||||
Handle CreateTextBox(Rect rect, const char *Text);
|
||||
Handle CreateCheckBox(Rect rect, const char *Text);
|
||||
Handle CreateRadioButton(Rect rect, const char *Text);
|
||||
Handle CreateComboBox(Rect rect, const char *Text);
|
||||
Handle CreateListBox(Rect rect, const char *Text);
|
||||
Handle CreateProgressBar(Rect rect, const char *Text);
|
||||
Handle CreateContextMenu(Rect rect, const char *Text);
|
||||
Handle CreatePanel(Rect rect, uint32_t Color);
|
||||
Handle CreateButton(Rect rect, const char *Text, uintptr_t OnClick = (uintptr_t) nullptr);
|
||||
Handle CreateLabel(Rect rect, const char *Text);
|
||||
Handle CreateTextBox(Rect rect, const char *Text);
|
||||
Handle CreateCheckBox(Rect rect, const char *Text);
|
||||
Handle CreateRadioButton(Rect rect, const char *Text);
|
||||
Handle CreateComboBox(Rect rect, const char *Text);
|
||||
Handle CreateListBox(Rect rect, const char *Text);
|
||||
Handle CreateProgressBar(Rect rect, const char *Text);
|
||||
Handle CreateContextMenu(Rect rect, const char *Text);
|
||||
|
||||
void SetText(Handle handle, const char *Text);
|
||||
void SetText(Handle handle, const char *Text);
|
||||
|
||||
WidgetCollection(void /* Window */ *ParentWindow);
|
||||
~WidgetCollection();
|
||||
WidgetCollection(void /* Window */ *ParentWindow);
|
||||
~WidgetCollection();
|
||||
|
||||
void OnMouseMove(Event *e);
|
||||
void OnMouseClick(Event *e);
|
||||
void OnMouseDoubleClick(Event *e);
|
||||
void OnMouseDown(Event *e);
|
||||
void OnMouseUp(Event *e);
|
||||
void OnMouseWheel(Event *e);
|
||||
void OnMouseEnter(Event *e);
|
||||
void OnMouseLeave(Event *e);
|
||||
void OnMouseHover(Event *e);
|
||||
void OnMouseDrag(Event *e);
|
||||
void OnMouseDragStart(Event *e);
|
||||
void OnMouseDragEnd(Event *e);
|
||||
void OnMouseMove(Event *e);
|
||||
void OnMouseClick(Event *e);
|
||||
void OnMouseDoubleClick(Event *e);
|
||||
void OnMouseDown(Event *e);
|
||||
void OnMouseUp(Event *e);
|
||||
void OnMouseWheel(Event *e);
|
||||
void OnMouseEnter(Event *e);
|
||||
void OnMouseLeave(Event *e);
|
||||
void OnMouseHover(Event *e);
|
||||
void OnMouseDrag(Event *e);
|
||||
void OnMouseDragStart(Event *e);
|
||||
void OnMouseDragEnd(Event *e);
|
||||
|
||||
void OnKeyDown(Event *e);
|
||||
void OnKeyUp(Event *e);
|
||||
void OnKeyPress(Event *e);
|
||||
void OnKeyDown(Event *e);
|
||||
void OnKeyUp(Event *e);
|
||||
void OnKeyPress(Event *e);
|
||||
|
||||
void OnShow(Event *e);
|
||||
void OnHide(Event *e);
|
||||
void OnDestroy(Event *e);
|
||||
void OnShow(Event *e);
|
||||
void OnHide(Event *e);
|
||||
void OnDestroy(Event *e);
|
||||
|
||||
void OnPaint(Event *e);
|
||||
void OnPaintBackground(Event *e);
|
||||
void OnPaintForeground(Event *e);
|
||||
};
|
||||
void OnPaint(Event *e);
|
||||
void OnPaintBackground(Event *e);
|
||||
void OnPaintForeground(Event *e);
|
||||
};
|
||||
|
||||
class Window
|
||||
{
|
||||
private:
|
||||
Memory::MemMgr *mem;
|
||||
ScreenBitmap *Buffer;
|
||||
Rect Position;
|
||||
Rect LastPosition;
|
||||
char Title[256];
|
||||
std::vector<WidgetCollection *> Widgets;
|
||||
void *ParentGUI;
|
||||
class Window
|
||||
{
|
||||
private:
|
||||
Memory::MemMgr *mem;
|
||||
ScreenBitmap *Buffer;
|
||||
Rect Position;
|
||||
Rect LastPosition;
|
||||
char Title[256];
|
||||
std::vector<WidgetCollection *> Widgets;
|
||||
void *ParentGUI;
|
||||
|
||||
bool Maximized;
|
||||
bool Minimized;
|
||||
bool Maximized;
|
||||
bool Minimized;
|
||||
|
||||
public:
|
||||
bool IsMaximized() { return Maximized; }
|
||||
bool IsMinimized() { return Minimized; }
|
||||
ScreenBitmap *GetBuffer() { return Buffer; }
|
||||
Rect GetPosition() { return Position; }
|
||||
Rect *GetPositionPtr() { return &Position; }
|
||||
const char *GetTitle() { return (const char *)Title; }
|
||||
void SetTitle(const char *Title) { strcpy(this->Title, Title); }
|
||||
void AddWidget(WidgetCollection *widget);
|
||||
public:
|
||||
bool IsMaximized() { return Maximized; }
|
||||
bool IsMinimized() { return Minimized; }
|
||||
ScreenBitmap *GetBuffer() { return Buffer; }
|
||||
Rect GetPosition() { return Position; }
|
||||
Rect *GetPositionPtr() { return &Position; }
|
||||
const char *GetTitle() { return (const char *)Title; }
|
||||
void SetTitle(const char *Title) { strcpy(this->Title, Title); }
|
||||
void AddWidget(WidgetCollection *widget);
|
||||
|
||||
Window(void *ParentGUI, Rect rect, const char *Title);
|
||||
~Window();
|
||||
Window(void *ParentGUI, Rect rect, const char *Title);
|
||||
~Window();
|
||||
|
||||
void OnMouseMove(Event *e);
|
||||
void OnMouseClick(Event *e);
|
||||
void OnMouseDoubleClick(Event *e);
|
||||
void OnMouseDown(Event *e);
|
||||
void OnMouseUp(Event *e);
|
||||
void OnMouseWheel(Event *e);
|
||||
void OnMouseEnter(Event *e);
|
||||
void OnMouseLeave(Event *e);
|
||||
void OnMouseHover(Event *e);
|
||||
void OnMouseDrag(Event *e);
|
||||
void OnMouseDragStart(Event *e);
|
||||
void OnMouseDragEnd(Event *e);
|
||||
void OnMouseMove(Event *e);
|
||||
void OnMouseClick(Event *e);
|
||||
void OnMouseDoubleClick(Event *e);
|
||||
void OnMouseDown(Event *e);
|
||||
void OnMouseUp(Event *e);
|
||||
void OnMouseWheel(Event *e);
|
||||
void OnMouseEnter(Event *e);
|
||||
void OnMouseLeave(Event *e);
|
||||
void OnMouseHover(Event *e);
|
||||
void OnMouseDrag(Event *e);
|
||||
void OnMouseDragStart(Event *e);
|
||||
void OnMouseDragEnd(Event *e);
|
||||
|
||||
void OnKeyDown(Event *e);
|
||||
void OnKeyUp(Event *e);
|
||||
void OnKeyPress(Event *e);
|
||||
void OnKeyDown(Event *e);
|
||||
void OnKeyUp(Event *e);
|
||||
void OnKeyPress(Event *e);
|
||||
|
||||
void OnFocusEnter(Event *e);
|
||||
void OnFocusLeave(Event *e);
|
||||
void OnFocusHover(Event *e);
|
||||
void OnFocusEnter(Event *e);
|
||||
void OnFocusLeave(Event *e);
|
||||
void OnFocusHover(Event *e);
|
||||
|
||||
void OnResize(Event *e);
|
||||
void OnMinimize(Event *e);
|
||||
void OnMaximize(Event *e);
|
||||
void OnMove(Event *e);
|
||||
void OnShow(Event *e);
|
||||
void OnHide(Event *e);
|
||||
void OnClose(Event *e);
|
||||
void OnDestroy(Event *e);
|
||||
void OnResize(Event *e);
|
||||
void OnMinimize(Event *e);
|
||||
void OnMaximize(Event *e);
|
||||
void OnMove(Event *e);
|
||||
void OnShow(Event *e);
|
||||
void OnHide(Event *e);
|
||||
void OnClose(Event *e);
|
||||
void OnDestroy(Event *e);
|
||||
|
||||
void OnPaint(Event *e);
|
||||
void OnPaintBackground(Event *e);
|
||||
void OnPaintForeground(Event *e);
|
||||
void OnPaintOverlay(Event *e);
|
||||
void OnPaintAll(Event *e);
|
||||
void OnPaintChildren(Event *e);
|
||||
void OnPaintChildrenBackground(Event *e);
|
||||
void OnPaintChildrenForeground(Event *e);
|
||||
void OnPaintChildrenBorder(Event *e);
|
||||
void OnPaintChildrenShadow(Event *e);
|
||||
void OnPaintChildrenOverlay(Event *e);
|
||||
void OnPaintChildrenAll(Event *e);
|
||||
};
|
||||
void OnPaint(Event *e);
|
||||
void OnPaintBackground(Event *e);
|
||||
void OnPaintForeground(Event *e);
|
||||
void OnPaintOverlay(Event *e);
|
||||
void OnPaintAll(Event *e);
|
||||
void OnPaintChildren(Event *e);
|
||||
void OnPaintChildrenBackground(Event *e);
|
||||
void OnPaintChildrenForeground(Event *e);
|
||||
void OnPaintChildrenBorder(Event *e);
|
||||
void OnPaintChildrenShadow(Event *e);
|
||||
void OnPaintChildrenOverlay(Event *e);
|
||||
void OnPaintChildrenAll(Event *e);
|
||||
};
|
||||
|
||||
class GUI
|
||||
{
|
||||
private:
|
||||
MouseData MouseArray[256];
|
||||
Memory::MemMgr *mem;
|
||||
Video::Font *CurrentFont;
|
||||
Rect Desktop;
|
||||
ScreenBitmap *BackBuffer;
|
||||
ScreenBitmap *DesktopBuffer;
|
||||
ScreenBitmap *OverlayBuffer;
|
||||
ScreenBitmap *CursorBuffer;
|
||||
std::vector<WidgetCollection *> Widgets;
|
||||
std::vector<Window *> Windows;
|
||||
CursorType Cursor = CursorType::Arrow;
|
||||
CursorType LastCursor = CursorType::Arrow;
|
||||
bool CursorVisible = true;
|
||||
bool IsRunning = false;
|
||||
class GUI
|
||||
{
|
||||
private:
|
||||
MouseData MouseArray[256];
|
||||
Memory::MemMgr *mem;
|
||||
Video::Font *CurrentFont;
|
||||
Rect Desktop;
|
||||
ScreenBitmap *BackBuffer;
|
||||
ScreenBitmap *DesktopBuffer;
|
||||
ScreenBitmap *OverlayBuffer;
|
||||
ScreenBitmap *CursorBuffer;
|
||||
std::vector<WidgetCollection *> Widgets;
|
||||
std::vector<Window *> Windows;
|
||||
CursorType Cursor = CursorType::Arrow;
|
||||
CursorType LastCursor = CursorType::Arrow;
|
||||
bool CursorVisible = true;
|
||||
bool IsRunning = false;
|
||||
|
||||
bool DesktopBufferRepaint = true;
|
||||
bool OverlayBufferRepaint = true;
|
||||
bool OverlayFullRepaint = true;
|
||||
bool CursorBufferRepaint = true;
|
||||
bool DesktopBufferRepaint = true;
|
||||
bool OverlayBufferRepaint = true;
|
||||
bool OverlayFullRepaint = true;
|
||||
bool CursorBufferRepaint = true;
|
||||
|
||||
void FetchInputs();
|
||||
void PaintDesktop();
|
||||
void PaintWidgets();
|
||||
void PaintWindows();
|
||||
void PaintCursor();
|
||||
void FetchInputs();
|
||||
void PaintDesktop();
|
||||
void PaintWidgets();
|
||||
void PaintWindows();
|
||||
void PaintCursor();
|
||||
|
||||
public:
|
||||
void SetCursorType(CursorType Type = CursorType::Visible) { this->Cursor = Type; }
|
||||
void Loop();
|
||||
void AddWindow(Window *window);
|
||||
void AddWidget(WidgetCollection *widget);
|
||||
GUI();
|
||||
~GUI();
|
||||
};
|
||||
public:
|
||||
void SetCursorType(CursorType Type = CursorType::Visible) { this->Cursor = Type; }
|
||||
void Loop();
|
||||
void AddWindow(Window *window);
|
||||
void AddWidget(WidgetCollection *widget);
|
||||
GUI();
|
||||
~GUI();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_GUI_H__
|
||||
|
400
include/pci.hpp
400
include/pci.hpp
@ -20,221 +20,223 @@
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
#include <vector>
|
||||
|
||||
namespace PCI
|
||||
{
|
||||
namespace Descriptors
|
||||
{
|
||||
enum PCIVendors
|
||||
{
|
||||
SymbiosLogic = 0x1000,
|
||||
RedHat = 0x1AF4,
|
||||
REDHat2 = 0x1B36,
|
||||
Realtek = 0x10EC,
|
||||
VirtualBox = 0x80EE,
|
||||
Ensoniq = 0x1274,
|
||||
QEMU = 0x1234,
|
||||
VMware = 0x15AD,
|
||||
IntelCorporation = 0x8086,
|
||||
AdvancedMicroDevices = 0x1022,
|
||||
NVIDIACorporation = 0x10DE
|
||||
};
|
||||
namespace Descriptors
|
||||
{
|
||||
enum PCIVendors
|
||||
{
|
||||
SymbiosLogic = 0x1000,
|
||||
RedHat = 0x1AF4,
|
||||
REDHat2 = 0x1B36,
|
||||
Realtek = 0x10EC,
|
||||
VirtualBox = 0x80EE,
|
||||
Ensoniq = 0x1274,
|
||||
QEMU = 0x1234,
|
||||
VMware = 0x15AD,
|
||||
IntelCorporation = 0x8086,
|
||||
AdvancedMicroDevices = 0x1022,
|
||||
NVIDIACorporation = 0x10DE
|
||||
};
|
||||
|
||||
const char *const DeviceClasses[]{
|
||||
"Unclassified",
|
||||
"Mass Storage Controller",
|
||||
"Network Controller",
|
||||
"Display Controller",
|
||||
"Multimedia Controller",
|
||||
"Memory Controller",
|
||||
"Bridge Device",
|
||||
"Simple Communication Controller",
|
||||
"Base System Peripheral",
|
||||
"Input Device Controller",
|
||||
"Docking Station",
|
||||
"Processor",
|
||||
"Serial Bus Controller",
|
||||
"Wireless Controller",
|
||||
"Intelligent Controller",
|
||||
"Satellite Communication Controller",
|
||||
"Encryption Controller",
|
||||
"Signal Processing Controller",
|
||||
"Processing Accelerator",
|
||||
"Non Essential Instrumentation"};
|
||||
const char *const DeviceClasses[]{
|
||||
"Unclassified",
|
||||
"Mass Storage Controller",
|
||||
"Network Controller",
|
||||
"Display Controller",
|
||||
"Multimedia Controller",
|
||||
"Memory Controller",
|
||||
"Bridge Device",
|
||||
"Simple Communication Controller",
|
||||
"Base System Peripheral",
|
||||
"Input Device Controller",
|
||||
"Docking Station",
|
||||
"Processor",
|
||||
"Serial Bus Controller",
|
||||
"Wireless Controller",
|
||||
"Intelligent Controller",
|
||||
"Satellite Communication Controller",
|
||||
"Encryption Controller",
|
||||
"Signal Processing Controller",
|
||||
"Processing Accelerator",
|
||||
"Non Essential Instrumentation"};
|
||||
|
||||
const char *MassStorageControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *NetworkControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *DisplayControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *CommunicationControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *BaseSystemPeripheralSubclassName(uint8_t SubclassCode);
|
||||
const char *SerialBusControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *BridgeDeviceSubclassName(uint8_t SubclassCode);
|
||||
const char *WirelessControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *GetVendorName(uint32_t VendorID);
|
||||
const char *GetDeviceName(uint32_t VendorID, uint32_t DeviceID);
|
||||
const char *GetSubclassName(uint8_t ClassCode, uint8_t SubclassCode);
|
||||
const char *GetProgIFName(uint8_t ClassCode, uint8_t SubclassCode, uint8_t ProgIF);
|
||||
}
|
||||
const char *MassStorageControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *NetworkControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *DisplayControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *CommunicationControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *BaseSystemPeripheralSubclassName(uint8_t SubclassCode);
|
||||
const char *SerialBusControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *BridgeDeviceSubclassName(uint8_t SubclassCode);
|
||||
const char *WirelessControllerSubclassName(uint8_t SubclassCode);
|
||||
const char *GetVendorName(uint32_t VendorID);
|
||||
const char *GetDeviceName(uint32_t VendorID, uint32_t DeviceID);
|
||||
const char *GetSubclassName(uint8_t ClassCode, uint8_t SubclassCode);
|
||||
const char *GetProgIFName(uint8_t ClassCode, uint8_t SubclassCode, uint8_t ProgIF);
|
||||
}
|
||||
|
||||
/* https://sites.uclouvain.be/SystInfo/usr/include/linux/pci_regs.h.html */
|
||||
enum PCICommands
|
||||
{
|
||||
/** @brief Enable response in I/O space */
|
||||
PCI_COMMAND_IO = 0x1,
|
||||
/** @brief Enable response in Memory space */
|
||||
PCI_COMMAND_MEMORY = 0x2,
|
||||
/** @brief Enable bus mastering */
|
||||
PCI_COMMAND_MASTER = 0x4,
|
||||
/** @brief Enable response to special cycles */
|
||||
PCI_COMMAND_SPECIAL = 0x8,
|
||||
/** @brief Use memory write and invalidate */
|
||||
PCI_COMMAND_INVALIDATE = 0x10,
|
||||
/** @brief Enable palette snooping */
|
||||
PCI_COMMAND_VGA_PALETTE = 0x20,
|
||||
/** @brief Enable parity checking */
|
||||
PCI_COMMAND_PARITY = 0x40,
|
||||
/** @brief Enable address/data stepping */
|
||||
PCI_COMMAND_WAIT = 0x80,
|
||||
/** @brief Enable SERR */
|
||||
PCI_COMMAND_SERR = 0x100,
|
||||
/** @brief Enable back-to-back writes */
|
||||
PCI_COMMAND_FAST_BACK = 0x200,
|
||||
/** @brief INTx Emulation Disable */
|
||||
PCI_COMMAND_INTX_DISABLE = 0x400
|
||||
};
|
||||
/* https://sites.uclouvain.be/SystInfo/usr/include/linux/pci_regs.h.html */
|
||||
enum PCICommands
|
||||
{
|
||||
/** @brief Enable response in I/O space */
|
||||
PCI_COMMAND_IO = 0x1,
|
||||
/** @brief Enable response in Memory space */
|
||||
PCI_COMMAND_MEMORY = 0x2,
|
||||
/** @brief Enable bus mastering */
|
||||
PCI_COMMAND_MASTER = 0x4,
|
||||
/** @brief Enable response to special cycles */
|
||||
PCI_COMMAND_SPECIAL = 0x8,
|
||||
/** @brief Use memory write and invalidate */
|
||||
PCI_COMMAND_INVALIDATE = 0x10,
|
||||
/** @brief Enable palette snooping */
|
||||
PCI_COMMAND_VGA_PALETTE = 0x20,
|
||||
/** @brief Enable parity checking */
|
||||
PCI_COMMAND_PARITY = 0x40,
|
||||
/** @brief Enable address/data stepping */
|
||||
PCI_COMMAND_WAIT = 0x80,
|
||||
/** @brief Enable SERR */
|
||||
PCI_COMMAND_SERR = 0x100,
|
||||
/** @brief Enable back-to-back writes */
|
||||
PCI_COMMAND_FAST_BACK = 0x200,
|
||||
/** @brief INTx Emulation Disable */
|
||||
PCI_COMMAND_INTX_DISABLE = 0x400
|
||||
};
|
||||
|
||||
struct PCIDeviceHeader
|
||||
{
|
||||
uint16_t VendorID;
|
||||
uint16_t DeviceID;
|
||||
uint16_t Command;
|
||||
uint16_t Status;
|
||||
uint8_t RevisionID;
|
||||
uint8_t ProgIF;
|
||||
uint8_t Subclass;
|
||||
uint8_t Class;
|
||||
uint8_t CacheLineSize;
|
||||
uint8_t LatencyTimer;
|
||||
uint8_t HeaderType;
|
||||
uint8_t BIST;
|
||||
};
|
||||
struct PCIDeviceHeader
|
||||
{
|
||||
uint16_t VendorID;
|
||||
uint16_t DeviceID;
|
||||
uint16_t Command;
|
||||
uint16_t Status;
|
||||
uint8_t RevisionID;
|
||||
uint8_t ProgIF;
|
||||
uint8_t Subclass;
|
||||
uint8_t Class;
|
||||
uint8_t CacheLineSize;
|
||||
uint8_t LatencyTimer;
|
||||
uint8_t HeaderType;
|
||||
uint8_t BIST;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 0
|
||||
*
|
||||
*/
|
||||
struct PCIHeader0
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t BAR0;
|
||||
uint32_t BAR1;
|
||||
uint32_t BAR2;
|
||||
uint32_t BAR3;
|
||||
uint32_t BAR4;
|
||||
uint32_t BAR5;
|
||||
uint32_t CardbusCISPointer;
|
||||
uint16_t SubsystemVendorID;
|
||||
uint16_t SubsystemID;
|
||||
uint32_t ExpansionROMBaseAddress;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t Reserved1;
|
||||
uint32_t Reserved2;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint8_t MinGrant;
|
||||
uint8_t MaxLatency;
|
||||
};
|
||||
/**
|
||||
* @brief PCI Header Type 0
|
||||
*
|
||||
*/
|
||||
struct PCIHeader0
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t BAR0;
|
||||
uint32_t BAR1;
|
||||
uint32_t BAR2;
|
||||
uint32_t BAR3;
|
||||
uint32_t BAR4;
|
||||
uint32_t BAR5;
|
||||
uint32_t CardbusCISPointer;
|
||||
uint16_t SubsystemVendorID;
|
||||
uint16_t SubsystemID;
|
||||
uint32_t ExpansionROMBaseAddress;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t Reserved1;
|
||||
uint32_t Reserved2;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint8_t MinGrant;
|
||||
uint8_t MaxLatency;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 1 (PCI-to-PCI Bridge)
|
||||
*/
|
||||
struct PCIHeader1
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t BAR0;
|
||||
uint32_t BAR1;
|
||||
uint8_t PrimaryBusNumber;
|
||||
uint8_t SecondaryBusNumber;
|
||||
uint8_t SubordinateBusNumber;
|
||||
uint8_t SecondaryLatencyTimer;
|
||||
uint8_t IOBase;
|
||||
uint8_t IOLimit;
|
||||
uint16_t SecondaryStatus;
|
||||
uint16_t MemoryBase;
|
||||
uint16_t MemoryLimit;
|
||||
uint16_t PrefetchableMemoryBase;
|
||||
uint16_t PrefetchableMemoryLimit;
|
||||
uint32_t PrefetchableMemoryBaseUpper32;
|
||||
uint32_t PrefetchableMemoryLimitUpper32;
|
||||
uint16_t IOBaseUpper16;
|
||||
uint16_t IOLimitUpper16;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t Reserved1;
|
||||
uint32_t ExpansionROMBaseAddress;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint16_t BridgeControl;
|
||||
};
|
||||
/**
|
||||
* @brief PCI Header Type 1 (PCI-to-PCI Bridge)
|
||||
*/
|
||||
struct PCIHeader1
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t BAR0;
|
||||
uint32_t BAR1;
|
||||
uint8_t PrimaryBusNumber;
|
||||
uint8_t SecondaryBusNumber;
|
||||
uint8_t SubordinateBusNumber;
|
||||
uint8_t SecondaryLatencyTimer;
|
||||
uint8_t IOBase;
|
||||
uint8_t IOLimit;
|
||||
uint16_t SecondaryStatus;
|
||||
uint16_t MemoryBase;
|
||||
uint16_t MemoryLimit;
|
||||
uint16_t PrefetchableMemoryBase;
|
||||
uint16_t PrefetchableMemoryLimit;
|
||||
uint32_t PrefetchableMemoryBaseUpper32;
|
||||
uint32_t PrefetchableMemoryLimitUpper32;
|
||||
uint16_t IOBaseUpper16;
|
||||
uint16_t IOLimitUpper16;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t Reserved1;
|
||||
uint32_t ExpansionROMBaseAddress;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint16_t BridgeControl;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief PCI Header Type 2 (PCI-to-CardBus Bridge)
|
||||
*/
|
||||
struct PCIHeader2
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t CardbusSocketRegistersBaseAddress;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t SecondaryStatus;
|
||||
uint8_t PCIbusNumber;
|
||||
uint8_t CardbusBusNumber;
|
||||
uint8_t SubordinateBusNumber;
|
||||
uint8_t CardbusLatencyTimer;
|
||||
uint32_t MemoryBase0;
|
||||
uint32_t MemoryLimit0;
|
||||
uint32_t MemoryBase1;
|
||||
uint32_t MemoryLimit1;
|
||||
uint32_t IOBase0;
|
||||
uint32_t IOLimit0;
|
||||
uint32_t IOBase1;
|
||||
uint32_t IOLimit1;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint16_t BridgeControl;
|
||||
uint16_t SubsystemVendorID;
|
||||
uint16_t SubsystemID;
|
||||
uint32_t LegacyBaseAddress;
|
||||
};
|
||||
/**
|
||||
* @brief PCI Header Type 2 (PCI-to-CardBus Bridge)
|
||||
*/
|
||||
struct PCIHeader2
|
||||
{
|
||||
PCIDeviceHeader Header;
|
||||
uint32_t CardbusSocketRegistersBaseAddress;
|
||||
uint8_t CapabilitiesPointer;
|
||||
uint8_t Reserved0;
|
||||
uint16_t SecondaryStatus;
|
||||
uint8_t PCIbusNumber;
|
||||
uint8_t CardbusBusNumber;
|
||||
uint8_t SubordinateBusNumber;
|
||||
uint8_t CardbusLatencyTimer;
|
||||
uint32_t MemoryBase0;
|
||||
uint32_t MemoryLimit0;
|
||||
uint32_t MemoryBase1;
|
||||
uint32_t MemoryLimit1;
|
||||
uint32_t IOBase0;
|
||||
uint32_t IOLimit0;
|
||||
uint32_t IOBase1;
|
||||
uint32_t IOLimit1;
|
||||
uint8_t InterruptLine;
|
||||
uint8_t InterruptPin;
|
||||
uint16_t BridgeControl;
|
||||
uint16_t SubsystemVendorID;
|
||||
uint16_t SubsystemID;
|
||||
uint32_t LegacyBaseAddress;
|
||||
};
|
||||
|
||||
struct DeviceConfig
|
||||
{
|
||||
uintptr_t BaseAddress;
|
||||
uint16_t PCISegGroup;
|
||||
uint8_t StartBus;
|
||||
uint8_t EndBus;
|
||||
uint32_t Reserved;
|
||||
} __packed;
|
||||
struct DeviceConfig
|
||||
{
|
||||
uintptr_t BaseAddress;
|
||||
uint16_t PCISegGroup;
|
||||
uint8_t StartBus;
|
||||
uint8_t EndBus;
|
||||
uint32_t Reserved;
|
||||
} __packed;
|
||||
|
||||
class PCI
|
||||
{
|
||||
private:
|
||||
std::vector<PCIDeviceHeader *> Devices;
|
||||
class PCI
|
||||
{
|
||||
private:
|
||||
std::vector<PCIDeviceHeader *> Devices;
|
||||
|
||||
public:
|
||||
std::vector<PCIDeviceHeader *> &GetDevices() { return Devices; }
|
||||
void EnumerateFunction(uintptr_t DeviceAddress, uintptr_t Function);
|
||||
void EnumerateDevice(uintptr_t BusAddress, uintptr_t Device);
|
||||
void EnumerateBus(uintptr_t BaseAddress, uintptr_t Bus);
|
||||
std::vector<PCIDeviceHeader *> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
||||
std::vector<PCIDeviceHeader *> FindPCIDevice(int VendorID, int DeviceID);
|
||||
public:
|
||||
std::vector<PCIDeviceHeader *> &GetDevices() { return Devices; }
|
||||
void MapPCIAddresses(PCIDeviceHeader *PCIDevice, Memory::PageTable *Table = nullptr);
|
||||
void EnumerateFunction(uintptr_t DeviceAddress, uintptr_t Function);
|
||||
void EnumerateDevice(uintptr_t BusAddress, uintptr_t Device);
|
||||
void EnumerateBus(uintptr_t BaseAddress, uintptr_t Bus);
|
||||
std::vector<PCIDeviceHeader *> FindPCIDevice(uint8_t Class, uint8_t Subclass, uint8_t ProgIF);
|
||||
std::vector<PCIDeviceHeader *> FindPCIDevice(int VendorID, int DeviceID);
|
||||
|
||||
PCI();
|
||||
~PCI();
|
||||
};
|
||||
PCI();
|
||||
~PCI();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_PCI_H__
|
||||
|
550
include/task.hpp
550
include/task.hpp
@ -32,331 +32,331 @@
|
||||
|
||||
namespace Tasking
|
||||
{
|
||||
typedef unsigned long IP;
|
||||
typedef __UINTPTR_TYPE__ IPOffset;
|
||||
typedef unsigned long UPID;
|
||||
typedef unsigned long UTID;
|
||||
typedef __UINTPTR_TYPE__ Token;
|
||||
typedef unsigned long IP;
|
||||
typedef __UINTPTR_TYPE__ IPOffset;
|
||||
typedef unsigned long UPID;
|
||||
typedef unsigned long UTID;
|
||||
typedef __UINTPTR_TYPE__ Token;
|
||||
|
||||
enum TaskArchitecture
|
||||
{
|
||||
UnknownArchitecture,
|
||||
x32,
|
||||
x64,
|
||||
ARM32,
|
||||
ARM64
|
||||
};
|
||||
enum TaskArchitecture
|
||||
{
|
||||
UnknownArchitecture,
|
||||
x32,
|
||||
x64,
|
||||
ARM32,
|
||||
ARM64
|
||||
};
|
||||
|
||||
enum TaskCompatibility
|
||||
{
|
||||
UnknownPlatform,
|
||||
Native,
|
||||
Linux,
|
||||
Windows
|
||||
};
|
||||
enum TaskCompatibility
|
||||
{
|
||||
UnknownPlatform,
|
||||
Native,
|
||||
Linux,
|
||||
Windows
|
||||
};
|
||||
|
||||
enum TaskTrustLevel
|
||||
{
|
||||
UnknownElevation,
|
||||
Kernel,
|
||||
System,
|
||||
User
|
||||
};
|
||||
enum TaskTrustLevel
|
||||
{
|
||||
UnknownElevation,
|
||||
Kernel,
|
||||
System,
|
||||
User
|
||||
};
|
||||
|
||||
enum TaskStatus
|
||||
{
|
||||
UnknownStatus,
|
||||
Ready,
|
||||
Running,
|
||||
Sleeping,
|
||||
Waiting,
|
||||
Stopped,
|
||||
Terminated
|
||||
};
|
||||
enum TaskStatus
|
||||
{
|
||||
UnknownStatus,
|
||||
Ready,
|
||||
Running,
|
||||
Sleeping,
|
||||
Waiting,
|
||||
Stopped,
|
||||
Terminated
|
||||
};
|
||||
|
||||
enum TaskPriority
|
||||
{
|
||||
UnknownPriority = 0,
|
||||
Idle = 1,
|
||||
Low = 2,
|
||||
Normal = 5,
|
||||
High = 8,
|
||||
Critical = 10
|
||||
};
|
||||
enum TaskPriority
|
||||
{
|
||||
UnknownPriority = 0,
|
||||
Idle = 1,
|
||||
Low = 2,
|
||||
Normal = 5,
|
||||
High = 8,
|
||||
Critical = 10
|
||||
};
|
||||
|
||||
struct TaskSecurity
|
||||
{
|
||||
TaskTrustLevel TrustLevel;
|
||||
Token UniqueToken;
|
||||
bool IsCritical;
|
||||
bool IsDebugEnabled;
|
||||
bool IsKernelDebugEnabled;
|
||||
};
|
||||
struct TaskSecurity
|
||||
{
|
||||
TaskTrustLevel TrustLevel;
|
||||
Token UniqueToken;
|
||||
bool IsCritical;
|
||||
bool IsDebugEnabled;
|
||||
bool IsKernelDebugEnabled;
|
||||
};
|
||||
|
||||
struct TaskInfo
|
||||
{
|
||||
uint64_t OldUserTime = 0;
|
||||
uint64_t OldKernelTime = 0;
|
||||
struct TaskInfo
|
||||
{
|
||||
size_t OldUserTime = 0;
|
||||
size_t OldKernelTime = 0;
|
||||
|
||||
uint64_t SleepUntil = 0;
|
||||
uint64_t KernelTime = 0, UserTime = 0, SpawnTime = 0, LastUpdateTime = 0;
|
||||
uint64_t Year, Month, Day, Hour, Minute, Second;
|
||||
bool Affinity[256]; // MAX_CPU
|
||||
TaskPriority Priority;
|
||||
TaskArchitecture Architecture;
|
||||
TaskCompatibility Compatibility;
|
||||
};
|
||||
size_t SleepUntil = 0;
|
||||
size_t KernelTime = 0, UserTime = 0, SpawnTime = 0, LastUpdateTime = 0;
|
||||
uint64_t Year, Month, Day, Hour, Minute, Second;
|
||||
bool Affinity[256]; // MAX_CPU
|
||||
TaskPriority Priority;
|
||||
TaskArchitecture Architecture;
|
||||
TaskCompatibility Compatibility;
|
||||
};
|
||||
|
||||
struct TCB
|
||||
{
|
||||
UTID ID;
|
||||
char Name[256];
|
||||
struct PCB *Parent;
|
||||
IP EntryPoint;
|
||||
IPOffset Offset;
|
||||
int ExitCode;
|
||||
Memory::StackGuard *Stack;
|
||||
Memory::MemMgr *Memory;
|
||||
TaskStatus Status;
|
||||
struct TCB
|
||||
{
|
||||
UTID ID;
|
||||
char Name[256];
|
||||
struct PCB *Parent;
|
||||
IP EntryPoint;
|
||||
IPOffset Offset;
|
||||
int ExitCode;
|
||||
Memory::StackGuard *Stack;
|
||||
Memory::MemMgr *Memory;
|
||||
TaskStatus Status;
|
||||
#if defined(a64)
|
||||
CPU::x64::TrapFrame Registers;
|
||||
uint64_t ShadowGSBase, GSBase, FSBase;
|
||||
CPU::x64::TrapFrame Registers;
|
||||
uint64_t ShadowGSBase, GSBase, FSBase;
|
||||
#elif defined(a32)
|
||||
CPU::x32::TrapFrame Registers; // TODO
|
||||
uint64_t ShadowGSBase, GSBase, FSBase;
|
||||
CPU::x32::TrapFrame Registers; // TODO
|
||||
uint64_t ShadowGSBase, GSBase, FSBase;
|
||||
#elif defined(aa64)
|
||||
uint64_t Registers; // TODO
|
||||
uint64_t Registers; // TODO
|
||||
#endif
|
||||
uintptr_t IPHistory[128];
|
||||
TaskSecurity Security;
|
||||
TaskInfo Info;
|
||||
CPU::x64::FXState *FPU;
|
||||
uintptr_t IPHistory[128];
|
||||
TaskSecurity Security;
|
||||
TaskInfo Info;
|
||||
CPU::x64::FXState *FPU;
|
||||
|
||||
void Rename(const char *name)
|
||||
{
|
||||
CriticalSection cs;
|
||||
if (strlen(name) > 256 || strlen(name) == 0)
|
||||
{
|
||||
debug("Invalid thread name");
|
||||
return;
|
||||
}
|
||||
void Rename(const char *name)
|
||||
{
|
||||
CriticalSection cs;
|
||||
if (strlen(name) > 256 || strlen(name) == 0)
|
||||
{
|
||||
debug("Invalid thread name");
|
||||
return;
|
||||
}
|
||||
|
||||
trace("Renaming thread %s to %s", Name, name);
|
||||
strncpy(Name, name, 256);
|
||||
}
|
||||
trace("Renaming thread %s to %s", Name, name);
|
||||
strncpy(Name, name, 256);
|
||||
}
|
||||
|
||||
void SetPriority(TaskPriority priority)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting priority of thread %s to %d", Name, priority);
|
||||
Info.Priority = priority;
|
||||
}
|
||||
void SetPriority(TaskPriority priority)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting priority of thread %s to %d", Name, priority);
|
||||
Info.Priority = priority;
|
||||
}
|
||||
|
||||
int GetExitCode() { return ExitCode; }
|
||||
int GetExitCode() { return ExitCode; }
|
||||
|
||||
void SetCritical(bool Critical)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting criticality of thread %s to %s", Name, Critical ? "true" : "false");
|
||||
Security.IsCritical = Critical;
|
||||
}
|
||||
void SetCritical(bool Critical)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting criticality of thread %s to %s", Name, Critical ? "true" : "false");
|
||||
Security.IsCritical = Critical;
|
||||
}
|
||||
|
||||
void SetDebugMode(bool Enable)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||
Security.IsDebugEnabled = Enable;
|
||||
}
|
||||
void SetDebugMode(bool Enable)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||
Security.IsDebugEnabled = Enable;
|
||||
}
|
||||
|
||||
void SetKernelDebugMode(bool Enable)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting kernel debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||
Security.IsKernelDebugEnabled = Enable;
|
||||
}
|
||||
};
|
||||
void SetKernelDebugMode(bool Enable)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting kernel debug mode of thread %s to %s", Name, Enable ? "true" : "false");
|
||||
Security.IsKernelDebugEnabled = Enable;
|
||||
}
|
||||
};
|
||||
|
||||
struct PCB
|
||||
{
|
||||
UPID ID;
|
||||
char Name[256];
|
||||
PCB *Parent;
|
||||
int ExitCode;
|
||||
TaskStatus Status;
|
||||
TaskSecurity Security;
|
||||
TaskInfo Info;
|
||||
std::vector<TCB *> Threads;
|
||||
std::vector<PCB *> Children;
|
||||
InterProcessCommunication::IPC *IPC;
|
||||
Memory::PageTable *PageTable;
|
||||
SymbolResolver::Symbols *ELFSymbolTable;
|
||||
VirtualFileSystem::Node *CurrentWorkingDirectory;
|
||||
VirtualFileSystem::Node *ProcessDirectory;
|
||||
VirtualFileSystem::Node *memDirectory;
|
||||
struct PCB
|
||||
{
|
||||
UPID ID;
|
||||
char Name[256];
|
||||
PCB *Parent;
|
||||
int ExitCode;
|
||||
TaskStatus Status;
|
||||
TaskSecurity Security;
|
||||
TaskInfo Info;
|
||||
std::vector<TCB *> Threads;
|
||||
std::vector<PCB *> Children;
|
||||
InterProcessCommunication::IPC *IPC;
|
||||
Memory::PageTable *PageTable;
|
||||
SymbolResolver::Symbols *ELFSymbolTable;
|
||||
VirtualFileSystem::Node *CurrentWorkingDirectory;
|
||||
VirtualFileSystem::Node *ProcessDirectory;
|
||||
VirtualFileSystem::Node *memDirectory;
|
||||
|
||||
void SetWorkingDirectory(VirtualFileSystem::Node *node)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting working directory of process %s to %#lx (%s)", Name, node, node->Name);
|
||||
CurrentWorkingDirectory = node;
|
||||
}
|
||||
};
|
||||
void SetWorkingDirectory(VirtualFileSystem::Node *node)
|
||||
{
|
||||
CriticalSection cs;
|
||||
trace("Setting working directory of process %s to %#lx (%s)", Name, node, node->Name);
|
||||
CurrentWorkingDirectory = node;
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Token Trust Level */
|
||||
enum TTL
|
||||
{
|
||||
UnknownTrustLevel = 0b0001,
|
||||
Untrusted = 0b0010,
|
||||
Trusted = 0b0100,
|
||||
TrustedByKernel = 0b1000,
|
||||
FullTrust = Trusted | TrustedByKernel
|
||||
};
|
||||
/** @brief Token Trust Level */
|
||||
enum TTL
|
||||
{
|
||||
UnknownTrustLevel = 0b0001,
|
||||
Untrusted = 0b0010,
|
||||
Trusted = 0b0100,
|
||||
TrustedByKernel = 0b1000,
|
||||
FullTrust = Trusted | TrustedByKernel
|
||||
};
|
||||
|
||||
class Security
|
||||
{
|
||||
private:
|
||||
struct TokenData
|
||||
{
|
||||
Token token;
|
||||
int TrustLevel;
|
||||
uint64_t OwnerID;
|
||||
bool Process;
|
||||
};
|
||||
class Security
|
||||
{
|
||||
private:
|
||||
struct TokenData
|
||||
{
|
||||
Token token;
|
||||
int TrustLevel;
|
||||
uint64_t OwnerID;
|
||||
bool Process;
|
||||
};
|
||||
|
||||
std::vector<TokenData> Tokens;
|
||||
std::vector<TokenData> Tokens;
|
||||
|
||||
public:
|
||||
Token CreateToken();
|
||||
bool TrustToken(Token token, TTL TrustLevel);
|
||||
bool AddTrustLevel(Token token, TTL TrustLevel);
|
||||
bool RemoveTrustLevel(Token token, TTL TrustLevel);
|
||||
bool UntrustToken(Token token);
|
||||
bool DestroyToken(Token token);
|
||||
bool IsTokenTrusted(Token token, TTL TrustLevel);
|
||||
bool IsTokenTrusted(Token token, int TrustLevel);
|
||||
int GetTokenTrustLevel(Token token);
|
||||
Security();
|
||||
~Security();
|
||||
};
|
||||
public:
|
||||
Token CreateToken();
|
||||
bool TrustToken(Token token, TTL TrustLevel);
|
||||
bool AddTrustLevel(Token token, TTL TrustLevel);
|
||||
bool RemoveTrustLevel(Token token, TTL TrustLevel);
|
||||
bool UntrustToken(Token token);
|
||||
bool DestroyToken(Token token);
|
||||
bool IsTokenTrusted(Token token, TTL TrustLevel);
|
||||
bool IsTokenTrusted(Token token, int TrustLevel);
|
||||
int GetTokenTrustLevel(Token token);
|
||||
Security();
|
||||
~Security();
|
||||
};
|
||||
|
||||
class Task : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
Security SecurityManager;
|
||||
UPID NextPID = 0;
|
||||
UTID NextTID = 0;
|
||||
class Task : public Interrupts::Handler
|
||||
{
|
||||
private:
|
||||
Security SecurityManager;
|
||||
UPID NextPID = 0;
|
||||
UTID NextTID = 0;
|
||||
|
||||
std::vector<PCB *> ProcessList;
|
||||
PCB *IdleProcess = nullptr;
|
||||
TCB *IdleThread = nullptr;
|
||||
TCB *CleanupThread = nullptr;
|
||||
std::atomic_uint64_t SchedulerTicks = 0;
|
||||
std::atomic_uint64_t LastTaskTicks = 0;
|
||||
std::atomic_int LastCore = 0;
|
||||
bool StopScheduler = false;
|
||||
bool InvalidPCB(PCB *pcb);
|
||||
bool InvalidTCB(TCB *tcb);
|
||||
std::vector<PCB *> ProcessList;
|
||||
PCB *IdleProcess = nullptr;
|
||||
TCB *IdleThread = nullptr;
|
||||
TCB *CleanupThread = nullptr;
|
||||
std::atomic_size_t SchedulerTicks = 0;
|
||||
std::atomic_size_t LastTaskTicks = 0;
|
||||
std::atomic_int LastCore = 0;
|
||||
bool StopScheduler = false;
|
||||
bool InvalidPCB(PCB *pcb);
|
||||
bool InvalidTCB(TCB *tcb);
|
||||
|
||||
void RemoveThread(TCB *tcb);
|
||||
void RemoveProcess(PCB *pcb);
|
||||
void RemoveThread(TCB *tcb);
|
||||
void RemoveProcess(PCB *pcb);
|
||||
|
||||
void UpdateUsage(TaskInfo *Info, TaskSecurity *Security, int Core);
|
||||
void UpdateUsage(TaskInfo *Info, TaskSecurity *Security, int Core);
|
||||
|
||||
bool FindNewProcess(void *CPUDataPointer);
|
||||
bool GetNextAvailableThread(void *CPUDataPointer);
|
||||
bool GetNextAvailableProcess(void *CPUDataPointer);
|
||||
bool SchedulerSearchProcessThread(void *CPUDataPointer);
|
||||
void UpdateProcessStatus();
|
||||
void WakeUpThreads();
|
||||
bool FindNewProcess(void *CPUDataPointer);
|
||||
bool GetNextAvailableThread(void *CPUDataPointer);
|
||||
bool GetNextAvailableProcess(void *CPUDataPointer);
|
||||
bool SchedulerSearchProcessThread(void *CPUDataPointer);
|
||||
void UpdateProcessStatus();
|
||||
void WakeUpThreads();
|
||||
|
||||
#if defined(a64)
|
||||
void Schedule(CPU::x64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
void Schedule(CPU::x64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
|
||||
#elif defined(a32)
|
||||
void Schedule(void *Frame);
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
void Schedule(void *Frame);
|
||||
void OnInterruptReceived(CPU::x32::TrapFrame *Frame);
|
||||
#elif defined(aa64)
|
||||
void Schedule(CPU::aarch64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
void Schedule(CPU::aarch64::TrapFrame *Frame);
|
||||
void OnInterruptReceived(CPU::aarch64::TrapFrame *Frame);
|
||||
#endif
|
||||
|
||||
public:
|
||||
void SetCleanupThread(TCB *Thread) { CleanupThread = Thread; }
|
||||
uint64_t GetSchedulerTicks() { return SchedulerTicks.load(); }
|
||||
uint64_t GetLastTaskTicks() { return LastTaskTicks.load(); }
|
||||
uint64_t GetLastCore() { return LastCore.load(); }
|
||||
std::vector<PCB *> GetProcessList() { return ProcessList; }
|
||||
Security *GetSecurityManager() { return &SecurityManager; }
|
||||
void CleanupProcessesThread();
|
||||
void Panic() { StopScheduler = true; }
|
||||
void Schedule();
|
||||
void SignalShutdown();
|
||||
void RevertProcessCreation(PCB *Process);
|
||||
void RevertThreadCreation(TCB *Thread);
|
||||
public:
|
||||
void SetCleanupThread(TCB *Thread) { CleanupThread = Thread; }
|
||||
size_t GetSchedulerTicks() { return SchedulerTicks.load(); }
|
||||
size_t GetLastTaskTicks() { return LastTaskTicks.load(); }
|
||||
int GetLastCore() { return LastCore.load(); }
|
||||
std::vector<PCB *> GetProcessList() { return ProcessList; }
|
||||
Security *GetSecurityManager() { return &SecurityManager; }
|
||||
void CleanupProcessesThread();
|
||||
void Panic() { StopScheduler = true; }
|
||||
void Schedule();
|
||||
void SignalShutdown();
|
||||
void RevertProcessCreation(PCB *Process);
|
||||
void RevertThreadCreation(TCB *Thread);
|
||||
|
||||
void KillThread(TCB *tcb, int Code)
|
||||
{
|
||||
tcb->Status = TaskStatus::Terminated;
|
||||
tcb->ExitCode = Code;
|
||||
}
|
||||
void KillThread(TCB *tcb, int Code)
|
||||
{
|
||||
tcb->Status = TaskStatus::Terminated;
|
||||
tcb->ExitCode = Code;
|
||||
}
|
||||
|
||||
void KillProcess(PCB *pcb, int Code)
|
||||
{
|
||||
pcb->Status = TaskStatus::Terminated;
|
||||
pcb->ExitCode = Code;
|
||||
}
|
||||
void KillProcess(PCB *pcb, int Code)
|
||||
{
|
||||
pcb->Status = TaskStatus::Terminated;
|
||||
pcb->ExitCode = Code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Current Process object
|
||||
* @return PCB*
|
||||
*/
|
||||
PCB *GetCurrentProcess();
|
||||
/**
|
||||
* @brief Get the Current Process object
|
||||
* @return PCB*
|
||||
*/
|
||||
PCB *GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* @brief Get the Current Thread object
|
||||
* @return TCB*
|
||||
*/
|
||||
TCB *GetCurrentThread();
|
||||
/**
|
||||
* @brief Get the Current Thread object
|
||||
* @return TCB*
|
||||
*/
|
||||
TCB *GetCurrentThread();
|
||||
|
||||
PCB *GetProcessByID(UPID ID);
|
||||
PCB *GetProcessByID(UPID ID);
|
||||
|
||||
TCB *GetThreadByID(UTID ID);
|
||||
TCB *GetThreadByID(UTID ID);
|
||||
|
||||
/** @brief Wait for process to terminate */
|
||||
void WaitForProcess(PCB *pcb);
|
||||
/** @brief Wait for process to terminate */
|
||||
void WaitForProcess(PCB *pcb);
|
||||
|
||||
/** @brief Wait for thread to terminate */
|
||||
void WaitForThread(TCB *tcb);
|
||||
/** @brief Wait for thread to terminate */
|
||||
void WaitForThread(TCB *tcb);
|
||||
|
||||
void WaitForProcessStatus(PCB *pcb, TaskStatus Status);
|
||||
void WaitForThreadStatus(TCB *tcb, TaskStatus Status);
|
||||
void WaitForProcessStatus(PCB *pcb, TaskStatus Status);
|
||||
void WaitForThreadStatus(TCB *tcb, TaskStatus Status);
|
||||
|
||||
/**
|
||||
* @brief Sleep for a given amount of milliseconds
|
||||
*
|
||||
* @param Milliseconds Amount of milliseconds to sleep
|
||||
*/
|
||||
void Sleep(uint64_t Milliseconds);
|
||||
/**
|
||||
* @brief Sleep for a given amount of milliseconds
|
||||
*
|
||||
* @param Milliseconds Amount of milliseconds to sleep
|
||||
*/
|
||||
void Sleep(uint64_t Milliseconds);
|
||||
|
||||
PCB *CreateProcess(PCB *Parent,
|
||||
const char *Name,
|
||||
TaskTrustLevel TrustLevel,
|
||||
void *Image = nullptr,
|
||||
bool DoNotCreatePageTable = false);
|
||||
PCB *CreateProcess(PCB *Parent,
|
||||
const char *Name,
|
||||
TaskTrustLevel TrustLevel,
|
||||
void *Image = nullptr,
|
||||
bool DoNotCreatePageTable = false);
|
||||
|
||||
TCB *CreateThread(PCB *Parent,
|
||||
IP EntryPoint,
|
||||
const char **argv = nullptr,
|
||||
const char **envp = nullptr,
|
||||
const std::vector<AuxiliaryVector> &auxv = std::vector<AuxiliaryVector>(),
|
||||
IPOffset Offset = 0,
|
||||
TaskArchitecture Architecture = TaskArchitecture::x64,
|
||||
TaskCompatibility Compatibility = TaskCompatibility::Native,
|
||||
bool ThreadNotReady = false);
|
||||
TCB *CreateThread(PCB *Parent,
|
||||
IP EntryPoint,
|
||||
const char **argv = nullptr,
|
||||
const char **envp = nullptr,
|
||||
const std::vector<AuxiliaryVector> &auxv = std::vector<AuxiliaryVector>(),
|
||||
IPOffset Offset = 0,
|
||||
TaskArchitecture Architecture = TaskArchitecture::x64,
|
||||
TaskCompatibility Compatibility = TaskCompatibility::Native,
|
||||
bool ThreadNotReady = false);
|
||||
|
||||
Task(const IP EntryPoint);
|
||||
~Task();
|
||||
};
|
||||
Task(const IP EntryPoint);
|
||||
~Task();
|
||||
};
|
||||
}
|
||||
|
||||
#define PEXIT(Code) TaskManager->GetCurrentProcess()->ExitCode = Code
|
||||
|
316
include/time.hpp
316
include/time.hpp
@ -23,180 +23,180 @@
|
||||
|
||||
namespace Time
|
||||
{
|
||||
struct Clock
|
||||
{
|
||||
int Year, Month, Day, Hour, Minute, Second;
|
||||
uint64_t Counter;
|
||||
};
|
||||
struct Clock
|
||||
{
|
||||
int Year, Month, Day, Hour, Minute, Second;
|
||||
size_t Counter;
|
||||
};
|
||||
|
||||
Clock ReadClock();
|
||||
Clock ConvertFromUnix(int Timestamp);
|
||||
Clock ReadClock();
|
||||
Clock ConvertFromUnix(int Timestamp);
|
||||
|
||||
enum Units
|
||||
{
|
||||
Femtoseconds,
|
||||
Picoseconds,
|
||||
Nanoseconds,
|
||||
Microseconds,
|
||||
Milliseconds,
|
||||
Seconds,
|
||||
Minutes,
|
||||
Hours,
|
||||
Days,
|
||||
Months,
|
||||
Years
|
||||
};
|
||||
enum Units
|
||||
{
|
||||
Femtoseconds,
|
||||
Picoseconds,
|
||||
Nanoseconds,
|
||||
Microseconds,
|
||||
Milliseconds,
|
||||
Seconds,
|
||||
Minutes,
|
||||
Hours,
|
||||
Days,
|
||||
Months,
|
||||
Years
|
||||
};
|
||||
|
||||
class HighPrecisionEventTimer
|
||||
{
|
||||
private:
|
||||
struct HPET
|
||||
{
|
||||
uintptr_t GeneralCapabilities;
|
||||
uintptr_t Reserved0;
|
||||
uintptr_t GeneralConfiguration;
|
||||
uintptr_t Reserved1;
|
||||
uintptr_t GeneralIntStatus;
|
||||
uintptr_t Reserved2;
|
||||
uintptr_t Reserved3[24];
|
||||
uintptr_t MainCounterValue;
|
||||
uintptr_t Reserved4;
|
||||
};
|
||||
class HighPrecisionEventTimer
|
||||
{
|
||||
private:
|
||||
struct HPET
|
||||
{
|
||||
uintptr_t GeneralCapabilities;
|
||||
uintptr_t Reserved0;
|
||||
uintptr_t GeneralConfiguration;
|
||||
uintptr_t Reserved1;
|
||||
uintptr_t GeneralIntStatus;
|
||||
uintptr_t Reserved2;
|
||||
uintptr_t Reserved3[24];
|
||||
uintptr_t MainCounterValue;
|
||||
uintptr_t Reserved4;
|
||||
};
|
||||
|
||||
uint32_t clk = 0;
|
||||
HPET *hpet = nullptr;
|
||||
uint64_t ClassCreationTime = 0;
|
||||
uint32_t clk = 0;
|
||||
HPET *hpet = nullptr;
|
||||
size_t ClassCreationTime = 0;
|
||||
|
||||
inline uint64_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
inline size_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool Sleep(uint64_t Duration, Units Unit);
|
||||
uint64_t GetCounter();
|
||||
uint64_t CalculateTarget(uint64_t Target, Units Unit);
|
||||
uint64_t GetNanosecondsSinceClassCreation();
|
||||
public:
|
||||
bool Sleep(size_t Duration, Units Unit);
|
||||
size_t GetCounter();
|
||||
size_t CalculateTarget(size_t Target, Units Unit);
|
||||
size_t GetNanosecondsSinceClassCreation();
|
||||
|
||||
HighPrecisionEventTimer(void *hpet);
|
||||
~HighPrecisionEventTimer();
|
||||
};
|
||||
HighPrecisionEventTimer(void *hpet);
|
||||
~HighPrecisionEventTimer();
|
||||
};
|
||||
|
||||
class TimeStampCounter
|
||||
{
|
||||
private:
|
||||
uint64_t clk = 0;
|
||||
uint64_t ClassCreationTime = 0;
|
||||
class TimeStampCounter
|
||||
{
|
||||
private:
|
||||
size_t clk = 0;
|
||||
size_t ClassCreationTime = 0;
|
||||
|
||||
inline uint64_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
inline size_t ConvertUnit(Units Unit)
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case Femtoseconds:
|
||||
return 1;
|
||||
case Picoseconds:
|
||||
return 1000;
|
||||
case Nanoseconds:
|
||||
return 1000000;
|
||||
case Microseconds:
|
||||
return 1000000000;
|
||||
case Milliseconds:
|
||||
return 1000000000000;
|
||||
case Seconds:
|
||||
return 1000000000000000;
|
||||
case Minutes:
|
||||
return 1000000000000000000;
|
||||
// case Hours:
|
||||
// return 1000000000000000000000;
|
||||
// case Days:
|
||||
// return 1000000000000000000000000;
|
||||
// case Months:
|
||||
// return 1000000000000000000000000000;
|
||||
// case Years:
|
||||
// return 1000000000000000000000000000000;
|
||||
default:
|
||||
error("Invalid time unit %d", Unit);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool Sleep(uint64_t Duration, Units Unit);
|
||||
uint64_t GetCounter();
|
||||
uint64_t CalculateTarget(uint64_t Target, Units Unit);
|
||||
uint64_t GetNanosecondsSinceClassCreation();
|
||||
public:
|
||||
bool Sleep(size_t Duration, Units Unit);
|
||||
size_t GetCounter();
|
||||
size_t CalculateTarget(size_t Target, Units Unit);
|
||||
size_t GetNanosecondsSinceClassCreation();
|
||||
|
||||
TimeStampCounter();
|
||||
~TimeStampCounter();
|
||||
};
|
||||
TimeStampCounter();
|
||||
~TimeStampCounter();
|
||||
};
|
||||
|
||||
class time
|
||||
{
|
||||
public:
|
||||
enum TimeActiveTimer
|
||||
{
|
||||
NONE = 0b0,
|
||||
RTC = 0b1,
|
||||
PIT = 0b10,
|
||||
HPET = 0b100,
|
||||
ACPI = 0b1000,
|
||||
APIC = 0b10000,
|
||||
TSC = 0b100000
|
||||
};
|
||||
class time
|
||||
{
|
||||
public:
|
||||
enum TimeActiveTimer
|
||||
{
|
||||
NONE = 0b0,
|
||||
RTC = 0b1,
|
||||
PIT = 0b10,
|
||||
HPET = 0b100,
|
||||
ACPI = 0b1000,
|
||||
APIC = 0b10000,
|
||||
TSC = 0b100000
|
||||
};
|
||||
|
||||
private:
|
||||
int SupportedTimers = 0;
|
||||
TimeActiveTimer ActiveTimer = NONE;
|
||||
private:
|
||||
int SupportedTimers = 0;
|
||||
TimeActiveTimer ActiveTimer = NONE;
|
||||
|
||||
HighPrecisionEventTimer *hpet;
|
||||
TimeStampCounter *tsc;
|
||||
HighPrecisionEventTimer *hpet;
|
||||
TimeStampCounter *tsc;
|
||||
|
||||
public:
|
||||
int GetSupportedTimers() { return SupportedTimers; }
|
||||
TimeActiveTimer GetActiveTimer() { return ActiveTimer; }
|
||||
bool ChangeActiveTimer(TimeActiveTimer Timer)
|
||||
{
|
||||
if (!(SupportedTimers & Timer))
|
||||
return false;
|
||||
ActiveTimer = Timer;
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
int GetSupportedTimers() { return SupportedTimers; }
|
||||
TimeActiveTimer GetActiveTimer() { return ActiveTimer; }
|
||||
bool ChangeActiveTimer(TimeActiveTimer Timer)
|
||||
{
|
||||
if (!(SupportedTimers & Timer))
|
||||
return false;
|
||||
ActiveTimer = Timer;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sleep(uint64_t Duration, Units Unit);
|
||||
uint64_t GetCounter();
|
||||
uint64_t CalculateTarget(uint64_t Target, Units Unit);
|
||||
uint64_t GetNanosecondsSinceClassCreation();
|
||||
void FindTimers(void *acpi);
|
||||
time();
|
||||
~time();
|
||||
};
|
||||
bool Sleep(size_t Duration, Units Unit);
|
||||
size_t GetCounter();
|
||||
size_t CalculateTarget(size_t Target, Units Unit);
|
||||
size_t GetNanosecondsSinceClassCreation();
|
||||
void FindTimers(void *acpi);
|
||||
time();
|
||||
~time();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !__FENNIX_KERNEL_TIME_H__
|
||||
|
Reference in New Issue
Block a user