diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 13:14:01 +0200 |
| commit | 20042235d1f53ae428aa154e64afdbae5d8d91ad (patch) | |
| tree | 6ea42d1b30505a57301f8ff2916c78ce94ff6eaf /dev/LibCompiler/PEF.h | |
| parent | 0561a8d0a6ae7588309a6e3513bbfeeef5f0aa15 (diff) | |
meta: update .clang-format, format codebase.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/LibCompiler/PEF.h')
| -rw-r--r-- | dev/LibCompiler/PEF.h | 191 |
1 files changed, 88 insertions, 103 deletions
diff --git a/dev/LibCompiler/PEF.h b/dev/LibCompiler/PEF.h index 1148dea..f32d830 100644 --- a/dev/LibCompiler/PEF.h +++ b/dev/LibCompiler/PEF.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved ------------------------------------------- */ @@ -11,14 +11,14 @@ // @file PEF.hpp // @brief Preferred Executable Format -#define kPefMagic "Joy!" +#define kPefMagic "Joy!" #define kPefMagicFat "yoJ!" -#define kPefExt ".exec" -#define kPefDylibExt ".dylib" -#define kPefLibExt ".lib" +#define kPefExt ".exec" +#define kPefDylibExt ".dylib" +#define kPefLibExt ".lib" #define kPefObjectExt ".obj" -#define kPefDebugExt ".dbg" +#define kPefDebugExt ".dbg" #define kPefDriverExt ".sys" #define kPefZero128 ".zero128" @@ -38,107 +38,92 @@ #define kPefStart "__ImageStart" -namespace LibCompiler -{ - enum - { - kPefArchStart = 99, - kPefArchIntel86S = 100, - kPefArchAMD64, - kPefArchRISCV, - kPefArch64000, /* 64x0 RISC architecture. */ - kPefArch32000, - kPefArchPowerPC, /* 64-bit POWER architecture. */ - kPefArchARM64, - kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1, - kPefArchInvalid = 0xFF, - }; - - enum - { - kPefSubArchAMD, - kPefSubArchIntel, - kPefSubArchARM, - kPefSubArchGeneric, - kPefSubArchIBM, - }; - - enum - { - kPefKindExec = 1, /* .o */ - kPefKindDylib = 2, /* .dylib */ - kPefKindObject = 4, /* .obj */ - kPefKindDebug = 5, /* .dbg */ - kPefKindDriver = 6, - kPefKindCount, - }; - - /* PEF container */ - typedef struct PEFContainer final - { - CharType Magic[kPefMagicLen]; - UInt32 Linker; - UInt32 Version; - UInt32 Kind; - UInt32 Abi; - UInt32 Cpu; - UInt32 SubCpu; /* Cpu specific information */ - UIntPtr Start; /* Origin of code */ - SizeType HdrSz; /* Size of header */ - SizeType Count; /* container header count */ - } PACKED PEFContainer, *PEFContainerPtr; - - /* First PEFCommandHeader starts after PEFContainer */ - /* Last container is __exec_end */ - - /* PEF executable section and commands. */ - - typedef struct PEFCommandHeader final - { - CharType Name[kPefNameLen]; /* container name */ - UInt32 Cpu; /* container cpu */ - UInt32 SubCpu; /* container sub-cpu */ - UInt32 Flags; /* container flags */ - UInt16 Kind; /* container kind */ - UIntPtr Offset; /* file offset */ - SizeType Size; /* file size */ - } PACKED PEFCommandHeader, *PEFCommandHeaderPtr; - - enum - { - kPefCode = 0xC, - kPefData = 0xD, - kPefZero = 0xE, - kPefLinkerID = 0x1, - kPefCount = 4, - kPefInvalid = 0xFF, - }; -} // namespace LibCompiler - -inline std::ofstream& operator<<(std::ofstream& fp, - LibCompiler::PEFContainer& container) -{ - fp.write((char*)&container, sizeof(LibCompiler::PEFContainer)); - return fp; +namespace LibCompiler { +enum { + kPefArchStart = 99, + kPefArchIntel86S = 100, + kPefArchAMD64, + kPefArchRISCV, + kPefArch64000, /* 64x0 RISC architecture. */ + kPefArch32000, + kPefArchPowerPC, /* 64-bit POWER architecture. */ + kPefArchARM64, + kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1, + kPefArchInvalid = 0xFF, +}; + +enum { + kPefSubArchAMD, + kPefSubArchIntel, + kPefSubArchARM, + kPefSubArchGeneric, + kPefSubArchIBM, +}; + +enum { + kPefKindExec = 1, /* .o */ + kPefKindDylib = 2, /* .dylib */ + kPefKindObject = 4, /* .obj */ + kPefKindDebug = 5, /* .dbg */ + kPefKindDriver = 6, + kPefKindCount, +}; + +/* PEF container */ +typedef struct PEFContainer final { + CharType Magic[kPefMagicLen]; + UInt32 Linker; + UInt32 Version; + UInt32 Kind; + UInt32 Abi; + UInt32 Cpu; + UInt32 SubCpu; /* Cpu specific information */ + UIntPtr Start; /* Origin of code */ + SizeType HdrSz; /* Size of header */ + SizeType Count; /* container header count */ +} PACKED PEFContainer, *PEFContainerPtr; + +/* First PEFCommandHeader starts after PEFContainer */ +/* Last container is __exec_end */ + +/* PEF executable section and commands. */ + +typedef struct PEFCommandHeader final { + CharType Name[kPefNameLen]; /* container name */ + UInt32 Cpu; /* container cpu */ + UInt32 SubCpu; /* container sub-cpu */ + UInt32 Flags; /* container flags */ + UInt16 Kind; /* container kind */ + UIntPtr Offset; /* file offset */ + SizeType Size; /* file size */ +} PACKED PEFCommandHeader, *PEFCommandHeaderPtr; + +enum { + kPefCode = 0xC, + kPefData = 0xD, + kPefZero = 0xE, + kPefLinkerID = 0x1, + kPefCount = 4, + kPefInvalid = 0xFF, +}; +} // namespace LibCompiler + +inline std::ofstream& operator<<(std::ofstream& fp, LibCompiler::PEFContainer& container) { + fp.write((char*) &container, sizeof(LibCompiler::PEFContainer)); + return fp; } -inline std::ofstream& operator<<(std::ofstream& fp, - LibCompiler::PEFCommandHeader& container) -{ - fp.write((char*)&container, sizeof(LibCompiler::PEFCommandHeader)); - return fp; +inline std::ofstream& operator<<(std::ofstream& fp, LibCompiler::PEFCommandHeader& container) { + fp.write((char*) &container, sizeof(LibCompiler::PEFCommandHeader)); + return fp; } -inline std::ifstream& operator>>(std::ifstream& fp, - LibCompiler::PEFContainer& container) -{ - fp.read((char*)&container, sizeof(LibCompiler::PEFContainer)); - return fp; +inline std::ifstream& operator>>(std::ifstream& fp, LibCompiler::PEFContainer& container) { + fp.read((char*) &container, sizeof(LibCompiler::PEFContainer)); + return fp; } -inline std::ifstream& operator>>(std::ifstream& fp, - LibCompiler::PEFCommandHeader& container) -{ - fp.read((char*)&container, sizeof(LibCompiler::PEFCommandHeader)); - return fp; +inline std::ifstream& operator>>(std::ifstream& fp, LibCompiler::PEFCommandHeader& container) { + fp.read((char*) &container, sizeof(LibCompiler::PEFCommandHeader)); + return fp; } |
