mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-01 10:29:16 +00:00
feat(kernel/driver): implement built-in driver support
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
@ -38,6 +38,51 @@
|
||||
#include <io.h>
|
||||
#include <list>
|
||||
|
||||
struct BuiltInDriver
|
||||
{
|
||||
char Name[32] = {'\0'};
|
||||
char Description[64] = {'\0'};
|
||||
char Author[32] = {'\0'};
|
||||
struct
|
||||
{
|
||||
int Major, Minor, Patch;
|
||||
} Version = {0, 0, 0};
|
||||
char License[32] = {'\0'};
|
||||
bool Initialized = false;
|
||||
int ErrorCode = 0;
|
||||
|
||||
int (*Entry)() = nullptr;
|
||||
int (*Final)() = nullptr;
|
||||
int (*Panic)() = nullptr;
|
||||
int (*Probe)() = nullptr;
|
||||
uintptr_t EntryPoint = 0;
|
||||
};
|
||||
|
||||
extern const BuiltInDriver __kernel_builtin_drivers_start[];
|
||||
extern const BuiltInDriver __kernel_builtin_drivers_end[];
|
||||
|
||||
#define REGISTER_BUILTIN_DRIVER(driverName, desc, auth, maj, min, patch, \
|
||||
entryFunc, finalFunc, panicFunc, initFunc) \
|
||||
int __builtin_driver_start_##driverName(dev_t id) \
|
||||
{ \
|
||||
DriverID = id; \
|
||||
return 0; \
|
||||
} \
|
||||
static const BuiltInDriver __builtin_driver_##driverName \
|
||||
__attribute__((section(".builtin_drivers"), used)) = { \
|
||||
#driverName, \
|
||||
desc, \
|
||||
auth, \
|
||||
{maj, min, patch}, \
|
||||
"", \
|
||||
false, \
|
||||
0, \
|
||||
entryFunc, \
|
||||
finalFunc, \
|
||||
panicFunc, \
|
||||
initFunc, \
|
||||
(uintptr_t)__builtin_driver_start_##driverName}
|
||||
|
||||
namespace Driver
|
||||
{
|
||||
char GetScanCode(uint8_t ScanCode, bool Upper);
|
||||
@ -50,10 +95,10 @@ namespace Driver
|
||||
RingBuffer<InputReport> *InputReports;
|
||||
};
|
||||
|
||||
struct DriverObject
|
||||
struct DriverObject : BuiltInDriver
|
||||
{
|
||||
bool IsBuiltIn = false;
|
||||
uintptr_t BaseAddress = 0;
|
||||
uintptr_t EntryPoint = 0;
|
||||
Memory::VirtualMemoryArea *vma;
|
||||
|
||||
/* Path has the same pointer as in the Node */
|
||||
@ -61,22 +106,6 @@ namespace Driver
|
||||
std::unordered_map<uint8_t, void *> *InterruptHandlers;
|
||||
std::unordered_map<dev_t, DriverHandlers> *DeviceOperations;
|
||||
dev_t ID = 0;
|
||||
|
||||
char Name[32] = {'\0'};
|
||||
char Description[64] = {'\0'};
|
||||
char Author[32] = {'\0'};
|
||||
struct
|
||||
{
|
||||
int Major, Minor, Patch;
|
||||
} Version = {0, 0, 0};
|
||||
char License[32] = {'\0'};
|
||||
bool Initialized = false;
|
||||
int ErrorCode = 0;
|
||||
|
||||
int (*Entry)() = nullptr;
|
||||
int (*Final)() = nullptr;
|
||||
int (*Panic)() = nullptr;
|
||||
int (*Probe)() = nullptr;
|
||||
};
|
||||
|
||||
class Manager
|
||||
@ -93,7 +122,6 @@ namespace Driver
|
||||
FileNode *devNode = nullptr;
|
||||
FileNode *devInputNode = nullptr;
|
||||
|
||||
|
||||
int LoadDriverFile(DriverObject &Drv, FileNode *File);
|
||||
void ReloadDriver(dev_t driverID);
|
||||
|
||||
@ -153,7 +181,6 @@ namespace Driver
|
||||
|
||||
dev_t RegisterDevice(dev_t DriverID, DeviceType Type, const InodeOperations *Operations);
|
||||
int ReportInputEvent(dev_t DriverID, InputReport *Report);
|
||||
|
||||
int UnregisterDevice(dev_t DriverID, dev_t Device);
|
||||
|
||||
void *AllocateMemory(dev_t DriverID, size_t Pages);
|
||||
@ -168,4 +195,73 @@ namespace Driver
|
||||
|
||||
void *GetSymbolByName(const char *Name, int Version);
|
||||
|
||||
#ifndef NO_API_IN_HEADER
|
||||
namespace v0
|
||||
{
|
||||
typedef int CriticalState;
|
||||
|
||||
void KernelPrint(dev_t DriverID, const char *Format, va_list args);
|
||||
void KernelLog(dev_t DriverID, const char *Format, va_list args);
|
||||
|
||||
CriticalState EnterCriticalSection(dev_t DriverID);
|
||||
void LeaveCriticalSection(dev_t DriverID, CriticalState PreviousState);
|
||||
|
||||
int RegisterInterruptHandler(dev_t DriverID, uint8_t IRQ, void *Handler);
|
||||
int OverrideInterruptHandler(dev_t DriverID, uint8_t IRQ, void *Handler);
|
||||
int UnregisterInterruptHandler(dev_t DriverID, uint8_t IRQ, void *Handler);
|
||||
int UnregisterAllInterruptHandlers(dev_t DriverID, void *Handler);
|
||||
|
||||
dev_t RegisterFileSystem(dev_t DriverID, FileSystemInfo *Info, struct Inode *Root);
|
||||
int UnregisterFileSystem(dev_t DriverID, dev_t Device);
|
||||
|
||||
pid_t CreateKernelProcess(dev_t DriverID, const char *Name);
|
||||
pid_t CreateKernelThread(dev_t DriverID, pid_t pId, const char *Name, void *EntryPoint, void *Argument);
|
||||
pid_t GetCurrentProcess(dev_t DriverID);
|
||||
int KillProcess(dev_t DriverID, pid_t pId, int ExitCode);
|
||||
int KillThread(dev_t DriverID, pid_t tId, pid_t pId, int ExitCode);
|
||||
void Yield(dev_t DriverID);
|
||||
void Sleep(dev_t DriverID, uint64_t Milliseconds);
|
||||
|
||||
void PIC_EOI(dev_t DriverID, uint8_t IRQ);
|
||||
void IRQ_MASK(dev_t DriverID, uint8_t IRQ);
|
||||
void IRQ_UNMASK(dev_t DriverID, uint8_t IRQ);
|
||||
|
||||
void PS2Wait(dev_t DriverID, const bool Output);
|
||||
void PS2WriteCommand(dev_t DriverID, uint8_t Command);
|
||||
void PS2WriteData(dev_t DriverID, uint8_t Data);
|
||||
uint8_t PS2ReadData(dev_t DriverID);
|
||||
uint8_t PS2ReadStatus(dev_t DriverID);
|
||||
uint8_t PS2ReadAfterACK(dev_t DriverID);
|
||||
void PS2ClearOutputBuffer(dev_t DriverID);
|
||||
int PS2ACKTimeout(dev_t DriverID);
|
||||
|
||||
void *AllocateMemory(dev_t DriverID, size_t Pages);
|
||||
void FreeMemory(dev_t DriverID, void *Pointer, size_t Pages);
|
||||
void *MemoryCopy(dev_t DriverID, void *Destination, const void *Source, size_t Length);
|
||||
void *MemorySet(dev_t DriverID, void *Destination, int Value, size_t Length);
|
||||
void *MemoryMove(dev_t DriverID, void *Destination, const void *Source, size_t Length);
|
||||
size_t StringLength(dev_t DriverID, const char String[]);
|
||||
char *_strstr(dev_t DriverID, const char *Haystack, const char *Needle);
|
||||
|
||||
void MapPages(dev_t MajorID, void *PhysicalAddress, void *VirtualAddress, size_t Pages, uint32_t Flags);
|
||||
void UnmapPages(dev_t MajorID, void *VirtualAddress, size_t Pages);
|
||||
void AppendMapFlag(dev_t MajorID, void *Address, PageMapFlags Flag);
|
||||
void RemoveMapFlag(dev_t MajorID, void *Address, PageMapFlags Flag);
|
||||
|
||||
void *Znwm(size_t Size);
|
||||
void ZdlPvm(void *Pointer, size_t Size);
|
||||
|
||||
__PCIArray *GetPCIDevices(dev_t DriverID, uint16_t _Vendors[], uint16_t _Devices[]);
|
||||
void InitializePCI(dev_t DriverID, void *_Header);
|
||||
uint32_t GetBAR(dev_t DriverID, uint8_t i, void *_Header);
|
||||
uint8_t iLine(dev_t DriverID, PCI::PCIDevice *Device);
|
||||
uint8_t iPin(dev_t DriverID, PCI::PCIDevice *Device);
|
||||
|
||||
dev_t CreateDeviceFile(dev_t DriverID, const char *name, mode_t mode, const InodeOperations *Operations);
|
||||
dev_t RegisterDevice(dev_t DriverID, DeviceType Type, const InodeOperations *Operations);
|
||||
int UnregisterDevice(dev_t DriverID, dev_t Device);
|
||||
int ReportInputEvent(dev_t DriverID, InputReport *Report);
|
||||
}
|
||||
#endif // !NO_API_IN_HEADER
|
||||
|
||||
#endif // !__FENNIX_KERNEL_DRIVER_H__
|
||||
|
Reference in New Issue
Block a user