From fbbcfd27436fe61799c79aec14f9c2c3fdf73497 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 18 Jun 2025 10:27:31 +0200 Subject: feat: PEF format update `5.0` and codebase refactors. Signed-off-by: Amlal El Mahrouss --- dev/LibCompiler/AE.h | 14 +++++++------- dev/LibCompiler/BasicString.h | 8 ++++---- dev/LibCompiler/CodeGen.h | 16 ++++++++-------- dev/LibCompiler/Frontend.h | 8 ++++---- dev/LibCompiler/PEF.h | 22 +++++++++++----------- dev/LibCompiler/src/Backend/AssemblerAMD64.cc | 2 +- dev/LibCompiler/src/BasicString.cc | 2 +- dev/LibCompiler/src/CodeGen.cc | 2 +- dev/LibCompiler/src/Frontend.cc | 10 +++++----- .../src/Frontend/CompilerCPlusPlusAMD64.cc | 2 +- dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc | 3 ++- .../src/Macro/CPlusPlusCompilerPreProcessor.cc | 2 +- 12 files changed, 46 insertions(+), 45 deletions(-) (limited to 'dev/LibCompiler') diff --git a/dev/LibCompiler/AE.h b/dev/LibCompiler/AE.h index 8c05c3a..f42b9d7 100644 --- a/dev/LibCompiler/AE.h +++ b/dev/LibCompiler/AE.h @@ -28,14 +28,14 @@ namespace LibCompiler { // One thing to keep in mind. // This object format, is reloctable. typedef struct AEHeader final { - Char fMagic[kAEMagLen]; - Char fArch; - Char fSubArch; + Char fMagic[kAEMagLen]; + Char fArch; + Char fSubArch; SizeType fCount; - Char fSize; + Char fSize; SizeType fStartCode; SizeType fCodeSize; - Char fPad[kAEPad]; + Char fPad[kAEPad]; } PACKED AEHeader, *AEHeaderPtr; // @brief Advanced Executable Record. @@ -43,12 +43,12 @@ typedef struct AEHeader final { // fKind must be filled with PEF fields. typedef struct AERecordHeader final { - Char fName[kAESymbolLen]; + Char fName[kAESymbolLen]; SizeType fKind; SizeType fSize; SizeType fFlags; UIntPtr fOffset; - Char fPad[kAEPad]; + Char fPad[kAEPad]; } PACKED AERecordHeader, *AERecordHeaderPtr; enum { diff --git a/dev/LibCompiler/BasicString.h b/dev/LibCompiler/BasicString.h index 5af9da9..38e585f 100644 --- a/dev/LibCompiler/BasicString.h +++ b/dev/LibCompiler/BasicString.h @@ -43,7 +43,7 @@ class BasicString final { Char* Data(); const Char* CData() const; - SizeType Length() const; + SizeType Length() const; bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; @@ -59,9 +59,9 @@ class BasicString final { bool operator!() { return !m_Data || m_Data[0] == 0; } private: - Char* m_Data{nullptr}; - SizeType m_Sz{0}; - SizeType m_Cur{0}; + Char* m_Data{nullptr}; + SizeType m_Sz{0}; + SizeType m_Cur{0}; friend class StringBuilder; }; diff --git a/dev/LibCompiler/CodeGen.h b/dev/LibCompiler/CodeGen.h index b932cdf..43242b3 100644 --- a/dev/LibCompiler/CodeGen.h +++ b/dev/LibCompiler/CodeGen.h @@ -74,8 +74,8 @@ union NumberCast64 final { ~NumberCast64() { raw = 0; } - Char number[8]; - UInt64 raw; + Char number[8]; + UInt64 raw; }; union NumberCast32 final { @@ -84,8 +84,8 @@ union NumberCast32 final { ~NumberCast32() { raw = 0; } - Char number[4]; - UInt32 raw; + Char number[4]; + UInt32 raw; }; union NumberCast16 final { @@ -94,8 +94,8 @@ union NumberCast16 final { ~NumberCast16() { raw = 0; } - Char number[2]; - UInt16 raw; + Char number[2]; + UInt16 raw; }; union NumberCast8 final { @@ -104,8 +104,8 @@ union NumberCast8 final { ~NumberCast8() { raw = 0; } - Char number; - UInt8 raw; + Char number; + UInt8 raw; }; class EncoderInterface { diff --git a/dev/LibCompiler/Frontend.h b/dev/LibCompiler/Frontend.h index f39c9d4..5628f9a 100644 --- a/dev/LibCompiler/Frontend.h +++ b/dev/LibCompiler/Frontend.h @@ -79,22 +79,22 @@ struct SyntaxLeafList final { std::vector fLeafList; SizeType fNumLeafs; - size_t SizeOf() { return fNumLeafs; } + SizeType SizeOf() { return fNumLeafs; } std::vector& Get() { return fLeafList; } - SyntaxLeaf& At(size_t index) { return fLeafList[index]; } + SyntaxLeaf& At(SizeType index) { return fLeafList[index]; } }; /// find the perfect matching word in a haystack. /// \param haystack base string /// \param needle the string we search for. /// \return if we found it or not. -BOOL find_word(std::string haystack, std::string needle) noexcept; +BOOL find_word(STLString haystack, STLString needle) noexcept; /// find a word within strict conditions and returns a range of it. /// \param haystack /// \param needle /// \return position of needle. -std::size_t find_word_range(std::string haystack, std::string needle) noexcept; +SizeType find_word_range(STLString haystack, STLString needle) noexcept; /// @brief Compiler backend, implements a frontend, such as C, C++... /// See Toolchain, for some examples. diff --git a/dev/LibCompiler/PEF.h b/dev/LibCompiler/PEF.h index 3f5a2b1..08ace3c 100644 --- a/dev/LibCompiler/PEF.h +++ b/dev/LibCompiler/PEF.h @@ -8,11 +8,11 @@ #include -// @file PEF.hpp +// @file PEF.h // @brief Preferred Executable Format -#define kPefMagic "Joy!" -#define kPefMagicFat "yoJ!" +#define kPefMagic "Open" +#define kPefMagicFat "nepO" #define kPefExt ".exec" #define kPefDylibExt ".dylib" @@ -31,7 +31,7 @@ #define kPefMagicLen (5) -#define kPefVersion (4) +#define kPefVersion (0x0500) #define kPefNameLen (255) #define kPefBaseOrigin (0x40000000) @@ -53,10 +53,10 @@ enum { }; enum { + kPefSubArchGeneric, kPefSubArchAMD = 200, kPefSubArchIntel, kPefSubArchARM, - kPefSubArchGeneric, kPefSubArchIBM, }; @@ -71,7 +71,7 @@ enum { /* PEF container */ typedef struct PEFContainer final { - Char Magic[kPefMagicLen]; + Char Magic[kPefMagicLen]; UInt32 Linker; /* Linker used to link executable */ UInt32 Version; UInt32 Kind; @@ -90,23 +90,23 @@ typedef struct PEFContainer final { /* PEF executable section and commands. */ typedef struct PEFCommandHeader final { - Char Name[kPefNameLen]; /* container name */ + Char 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 */ - UIntPtr VMAddress; /* VM offset */ - SizeType Size; /* file size */ + UIntPtr Offset; /* File offset */ + UIntPtr VMAddress; /* Virtual Address */ + SizeType Size; /* Virtual Size */ } PACKED PEFCommandHeader, *PEFCommandHeaderPtr; enum { + kPefInvalid = 0x0, kPefCode = 0xC, kPefData = 0xD, kPefZero = 0xE, kPefLinkerID = 0x1, kPefCount = 4, - kPefInvalid = 0xFF, }; } // namespace LibCompiler diff --git a/dev/LibCompiler/src/Backend/AssemblerAMD64.cc b/dev/LibCompiler/src/Backend/AssemblerAMD64.cc index 3a717ba..4d03fd7 100644 --- a/dev/LibCompiler/src/Backend/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/Backend/AssemblerAMD64.cc @@ -957,7 +957,7 @@ bool LibCompiler::EncoderAMD64::WriteLine(std::string line, std::string file) { struct RegMapAMD64 { LibCompiler::STLString fName; - i64_byte_t fModRM; + i64_byte_t fModRM; }; std::vector kRegisterList{ diff --git a/dev/LibCompiler/src/BasicString.cc b/dev/LibCompiler/src/BasicString.cc index 41989fe..c4cb763 100644 --- a/dev/LibCompiler/src/BasicString.cc +++ b/dev/LibCompiler/src/BasicString.cc @@ -8,7 +8,7 @@ */ /** - * @file BasicString.cxx + * @file BasicString.cc * @author Amlal (amlal@el-mahrouss-logic.com) * @brief C++ string manipulation API. * @version 0.2 diff --git a/dev/LibCompiler/src/CodeGen.cc b/dev/LibCompiler/src/CodeGen.cc index 3f215c5..7208d65 100644 --- a/dev/LibCompiler/src/CodeGen.cc +++ b/dev/LibCompiler/src/CodeGen.cc @@ -8,7 +8,7 @@ #include /** - * @file AssemblyFactory.cxx + * @file CodeGen.cc * @author amlal (amlal@nekernel.org) * @brief Assembler Kit * @version 0.1 diff --git a/dev/LibCompiler/src/Frontend.cc b/dev/LibCompiler/src/Frontend.cc index 69ff6fd..2ed5309 100644 --- a/dev/LibCompiler/src/Frontend.cc +++ b/dev/LibCompiler/src/Frontend.cc @@ -11,11 +11,11 @@ namespace LibCompiler { /// \param haystack base string /// \param needle the string we search for. /// \return if we found it or not. -bool find_word(std::string haystack, std::string needle) noexcept { +BOOL find_word(STLString haystack, STLString needle) noexcept { auto index = haystack.find(needle); // check for needle validity. - if (index == std::string::npos) return false; + if (index == STLString::npos) return false; // declare lambda auto not_part_of_word = [&](int index) { @@ -33,11 +33,11 @@ bool find_word(std::string haystack, std::string needle) noexcept { /// \param haystack /// \param needle /// \return position of needle. -std::size_t find_word_range(std::string haystack, std::string needle) noexcept { +SizeType find_word_range(STLString haystack, STLString needle) noexcept { auto index = haystack.find(needle); // check for needle validity. - if (index == std::string::npos) return false; + if (index == STLString::npos) return false; if (!isalnum((haystack[index + needle.size() + 1])) && !isdigit(haystack[index + needle.size() + 1]) && @@ -46,6 +46,6 @@ std::size_t find_word_range(std::string haystack, std::string needle) noexcept { return index; } - return std::string::npos; + return STLString::npos; } } // namespace LibCompiler \ No newline at end of file diff --git a/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc b/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc index 4a1a1f7..984d059 100644 --- a/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc +++ b/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc @@ -1,7 +1,7 @@ /* * ======================================================== * - * cxxdrv + * CompilerCPlusPlusAMD64 CPlusPlus Compiler Driver * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. * * ======================================================== diff --git a/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc b/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc index b58c786..a383351 100644 --- a/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc +++ b/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc @@ -69,7 +69,7 @@ namespace Detail { struct DynamicLinkerBlob final { std::vector mBlob{}; // PEF code/bss/data blob. - UIntPtr mOffset{0UL}; // the offset of the PEF container header... + UIntPtr mOffset{0UL}; // the offset of the PEF container header... }; } // namespace Detail @@ -367,6 +367,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) { } kConsoleOut << "Not an AE container: " << objectFile << std::endl; + // don't continue, it is a fatal error. return LIBCOMPILER_EXEC_ERROR; } diff --git a/dev/LibCompiler/src/Macro/CPlusPlusCompilerPreProcessor.cc b/dev/LibCompiler/src/Macro/CPlusPlusCompilerPreProcessor.cc index 2c7c551..f9986f4 100644 --- a/dev/LibCompiler/src/Macro/CPlusPlusCompilerPreProcessor.cc +++ b/dev/LibCompiler/src/Macro/CPlusPlusCompilerPreProcessor.cc @@ -1,7 +1,7 @@ /* * ======================================================== * - * bpp + * CPlusPlusCompilerPreProcessor Preprocessor Driver * Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved. * * ======================================================== -- cgit v1.2.3