From e1ffe04db570e63bd3c855fc4361ed8de6b5f435 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 13 May 2025 23:48:47 +0200 Subject: feat(LibDebugger): expand KDBG's protocol, by reworking the packet structure. Signed-off-by: Amlal El Mahrouss --- dev/LibDebugger/NeKernelContract.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'dev/LibDebugger/NeKernelContract.h') diff --git a/dev/LibDebugger/NeKernelContract.h b/dev/LibDebugger/NeKernelContract.h index 8e54ab2..e645db8 100644 --- a/dev/LibDebugger/NeKernelContract.h +++ b/dev/LibDebugger/NeKernelContract.h @@ -29,30 +29,35 @@ namespace LibDebugger::NeKernel { class NeKernelContract; namespace Detail { - class NeKernelPortHeader; + class NeKernelDebugHeader; inline constexpr size_t kDebugTypeLen = 256U; typedef char rt_debug_type[kDebugTypeLen]; - class NeKernelPortHeader final { + class NeKernelDebugHeader final { public: - int16_t fPort; - int16_t fPortBsy; + int16_t fPort; + int16_t fPortKind; + rt_debug_type fPortBlob; }; } // namespace Detail class NeKernelContract : public DebuggerContract { public: NeKernelContract(); - virtual ~NeKernelContract(); + ~NeKernelContract() override; + + public: + NeKernelContract& operator=(const NeKernelContract&) = default; + NeKernelContract(const NeKernelContract&) = default; // Override additional methods from DebuggerContract - virtual bool Attach(std::string path, std::string argv, ProcessID& pid) noexcept override; - virtual bool Breakpoint(std::string symbol) noexcept override; - virtual bool Break() noexcept override; - virtual bool Continue() noexcept override; - virtual bool Detach() noexcept override; + bool Attach(std::string path, std::string argv, ProcessID& pid) noexcept override; + bool Breakpoint(std::string symbol) noexcept override; + bool Break() noexcept override; + bool Continue() noexcept override; + bool Detach() noexcept override; private: std::string m_ip_address; -- cgit v1.2.3 From bdab776c880e4f4868332c451b028684f54ecd5d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 09:57:27 +0200 Subject: feat(kdbg): add m_socket field, to hold its file descriptor. Signed-off-by: Amlal El Mahrouss --- dev/LibDebugger/NeKernelContract.h | 1 + 1 file changed, 1 insertion(+) (limited to 'dev/LibDebugger/NeKernelContract.h') diff --git a/dev/LibDebugger/NeKernelContract.h b/dev/LibDebugger/NeKernelContract.h index e645db8..0245638 100644 --- a/dev/LibDebugger/NeKernelContract.h +++ b/dev/LibDebugger/NeKernelContract.h @@ -62,6 +62,7 @@ class NeKernelContract : public DebuggerContract { private: std::string m_ip_address; std::string m_port; + int64_t m_socket{0}; }; } // namespace LibDebugger::NeKernel -- cgit v1.2.3 From 94ceccd5acda2fd035eb55235126b944b0915576 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 14:27:43 +0200 Subject: dev(kdbg): Working on NeKernel Debugger. how: - Load vmkrnl.efi. - Keep track of IP, Stack, and debugging information related to the kernel. - Make use of breakpoints and provide lldb grade experience. Signed-off-by: Amlal El Mahrouss --- .gitignore | 1 + compile_flags.txt | 3 +- dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc | 4 +- dev/LibDebugger/CommonCLI.inl | 18 +++++ dev/LibDebugger/NeKernelContract.h | 4 + dev/LibDebugger/POSIXMachContract.h | 2 +- dev/LibDebugger/src/NeKernelContract.cc | 34 +++++++++ dev/LibDebugger/src/NeKernelContractCLI.cc | 35 +++++++++ dev/LibDebugger/src/POSIXMachContract.cc | 102 -------------------------- dev/LibDebugger/src/POSIXMachContractCLI.cc | 95 ++++++++++++++++++++++++ docs/drawio/LIBCOMPILER_DESIGN.drawio | 0 docs/drawio/LIBDEBUGGER_DESIGN.drawio | 47 ++++++++++++ ld-nekernel.json | 17 +++++ ld-osx.json | 1 + man/cxxdrv.7 | 34 +++++++++ man/ld64.7 | 8 +- 16 files changed, 296 insertions(+), 109 deletions(-) create mode 100644 dev/LibDebugger/CommonCLI.inl create mode 100644 dev/LibDebugger/src/NeKernelContract.cc create mode 100644 dev/LibDebugger/src/NeKernelContractCLI.cc delete mode 100644 dev/LibDebugger/src/POSIXMachContract.cc create mode 100644 dev/LibDebugger/src/POSIXMachContractCLI.cc create mode 100644 docs/drawio/LIBCOMPILER_DESIGN.drawio create mode 100644 docs/drawio/LIBDEBUGGER_DESIGN.drawio create mode 100644 ld-nekernel.json create mode 100644 man/cxxdrv.7 (limited to 'dev/LibDebugger/NeKernelContract.h') diff --git a/.gitignore b/.gitignore index 2b6cb14..c3f92c5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ tools/cxxdrv tools/dbg tools/cppdrv +tools/kdbg *.pp *.masm diff --git a/compile_flags.txt b/compile_flags.txt index 6c24593..5537eca 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -5,4 +5,5 @@ -Isdk/ -I./ -DLC_USE_STRUCTS --xc++ \ No newline at end of file +-xc++ +-DLD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc index ace6d17..051529d 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc @@ -899,7 +899,9 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) { return kExitNO; } - kFactory.Compile(argv_i, kMachine); + if (kFactory.Compile(argv_i, kMachine) != kExitOK) { + Detail::print_error("Compiler error, see log for details.\n", "cxxdrv"); + } } return kExitNO; diff --git a/dev/LibDebugger/CommonCLI.inl b/dev/LibDebugger/CommonCLI.inl new file mode 100644 index 0000000..0660bb3 --- /dev/null +++ b/dev/LibDebugger/CommonCLI.inl @@ -0,0 +1,18 @@ + +static BOOL kKeepRunning = false; + +#ifdef LD_NEKERNEL_DEBUGGER +static LibDebugger::NeKernel::NeKernelContract kKernelDebugger; +#else +static LibDebugger::POSIX::POSIXMachContract kDebugger; +#endif + +static LibDebugger::ProcessID kPID = 0L; +static LibDebugger::CAddress kActiveAddress = nullptr; +static std::string kPath = ""; + +#define kBlank "\e[0;30m" +#define kRed "\e[0;31m" +#define kWhite "\e[0;97m" + +#define kStdOut (std::cout << kRed << "dbg: " << kWhite) \ No newline at end of file diff --git a/dev/LibDebugger/NeKernelContract.h b/dev/LibDebugger/NeKernelContract.h index 0245638..b63dcb9 100644 --- a/dev/LibDebugger/NeKernelContract.h +++ b/dev/LibDebugger/NeKernelContract.h @@ -6,6 +6,8 @@ #ifndef LD_NEKERNEL_CONTRACT_H #define LD_NEKERNEL_CONTRACT_H +#ifdef LD_NEKERNEL_DEBUGGER + #include #include @@ -66,4 +68,6 @@ class NeKernelContract : public DebuggerContract { }; } // namespace LibDebugger::NeKernel +#endif // ifdef LD_NEKERNEL_DEBUGGER + #endif // LD_NEKERNEL_CONTRACT_H \ No newline at end of file diff --git a/dev/LibDebugger/POSIXMachContract.h b/dev/LibDebugger/POSIXMachContract.h index 5904cd2..1d7561a 100644 --- a/dev/LibDebugger/POSIXMachContract.h +++ b/dev/LibDebugger/POSIXMachContract.h @@ -4,7 +4,7 @@ #pragma once -#ifdef __APPLE__ +#ifdef LD_MACH_DEBUGGER /// @file POSIXMachContract.h /// @brief POSIX Mach debugger. diff --git a/dev/LibDebugger/src/NeKernelContract.cc b/dev/LibDebugger/src/NeKernelContract.cc new file mode 100644 index 0000000..e653d12 --- /dev/null +++ b/dev/LibDebugger/src/NeKernelContract.cc @@ -0,0 +1,34 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: NeKernelContract.cc + Purpose: NeKernel Debugger +*/ + +#ifdef LD_NEKERNEL_DEBUGGER + +#include +#include +#include + +#include +#include +#include + +using namespace LibDebugger::NeKernel; + +NeKernelContract::NeKernelContract() = default; + +NeKernelContract::~NeKernelContract() = default; + +bool NeKernelContract::Attach(std::string path, std::string argv, ProcessID& pid) noexcept { return false; } + +bool NeKernelContract::Breakpoint(std::string symbol) noexcept { return false; } + +bool NeKernelContract::Break() noexcept { return false; } + +bool NeKernelContract::Continue() noexcept { return false; } + +bool NeKernelContract::Detach() noexcept { return false; } + +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc new file mode 100644 index 0000000..1f05ff2 --- /dev/null +++ b/dev/LibDebugger/src/NeKernelContractCLI.cc @@ -0,0 +1,35 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: NeKernelContract.cc + Purpose: NeKernel Debugger CLI. +*/ + +#ifdef LD_NEKERNEL_DEBUGGER + +#include +#include +#include + +#include +#include +#include + +#include + +using namespace LibDebugger::NeKernel; + +LIBCOMPILER_MODULE(DebuggerNeKernel) { + pfd::notify("Debugger Event", + "Kernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kStdOut << "[+] Kernel image set to: " << kPath << "\n"; + } + + + return EXIT_SUCCESS; +} + +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibDebugger/src/POSIXMachContract.cc b/dev/LibDebugger/src/POSIXMachContract.cc deleted file mode 100644 index 2753e9a..0000000 --- a/dev/LibDebugger/src/POSIXMachContract.cc +++ /dev/null @@ -1,102 +0,0 @@ -/*** - (C) 2025 Amlal El Mahrouss - */ - -#ifdef __APPLE__ - -#include -#include -#include -#include -#include -#include - -static BOOL kKeepRunning = false; -static LibDebugger::POSIX::POSIXMachContract kDebugger; -static LibDebugger::ProcessID kPID = 0L; -static LibDebugger::CAddress kActiveAddress = nullptr; -static std::string kPath = ""; - -#define kBlank "\e[0;30m" -#define kRed "\e[0;31m" -#define kWhite "\e[0;97m" - -#define kStdOut (std::cout << kRed << "dbg: " << kWhite) - -/// @internal -/// @brief Handles CTRL-C signal on debugger. -static void dbgi_ctrlc_handler(std::int32_t _) { - if (!kPID) { - return; - } - - auto list = kDebugger.Get(); - - kDebugger.Break(); - - pfd::notify("Debugger Event", "Breakpoint hit!"); - - kKeepRunning = false; -} - -LIBCOMPILER_MODULE(DebuggerMachPOSIX) { - pfd::notify("Debugger Event", - "Userland Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); - - if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { - kPath = argv[2]; - kDebugger.SetPath(kPath); - - kStdOut << "[+] Path set to: " << kPath << "\n"; - } - - ::signal(SIGINT, dbgi_ctrlc_handler); - - while (YES) { - if (kKeepRunning) { - continue; - } - - std::string cmd; - std::getline(std::cin, cmd); - - if (cmd == "c" || cmd == "cont" || cmd == "continue") { - if (kDebugger.Continue()) { - kKeepRunning = true; - - kStdOut << "[+] Continuing...\n"; - - pfd::notify("Debugger Event", "Continuing..."); - } - } - - if (cmd == "d" || cmd == "detach") kDebugger.Detach(); - - if (cmd == "start") { - kStdOut << "[?] Enter a argument to use: "; - std::getline(std::cin, cmd); - - kDebugger.Attach(kPath, cmd, kPID); - } - - if (cmd == "exit") { - if (kPID > 0) kDebugger.Detach(); - - break; - } - - if (cmd == "break" || cmd == "b") { - kStdOut << "[?] Enter a symbol to break on: "; - - std::getline(std::cin, cmd); - - if (kDebugger.Breakpoint(cmd)) { - pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); - } - } - } - - return EXIT_SUCCESS; -} - -#endif \ No newline at end of file diff --git a/dev/LibDebugger/src/POSIXMachContractCLI.cc b/dev/LibDebugger/src/POSIXMachContractCLI.cc new file mode 100644 index 0000000..90cebc3 --- /dev/null +++ b/dev/LibDebugger/src/POSIXMachContractCLI.cc @@ -0,0 +1,95 @@ +/*** + LibDebugger + (C) 2025 Amlal El Mahrouss + File: POSIXMachContract.cc + Purpose: OS X/Darwin Debugger +*/ + +#ifdef LD_MACH_DEBUGGER + +#include +#include +#include +#include +#include +#include + +#include + +/// @internal +/// @brief Handles CTRL-C signal on debugger. +static void dbgi_ctrlc_handler(std::int32_t _) { + if (!kPID) { + return; + } + + auto list = kDebugger.Get(); + + kDebugger.Break(); + + pfd::notify("Debugger Event", "Breakpoint hit!"); + + kKeepRunning = false; +} + +LIBCOMPILER_MODULE(DebuggerMachPOSIX) { + pfd::notify("Debugger Event", + "Userland Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kDebugger.SetPath(kPath); + + kStdOut << "[+] Image set to: " << kPath << "\n"; + } + + ::signal(SIGINT, dbgi_ctrlc_handler); + + while (YES) { + if (kKeepRunning) { + continue; + } + + std::string cmd; + std::getline(std::cin, cmd); + + if (cmd == "c" || cmd == "cont" || cmd == "continue") { + if (kDebugger.Continue()) { + kKeepRunning = true; + + kStdOut << "[+] Continuing...\n"; + + pfd::notify("Debugger Event", "Continuing..."); + } + } + + if (cmd == "d" || cmd == "detach") kDebugger.Detach(); + + if (cmd == "start") { + kStdOut << "[?] Enter a argument to use: "; + std::getline(std::cin, cmd); + + kDebugger.Attach(kPath, cmd, kPID); + } + + if (cmd == "exit") { + if (kPID > 0) kDebugger.Detach(); + + break; + } + + if (cmd == "break" || cmd == "b") { + kStdOut << "[?] Enter a symbol to break on: "; + + std::getline(std::cin, cmd); + + if (kDebugger.Breakpoint(cmd)) { + pfd::notify("Debugger Event", "Add Breakpoint at: " + cmd); + } + } + } + + return EXIT_SUCCESS; +} + +#endif \ No newline at end of file diff --git a/docs/drawio/LIBCOMPILER_DESIGN.drawio b/docs/drawio/LIBCOMPILER_DESIGN.drawio new file mode 100644 index 0000000..e69de29 diff --git a/docs/drawio/LIBDEBUGGER_DESIGN.drawio b/docs/drawio/LIBDEBUGGER_DESIGN.drawio new file mode 100644 index 0000000..0b3802d --- /dev/null +++ b/docs/drawio/LIBDEBUGGER_DESIGN.drawio @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ld-nekernel.json b/ld-nekernel.json new file mode 100644 index 0000000..ab7cabb --- /dev/null +++ b/ld-nekernel.json @@ -0,0 +1,17 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": [ + "./dev/LibDebugger", + "./dev" + ], + "sources_path": ["dev/LibDebugger/src/*.cc"], + "output_name": "/usr/local/lib/libDebugger.dylib", + "compiler_flags": ["-fPIC", "-shared"], + "cpp_macros": [ + "__LIBCOMPILER__=202401", + "LC_USE_STRUCTS=1", + "LD_NEKERNEL_DEBUGGER", + "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" + ] +} diff --git a/ld-osx.json b/ld-osx.json index c26b060..6a0eb5b 100644 --- a/ld-osx.json +++ b/ld-osx.json @@ -11,6 +11,7 @@ "cpp_macros": [ "__LIBCOMPILER__=202401", "LC_USE_STRUCTS=1", + "LD_MACH_DEBUGGER", "kDistReleaseBranch=$(git rev-parse --abbrev-ref HEAD)-$(uuidgen)" ] } diff --git a/man/cxxdrv.7 b/man/cxxdrv.7 new file mode 100644 index 0000000..20e28fd --- /dev/null +++ b/man/cxxdrv.7 @@ -0,0 +1,34 @@ +.TH LD64 1 "LibCompiler" "January 2025" "NeKernel Manual" +.SH NAME +.B cxxdrv +\- AE 64-bit C++ compiler for NeKernel + +.SH SYNOPSIS +.B cxxdrv %OPTIONS% %INPUT_FILES% + +.SH DESCRIPTION +.B cxxdrv +is the dedicated compiler used by NeKernel, it compiles to the AE object format. + +.SH OPTIONS +.TP +.B -output +Specify the output file. + +.SH USAGE EXAMPLES +.TP +.B Generate object file from the main.cpp unit. +.B cxxdrv main.cpp + +.SH EXIT STATUS +.TP +0 Successful compilation. +.TP +1 Error encountered during compilation of the C++ unit(s). + +.SH SEE ALSO +.BR cxxdrv (7), asm (7) + +.SH AUTHOR +Amlal El Mahrouss + diff --git a/man/ld64.7 b/man/ld64.7 index 56e192f..338732f 100644 --- a/man/ld64.7 +++ b/man/ld64.7 @@ -1,7 +1,7 @@ .TH LD64 1 "LibCompiler" "January 2025" "NeKernel Manual" .SH NAME .B ld64 -\- PEF binary format linker for NeKernel +\- PEF 64-bit linker for NeKernel .SH SYNOPSIS .B ld64 %OPTIONS% %INPUT_FILES% -output %OUTPUT_FILE% @@ -17,8 +17,8 @@ Specify the output file. .SH USAGE EXAMPLES .TP -.B Generate a memory layout report: -.B ld64 main.o -output app.exec +.B Generate an executable file from an AE object. +.B ld64 main.obj -output app.exec .SH EXIT STATUS .TP @@ -27,7 +27,7 @@ Specify the output file. 1 Error encountered during linking. .SH SEE ALSO -.BR nekernel (7), asm (1) +.BR cxxdrv (7), asm (1) .SH AUTHOR Amlal El Mahrouss -- cgit v1.2.3 From 9f031e69aace747feb5bac78eccb9a1d5df81f74 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 17:49:19 +0200 Subject: feat(cc): Rename Parser.h to CompilerFrontend.h, refactor codebase accordingly. why: - To make its intent clearer, and avoid future confusions. also: - Ran ./format.sh to the codebase. Signed-off-by: Amlal El Mahrouss --- dev/LibCompiler/CompilerFrontend.h | 149 +++++++++++++++++++++ dev/LibCompiler/Detail/AsmUtils.h | 2 +- dev/LibCompiler/Detail/ClUtils.h | 2 +- dev/LibCompiler/Parser.h | 149 --------------------- dev/LibCompiler/src/Assembler32x0.cc | 2 +- dev/LibCompiler/src/Assembler64x0.cc | 2 +- dev/LibCompiler/src/AssemblerAMD64.cc | 2 +- dev/LibCompiler/src/AssemblerARM64.cc | 2 +- dev/LibCompiler/src/AssemblerPowerPC.cc | 2 +- dev/LibCompiler/src/CCompiler64x0.cc | 2 +- dev/LibCompiler/src/CCompilerARM64.cc | 2 +- dev/LibCompiler/src/CCompilerPower64.cc | 2 +- dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc | 2 +- .../src/CPlusPlusCompilerPreProcessor.cc | 2 +- dev/LibDebugger/CommonCLI.inl | 8 +- dev/LibDebugger/NeKernelContract.h | 2 +- dev/LibDebugger/src/NeKernelContract.cc | 22 ++- dev/LibDebugger/src/NeKernelContractCLI.cc | 21 ++- tests/example.cc | 6 +- 19 files changed, 195 insertions(+), 186 deletions(-) create mode 100644 dev/LibCompiler/CompilerFrontend.h delete mode 100644 dev/LibCompiler/Parser.h (limited to 'dev/LibDebugger/NeKernelContract.h') diff --git a/dev/LibCompiler/CompilerFrontend.h b/dev/LibCompiler/CompilerFrontend.h new file mode 100644 index 0000000..858473b --- /dev/null +++ b/dev/LibCompiler/CompilerFrontend.h @@ -0,0 +1,149 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved + +------------------------------------------- */ + +#pragma once + +#include + +namespace LibCompiler { +inline auto kInvalidFrontend = "NA"; + +/// @brief Compiler backend, implements a frontend, such as C, C++... +/// See Toolchain, for some examples. +class ICompilerFrontend { + public: + explicit ICompilerFrontend() = default; + virtual ~ICompilerFrontend() = default; + + LIBCOMPILER_COPY_DEFAULT(ICompilerFrontend); + + // NOTE: cast this to your user defined ast. + typedef void* AstType; + + //! @brief Compile a syntax tree ouf of the text. + //! Also takes the source file name for metadata. + + virtual bool Compile(std::string text, std::string file) = 0; + + //! @brief What language are we dealing with? + virtual const char* Language() { return kInvalidFrontend; } + + virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; } +}; + +struct SyntaxLeafList; +struct SyntaxLeafList; +struct CompilerKeyword; + +/// we want to do that because to separate keywords. +enum KeywordKind { + kKeywordKindNamespace, + kKeywordKindFunctionStart, + kKeywordKindFunctionEnd, + kKeywordKindVariable, + kKeywordKindVariablePtr, + kKeywordKindType, + kKeywordKindTypePtr, + kKeywordKindExpressionBegin, + kKeywordKindExpressionEnd, + kKeywordKindArgSeparator, + kKeywordKindBodyStart, + kKeywordKindBodyEnd, + kKeywordKindClass, + kKeywordKindPtrAccess, + kKeywordKindAccess, + kKeywordKindIf, + kKeywordKindElse, + kKeywordKindElseIf, + kKeywordKindVariableAssign, + kKeywordKindVariableDec, + kKeywordKindVariableInc, + kKeywordKindConstant, + kKeywordKindTypedef, + kKeywordKindEndInstr, + kKeywordKindSpecifier, + kKeywordKindInvalid, + kKeywordKindReturn, + kKeywordKindCommentInline, + kKeywordKindCommentMultiLineStart, + kKeywordKindCommentMultiLineEnd, + kKeywordKindEq, + kKeywordKindNotEq, + kKeywordKindGreaterEq, + kKeywordKindLessEq, + kKeywordKindPtr, +}; + +/// \brief Compiler keyword information struct. +struct CompilerKeyword { + std::string keyword_name; + KeywordKind keyword_kind = kKeywordKindInvalid; +}; +struct SyntaxLeafList final { + struct SyntaxLeaf final { + Int32 fUserType; +#ifdef LC_USE_STRUCTS + CompilerKeyword fUserData; +#else + std::string fUserData; +#endif + + SyntaxLeaf() = default; + + std::string fUserValue; + struct SyntaxLeaf* fNext; + }; + + std::vector fLeafList; + SizeType fNumLeafs; + + size_t SizeOf() { return fNumLeafs; } + std::vector& Get() { return fLeafList; } + SyntaxLeaf& At(size_t 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. +inline bool find_word(std::string haystack, std::string needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == std::string::npos) return false; + + // declare lambda + auto not_part_of_word = [&](int index) { + if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; + + if (index <= 0 || index >= haystack.size()) return true; + + return false; + }; + + return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); +} + +/// find a word within strict conditions and returns a range of it. +/// \param haystack +/// \param needle +/// \return position of needle. +inline std::size_t find_word_range(std::string haystack, std::string needle) noexcept { + auto index = haystack.find(needle); + + // check for needle validity. + if (index == std::string::npos) return false; + + if (!isalnum((haystack[index + needle.size() + 1])) && + !isdigit(haystack[index + needle.size() + 1]) && + !isalnum((haystack[index - needle.size() - 1])) && + !isdigit(haystack[index - needle.size() - 1])) { + return index; + } + + return std::string::npos; +} +} // namespace LibCompiler diff --git a/dev/LibCompiler/Detail/AsmUtils.h b/dev/LibCompiler/Detail/AsmUtils.h index 559df5f..77805c1 100644 --- a/dev/LibCompiler/Detail/AsmUtils.h +++ b/dev/LibCompiler/Detail/AsmUtils.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include diff --git a/dev/LibCompiler/Detail/ClUtils.h b/dev/LibCompiler/Detail/ClUtils.h index f47101a..a809cdf 100644 --- a/dev/LibCompiler/Detail/ClUtils.h +++ b/dev/LibCompiler/Detail/ClUtils.h @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #define kZero64Section ".zero64" diff --git a/dev/LibCompiler/Parser.h b/dev/LibCompiler/Parser.h deleted file mode 100644 index 6baff7e..0000000 --- a/dev/LibCompiler/Parser.h +++ /dev/null @@ -1,149 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025 Amlal EL Mahrous, all rights reserved - -------------------------------------------- */ - -#pragma once - -#include - -namespace LibCompiler { -inline auto kInvalidFrontend = "NA"; - -/// @brief Compiler backend, implements a frontend, such as C, C++... -/// See Toolchain, for some examples. -class ICompilerFrontend { - public: - explicit ICompilerFrontend() = default; - virtual ~ICompilerFrontend() = default; - - LIBCOMPILER_COPY_DEFAULT(ICompilerFrontend); - - // NOTE: cast this to your user defined ast. - typedef void* AstType; - - //! @brief Compile a syntax tree ouf of the text. - //! Also takes the source file name for metadata. - - virtual bool Compile(std::string text, std::string file) = 0; - - //! @brief What language are we dealing with? - virtual const char* Language() { return kInvalidFrontend; } - - virtual bool IsValid() { return strcmp(this->Language(), kInvalidFrontend) > 0; } -}; - -struct SyntaxLeafList; -struct SyntaxLeafList; -struct CompilerKeyword; - -/// we want to do that because to separate keywords. -enum KeywordKind { - kKeywordKindNamespace, - kKeywordKindFunctionStart, - kKeywordKindFunctionEnd, - kKeywordKindVariable, - kKeywordKindVariablePtr, - kKeywordKindType, - kKeywordKindTypePtr, - kKeywordKindExpressionBegin, - kKeywordKindExpressionEnd, - kKeywordKindArgSeparator, - kKeywordKindBodyStart, - kKeywordKindBodyEnd, - kKeywordKindClass, - kKeywordKindPtrAccess, - kKeywordKindAccess, - kKeywordKindIf, - kKeywordKindElse, - kKeywordKindElseIf, - kKeywordKindVariableAssign, - kKeywordKindVariableDec, - kKeywordKindVariableInc, - kKeywordKindConstant, - kKeywordKindTypedef, - kKeywordKindEndInstr, - kKeywordKindSpecifier, - kKeywordKindInvalid, - kKeywordKindReturn, - kKeywordKindCommentInline, - kKeywordKindCommentMultiLineStart, - kKeywordKindCommentMultiLineEnd, - kKeywordKindEq, - kKeywordKindNotEq, - kKeywordKindGreaterEq, - kKeywordKindLessEq, - kKeywordKindPtr, -}; - -/// \brief Compiler keyword information struct. -struct CompilerKeyword { - std::string keyword_name; - KeywordKind keyword_kind = kKeywordKindInvalid; -}; -struct SyntaxLeafList final { - struct SyntaxLeaf final { - Int32 fUserType; -#ifdef LC_USE_STRUCTS - CompilerKeyword fUserData; -#else - std::string fUserData; -#endif - - SyntaxLeaf() = default; - - std::string fUserValue; - struct SyntaxLeaf* fNext; - }; - - std::vector fLeafList; - SizeType fNumLeafs; - - size_t SizeOf() { return fNumLeafs; } - std::vector& Get() { return fLeafList; } - SyntaxLeaf& At(size_t 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. -inline bool find_word(std::string haystack, std::string needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == std::string::npos) return false; - - // declare lambda - auto not_part_of_word = [&](int index) { - if (std::isspace(haystack[index]) || std::ispunct(haystack[index])) return true; - - if (index <= 0 || index >= haystack.size()) return true; - - return false; - }; - - return not_part_of_word(index - 1) && not_part_of_word(index + needle.size()); -} - -/// find a word within strict conditions and returns a range of it. -/// \param haystack -/// \param needle -/// \return position of needle. -inline std::size_t find_word_range(std::string haystack, std::string needle) noexcept { - auto index = haystack.find(needle); - - // check for needle validity. - if (index == std::string::npos) return false; - - if (!isalnum((haystack[index + needle.size() + 1])) && - !isdigit(haystack[index + needle.size() + 1]) && - !isalnum((haystack[index - needle.size() - 1])) && - !isdigit(haystack[index - needle.size() - 1])) { - return index; - } - - return false; -} -} // namespace LibCompiler diff --git a/dev/LibCompiler/src/Assembler32x0.cc b/dev/LibCompiler/src/Assembler32x0.cc index ac24946..44850f6 100644 --- a/dev/LibCompiler/src/Assembler32x0.cc +++ b/dev/LibCompiler/src/Assembler32x0.cc @@ -21,8 +21,8 @@ #include #include +#include #include -#include ///////////////////// diff --git a/dev/LibCompiler/src/Assembler64x0.cc b/dev/LibCompiler/src/Assembler64x0.cc index 8483e9e..a7c3efc 100644 --- a/dev/LibCompiler/src/Assembler64x0.cc +++ b/dev/LibCompiler/src/Assembler64x0.cc @@ -21,9 +21,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/AssemblerAMD64.cc b/dev/LibCompiler/src/AssemblerAMD64.cc index 5e9a7cd..3fdb197 100644 --- a/dev/LibCompiler/src/AssemblerAMD64.cc +++ b/dev/LibCompiler/src/AssemblerAMD64.cc @@ -28,8 +28,8 @@ #include #include +#include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/AssemblerARM64.cc b/dev/LibCompiler/src/AssemblerARM64.cc index 8686edb..c8b66f7 100644 --- a/dev/LibCompiler/src/AssemblerARM64.cc +++ b/dev/LibCompiler/src/AssemblerARM64.cc @@ -19,10 +19,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/AssemblerPowerPC.cc b/dev/LibCompiler/src/AssemblerPowerPC.cc index f2c3be3..a438aed 100644 --- a/dev/LibCompiler/src/AssemblerPowerPC.cc +++ b/dev/LibCompiler/src/AssemblerPowerPC.cc @@ -19,10 +19,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/CCompiler64x0.cc b/dev/LibCompiler/src/CCompiler64x0.cc index 79d32ce..e43e16b 100644 --- a/dev/LibCompiler/src/CCompiler64x0.cc +++ b/dev/LibCompiler/src/CCompiler64x0.cc @@ -11,8 +11,8 @@ /// TODO: none #include +#include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/CCompilerARM64.cc b/dev/LibCompiler/src/CCompilerARM64.cc index a5ddf43..b60ef4f 100644 --- a/dev/LibCompiler/src/CCompilerARM64.cc +++ b/dev/LibCompiler/src/CCompilerARM64.cc @@ -11,8 +11,8 @@ /// TODO: none #include +#include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/CCompilerPower64.cc b/dev/LibCompiler/src/CCompilerPower64.cc index f2eba43..30a1ab3 100644 --- a/dev/LibCompiler/src/CCompilerPower64.cc +++ b/dev/LibCompiler/src/CCompilerPower64.cc @@ -8,8 +8,8 @@ */ #include +#include #include -#include #include #include #include diff --git a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc index 051529d..92bf9ad 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc @@ -17,8 +17,8 @@ // extern_segment, @autodelete { ... }, fn foo() -> auto { ... } #include +#include #include -#include #include #include diff --git a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc b/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc index 5d035da..9981f37 100644 --- a/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc +++ b/dev/LibCompiler/src/CPlusPlusCompilerPreProcessor.cc @@ -9,8 +9,8 @@ /// BUGS: 0 +#include #include -#include #include #include #include diff --git a/dev/LibDebugger/CommonCLI.inl b/dev/LibDebugger/CommonCLI.inl index 0660bb3..c917295 100644 --- a/dev/LibDebugger/CommonCLI.inl +++ b/dev/LibDebugger/CommonCLI.inl @@ -1,5 +1,5 @@ -static BOOL kKeepRunning = false; +static BOOL kKeepRunning = false; #ifdef LD_NEKERNEL_DEBUGGER static LibDebugger::NeKernel::NeKernelContract kKernelDebugger; @@ -7,9 +7,9 @@ static LibDebugger::NeKernel::NeKernelContract kKernelDebugger; static LibDebugger::POSIX::POSIXMachContract kDebugger; #endif -static LibDebugger::ProcessID kPID = 0L; -static LibDebugger::CAddress kActiveAddress = nullptr; -static std::string kPath = ""; +static LibDebugger::ProcessID kPID = 0L; +static LibDebugger::CAddress kActiveAddress = nullptr; +static std::string kPath = ""; #define kBlank "\e[0;30m" #define kRed "\e[0;31m" diff --git a/dev/LibDebugger/NeKernelContract.h b/dev/LibDebugger/NeKernelContract.h index b63dcb9..78140e7 100644 --- a/dev/LibDebugger/NeKernelContract.h +++ b/dev/LibDebugger/NeKernelContract.h @@ -68,6 +68,6 @@ class NeKernelContract : public DebuggerContract { }; } // namespace LibDebugger::NeKernel -#endif // ifdef LD_NEKERNEL_DEBUGGER +#endif // ifdef LD_NEKERNEL_DEBUGGER #endif // LD_NEKERNEL_CONTRACT_H \ No newline at end of file diff --git a/dev/LibDebugger/src/NeKernelContract.cc b/dev/LibDebugger/src/NeKernelContract.cc index e653d12..33c0c48 100644 --- a/dev/LibDebugger/src/NeKernelContract.cc +++ b/dev/LibDebugger/src/NeKernelContract.cc @@ -21,14 +21,24 @@ NeKernelContract::NeKernelContract() = default; NeKernelContract::~NeKernelContract() = default; -bool NeKernelContract::Attach(std::string path, std::string argv, ProcessID& pid) noexcept { return false; } +bool NeKernelContract::Attach(std::string path, std::string argv, ProcessID& pid) noexcept { + return false; +} -bool NeKernelContract::Breakpoint(std::string symbol) noexcept { return false; } +bool NeKernelContract::Breakpoint(std::string symbol) noexcept { + return false; +} -bool NeKernelContract::Break() noexcept { return false; } +bool NeKernelContract::Break() noexcept { + return false; +} -bool NeKernelContract::Continue() noexcept { return false; } +bool NeKernelContract::Continue() noexcept { + return false; +} -bool NeKernelContract::Detach() noexcept { return false; } +bool NeKernelContract::Detach() noexcept { + return false; +} -#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc index 1f05ff2..dddefda 100644 --- a/dev/LibDebugger/src/NeKernelContractCLI.cc +++ b/dev/LibDebugger/src/NeKernelContractCLI.cc @@ -20,16 +20,15 @@ using namespace LibDebugger::NeKernel; LIBCOMPILER_MODULE(DebuggerNeKernel) { - pfd::notify("Debugger Event", - "Kernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); - - if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { - kPath = argv[2]; - kStdOut << "[+] Kernel image set to: " << kPath << "\n"; - } - - - return EXIT_SUCCESS; + pfd::notify("Debugger Event", + "Kernel Debugger\n(C) 2025 Amlal El Mahrouss, all rights reserved."); + + if (argc >= 3 && std::string(argv[1]) == "-p" && argv[2] != nullptr) { + kPath = argv[2]; + kStdOut << "[+] Kernel image set to: " << kPath << "\n"; + } + + return EXIT_SUCCESS; } -#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file +#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file diff --git a/tests/example.cc b/tests/example.cc index 2e2a364..9ee2a30 100644 --- a/tests/example.cc +++ b/tests/example.cc @@ -1,5 +1,5 @@ -#define AppMain __ImageStart -#warning TestCase #1 +#define main __ImageStart +#warning test macro warning #1 int bar() { int yyy = 100; @@ -11,6 +11,6 @@ int foo() { return bar(); } -int AppMain() { +int main() { return foo(); } -- cgit v1.2.3