diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-19 17:33:26 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-19 17:33:26 +0200 |
| commit | befde76cfa46c766e81f74eb5ac65d3dae2dde87 (patch) | |
| tree | 45b2f9fd6b3f9605c2747485bd24483192f99e73 | |
| parent | 3afc481dc64a07fe7fcaff9ce7a12a492c3ec8e7 (diff) | |
dev, LibCompiler, tooling: refactor and separate components into modules
(cppdrv, cxxdrv)
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
40 files changed, 145 insertions, 216 deletions
@@ -13,6 +13,7 @@ tools/ld64 tools/cxxdrv tools/dbg +tools/cppdrv *.pp *.masm diff --git a/dev/LibCompiler/NFC/AE.h b/dev/LibCompiler/AE.h index fdf42a5..fdf42a5 100644 --- a/dev/LibCompiler/NFC/AE.h +++ b/dev/LibCompiler/AE.h diff --git a/dev/LibCompiler/AAL/AssemblyInterface.h b/dev/LibCompiler/AssemblyInterface.h index a9ca95b..622e2ff 100644 --- a/dev/LibCompiler/AAL/AssemblyInterface.h +++ b/dev/LibCompiler/AssemblyInterface.h @@ -8,7 +8,7 @@ #include <LibCompiler/Macros.h> #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/StringView.h> +#include <LibCompiler/StringView.h> #define ASSEMBLY_INTERFACE : public LibCompiler::AssemblyInterface diff --git a/dev/LibCompiler/AAL/CPU/32x0.h b/dev/LibCompiler/Backend/32x0.h index 007beab..32f31ff 100644 --- a/dev/LibCompiler/AAL/CPU/32x0.h +++ b/dev/LibCompiler/Backend/32x0.h @@ -9,7 +9,7 @@ #include <LibCompiler/Defines.h> // @brief 32x0 support. -// @file CPU/32x0.hpp +// @file Backend/32x0.hpp #define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, \ diff --git a/dev/LibCompiler/AAL/CPU/64x0.h b/dev/LibCompiler/Backend/64x0.h index 4944e3b..a0084b1 100644 --- a/dev/LibCompiler/AAL/CPU/64x0.h +++ b/dev/LibCompiler/Backend/64x0.h @@ -10,7 +10,7 @@ #include <vector> // @brief 64x0 support. -// @file CPU/64x0.hpp +// @file Backend/64x0.hpp #define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ {.fName = __NAME, \ diff --git a/dev/LibCompiler/AAL/CPU/amd64.h b/dev/LibCompiler/Backend/amd64.h index 0717dc1..8486b01 100644 --- a/dev/LibCompiler/AAL/CPU/amd64.h +++ b/dev/LibCompiler/Backend/amd64.h @@ -9,7 +9,7 @@ #include <LibCompiler/Defines.h> // @brief AMD64 support. -// @file CPU/amd64.hpp +// @file Backend/amd64.hpp #define kAsmOpcodeDecl(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, diff --git a/dev/LibCompiler/AAL/CPU/arm64.h b/dev/LibCompiler/Backend/arm64.h index 02a2bf2..08096ee 100644 --- a/dev/LibCompiler/AAL/CPU/arm64.h +++ b/dev/LibCompiler/Backend/arm64.h @@ -10,7 +10,7 @@ Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved #include <LibCompiler/Defines.h> /// @brief ARM64 encoding support. -/// @file CPU/arm64.hpp +/// @file Backend/arm64.hpp struct CpuOpcodeArm64; diff --git a/dev/LibCompiler/AAL/CPU/power64.h b/dev/LibCompiler/Backend/power64.h index 0f797a5..0f797a5 100644 --- a/dev/LibCompiler/AAL/CPU/power64.h +++ b/dev/LibCompiler/Backend/power64.h diff --git a/dev/LibCompiler/Defines.h b/dev/LibCompiler/Defines.h index b13cd86..07f3b33 100644 --- a/dev/LibCompiler/Defines.h +++ b/dev/LibCompiler/Defines.h @@ -23,6 +23,10 @@ #define NO false #endif // ifndef NO +#ifndef BOOL +#define BOOL bool +#endif // ifndef BOOL + #define SizeType size_t #define VoidPtr void* diff --git a/dev/LibCompiler/NFC/ErrorID.h b/dev/LibCompiler/ErrorID.h index e7f06e1..b105f9b 100644 --- a/dev/LibCompiler/NFC/ErrorID.h +++ b/dev/LibCompiler/ErrorID.h @@ -10,9 +10,9 @@ #pragma once #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/ErrorOr.h> +#include <LibCompiler/ErrorOr.h> -#define LIBCOMPILER_SUCCESSS 0 +#define LIBCOMPILER_SUCCESSS 0 #define LIBCOMPILER_EXEC_ERROR -30 #define LIBCOMPILER_FILE_NOT_FOUND -31 #define LIBCOMPILER_DIR_NOT_FOUND -32 diff --git a/dev/LibCompiler/NFC/ErrorOr.h b/dev/LibCompiler/ErrorOr.h index 9dc607e..2a6d590 100644 --- a/dev/LibCompiler/NFC/ErrorOr.h +++ b/dev/LibCompiler/ErrorOr.h @@ -10,7 +10,7 @@ #pragma once #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/Ref.h> +#include <LibCompiler/Ref.h> namespace LibCompiler { diff --git a/dev/LibCompiler/NFC/PEF.h b/dev/LibCompiler/PEF.h index 1148dea..1148dea 100644 --- a/dev/LibCompiler/NFC/PEF.h +++ b/dev/LibCompiler/PEF.h diff --git a/dev/LibCompiler/Parser.h b/dev/LibCompiler/Parser.h index 74eb204..cb0e470 100644 --- a/dev/LibCompiler/Parser.h +++ b/dev/LibCompiler/Parser.h @@ -6,7 +6,7 @@ #pragma once -#include <LibCompiler/AAL/AssemblyInterface.h> +#include <LibCompiler/AssemblyInterface.h> namespace LibCompiler { diff --git a/dev/LibCompiler/NFC/Ref.h b/dev/LibCompiler/Ref.h index 117083c..117083c 100644 --- a/dev/LibCompiler/NFC/Ref.h +++ b/dev/LibCompiler/Ref.h diff --git a/dev/LibCompiler/NFC/StringView.h b/dev/LibCompiler/StringView.h index 16578e0..b65121e 100644 --- a/dev/LibCompiler/NFC/StringView.h +++ b/dev/LibCompiler/StringView.h @@ -10,7 +10,7 @@ #pragma once #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/ErrorOr.h> +#include <LibCompiler/ErrorOr.h> namespace LibCompiler { diff --git a/dev/LibCompiler/NFC/XCOFF.h b/dev/LibCompiler/XCOFF.h index 862c363..862c363 100644 --- a/dev/LibCompiler/NFC/XCOFF.h +++ b/dev/LibCompiler/XCOFF.h diff --git a/dev/LibCompiler/src/Assembler32x0.cc b/dev/LibCompiler/src/Assembler32x0.cc index 0eaf78a..1790b8b 100644 --- a/dev/LibCompiler/src/Assembler32x0.cc +++ b/dev/LibCompiler/src/Assembler32x0.cc @@ -19,10 +19,10 @@ #define __ASM_NEED_32x0__ 1 -#include <LibCompiler/AAL/CPU/32x0.h> +#include <LibCompiler/Backend/32x0.h> #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/AE.h> -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/AE.h> +#include <LibCompiler/PEF.h> ///////////////////// diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Assembler64x0.cc index b074e9f..7630adf 100644 --- a/dev/LibCompiler/src/Assembler64x0.cc +++ b/dev/LibCompiler/src/Assembler64x0.cc @@ -19,10 +19,10 @@ #define __ASM_NEED_64x0__ 1 -#include <LibCompiler/AAL/CPU/64x0.h> +#include <LibCompiler/Backend/64x0.h> #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/AE.h> -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/AE.h> +#include <LibCompiler/PEF.h> #include <algorithm> #include <filesystem> #include <fstream> diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc index d71caf2..be77ce9 100644 --- a/dev/LibCompiler/src/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/AssemblerAMD64.cc @@ -26,10 +26,10 @@ #define kAssemblerPragmaSymStr "#" #define kAssemblerPragmaSym '#' -#include <LibCompiler/AAL/CPU/amd64.h> +#include <LibCompiler/Backend/amd64.h> #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/AE.h> -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/AE.h> +#include <LibCompiler/PEF.h> #include <algorithm> #include <cstdlib> #include <filesystem> diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc index e402b7f..52b78d6 100644 --- a/dev/LibCompiler/src/AssemblerARM64.cc +++ b/dev/LibCompiler/src/AssemblerARM64.cc @@ -17,11 +17,11 @@ #define __ASM_NEED_ARM64__ 1 -#include <LibCompiler/NFC/ErrorID.h> -#include <LibCompiler/AAL/CPU/arm64.h> -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/ErrorID.h> +#include <LibCompiler/Backend/arm64.h> +#include <LibCompiler/PEF.h> #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/AE.h> +#include <LibCompiler/AE.h> #include <LibCompiler/Version.h> #include <filesystem> #include <algorithm> diff --git a/dev/LibCompiler/src/AssemblerPower.cc b/dev/LibCompiler/src/AssemblerPower.cc index 7cb4ca0..59f7ed6 100644 --- a/dev/LibCompiler/src/AssemblerPower.cc +++ b/dev/LibCompiler/src/AssemblerPower.cc @@ -17,11 +17,11 @@ #define __ASM_NEED_PPC__ 1 -#include <LibCompiler/NFC/ErrorID.h> -#include <LibCompiler/AAL/CPU/power64.h> -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/ErrorID.h> +#include <LibCompiler/Backend/power64.h> +#include <LibCompiler/PEF.h> #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/AE.h> +#include <LibCompiler/AE.h> #include <LibCompiler/Version.h> #include <filesystem> #include <algorithm> diff --git a/dev/LibCompiler/src/AssemblyFactory.cc b/dev/LibCompiler/src/AssemblyFactory.cc index 46ebed3..e70f279 100644 --- a/dev/LibCompiler/src/AssemblyFactory.cc +++ b/dev/LibCompiler/src/AssemblyFactory.cc @@ -4,8 +4,8 @@ ------------------------------------------- */ -#include <LibCompiler/AAL/AssemblyInterface.h> -#include <LibCompiler/NFC/ErrorID.h> +#include <LibCompiler/AssemblyInterface.h> +#include <LibCompiler/ErrorID.h> /** * @file AssemblyFactory.cxx diff --git a/dev/LibCompiler/src/CCompiler64x0.cc b/dev/LibCompiler/src/CCompiler64x0.cc index 19446af..89fc682 100644 --- a/dev/LibCompiler/src/CCompiler64x0.cc +++ b/dev/LibCompiler/src/CCompiler64x0.cc @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include <LibCompiler/AAL/CPU/64x0.h> +#include <LibCompiler/Backend/64x0.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> #include <cstdio> diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc index ac09cbd..5d3e892 100644 --- a/dev/LibCompiler/src/CCompilerARM64.cc +++ b/dev/LibCompiler/src/CCompilerARM64.cc @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include <LibCompiler/AAL/CPU/arm64.h> +#include <LibCompiler/Backend/arm64.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> #include <cstdio> diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc index 63b2794..ac35c4a 100644 --- a/dev/LibCompiler/src/CCompilerPower64.cc +++ b/dev/LibCompiler/src/CCompilerPower64.cc @@ -7,7 +7,7 @@ * ======================================================== */ -#include <LibCompiler/AAL/CPU/power64.h> +#include <LibCompiler/Backend/power64.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> #include <fstream> @@ -21,7 +21,7 @@ #define kExitOK 0 -/// @author EL Mahrouss Amlal (amlel) +/// @author EL Mahrouss Amlal (amlal@nekernel.org) /// @file cc.cxx /// @brief POWER64 C Compiler. diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc index 96a2873..c053920 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc @@ -19,7 +19,7 @@ // extern_segment, @autodelete { ... }, fn foo() -> auto { ... } -#include <LibCompiler/AAL/CPU/amd64.h> +#include <LibCompiler/Backend/amd64.h> #include <LibCompiler/Parser.h> #include <LibCompiler/UUID.h> @@ -1078,27 +1078,27 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) continue; } - if (strcmp(argv[index], "--cl:version") == 0) + if (strcmp(argv[index], "-version") == 0) { kSplashCxx(); return kExitOK; } - if (strcmp(argv[index], "--cl:verbose") == 0) + if (strcmp(argv[index], "-cxx-verbose") == 0) { kState.fVerbose = true; continue; } - if (strcmp(argv[index], "--cl:h") == 0) + if (strcmp(argv[index], "-h") == 0) { cxx_print_help(); return kExitOK; } - if (strcmp(argv[index], "--cl:c++-dialect") == 0) + if (strcmp(argv[index], "-cxx-dialect") == 0) { if (kCompilerFrontend) std::cout << kCompilerFrontend->Language() << "\n"; @@ -1106,7 +1106,7 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) return kExitOK; } - if (strcmp(argv[index], "--cl:max-err") == 0) + if (strcmp(argv[index], "-max-err") == 0) { try { diff --git a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc b/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc index 6a4e9cd..336ca5a 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc @@ -10,7 +10,7 @@ /// BUGS: 0 #include <LibCompiler/Parser.h> -#include <LibCompiler/NFC/ErrorID.h> +#include <LibCompiler/ErrorID.h> #include <algorithm> #include <filesystem> #include <fstream> @@ -419,7 +419,7 @@ void bpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) } else { - throw std::runtime_error("internal: Internal C++ error. (Please report that bug.)"); + throw std::runtime_error("bpp: Internal error."); } } diff --git a/dev/LibCompiler/src/Detail/AsmUtils.h b/dev/LibCompiler/src/Detail/AsmUtils.h index 29dbcbe..997564c 100644 --- a/dev/LibCompiler/src/Detail/AsmUtils.h +++ b/dev/LibCompiler/src/Detail/AsmUtils.h @@ -6,7 +6,7 @@ #pragma once -#include <LibCompiler/AAL/AssemblyInterface.h> +#include <LibCompiler/AssemblyInterface.h> #include <LibCompiler/Parser.h> using namespace LibCompiler; diff --git a/dev/LibCompiler/src/Detail/ClUtils.h b/dev/LibCompiler/src/Detail/ClUtils.h index aa1e0f6..fe788a2 100644 --- a/dev/LibCompiler/src/Detail/ClUtils.h +++ b/dev/LibCompiler/src/Detail/ClUtils.h @@ -6,7 +6,7 @@ #pragma once -#include <LibCompiler/AAL/AssemblyInterface.h> +#include <LibCompiler/AssemblyInterface.h> #include <LibCompiler/Parser.h> #define kZero64Section ".zero64" diff --git a/dev/LibCompiler/src/DynamicLinkerPEF.cc b/dev/LibCompiler/src/DynamicLinkerPEF.cc index 22f268c..6410885 100644 --- a/dev/LibCompiler/src/DynamicLinkerPEF.cc +++ b/dev/LibCompiler/src/DynamicLinkerPEF.cc @@ -7,28 +7,28 @@ ------------------------------------------- */ -/// @author EL Mahrouss Amlal (amlel) +/// @author EL Mahrouss Amlal (amlal@nekernel.org) /// @brief NeKernel 64-bit PEF Linker. -/// Last Rev: Sat Feb 24 CET 2024 +/// Last Rev: Sat Apr 19 CET 2025 /// @note Do not look up for anything with .code64/.data64/.zero64! /// It will be loaded when the program loader will start the image. //! Toolchain Kit. #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/ErrorID.h> +#include <LibCompiler/ErrorID.h> //! Assembler Kit -#include <LibCompiler/AAL/AssemblyInterface.h> +#include <LibCompiler/AssemblyInterface.h> //! Preferred Executable Format -#include <LibCompiler/NFC/PEF.h> +#include <LibCompiler/PEF.h> #include <LibCompiler/UUID.h> //! Release macros. #include <LibCompiler/Version.h> //! Advanced Executable Object Format. -#include <LibCompiler/NFC/AE.h> +#include <LibCompiler/AE.h> #include <cstdint> #define kLinkerVersionStr "\e[0;97m NeKernel 64-Bit Linker (Preferred Executable) %s, (c) Amlal El Mahrouss 2024-2025, all rights reserved.\n" @@ -100,79 +100,79 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) */ for (size_t linker_arg = 1; linker_arg < argc; ++linker_arg) { - if (StringCompare(argv[linker_arg], "--ld64:help") == 0) + if (StringCompare(argv[linker_arg], "-help") == 0) { kLinkerSplash(); - kStdOut << "--ld64:version: Show linker version.\n"; - kStdOut << "--ld64:help: Show linker help.\n"; - kStdOut << "--ld64:verbose: Enable linker trace.\n"; - kStdOut << "--ld64:dylib: Output as a Dyanmic PEF.\n"; - kStdOut << "--ld64:fat: Output as a FAT PEF.\n"; - kStdOut << "--ld64:32k: Output as a 32x0 PEF.\n"; - kStdOut << "--ld64:64k: Output as a 64x0 PEF.\n"; - kStdOut << "--ld64:amd64: Output as a AMD64 PEF.\n"; - kStdOut << "--ld64:rv64: Output as a RISC-V PEF.\n"; - kStdOut << "--ld64:power64: Output as a POWER PEF.\n"; - kStdOut << "--ld64:arm64: Output as a ARM64 PEF.\n"; - kStdOut << "--ld64:output: Select the output file name.\n"; + kStdOut << "-version: Show linker version.\n"; + kStdOut << "-help: Show linker help.\n"; + kStdOut << "-ld-verbose: Enable linker trace.\n"; + kStdOut << "-dylib: Output as a Dyanmic PEF.\n"; + kStdOut << "-fat: Output as a FAT PEF.\n"; + kStdOut << "-32k: Output as a 32x0 PEF.\n"; + kStdOut << "-64k: Output as a 64x0 PEF.\n"; + kStdOut << "-amd64: Output as a AMD64 PEF.\n"; + kStdOut << "-rv64: Output as a RISC-V PEF.\n"; + kStdOut << "-power64: Output as a POWER PEF.\n"; + kStdOut << "-arm64: Output as a ARM64 PEF.\n"; + kStdOut << "-output: Select the output file name.\n"; return EXIT_SUCCESS; } - else if (StringCompare(argv[linker_arg], "--ld64:version") == 0) + else if (StringCompare(argv[linker_arg], "-version") == 0) { kLinkerSplash(); return EXIT_SUCCESS; } - else if (StringCompare(argv[linker_arg], "--ld64:fat-binary") == 0) + else if (StringCompare(argv[linker_arg], "-fat-binary") == 0) { kFatBinaryEnable = true; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:64k") == 0) + else if (StringCompare(argv[linker_arg], "-64k") == 0) { kArch = LibCompiler::kPefArch64000; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:amd64") == 0) + else if (StringCompare(argv[linker_arg], "-amd64") == 0) { kArch = LibCompiler::kPefArchAMD64; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:32k") == 0) + else if (StringCompare(argv[linker_arg], "-32k") == 0) { kArch = LibCompiler::kPefArch32000; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:power64") == 0) + else if (StringCompare(argv[linker_arg], "-power64") == 0) { kArch = LibCompiler::kPefArchPowerPC; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:riscv64") == 0) + else if (StringCompare(argv[linker_arg], "-riscv64") == 0) { kArch = LibCompiler::kPefArchRISCV; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:arm64") == 0) + else if (StringCompare(argv[linker_arg], "-arm64") == 0) { kArch = LibCompiler::kPefArchARM64; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:verbose") == 0) + else if (StringCompare(argv[linker_arg], "-ld-verbose") == 0) { kVerbose = true; continue; } - else if (StringCompare(argv[linker_arg], "--ld64:dylib") == 0) + else if (StringCompare(argv[linker_arg], "-dylib") == 0) { if (kOutput.empty()) { @@ -188,7 +188,7 @@ LIBCOMPILER_MODULE(DynamicLinker64PEF) continue; } - else if (StringCompare(argv[linker_arg], "--ld64:output") == 0) + else if (StringCompare(argv[linker_arg], "-output") == 0) { if ((linker_arg + 1) > argc) continue; diff --git a/dev/LibCompiler/src/StringView.cc b/dev/LibCompiler/src/StringView.cc index 30f1b5f..a3bbb4c 100644 --- a/dev/LibCompiler/src/StringView.cc +++ b/dev/LibCompiler/src/StringView.cc @@ -18,7 +18,7 @@ * */ -#include <LibCompiler/NFC/StringView.h> +#include <LibCompiler/StringView.h> namespace LibCompiler { diff --git a/dev/LibDebugger/DebuggerContract.h b/dev/LibDebugger/DebuggerContract.h index 5d4f728..540ad08 100644 --- a/dev/LibDebugger/DebuggerContract.h +++ b/dev/LibDebugger/DebuggerContract.h @@ -9,8 +9,8 @@ namespace LibDebugger { - typedef uint64_t ProcessID; - typedef char* CAddress; + typedef uint64_t ProcessID; + typedef char* CAddress; /// \brief Debugger contract class in C++, as per the design states. /// \author Amlal El Mahrouss @@ -18,7 +18,7 @@ namespace LibDebugger { public: explicit DebuggerContract() = default; - virtual ~DebuggerContract() = default; + virtual ~DebuggerContract() = default; public: DebuggerContract& operator=(const DebuggerContract&) = default; @@ -26,9 +26,9 @@ namespace LibDebugger public: virtual bool Attach(ProcessID pid) noexcept = 0; - virtual bool Break(CAddress addr) noexcept = 0; - virtual bool Continue() noexcept = 0; - virtual bool Detach() noexcept = 0; + virtual bool Break(CAddress addr) noexcept = 0; + virtual bool Continue() noexcept = 0; + virtual bool Detach() noexcept = 0; virtual std::unordered_map<uintptr_t, uintptr_t>& Get() { @@ -39,4 +39,4 @@ namespace LibDebugger pid_t m_pid; std::unordered_map<uintptr_t, uintptr_t> m_breakpoints; }; -} // namespace LibDebugger::POSIX +} // namespace LibDebugger diff --git a/dev/LibDebugger/POSIXMachContract.h b/dev/LibDebugger/POSIXMachContract.h index 6ff083f..1962202 100644 --- a/dev/LibDebugger/POSIXMachContract.h +++ b/dev/LibDebugger/POSIXMachContract.h @@ -12,6 +12,7 @@ /// @brief POSIX/Mach debugger. #include <LibDebugger/DebuggerContract.h> +#include <LibCompiler/Defines.h> #include <sys/ptrace.h> #include <sys/types.h> @@ -35,7 +36,7 @@ namespace LibDebugger::POSIX { /// \brief POSIXMachContract engine interface class in C++ /// \author Amlal El Mahrouss - class POSIXMachContract final : public DebuggerContract + class POSIXMachContract : public DebuggerContract { public: explicit POSIXMachContract() = default; @@ -46,7 +47,7 @@ namespace LibDebugger::POSIX POSIXMachContract(const POSIXMachContract&) = default; public: - bool Attach(ProcessID pid) noexcept override + BOOL Attach(ProcessID pid) noexcept override { #ifdef __APPLE__ if (pid == 0) @@ -69,7 +70,7 @@ namespace LibDebugger::POSIX #endif } - bool Break(CAddress addr) noexcept override + BOOL Break(CAddress addr) noexcept override { #ifdef __APPLE__ task_read_t task; @@ -100,7 +101,7 @@ namespace LibDebugger::POSIX #endif } - bool Continue() noexcept override + BOOL Continue() noexcept override { #ifdef __APPLE__ task_read_t task; @@ -122,7 +123,7 @@ namespace LibDebugger::POSIX #endif } - bool Detach() noexcept override + BOOL Detach() noexcept override { #ifdef __APPLE__ this->Continue(); diff --git a/dev/LibDebugger/src/POSIXMachContract.cc b/dev/LibDebugger/src/POSIXMachContract.cc index 4e7212c..cfce841 100644 --- a/dev/LibDebugger/src/POSIXMachContract.cc +++ b/dev/LibDebugger/src/POSIXMachContract.cc @@ -10,9 +10,9 @@ #ifndef _WIN32 -static bool kKeepRunning = false; +static BOOL kKeepRunning = false; static LibDebugger::POSIX::POSIXMachContract kDebugger; -static pid_t kPID = 0L; +static LibDebugger::ProcessID kPID = 0L; static LibDebugger::CAddress kActiveAddress = nullptr; /// @internal @@ -33,7 +33,7 @@ static void dbgi_ctrlc_handler(std::int32_t _) kKeepRunning = false; } -LIBCOMPILER_MODULE(DebuggerPOSIX) +LIBCOMPILER_MODULE(DebuggerMachPOSIX) { pfd::notify("Debugger Event", "NeKernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); diff --git a/man/dbg.7 b/man/dbg.7 deleted file mode 100644 index a32c029..0000000 --- a/man/dbg.7 +++ /dev/null @@ -1,67 +0,0 @@ -.TH DBG 1 "LibCompiler" "January 2025" "NeKernel Manual" -.SH NAME -.B dbg -\- NeKernel internal debugger - -.SH SYNOPSIS -.B dbg -[␌IOPTIONS␌R] [␌ICOMMAND␌R] - -.SH DESCRIPTION -.B dbg -is the internal debugging tool for NeKernel. It provides a low-level -interface for inspecting and manipulating running processes, -memory, and kernel state. - -.SH OPTIONS -.TP -.B -p -Attach to a process by its PID. -.TP -.B -s -Start a new debugging session. -.TP -.B -m -Enable memory inspection mode. -.TP -.B -r -Display register values. -.TP -.B -b -Set a breakpoint at a function or address. -.TP -.B -c -Continue execution after a breakpoint. -.TP -.B -h -Display help information. - -.SH USAGE EXAMPLES -.TP -.B Start a new debugging session: -.B dbg -s -.TP -.B Attach to a running process (PID 1234): -.B dbg -p 1234 -.TP -.B Inspect memory at address 0x1000: -.B dbg -m 0x1000 -.TP -.B Set a breakpoint at function "main": -.B dbg -b main -.TP -.B Display register values: -.B dbg -r - -.SH EXIT STATUS -.TP -0 Successful execution. -.TP -1 Error occurred during debugging. - -.SH SEE ALSO -.BR nekernel (7), gdb (1) - -.SH AUTHOR -Amlal El Mahrouss - @@ -4,50 +4,21 @@ \- PEF binary format linker for NeKernel .SH SYNOPSIS -.B ld64 -[␌IOPTIONS␌R] [␌IINPUT_FILES␌R] -o ␌IOUTPUT_FILE␌R +.B ld64 %OPTIONS% %INPUT_FILES% -output %OUTPUT_FILE% .SH DESCRIPTION .B ld64 is the dedicated linker for the Preferred Executable Format (PEF) used by NeKernel. -It links object files into a PEF executable suitable for execution within the NeKernel environment. .SH OPTIONS .TP -.B -o <file> +.B -output <file> Specify the output file. -.TP -.B -L <path> -Add a library search path. -.TP -.B -l <lib> -Link against the specified library. -.TP -.B -T <script> -Specify a linker script. -.TP -.B -e <symbol> -Set the entry point symbol. -.TP -.B -M -Display the memory layout of the linked binary. -.TP -.B -v -Enable verbose output. -.TP -.B -h -Show help information. .SH USAGE EXAMPLES .TP -.B Link object files into a PEF binary: -.B ld64 main.o utils.o -o app.exe -.TP -.B Link with a custom entry point: -.B ld64 -e _start main.o -o app.exe -.TP .B Generate a memory layout report: -.B ld64 -M main.o -o app.exe +.B ld64 main.o -output app.exec .SH EXIT STATUS .TP diff --git a/tools/cppdrv.cc b/tools/cppdrv.cc new file mode 100644 index 0000000..209b86e --- /dev/null +++ b/tools/cppdrv.cc @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + +------------------------------------------- */ + +/// @file cxxdrv.cc +/// @brief NE C++ frontend compiler. + +#include <LibCompiler/Defines.h> +#include <LibCompiler/ErrorID.h> +#include <LibCompiler/Version.h> +#include <iostream> +#include <cstring> +#include <vector> + +LC_IMPORT_C int CPlusPlusPreprocessorMain(int argc, char const* argv[]); + +int main(int argc, char const* argv[]) +{ + if (auto code = CPlusPlusPreprocessorMain(2, argv); + code > 0) + { + std::printf("cxxdrv: compiler exited with code %i.\n", code); + + return LIBCOMPILER_EXEC_ERROR; + } + + return LIBCOMPILER_SUCCESSS; +}
\ No newline at end of file diff --git a/tools/cppdrv.json b/tools/cppdrv.json new file mode 100644 index 0000000..9a4282c --- /dev/null +++ b/tools/cppdrv.json @@ -0,0 +1,12 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["../dev/LibCompiler", "../dev/", "../dev/LibCompiler/src/Detail"], + "sources_path": ["cppdrv.cc"], + "output_name": "cppdrv", + "compiler_flags": ["-L/usr/local/lib", "-lCompiler"], + "cpp_macros": [ + "__CXXDRV__=202504", + "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" + ] +} diff --git a/tools/cxxdrv.cc b/tools/cxxdrv.cc index e5d6334..1d59c5c 100644 --- a/tools/cxxdrv.cc +++ b/tools/cxxdrv.cc @@ -8,39 +8,17 @@ /// @brief NE C++ frontend compiler. #include <LibCompiler/Defines.h> -#include <LibCompiler/NFC/ErrorID.h> +#include <LibCompiler/ErrorID.h> #include <LibCompiler/Version.h> #include <iostream> #include <cstring> #include <vector> -LC_IMPORT_C int CPlusPlusPreprocessorMain(int argc, char const* argv[]); LC_IMPORT_C int CompilerCPlusPlusAMD64(int argc, char const* argv[]); LC_IMPORT_C int AssemblerMainAMD64(int argc, char const* argv[]); int main(int argc, char const* argv[]) { - for (size_t index_arg = 0; index_arg < argc; ++index_arg) - { - if (strstr(argv[index_arg], "--cxxdrv:h")) - { - std::printf("cxxdrv: C++ Compiler Driver.\n"); - std::printf("cxxdrv: Version: %s, Release: %s.\n", kDistVersion, kDistRelease); - std::printf("cxxdrv: Designed by Amlal El Mahrouss, Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.\n"); - std::printf("libCompiler.dylib: Designed by Amlal El Mahrouss, Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.\n"); - - return 0; - } - } - - if (auto code = CPlusPlusPreprocessorMain(2, argv); - code > 0) - { - std::printf("cxxdrv: compiler exited with code %i.", code); - - return LIBCOMPILER_EXEC_ERROR; - } - std::vector<std::string> args_list_cxx; std::vector<std::string> args_list_asm; @@ -69,7 +47,6 @@ int main(int argc, char const* argv[]) } } - for (auto& cli : args_list_cxx) { const char* arr_cli[] = {argv[0], cli.data()}; @@ -77,7 +54,7 @@ int main(int argc, char const* argv[]) if (auto code = CompilerCPlusPlusAMD64(2, arr_cli); code > 0) { - std::printf("cxxdrv: compiler exited with code %i.", code); + std::printf("cxxdrv: compiler exited with code %i.\n", code); return LIBCOMPILER_EXEC_ERROR; } @@ -90,7 +67,7 @@ int main(int argc, char const* argv[]) if (auto code = AssemblerMainAMD64(2, arr_cli); code > 0) { - std::printf("cxxdrv: assembler exited with code %i.", code); + std::printf("cxxdrv: assembler exited with code %i.\n", code); } } diff --git a/tools/dbg.cc b/tools/dbg.cc index d63f574..67b942e 100644 --- a/tools/dbg.cc +++ b/tools/dbg.cc @@ -9,11 +9,11 @@ /// @file dbg.cxx /// @brief NE debugger. -LC_IMPORT_C int DebuggerPOSIX(int argc, char const* argv[]); +LC_IMPORT_C int DebuggerMachPOSIX(int argc, char const* argv[]); /// @brief Debugger entrypoint. /// @return Status code of debugger. int main(int argc, char const* argv[]) { - return DebuggerPOSIX(argc, argv); + return DebuggerMachPOSIX(argc, argv); } |
