From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/DeviceManager.hpp | 131 +++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Kernel/KernelKit/DeviceManager.hpp (limited to 'Kernel/KernelKit/DeviceManager.hpp') diff --git a/Kernel/KernelKit/DeviceManager.hpp b/Kernel/KernelKit/DeviceManager.hpp new file mode 100644 index 00000000..d6a2849d --- /dev/null +++ b/Kernel/KernelKit/DeviceManager.hpp @@ -0,0 +1,131 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Add kDeviceCnt (amlel) + + ------------------------------------------- */ + +#pragma once + +/* NewOS device interface manager. */ +/* @file KernelKit/DeviceManager.hpp */ +/* @brief Device abstraction and I/O buffer. */ + +#include +#include + +#define kDriveManagerCount 4U + +// Last Rev +// Wed, Apr 3, 2024 9:09:41 AM + +namespace NewOS +{ + template + class DeviceInterface; + + template + class DeviceInterface + { + public: + explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + : fOut(Out), fIn(In) + { + } + + virtual ~DeviceInterface() = default; + + public: + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; + + public: + virtual DeviceInterface& operator<<(T Data) + { + fOut(Data); + return *this; + } + + virtual DeviceInterface& operator>>(T Data) + { + fIn(Data); + return *this; + } + + virtual const char* Name() const + { + return "DeviceInterface"; + } + + operator bool() + { + return fOut && fIn; + } + bool operator!() + { + return !fOut && !fIn; + } + + private: + void (*fOut)(T Data); + void (*fIn)(T Data); + }; + + /// + /// @brief Input Output Buffer + /// Used mainly to communicate between hardware. + /// + template + class IOBuf final + { + public: + explicit IOBuf(T Dat) + : fData(Dat) + { + // at least pass something valid when instancating this struct. + MUST_PASS(Dat); + } + + IOBuf& operator=(const IOBuf&) = default; + IOBuf(const IOBuf&) = default; + + ~IOBuf() = default; + + public: + template + R operator->() const + { + return fData; + } + + template + R& operator[](Size index) const + { + return fData[index]; + } + + private: + T fData; + }; + + ///! @brief Device enum types. + enum + { + kDeviceTypeIDE, + kDeviceTypeEthernet, + kDeviceTypeWiFi, + kDeviceTypeRS232, + kDeviceTypeSCSI, + kDeviceTypeSHCI, + kDeviceTypeUSB, + kDeviceTypeMedia, + kDeviceTypeCount, + }; +} // namespace NewOS -- cgit v1.2.3