diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | compile_flags.txt | 3 | ||||
| -rw-r--r-- | dev/LibCompiler/src/CPlusPlusCompilerAMD64.cc | 4 | ||||
| -rw-r--r-- | dev/LibDebugger/CommonCLI.inl | 18 | ||||
| -rw-r--r-- | dev/LibDebugger/NeKernelContract.h | 4 | ||||
| -rw-r--r-- | dev/LibDebugger/POSIXMachContract.h | 2 | ||||
| -rw-r--r-- | dev/LibDebugger/src/NeKernelContract.cc | 34 | ||||
| -rw-r--r-- | dev/LibDebugger/src/NeKernelContractCLI.cc | 35 | ||||
| -rw-r--r-- | dev/LibDebugger/src/POSIXMachContractCLI.cc (renamed from dev/LibDebugger/src/POSIXMachContract.cc) | 21 | ||||
| -rw-r--r-- | docs/drawio/LIBCOMPILER_DESIGN.drawio | 0 | ||||
| -rw-r--r-- | docs/drawio/LIBDEBUGGER_DESIGN.drawio | 47 | ||||
| -rw-r--r-- | ld-nekernel.json | 17 | ||||
| -rw-r--r-- | ld-osx.json | 1 | ||||
| -rw-r--r-- | man/cxxdrv.7 | 34 | ||||
| -rw-r--r-- | man/ld64.7 | 8 |
15 files changed, 208 insertions, 21 deletions
@@ -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 <LibDebugger/DebuggerContract.h> #include <sys/socket.h> @@ -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 <LibCompiler/Defines.h> +#include <LibDebugger/NeKernelContract.h> +#include <Vendor/Dialogs.h> + +#include <cstdint> +#include <iostream> +#include <string> + +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 <LibCompiler/Defines.h> +#include <LibDebugger/NeKernelContract.h> +#include <Vendor/Dialogs.h> + +#include <cstdint> +#include <iostream> +#include <string> + +#include <LibDebugger/CommonCLI.inl> + +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/POSIXMachContractCLI.cc index 2753e9a..90cebc3 100644 --- a/dev/LibDebugger/src/POSIXMachContract.cc +++ b/dev/LibDebugger/src/POSIXMachContractCLI.cc @@ -1,8 +1,11 @@ /*** + LibDebugger (C) 2025 Amlal El Mahrouss - */ + File: POSIXMachContract.cc + Purpose: OS X/Darwin Debugger +*/ -#ifdef __APPLE__ +#ifdef LD_MACH_DEBUGGER #include <LibCompiler/Defines.h> #include <LibDebugger/POSIXMachContract.h> @@ -11,17 +14,7 @@ #include <iostream> #include <string> -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) +#include <LibDebugger/CommonCLI.inl> /// @internal /// @brief Handles CTRL-C signal on debugger. @@ -47,7 +40,7 @@ LIBCOMPILER_MODULE(DebuggerMachPOSIX) { kPath = argv[2]; kDebugger.SetPath(kPath); - kStdOut << "[+] Path set to: " << kPath << "\n"; + kStdOut << "[+] Image set to: " << kPath << "\n"; } ::signal(SIGINT, dbgi_ctrlc_handler); diff --git a/docs/drawio/LIBCOMPILER_DESIGN.drawio b/docs/drawio/LIBCOMPILER_DESIGN.drawio new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/docs/drawio/LIBCOMPILER_DESIGN.drawio 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 @@ +<mxfile host="65bd71144e"> + <diagram id="rBoUEB_FcKsNnY3-oVdp" name="Page-1"> + <mxGraphModel dx="822" dy="556" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> + <root> + <mxCell id="0"/> + <mxCell id="1" parent="0"/> + <mxCell id="5" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" target="4"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="410" y="180" as="sourcePoint"/> + </mxGeometry> + </mxCell> + <mxCell id="6" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="3"> + <mxGeometry relative="1" as="geometry"/> + </mxCell> + <mxCell id="2" value="LD Contract" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxGeometry x="350" y="120" width="120" height="60" as="geometry"/> + </mxCell> + <mxCell id="12" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="3" target="11"> + <mxGeometry relative="1" as="geometry"/> + </mxCell> + <mxCell id="3" value="LD Contract<div>(A)</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxGeometry x="280" y="230" width="120" height="60" as="geometry"/> + </mxCell> + <mxCell id="10" style="edgeStyle=none;html=1;" edge="1" parent="1" source="4" target="8"> + <mxGeometry relative="1" as="geometry"/> + </mxCell> + <mxCell id="4" value="LD Contract<div>(B)</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxGeometry x="440" y="230" width="120" height="60" as="geometry"/> + </mxCell> + <mxCell id="9" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="8" target="4"> + <mxGeometry relative="1" as="geometry"/> + </mxCell> + <mxCell id="8" value="Entrypoint of B" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxGeometry x="620" y="230" width="120" height="60" as="geometry"/> + </mxCell> + <mxCell id="13" style="edgeStyle=none;html=1;" edge="1" parent="1" source="11"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="340" y="290" as="targetPoint"/> + </mxGeometry> + </mxCell> + <mxCell id="11" value="Entrypoint of A" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"> + <mxGeometry x="280" y="330" width="120" height="60" as="geometry"/> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile>
\ 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 <file> +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 + @@ -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 |
