diff options
Diffstat (limited to 'Private/KernelKit')
| -rw-r--r-- | Private/KernelKit/Framebuffer.hpp | 6 | ||||
| -rw-r--r-- | Private/KernelKit/PCI/IO-Impl-AMD64.inl | 46 | ||||
| -rw-r--r-- | Private/KernelKit/PCI/IO.hpp | 77 | ||||
| -rw-r--r-- | Private/KernelKit/PE.hpp | 72 | ||||
| -rw-r--r-- | Private/KernelKit/PEF.hpp | 90 |
5 files changed, 189 insertions, 102 deletions
diff --git a/Private/KernelKit/Framebuffer.hpp b/Private/KernelKit/Framebuffer.hpp index a0a0e4c5..4266220d 100644 --- a/Private/KernelKit/Framebuffer.hpp +++ b/Private/KernelKit/Framebuffer.hpp @@ -7,8 +7,8 @@ * ======================================================== */ -#ifndef _INC_FB_HPP__ -#define _INC_FB_HPP__ +#ifndef __INC_FB_HPP__ +#define __INC_FB_HPP__ #include <NewKit/Defines.hpp> #include <NewKit/Ref.hpp> @@ -56,4 +56,4 @@ namespace HCore }; } // namespace HCore -#endif /* ifndef _INC_FB_HPP__ */ +#endif /* ifndef __INC_FB_HPP__ */ diff --git a/Private/KernelKit/PCI/IO-Impl-AMD64.inl b/Private/KernelKit/PCI/IO-Impl-AMD64.inl new file mode 100644 index 00000000..c5247d13 --- /dev/null +++ b/Private/KernelKit/PCI/IO-Impl-AMD64.inl @@ -0,0 +1,46 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: IO-Impl-AMD64.hpp + Purpose: I/O for AMD64. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +namespace HCore { +template <SizeT Sz> +template <typename T> +T IOArray<Sz>::In(SizeT index) { + switch (sizeof(T)) { + case 4: + return HAL::in32(m_Ports[index].Leak()); + case 2: + return HAL::in16(m_Ports[index].Leak()); + case 1: + return HAL::in8(m_Ports[index].Leak()); + default: + return 0xFFFF; + } +} + +template <SizeT Sz> +template <typename T> +void IOArray<Sz>::Out(SizeT index, T value) { + switch (sizeof(T)) { +#ifdef __x86_64__ + case 4: + HAL::out32(m_Ports[index].Leak(), value); + case 2: + HAL::out16(m_Ports[index].Leak(), value); + case 1: + HAL::out8(m_Ports[index].Leak(), value); +#endif + default: + break; + } +} +} // namespace HCore diff --git a/Private/KernelKit/PCI/IO.hpp b/Private/KernelKit/PCI/IO.hpp index bcc728f4..778650b6 100644 --- a/Private/KernelKit/PCI/IO.hpp +++ b/Private/KernelKit/PCI/IO.hpp @@ -9,69 +9,44 @@ #pragma once -#include <NewKit/Defines.hpp> - #include <ArchKit/Arch.hpp> #include <NewKit/Array.hpp> +#include <NewKit/Defines.hpp> #include <NewKit/Ref.hpp> -namespace HCore -{ -template<SizeT Sz> -class IOArray final -{ - public: - IOArray() = delete; +namespace HCore { +template <SizeT Sz> +class IOArray final { + public: + IOArray() = delete; - IOArray(nullPtr) = delete; + IOArray(nullPtr) = delete; - explicit IOArray(Array <UShort, Sz> &ports) : m_Ports(ports) {} - ~IOArray() {} + explicit IOArray(Array<UShort, Sz> &ports) : m_Ports(ports) {} + ~IOArray() {} - IOArray &operator=(const IOArray &) = default; + IOArray &operator=(const IOArray &) = default; - IOArray(const IOArray &) = default; + IOArray(const IOArray &) = default; - operator bool() { - return !m_Ports.Empty(); - } + operator bool() { return !m_Ports.Empty(); } - public: - template<typename T> - T In(SizeT index) { - switch (sizeof(T)) { -#ifdef __x86_64__ - case 4: - return HAL::in32(m_Ports[index].Leak()); - case 2: - return HAL::in16(m_Ports[index].Leak()); - case 1: - return HAL::in8(m_Ports[index].Leak()); -#endif - default: - return 0xFFFF; - } - } + public: + template <typename T> + T In(SizeT index); - template<typename T> - void Out(SizeT index, T value) { - switch (sizeof(T)) { -#ifdef __x86_64__ - case 4: - HAL::out32(m_Ports[index].Leak(), value); - case 2: - HAL::out16(m_Ports[index].Leak(), value); - case 1: - HAL::out8(m_Ports[index].Leak(), value); -#endif - default: - break; - } - } + template <typename T> + void Out(SizeT index, T value); - private: - Array <UShort, Sz> m_Ports; + private: + Array<UShort, Sz> m_Ports; }; using IOArray16 = IOArray<16>; -} // namespace HCore +} // namespace HCore + +#ifdef __x86_64__ +#include <KernelKit/PCI/IO-Impl-AMD64.inl> +#else +#error Please provide platform specific code for the I/O +#endif // ifdef __x86_64__ diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp new file mode 100644 index 00000000..6ac8d428 --- /dev/null +++ b/Private/KernelKit/PE.hpp @@ -0,0 +1,72 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: PE.hpp + Purpose: Portable Executable for HCore. + + Revision History: + + 30/01/24: Added file (amlel) + +------------------------------------------- */ + +#ifdef __PE__ +#define __PE__ + +#include <NewKit/Defines.hpp> + +typedef HCore::UInt32 U32; +typedef HCore::UInt16 U16; +typedef HCore::UInt8 U8; + +#define kPeMagic 0x00004550 + +struct ExecHeader final { + U32 mMagic; // PE\0\0 or 0x00004550 + U16 mMachine; + U16 mNumberOfSections; + U32 mTimeDateStamp; + U32 mPointerToSymbolTable; + U32 mNumberOfSymbols; + U16 mSizeOfOptionalHeader; + U16 mCharacteristics; +}; + +#define kMagPE32 0x010b +#define kMagPE64 0x020b + +struct ExecOptionalHeader { + U16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit) + U8 mMajorLinkerVersion; + U8 mMinorLinkerVersion; + U32 mSizeOfCode; + U32 mSizeOfInitializedData; + U32 mSizeOfUninitializedData; + U32 mAddressOfEntryPoint; + U32 mBaseOfCode; + U32 mBaseOfData; + U32 mImageBase; + U32 mSectionAlignment; + U32 mFileAlignment; + U16 mMajorOperatingSystemVersion; + U16 mMinorOperatingSystemVersion; + U16 mMajorImageVersion; + U16 mMinorImageVersion; + U16 mMajorSubsystemVersion; + U16 mMinorSubsystemVersion; + U32 mWin32VersionValue; + U32 mSizeOfImage; + U32 mSizeOfHeaders; + U32 mCheckSum; + U16 mSubsystem; + U16 mDllCharacteristics; + U32 mSizeOfStackReserve; + U32 mSizeOfStackCommit; + U32 mSizeOfHeapReserve; + U32 mSizeOfHeapCommit; + U32 mLoaderFlags; + U32 mNumberOfRvaAndSizes; +}; + +#endif /* ifndef __PE__ */ diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index f259d8ac..d6c7ec87 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -7,8 +7,8 @@ * ======================================================== */ -#ifndef _INC_LOADER_PEF_HPP -#define _INC_LOADER_PEF_HPP +#ifndef __PEF_HPP__ +#define __PEF_HPP__ #include <CompilerKit/CompilerKit.hpp> #include <KernelKit/Loader.hpp> @@ -24,38 +24,34 @@ // @brief Preferred Executable Format, a format designed for any computer. -namespace HCore -{ -enum -{ - kPefArchIntel86S, - kPefArchAMD64, - kPefArchRISCV, - kPefArch64x0, /* 64x000. */ - kPefArch32x0, - kPefArchInvalid = 0xFF, +namespace HCore { +enum { + kPefArchIntel86S, + kPefArchAMD64, + kPefArchRISCV, + kPefArch64x0, /* 64x000. */ + kPefArch32x0, + kPefArchInvalid = 0xFF, }; -enum -{ - kPefKindExec = 1, /* .exe */ - kPefKindSharedObject = 2, /* .lib */ - kPefKindObject = 4, /* .obj */ - kPefKindDebug = 5, /* .debug */ +enum { + kPefKindExec = 1, /* .exe */ + kPefKindSharedObject = 2, /* .lib */ + kPefKindObject = 4, /* .obj */ + kPefKindDebug = 5, /* .debug */ }; -typedef struct PEFContainer final -{ - Char Magic[kPefMagicLen]; - UInt32 Linker; - UInt32 Version; - UInt32 Kind; - UInt32 Abi; - UInt32 Cpu; - UInt32 SubCpu; /* Cpu specific information */ - UIntPtr Start; - SizeT HdrSz; /* Size of header */ - SizeT Count; /* container header count */ +typedef struct PEFContainer final { + Char Magic[kPefMagicLen]; + UInt32 Linker; + UInt32 Version; + UInt32 Kind; + UInt32 Abi; + UInt32 Cpu; + UInt32 SubCpu; /* Cpu specific information */ + UIntPtr Start; + SizeT HdrSz; /* Size of header */ + SizeT Count; /* container header count */ } __attribute__((packed)) PEFContainer; /* First PEFCommandHeader starts after PEFContainer */ @@ -63,33 +59,31 @@ typedef struct PEFContainer final /* PEF executable section and commands. */ -typedef struct PEFCommandHeader final -{ - Char Name[kPefNameLen]; /* container name */ - UInt32 Flags; /* container flags */ - UInt16 Kind; /* container kind */ - UIntPtr Offset; /* content offset */ - SizeT Size; /* content Size */ +typedef struct PEFCommandHeader final { + Char Name[kPefNameLen]; /* container name */ + UInt32 Flags; /* container flags */ + UInt16 Kind; /* container kind */ + UIntPtr Offset; /* content offset */ + SizeT Size; /* content Size */ } __attribute__((packed)) PEFCommandHeader; -enum -{ - kPefCode = 0xC, - kPefData = 0xD, - kPefZero = 0xE, - kPefLinkerID = 0x1, +enum { + kPefCode = 0xC, + kPefData = 0xD, + kPefZero = 0xE, + kPefLinkerID = 0x1, }; -} // namespace HCore +} // namespace HCore -#define kPefExt ".cm" -#define kPefDylibExt ".dlib" +#define kPefExt ".exe" +#define kPefDylibExt ".dll" #define kPefLibExt ".lib" #define kPefObjectExt ".obj" -#define kPefDebugExt ".cmdbg" +#define kPefDebugExt ".pdb" // HCore System Binary Interface. #define kPefAbi (0xDEAD2) #define kPefStart "__start" -#endif /* ifndef _INC_LOADER_PEF_HPP */ +#endif /* ifndef __PEF_HPP__ */ |
