Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Fix driver implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderIce2 committed Jul 7, 2024
1 parent 3e5177d commit 51ea074
Show file tree
Hide file tree
Showing 29 changed files with 3,002 additions and 1,443 deletions.
812 changes: 495 additions & 317 deletions core/driver/api.cpp

Large diffs are not rendered by default.

634 changes: 634 additions & 0 deletions core/driver/daemon.cpp

Large diffs are not rendered by default.

533 changes: 253 additions & 280 deletions core/driver/driver.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exec/binary_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace Execute
BinaryType GetBinaryType(std::string Path)
{
FileNode *node = fs->GetByPath(Path.c_str(), nullptr);
assert(node != nullptr);
return GetBinaryType(node);
}
}
87 changes: 79 additions & 8 deletions include/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@

#include <types.h>

#include <interface/driver.h>
#include <interface/input.h>
#include <filesystem.hpp>
#include <unordered_map>
#include <memory.hpp>
#include <ints.hpp>
#include <lock.hpp>
#include <task.hpp>
#include <ring.hpp>
#include <debug.h>
#include <cpu.hpp>
#include <pci.hpp>
#include <vector>
#include <bitset>
#include <elf.h>
#include <io.h>
#include <list>

Expand All @@ -38,20 +43,32 @@ namespace Driver
char GetScanCode(uint8_t ScanCode, bool Upper);
bool IsValidChar(uint8_t ScanCode);

struct DriverHandlers
{
const InodeOperations *Ops = nullptr;
struct Inode *Node = nullptr;
RingBuffer<InputReport> *InputReports;
};

struct DriverObject
{
uintptr_t BaseAddress = 0;
uintptr_t EntryPoint = 0;
Memory::VirtualMemoryArea *vma = nullptr;
Memory::VirtualMemoryArea *vma;

/* Path has the same pointer as in the Node */
std::string Path;
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'};
char Version[16] = {'\0'};
struct
{
int Major, Minor, Patch;
} Version = {0, 0, 0};
char License[32] = {'\0'};
bool Initialized = false;
int ErrorCode = 0;
Expand All @@ -67,27 +84,81 @@ namespace Driver
private:
NewLock(ModuleInitLock);
std::unordered_map<dev_t, DriverObject> Drivers;
dev_t DriverIDCounter = 0;

int LoadDriverFile(uintptr_t &EntryPoint,
uintptr_t &BaseAddress,
Memory::VirtualMemoryArea *dVma,
FileNode *rDrv);
/**
* 0 - generic null/zero/random/etc devices
* 1 - input/... devices
*/
dev_t DriverIDCounter = 2;
FileNode *devNode = nullptr;
FileNode *devInputNode = nullptr;

int LoadDriverFile(DriverObject &Drv, FileNode *File);

void InitializeDaemonFS();

dev_t RegisterInputDevice(std::unordered_map<dev_t, DriverHandlers> *, dev_t, size_t, const InodeOperations *);
dev_t RegisterBlockDevice(std::unordered_map<dev_t, DriverHandlers> *, dev_t, size_t, const InodeOperations *);

public:
RingBuffer<KeyboardReport> GlobalKeyboardInputReports;
RingBuffer<MouseReport> GlobalMouseInputReports;

struct DeviceInode
{
struct Inode Node;
FileNode *Parent;
Inode *ParentInode;
std::string Name;
std::vector<DeviceInode *> Children;
};

std::unordered_map<dev_t, DriverObject> &
GetDrivers() { return Drivers; }

void Daemon();
void PreloadDrivers();
void LoadAllDrivers();
void UnloadAllDrivers();
void Panic();

/** Prefixes:
* - dsk (any disk device)
* - dsk0p0 (disk 0, partition 0)
* - blk (block device)
* - eth (Ethernet device)
* - wlan (Wireless LAN device)
* - lo (Loopback device)
* - kb (Keyboard device)
* - ms (Mouse device)
* - js (Joystick device)
* - tp (Touchpad device)
* - tc (Touchscreen device)
* - cam (Camera device)
* - spk (Speaker device)
* - mic (Microphone device)
* - snd (Sound device)
* - tty (Serial device)
* - lp (Parallel device)
* - gpu (Graphics device)
* - fb (Framebuffer device)
* - usb (USB device)
* - usb0dsk0p0 (USB 0, disk 0, partition 0; for USB storage)
*/
dev_t CreateIncrementalDevice(dev_t DriverID, const std::string &Prefix, mode_t Mode, InodeOperations *Ops);

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);

Manager();
~Manager();
};

void PopulateDriverAPI(void *API);
void ManagerDaemonWrapper();
}

void *GetSymbolByName(const char *Name, int Version);

#endif // !__FENNIX_KERNEL_DRIVER_H__
11 changes: 10 additions & 1 deletion include/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static_assert(IFTODT(S_IFCHR) == DT_CHR);
else \
return fsi->Ops.op(this->Node, ##__VA_ARGS__)

#define FSROOT(num) "\002root-" #num "\003"

class FileNode
{
public:
Expand Down Expand Up @@ -83,6 +85,7 @@ namespace vfs
{
Inode Node;
std::string Name;
std::string FriendlyName;
std::vector<Inode *> Children;
};

Expand All @@ -106,14 +109,16 @@ namespace vfs
std::unordered_map<dev_t, FSMountInfo> DeviceMap;
std::atomic_bool RegisterLock = false;

FileNode *__CacheRecursiveSearch(FileNode *, const char *, bool);
FileNode *CacheSearchReturnLast(FileNode *Parent, const char **Path);
FileNode *CacheRecursiveSearch(FileNode *Root, const char *NameOrPath, bool IsName);
FileNode *CacheLookup(const char *Path);
FileNode *CreateCacheNode(FileNode *Parent, Inode *Node, const char *Name, mode_t Mode);

int RemoveCacheNode(FileNode *Node);

public:
vfsInode *FileSystemRoots = nullptr;
std::unordered_map<ino_t, FileNode *> FileRoots;

bool PathIsRelative(const char *Path);
bool PathIsAbsolute(const char *Path) { return !PathIsRelative(Path); }
Expand All @@ -140,7 +145,11 @@ namespace vfs
FileNode *Create(FileNode *Parent, const char *Name, mode_t Mode);
FileNode *ForceCreate(FileNode *Parent, const char *Name, mode_t Mode);

FileNode *Mount(FileNode *Parent, Inode *Node, const char *Path);
int Unmount(const char *Path);

FileNode *GetByPath(const char *Path, FileNode *Parent);
std::string GetByNode(FileNode *Node);
FileNode *CreateLink(const char *Path, FileNode *Parent, const char *Target);
FileNode *CreateLink(const char *Path, FileNode *Parent, FileNode *Target);
bool PathExists(const char *Path, FileNode *Parent);
Expand Down
Loading

0 comments on commit 51ea074

Please sign in to comment.