summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md28
-rw-r--r--dev/LibCompiler/BasicString.h2
-rw-r--r--dev/LibCompiler/CodeGen.h2
-rw-r--r--dev/LibCompiler/Defines.h9
-rw-r--r--dev/LibCompiler/Util/AsmUtils.h (renamed from dev/LibCompiler/Util/LCAsmUtils.h)2
-rw-r--r--dev/LibCompiler/Util/CompilerUtils.h (renamed from dev/LibCompiler/Util/LCClUtils.h)1
-rw-r--r--dev/LibCompiler/Util/DylibHelpers.h2
-rw-r--r--dev/LibCompiler/deprecated/Frontend/CCompiler64x0.cc2
-rw-r--r--dev/LibCompiler/deprecated/Frontend/CCompilerARM64.cc2
-rw-r--r--dev/LibCompiler/deprecated/Frontend/CCompilerPower64.cc2
-rw-r--r--dev/LibCompiler/src/Backend/Assembler32x0.cc20
-rw-r--r--dev/LibCompiler/src/Backend/Assembler64x0.cc9
-rw-r--r--dev/LibCompiler/src/Backend/AssemblerAMD64.cc6
-rw-r--r--dev/LibCompiler/src/Backend/AssemblerARM64.cc6
-rw-r--r--dev/LibCompiler/src/Backend/AssemblerPowerPC.cc6
-rw-r--r--dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc (renamed from dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc)11
-rw-r--r--dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc2
-rw-r--r--dev/LibDebugger/src/NeKernelContractCLI.cc14
-rw-r--r--meta/png/nekernel.pngbin0 -> 156843 bytes
-rw-r--r--sample/.keep0
-rw-r--r--sample/asm/exit_nekernel_abi.asm (renamed from tests/exit_nekernel_abi.asm)0
-rw-r--r--sample/asm/return_5_rax.asm (renamed from tests/return_5_rax.asm)0
-rw-r--r--sample/cxx/example.cc (renamed from tests/example.cc)0
-rw-r--r--tools/cxxdrv.cc9
24 files changed, 80 insertions, 55 deletions
diff --git a/README.md b/README.md
index 97a5750..b76a345 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,21 @@
-# NeKernel C/C++
+<!-- Read Me of NeKernel C++ -->
+
+<div align="center">
+ <img src="meta/png/nekernel.png" alt="Logo" width="256"/>
+</div>
+
+<br/>
![CI](https://github.com/amlel-el-mahrouss/cc/actions/workflows/c-cpp.yml/badge.svg)
[![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-blue.svg)](LICENSE)
-## Notice for Documentation:
+## Requirements:
+
+- [CLang](https://clang.llvm.org/)
+- [GIT](https://git-scm.com/)
+- [BTB](https://github.com/nekernel-org/btb)
+
+## Notice for Doxygen:
- Use the doxygen command to build documentation.
@@ -11,16 +23,12 @@
- Always use `format.sh` before commiting and pushing your code!
-## Requirements:
+## Getting Started:
-- [CLang](https://clang.llvm.org/)
-- [GIT](https://git-scm.com/)
-- [BTB](https://github.com/nekernel-org/btb)
-
-## Cloning:
-
-```
+```sh
git clone git@github.com:nekernel-org/cc.git
+cd cc
+# Either build debugger or compiler using btb
```
###### Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.
diff --git a/dev/LibCompiler/BasicString.h b/dev/LibCompiler/BasicString.h
index b69deae..53b21d3 100644
--- a/dev/LibCompiler/BasicString.h
+++ b/dev/LibCompiler/BasicString.h
@@ -71,7 +71,7 @@ class BasicString final {
* @note These results shall call be delete[] after they're used.
*/
struct StringBuilder final {
- static BasicString Construct(const CharType* data);
+ static BasicString Construct(const CharType* data);
static const char* FromInt(const char* fmt, int n);
static const char* FromBool(const char* fmt, bool n);
static const char* Format(const char* fmt, const char* from);
diff --git a/dev/LibCompiler/CodeGen.h b/dev/LibCompiler/CodeGen.h
index 8edcff1..a189b93 100644
--- a/dev/LibCompiler/CodeGen.h
+++ b/dev/LibCompiler/CodeGen.h
@@ -6,9 +6,9 @@
#pragma once
+#include <LibCompiler/BasicString.h>
#include <LibCompiler/Defines.h>
#include <LibCompiler/Macros.h>
-#include <LibCompiler/BasicString.h>
#define LC_ASSEMBLY_INTERFACE : public ::LibCompiler::AssemblyInterface
#define LC_ENCODER : public ::LibCompiler::EncoderInterface
diff --git a/dev/LibCompiler/Defines.h b/dev/LibCompiler/Defines.h
index 1735606..24d9a96 100644
--- a/dev/LibCompiler/Defines.h
+++ b/dev/LibCompiler/Defines.h
@@ -138,6 +138,15 @@ inline bool to_str(CharType* str, Int32 limit, Int32 base) noexcept {
return true;
}
+inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept {
+ if (handler == nullptr) return false;
+
+ if (::signal(signal, handler) == SIG_ERR) {
+ return false;
+ }
+
+ return true;
+}
} // namespace LibCompiler
#define PACKED __attribute__((packed))
diff --git a/dev/LibCompiler/Util/LCAsmUtils.h b/dev/LibCompiler/Util/AsmUtils.h
index 7728444..f176eda 100644
--- a/dev/LibCompiler/Util/LCAsmUtils.h
+++ b/dev/LibCompiler/Util/AsmUtils.h
@@ -9,7 +9,7 @@
#include <LibCompiler/CodeGen.h>
#include <LibCompiler/Frontend.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
using namespace LibCompiler;
diff --git a/dev/LibCompiler/Util/LCClUtils.h b/dev/LibCompiler/Util/CompilerUtils.h
index 94a113c..19e247d 100644
--- a/dev/LibCompiler/Util/LCClUtils.h
+++ b/dev/LibCompiler/Util/CompilerUtils.h
@@ -77,7 +77,6 @@ inline void drvi_crash_handler(std::int32_t id) {
kStdOut << "ERRNO: " << errno << std::endl;
kStdOut << "ERRNO(STRING): " << strerror(errno) << std::endl;
-
switch (id) {
case SIGSEGV: {
kStdOut << "SIGNAL: Segmentation Fault." << kBlank << std::endl;
diff --git a/dev/LibCompiler/Util/DylibHelpers.h b/dev/LibCompiler/Util/DylibHelpers.h
index 71ca230..e61cf9c 100644
--- a/dev/LibCompiler/Util/DylibHelpers.h
+++ b/dev/LibCompiler/Util/DylibHelpers.h
@@ -9,5 +9,5 @@
#include <LibCompiler/Defines.h>
#include <dlfcn.h>
-typedef Int32(*LibCompilerEntrypoint)(Int32 argc, CharType const* argv[]);
+typedef Int32 (*LibCompilerEntrypoint)(Int32 argc, CharType const* argv[]);
typedef VoidPtr DylibHandle;
diff --git a/dev/LibCompiler/deprecated/Frontend/CCompiler64x0.cc b/dev/LibCompiler/deprecated/Frontend/CCompiler64x0.cc
index fc31ef9..7b908f7 100644
--- a/dev/LibCompiler/deprecated/Frontend/CCompiler64x0.cc
+++ b/dev/LibCompiler/deprecated/Frontend/CCompiler64x0.cc
@@ -13,7 +13,7 @@
#include <LibCompiler/Backend/64x0.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/UUID.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
#include <cstdio>
#include <fstream>
#include <iostream>
diff --git a/dev/LibCompiler/deprecated/Frontend/CCompilerARM64.cc b/dev/LibCompiler/deprecated/Frontend/CCompilerARM64.cc
index 02e39f9..9e62747 100644
--- a/dev/LibCompiler/deprecated/Frontend/CCompilerARM64.cc
+++ b/dev/LibCompiler/deprecated/Frontend/CCompilerARM64.cc
@@ -13,7 +13,7 @@
#include <LibCompiler/Backend/Aarch64.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/UUID.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
#include <cstdio>
#include <fstream>
#include <iostream>
diff --git a/dev/LibCompiler/deprecated/Frontend/CCompilerPower64.cc b/dev/LibCompiler/deprecated/Frontend/CCompilerPower64.cc
index 216891a..233ad98 100644
--- a/dev/LibCompiler/deprecated/Frontend/CCompilerPower64.cc
+++ b/dev/LibCompiler/deprecated/Frontend/CCompilerPower64.cc
@@ -10,7 +10,7 @@
#include <LibCompiler/Backend/PowerPC.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/UUID.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
#include <cstdio>
#include <fstream>
#include <iostream>
diff --git a/dev/LibCompiler/src/Backend/Assembler32x0.cc b/dev/LibCompiler/src/Backend/Assembler32x0.cc
index 683b866..b7ff321 100644
--- a/dev/LibCompiler/src/Backend/Assembler32x0.cc
+++ b/dev/LibCompiler/src/Backend/Assembler32x0.cc
@@ -17,26 +17,15 @@
/////////////////////////////////////////////////////////////////////////////////////////
+#ifndef __ASM_NEED_32x0__
#define __ASM_NEED_32x0__ 1
+#endif
#include <LibCompiler/AE.h>
#include <LibCompiler/Backend/32x0.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/PEF.h>
-
-/////////////////////
-
-// ANSI ESCAPE CODES
-
-/////////////////////
-
-#define kBlank "\e[0;30m"
-#define kRed "\e[0;31m"
-#define kWhite "\e[0;97m"
-#define kYellow "\e[0;33m"
-
-#define kStdOut (std::cout << kWhite)
-#define kStdErr (std::cout << kRed)
+#include <LibCompiler/Util/CompilerUtils.h>
/////////////////////////////////////////////////////////////////////////////////////////
@@ -45,5 +34,6 @@
/////////////////////////////////////////////////////////////////////////////////////////
LIBCOMPILER_MODULE(NEAssemblerMain32000) {
- return 0;
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
+ return EXIT_SUCCESS;
}
diff --git a/dev/LibCompiler/src/Backend/Assembler64x0.cc b/dev/LibCompiler/src/Backend/Assembler64x0.cc
index fb96708..765bea2 100644
--- a/dev/LibCompiler/src/Backend/Assembler64x0.cc
+++ b/dev/LibCompiler/src/Backend/Assembler64x0.cc
@@ -17,13 +17,15 @@
/////////////////////////////////////////////////////////////////////////////////////////
+#ifndef __ASM_NEED_64x0__
#define __ASM_NEED_64x0__ 1
+#endif
#include <LibCompiler/AE.h>
#include <LibCompiler/Backend/64x0.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/PEF.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
#include <algorithm>
#include <filesystem>
#include <fstream>
@@ -38,8 +40,7 @@
static char kOutputArch = LibCompiler::kPefArch64000;
-/// @note The 64x0 is VLSIW, so we need to jump to 4 bytes.
-constexpr auto k64x0IPAlignment = 0x4U;
+constexpr auto k64x0IPAlignment = 0x1U;
static std::size_t kCounter = 1UL;
@@ -67,7 +68,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
LIBCOMPILER_MODULE(AssemblerMain64x0) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
diff --git a/dev/LibCompiler/src/Backend/AssemblerAMD64.cc b/dev/LibCompiler/src/Backend/AssemblerAMD64.cc
index e9f3ad5..6551743 100644
--- a/dev/LibCompiler/src/Backend/AssemblerAMD64.cc
+++ b/dev/LibCompiler/src/Backend/AssemblerAMD64.cc
@@ -21,7 +21,9 @@
/////////////////////////////////////////////////////////////////////////////////////////
+#ifndef __ASM_NEED_AMD64__
#define __ASM_NEED_AMD64__ 1
+#endif
#define kAssemblerPragmaSymStr "#"
#define kAssemblerPragmaSym '#'
@@ -74,7 +76,7 @@ static const std::string kUndefinedSymbol = ":UndefinedSymbol:";
// \brief forward decl.
static bool asm_read_attributes(std::string line);
-#include <LibCompiler/Util/LCAsmUtils.h>
+#include <LibCompiler/Util/AsmUtils.h>
/////////////////////////////////////////////////////////////////////////////////////////
@@ -85,7 +87,7 @@ static bool asm_read_attributes(std::string line);
LIBCOMPILER_MODULE(AssemblerMainAMD64) {
//////////////// CPU OPCODES BEGIN ////////////////
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
std::string opcodes_jump[kJumpLimit] = {"ja", "jae", "jb", "jbe", "jc", "je", "jg", "jge",
"jl", "jle", "jna", "jnae", "jnb", "jnbe", "jnc", "jne",
diff --git a/dev/LibCompiler/src/Backend/AssemblerARM64.cc b/dev/LibCompiler/src/Backend/AssemblerARM64.cc
index 8fad6b5..142dcc7 100644
--- a/dev/LibCompiler/src/Backend/AssemblerARM64.cc
+++ b/dev/LibCompiler/src/Backend/AssemblerARM64.cc
@@ -15,14 +15,16 @@
/////////////////////////////////////////////////////////////////////////////////////////
+#ifndef __ASM_NEED_ARM64__
#define __ASM_NEED_ARM64__ 1
+#endif
#include <LibCompiler/AE.h>
#include <LibCompiler/Backend/Aarch64.h>
#include <LibCompiler/ErrorID.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/PEF.h>
-#include <LibCompiler/Util/LCAsmUtils.h>
+#include <LibCompiler/Util/AsmUtils.h>
#include <LibCompiler/Version.h>
#include <algorithm>
#include <filesystem>
@@ -71,7 +73,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
LIBCOMPILER_MODULE(AssemblerMainARM64) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
diff --git a/dev/LibCompiler/src/Backend/AssemblerPowerPC.cc b/dev/LibCompiler/src/Backend/AssemblerPowerPC.cc
index 86a70b9..3134748 100644
--- a/dev/LibCompiler/src/Backend/AssemblerPowerPC.cc
+++ b/dev/LibCompiler/src/Backend/AssemblerPowerPC.cc
@@ -15,14 +15,16 @@
/////////////////////////////////////////////////////////////////////////////////////////
+#ifndef __ASM_NEED_PPC__
#define __ASM_NEED_PPC__ 1
+#endif
#include <LibCompiler/AE.h>
#include <LibCompiler/Backend/PowerPC.h>
#include <LibCompiler/ErrorID.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/PEF.h>
-#include <LibCompiler/Util/LCAsmUtils.h>
+#include <LibCompiler/Util/AsmUtils.h>
#include <LibCompiler/Version.h>
#include <algorithm>
#include <filesystem>
@@ -71,7 +73,7 @@ static bool asm_read_attributes(std::string line);
/////////////////////////////////////////////////////////////////////////////////////////
LIBCOMPILER_MODULE(AssemblerMainPower64) {
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
for (size_t i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
diff --git a/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc b/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc
index 217f86b..df9035d 100644
--- a/dev/LibCompiler/src/Frontend/CPlusPlusCompilerAMD64.cc
+++ b/dev/LibCompiler/src/Frontend/CompilerCPlusPlusAMD64.cc
@@ -9,7 +9,6 @@
/// BUGS: 1
-#include "LibCompiler/Defines.h"
#define kPrintF printf
#define kExitOK (EXIT_SUCCESS)
@@ -20,7 +19,7 @@
#include <LibCompiler/Backend/X64.h>
#include <LibCompiler/Frontend.h>
#include <LibCompiler/UUID.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
/* NeKernel C++ Compiler Driver */
/* This is part of the LibCompiler. */
@@ -126,7 +125,8 @@ class CompilerFrontendCPlusPlus final LC_COMPILER_FRONTEND {
LIBCOMPILER_COPY_DEFAULT(CompilerFrontendCPlusPlus);
- LibCompiler::SyntaxLeafList::SyntaxLeaf Compile(const LibCompiler::STLString text, LibCompiler::STLString file) override;
+ LibCompiler::SyntaxLeafList::SyntaxLeaf Compile(const LibCompiler::STLString text,
+ LibCompiler::STLString file) override;
const char* Language() override;
};
@@ -736,6 +736,9 @@ class AssemblyCPlusPlusInterface final LC_ASSEMBLY_INTERFACE {
LibCompiler::STLString line_source;
+ out_fp << "#bits 64\n";
+ out_fp << "#org " << kOrigin << "\n\n";
+
while (std::getline(src_fp, line_source)) {
out_fp << kCompilerFrontend->Compile(line_source, src).fUserValue;
}
@@ -817,7 +820,7 @@ LIBCOMPILER_MODULE(CompilerCPlusPlusAMD64) {
kCompilerFrontend = new CompilerFrontendCPlusPlus();
kFactory.Mount(new AssemblyCPlusPlusInterface());
- ::signal(SIGSEGV, Detail::drvi_crash_handler);
+ LibCompiler::install_signal(SIGSEGV, Detail::drvi_crash_handler);
for (auto index = 1UL; index < argc; ++index) {
if (!argv[index]) break;
diff --git a/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc b/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc
index edfd47a..820b06d 100644
--- a/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc
+++ b/dev/LibCompiler/src/Linkers/DynamicLinkerPEF.cc
@@ -35,7 +35,7 @@
#include <LibCompiler/AE.h>
//! LibCompiler utils.
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
//! I/O stream from std c++
#include <iostream>
diff --git a/dev/LibDebugger/src/NeKernelContractCLI.cc b/dev/LibDebugger/src/NeKernelContractCLI.cc
index dddefda..0107b7c 100644
--- a/dev/LibDebugger/src/NeKernelContractCLI.cc
+++ b/dev/LibDebugger/src/NeKernelContractCLI.cc
@@ -23,12 +23,20 @@ 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) {
+ if (argc >= 3 && std::string(argv[1]) == "-k" && argv[2] != nullptr) {
kPath = argv[2];
- kStdOut << "[+] Kernel image set to: " << kPath << "\n";
+ kStdOut << "[+] Kernel (ne_kernel) set to: " << kPath << "\n";
+
+ kKernelDebugger.Attach(kPath, nullptr, kPID);
+ kKernelDebugger.Breakpoint("$HANDOVER_START");
+
+ return EXIT_SUCCESS;
}
- return EXIT_SUCCESS;
+ kStdOut << "Usage: " << argv[0] << " -k <kernel_path>\n";
+ kStdOut << "Example: " << argv[0] << " -k /path/to/ne_kernel\n";
+
+ return EXIT_FAILURE;
}
#endif // LD_NEKERNEL_DEBUGGER \ No newline at end of file
diff --git a/meta/png/nekernel.png b/meta/png/nekernel.png
new file mode 100644
index 0000000..565a1db
--- /dev/null
+++ b/meta/png/nekernel.png
Binary files differ
diff --git a/sample/.keep b/sample/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sample/.keep
diff --git a/tests/exit_nekernel_abi.asm b/sample/asm/exit_nekernel_abi.asm
index a97252f..a97252f 100644
--- a/tests/exit_nekernel_abi.asm
+++ b/sample/asm/exit_nekernel_abi.asm
diff --git a/tests/return_5_rax.asm b/sample/asm/return_5_rax.asm
index 82c0320..82c0320 100644
--- a/tests/return_5_rax.asm
+++ b/sample/asm/return_5_rax.asm
diff --git a/tests/example.cc b/sample/cxx/example.cc
index 9ee2a30..9ee2a30 100644
--- a/tests/example.cc
+++ b/sample/cxx/example.cc
diff --git a/tools/cxxdrv.cc b/tools/cxxdrv.cc
index a6f12ee..bc790ff 100644
--- a/tools/cxxdrv.cc
+++ b/tools/cxxdrv.cc
@@ -9,9 +9,9 @@
#include <LibCompiler/Defines.h>
#include <LibCompiler/ErrorID.h>
-#include <LibCompiler/Version.h>
-#include <LibCompiler/Util/LCClUtils.h>
+#include <LibCompiler/Util/CompilerUtils.h>
#include <LibCompiler/Util/DylibHelpers.h>
+#include <LibCompiler/Version.h>
static auto kPath = "/usr/local/lib/libCompiler.dylib";
@@ -21,11 +21,12 @@ Int32 main(Int32 argc, CharType const* argv[]) {
if (!handler) {
kStdOut;
std::printf("error: Could not load dylib in %s: %s\n", kPath, dlerror());
-
+
return EXIT_FAILURE;
}
- LibCompilerEntrypoint entrypoint_cxx = (LibCompilerEntrypoint)dlsym(handler, "CompilerCPlusPlusAMD64");
+ LibCompilerEntrypoint entrypoint_cxx =
+ (LibCompilerEntrypoint) dlsym(handler, "CompilerCPlusPlusAMD64");
if (!entrypoint_cxx) {
kStdOut;