mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Refactor filesystem & stl code
This commit is contained in:
@ -38,111 +38,6 @@ namespace Driver
|
||||
char GetScanCode(uint8_t ScanCode, bool Upper);
|
||||
bool IsValidChar(uint8_t ScanCode);
|
||||
|
||||
class SlaveDeviceFile : public vfs::Node
|
||||
{
|
||||
private:
|
||||
int /* DeviceDriverType */ DeviceType;
|
||||
|
||||
std::list<uint8_t> KeyQueue;
|
||||
|
||||
public:
|
||||
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
|
||||
typedef int (*drvClose_t)(dev_t, dev_t);
|
||||
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
|
||||
|
||||
drvOpen_t Open;
|
||||
drvClose_t Close;
|
||||
drvRead_t Read;
|
||||
drvWrite_t Write;
|
||||
drvIoctl_t Ioctl;
|
||||
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
int close() final;
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
void ClearBuffers();
|
||||
|
||||
int ReportKeyEvent(uint8_t ScanCode);
|
||||
|
||||
SlaveDeviceFile(const char *Name, vfs::Node *Parent, int Type, vfs::NodeType NType);
|
||||
~SlaveDeviceFile();
|
||||
};
|
||||
|
||||
class MasterDeviceFile : private vfs::Node
|
||||
{
|
||||
private:
|
||||
typedef dev_t maj_t;
|
||||
typedef dev_t min_t;
|
||||
char SlaveName[16];
|
||||
vfs::Node *SlaveParent;
|
||||
int /* DeviceDriverType */ DeviceType;
|
||||
min_t SlaveIDCounter = 0;
|
||||
|
||||
typedef std::unordered_map<min_t, SlaveDeviceFile *> *Slaves;
|
||||
std::unordered_map<maj_t, Slaves> SlavesMap;
|
||||
|
||||
std::list<uint8_t> RawKeyQueue;
|
||||
std::list<uint8_t> KeyQueue;
|
||||
bool UpperCase = false;
|
||||
bool CapsLock = false;
|
||||
|
||||
public:
|
||||
typedef int (*drvOpen_t)(dev_t, dev_t, int, mode_t);
|
||||
typedef int (*drvClose_t)(dev_t, dev_t);
|
||||
typedef size_t (*drvRead_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef size_t (*drvWrite_t)(dev_t, dev_t, uint8_t *, size_t, off_t);
|
||||
typedef int (*drvIoctl_t)(dev_t, dev_t, unsigned long, void *);
|
||||
|
||||
int open(int Flags, mode_t Mode) final;
|
||||
int close() final;
|
||||
size_t read(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
size_t write(uint8_t *Buffer,
|
||||
size_t Size,
|
||||
off_t Offset) final;
|
||||
int ioctl(unsigned long Request,
|
||||
void *Argp) final;
|
||||
|
||||
void ClearBuffers();
|
||||
|
||||
int ReportKeyEvent(maj_t ID, min_t MinorID, uint8_t ScanCode);
|
||||
int ReportMouseEvent(maj_t ID, min_t MinorID,
|
||||
bool LeftButton, bool RightButton, bool MiddleButton,
|
||||
bool Button4, bool Button5, bool Button6,
|
||||
bool Button7, bool Button8,
|
||||
uintptr_t X, uintptr_t Y, int8_t Z, bool Relative);
|
||||
|
||||
int ReportNetworkPacket(maj_t ID, min_t MinorID, void *Buffer, size_t Size);
|
||||
|
||||
int NewBlock(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
int NewAudio(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
int NewNet(maj_t ID, min_t MinorID, drvOpen_t Open, drvClose_t Close,
|
||||
drvRead_t Read, drvWrite_t Write, drvIoctl_t Ioctl);
|
||||
|
||||
dev_t Register(maj_t ID);
|
||||
int Unregister(maj_t ID, min_t MinorID);
|
||||
|
||||
MasterDeviceFile(const char *MasterName,
|
||||
const char *SlaveName,
|
||||
vfs::Node *Parent,
|
||||
int Type);
|
||||
~MasterDeviceFile();
|
||||
};
|
||||
|
||||
struct DriverObject
|
||||
{
|
||||
uintptr_t BaseAddress = 0;
|
||||
@ -150,7 +45,7 @@ namespace Driver
|
||||
Memory::VirtualMemoryArea *vma = nullptr;
|
||||
|
||||
/* Path has the same pointer as in the Node */
|
||||
const char *Path = nullptr;
|
||||
std::string Path;
|
||||
std::unordered_map<uint8_t, void *> *InterruptHandlers;
|
||||
|
||||
char Name[32] = {'\0'};
|
||||
@ -172,28 +67,18 @@ namespace Driver
|
||||
private:
|
||||
NewLock(ModuleInitLock);
|
||||
std::unordered_map<dev_t, DriverObject> Drivers;
|
||||
dev_t MajorIDCounter = 0;
|
||||
dev_t DriverIDCounter = 0;
|
||||
|
||||
int LoadDriverFile(uintptr_t &EntryPoint,
|
||||
uintptr_t &BaseAddress,
|
||||
Memory::VirtualMemoryArea *dVma,
|
||||
vfs::RefNode *rDrv);
|
||||
FileNode *rDrv);
|
||||
|
||||
public:
|
||||
MasterDeviceFile *InputMouseDev = nullptr;
|
||||
MasterDeviceFile *InputKeyboardDev = nullptr;
|
||||
|
||||
MasterDeviceFile *BlockSATADev = nullptr;
|
||||
MasterDeviceFile *BlockHDDev = nullptr;
|
||||
MasterDeviceFile *BlockNVMeDev = nullptr;
|
||||
|
||||
MasterDeviceFile *AudioDev = nullptr;
|
||||
|
||||
MasterDeviceFile *NetDev = nullptr;
|
||||
|
||||
std::unordered_map<dev_t, DriverObject> &
|
||||
GetDrivers() { return Drivers; }
|
||||
|
||||
void PreloadDrivers();
|
||||
void LoadAllDrivers();
|
||||
void UnloadAllDrivers();
|
||||
void Panic();
|
||||
|
Reference in New Issue
Block a user