summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-09 14:20:49 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-09 14:26:06 +0200
commitacd8297fe927e601a7173cec7ca5445fd4a9c74a (patch)
treed5610bc9f9cad2b93dd102ccb80eadb291d3fc1c
parent30a6f8174ab44c12ccdfb212a2f6895440581d1a (diff)
[IMP] [KRNL DLL] Update stop code, not using serial output anymore.
[IMP] [CRT DLL] Add CRT DLL as well. [HANDOVER] Update protocol by hiding an internal struct. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Boot/amd64-efi.make2
-rw-r--r--CRTKit/README.md5
-rw-r--r--CRTKit/__mpcc_defines.hxx23
-rw-r--r--CRTKit/__mpcc_exception.hxx12
-rw-r--r--CRTKit/__mpcc_iostream.hxx32
-rw-r--r--CRTKit/__mpcc_malloc.hxx8
-rw-r--r--CRTKit/__mpcc_runtime.cxx10
-rw-r--r--CRTKit/build.json10
-rw-r--r--Kernel/FirmwareKit/Handover.hxx12
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx10
-rw-r--r--[-rwxr-xr-x]Kernel/MoveAll.ARM64.sh0
-rw-r--r--[-rwxr-xr-x]Kernel/MoveAll.X64.sh0
-rw-r--r--Kernel/Sources/KernelCheck.cxx71
13 files changed, 121 insertions, 74 deletions
diff --git a/Boot/amd64-efi.make b/Boot/amd64-efi.make
index 12bd4941..650b1992 100644
--- a/Boot/amd64-efi.make
+++ b/Boot/amd64-efi.make
@@ -53,6 +53,7 @@ BOOT_LOADER=newosldr.exe
KERNEL=newoskrnl.dll
DDK=libDDK.dll
SCI=libSCI.dll
+CRT=libCRT.dll
.PHONY: invalid-recipe
invalid-recipe:
@@ -67,6 +68,7 @@ all: compile-amd64
$(COPY) ../Kernel/$(KERNEL) Sources/Root/$(KERNEL)
$(COPY) ../SCIKit/$(SCI) Sources/Root/$(SCI)
$(COPY) ../DDKit/$(DDK) Sources/Root/$(DDK)
+ $(COPY) ../CRTKit/$(CRT) Sources/Root/$(CRT)
$(COPY) Sources/$(BOOT_LOADER) Sources/Root/$(BOOT_LOADER)
ifneq ($(DEBUG_SUPPORT), )
diff --git a/CRTKit/README.md b/CRTKit/README.md
new file mode 100644
index 00000000..c7058527
--- /dev/null
+++ b/CRTKit/README.md
@@ -0,0 +1,5 @@
+# ZKA C++ RunTime
+
+This is the public interface of ZKA' RT, please check libNDK.dll instead.
+
+###### (c) ZKA Technologies, all rights reserved. \ No newline at end of file
diff --git a/CRTKit/__mpcc_defines.hxx b/CRTKit/__mpcc_defines.hxx
index 9dfe51af..dbd20493 100644
--- a/CRTKit/__mpcc_defines.hxx
+++ b/CRTKit/__mpcc_defines.hxx
@@ -95,4 +95,27 @@ typedef union double_cast {
#endif // ifdef __STD_CXX__
+namespace std
+{
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+} // namespace std
+
#endif /* __MPCC_DEFINES_HXX__ */
diff --git a/CRTKit/__mpcc_exception.hxx b/CRTKit/__mpcc_exception.hxx
index 012ff43f..23b4a99a 100644
--- a/CRTKit/__mpcc_exception.hxx
+++ b/CRTKit/__mpcc_exception.hxx
@@ -6,14 +6,16 @@
#pragma once
+#include <CRTKit/__mpcc_iostream.hxx>
+
+/// @brief CRT exit, with exit code (!!! exits all threads. !!!)
+/// @param code
+/// @return
extern "C" int __exit(int code);
+
/// @brief Standard C++ namespace
namespace std
{
- class ofstream;
-
- extern ofstream cout;
-
inline void __throw_general(void)
{
__exit(33);
@@ -21,14 +23,12 @@ namespace std
inline void __throw_domain_error(const char* error)
{
- cout << "ZKA C++: Domain error: " << error << "\r";
__throw_general();
__builtin_unreachable(); // prevent from continuing.
}
inline void __throw_bad_array_new_length(void)
{
- cout << "ZKAC C++: Bad array length.\r";
__throw_general();
__builtin_unreachable(); // prevent from continuing.
}
diff --git a/CRTKit/__mpcc_iostream.hxx b/CRTKit/__mpcc_iostream.hxx
new file mode 100644
index 00000000..1d93f1e4
--- /dev/null
+++ b/CRTKit/__mpcc_iostream.hxx
@@ -0,0 +1,32 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#pragma once
+
+/// @brief CRT exit, with exit code (!!! exits all threads. !!!)
+/// @param code
+/// @return
+extern "C" int __exit(int code);
+
+/// @brief Standard C++ namespace
+namespace std
+{
+ template <typename Encoding>
+ class ofstream;
+
+ template <typename Encoding>
+ class ostream
+ {
+ public:
+ ostream() = default;
+ virtual ~ostream() = default;
+
+ virtual ostream<Encoding>& operator<<(const Encoding* input_streamable) = 0;
+ virtual ostream<Encoding>& operator<<(Encoding* input_streamable) = 0;
+ };
+
+ extern ofstream<char> cout;
+}; \ No newline at end of file
diff --git a/CRTKit/__mpcc_malloc.hxx b/CRTKit/__mpcc_malloc.hxx
index 95a27f86..794cd5b4 100644
--- a/CRTKit/__mpcc_malloc.hxx
+++ b/CRTKit/__mpcc_malloc.hxx
@@ -6,22 +6,22 @@
#pragma once
-#include <NewKit/Defines.hxx>
+#include <CRTKit/__mpcc_defines.hxx>
namespace stdx
{
/// @brief allocate a new class.
/// @tparam KindClass the class type to allocate.
template <typename KindClass, typename... Args>
- inline Kernel::VoidPtr allocate(Args&&... args)
+ inline void* allocate(Args&&... args)
{
- return new KindClass(Kernel::forward(args)...);
+ return new KindClass(forward(args)...);
}
/// @brief free a class.
/// @tparam KindClass the class type to allocate.
template <typename KindClass>
- inline Kernel::Void release(KindClass ptr)
+ inline void release(KindClass ptr)
{
if (!ptr)
return;
diff --git a/CRTKit/__mpcc_runtime.cxx b/CRTKit/__mpcc_runtime.cxx
new file mode 100644
index 00000000..ba9bf8a7
--- /dev/null
+++ b/CRTKit/__mpcc_runtime.cxx
@@ -0,0 +1,10 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#include <CRTKit/__mpcc_alloca.hxx>
+#include <CRTKit/__mpcc_defines.hxx>
+#include <CRTKit/__mpcc_malloc.hxx>
+#include <CRTKit/__mpcc_exception.hxx>
diff --git a/CRTKit/build.json b/CRTKit/build.json
new file mode 100644
index 00000000..f9d69a57
--- /dev/null
+++ b/CRTKit/build.json
@@ -0,0 +1,10 @@
+{
+ "compiler_path": "x86_64-w64-mingw32-g++",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "./"],
+ "sources_path": ["*.cxx"],
+ "output_name": "libCRT.dll",
+ "compiler_flags": ["-ffreestanding", "-shared", "-std=c17", "-std=c++20", "-fno-rtti", "-fno-exceptions", " -Wl,--subsystem=17"],
+ "cpp_macros": ["__CRT_AMD64__", "cCRTVersion=0x0100"]
+ }
+ \ No newline at end of file
diff --git a/Kernel/FirmwareKit/Handover.hxx b/Kernel/FirmwareKit/Handover.hxx
index 23d92e59..75900508 100644
--- a/Kernel/FirmwareKit/Handover.hxx
+++ b/Kernel/FirmwareKit/Handover.hxx
@@ -51,18 +51,6 @@ namespace Kernel::HEL
kArchCount = 2,
};
- /**
-@brief The first struct that we read when inspecting The executable
-it tells us more about it and IS format independent.
-*/
- typedef struct HandoverHeader final
- {
- UInt64 f_TargetMagic;
- Int32 f_TargetType;
- Int32 f_TargetArch;
- UIntPtr f_TargetStartAddress;
- } __attribute__((packed)) HandoverHeader, *HandoverHeaderPtr;
-
struct HandoverInformationHeader
{
UInt64 f_Magic;
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 520d0833..93841bc1 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -84,6 +84,8 @@ EXTERN_C void hal_init_platform(
kTextOffsetY += 10;
cg_write_text("SMP OS (MAX 8 CORES).", kTextOffsetY, 10, RGB(0x00, 0x00, 0x00));
+ Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+
hal_real_init();
}
@@ -137,7 +139,6 @@ void hal_real_init(void)
constexpr auto cLPCSendMsg = 0x25;
constexpr auto cLPCOpenMsg = 0x26;
constexpr auto cLPCCloseMsg = 0x27;
- constexpr auto cLPCSanitizeMsg = 0x28;
kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
if (tls_check_syscall_impl(rdx) == false)
@@ -146,10 +147,6 @@ void hal_real_init(void)
}
};
- kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
- Kernel::ipc_sanitize_packet(reinterpret_cast<Kernel::IPC_MESSAGE_STRUCT*>(rdx));
- };
-
kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
// get HAC struct.
HEAP_ALLOC_INFO* rdxInf = reinterpret_cast<HEAP_ALLOC_INFO*>(rdx);
@@ -219,9 +216,6 @@ void hal_real_init(void)
kSyscalls[cLastExitInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
- kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fHooked = true;
Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
-
- Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
diff --git a/Kernel/MoveAll.ARM64.sh b/Kernel/MoveAll.ARM64.sh
index 5198559f..5198559f 100755..100644
--- a/Kernel/MoveAll.ARM64.sh
+++ b/Kernel/MoveAll.ARM64.sh
diff --git a/Kernel/MoveAll.X64.sh b/Kernel/MoveAll.X64.sh
index 664ad472..664ad472 100755..100644
--- a/Kernel/MoveAll.X64.sh
+++ b/Kernel/MoveAll.X64.sh
diff --git a/Kernel/Sources/KernelCheck.cxx b/Kernel/Sources/KernelCheck.cxx
index 4752024d..bf3d91b6 100644
--- a/Kernel/Sources/KernelCheck.cxx
+++ b/Kernel/Sources/KernelCheck.cxx
@@ -32,27 +32,27 @@ namespace Kernel
{
CGInit();
- auto panicBack = RGB(0xDC, 0xF5, 0xF5);
- auto panicTxt = RGB(0, 0, 0);
-
+ auto panicBack = RGB(0xff, 0x3a, 0x3a);
+ auto panicTxt = RGB(0xff, 0xff, 0xff);
+
CGDrawInRegion(panicBack, UIAccessibilty::The().Height(), UIAccessibilty::The().Width(), 0, 0);
auto start_y = 10;
- auto x = 10;
+ auto x = 10;
- cg_write_text("*** Kernel panic! ***\rnewoskrnl.dll stopped working properly so we had to shut it down.", start_y, x, panicTxt);
+ cg_write_text("newoskrnl.dll stopped working properly so we had to stop.", start_y, x, panicTxt);
CGFini();
// Show the QR code now.
- constexpr auto cVer = 4;
- const auto cECC = qr::Ecc::H;
- const auto cInput = cWebsiteMacro;
- const auto cInputLen = rt_string_len(cWebsiteMacro);
+ constexpr auto cVer = 4;
+ const auto cECC = qr::Ecc::H;
+ const auto cInput = cWebsiteMacro;
+ const auto cInputLen = rt_string_len(cWebsiteMacro);
- qr::Qr<cVer> encoder;
- qr::QrDelegate encoderDelegate;
+ qr::Qr<cVer> encoder;
+ qr::QrDelegate encoderDelegate;
encoder.encode(cInput, cInputLen, cECC, 0); // Manual mask 0
@@ -61,85 +61,68 @@ namespace Kernel
// tell delegate to draw encoded QR now.
encoderDelegate.draw<cVer>(encoder, cWhereStartX,
- cWhereStartY);
-
- // ******* //
- // shows in debug only.
- // ******* //
+ cWhereStartY);
- kcout << "*** STOP *** \r";
- kcout << "*** Kernel has trigerred a runtime stop. *** \r";
+ start_y += 10;
switch (id)
{
case RUNTIME_CHECK_PROCESS: {
- kcout << "*** CAUSE: RUNTIME_CHECK_PROCESS *** \r";
- kcout << "*** WHAT: BAD DRIVER. *** \r";
+ cg_write_text("Scheduler error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_ACPI: {
- kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r";
- kcout << "*** WHAT: ACPI ERROR, UNSTABLE STATE. *** \r";
+ cg_write_text("ACPI error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_POINTER: {
- kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r";
- kcout << "*** WHAT: HEAP CRC32 ERROR, UNSTABLE STATE. *** \r";
+ cg_write_text("Kernel heap error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_BAD_BEHAVIOR: {
- kcout << "*** CAUSE: RUNTIME_CHECK_BAD_BEHAVIOR *** \r";
- kcout << "*** WHAT: KERNEL BECAME UNSTABLE. *** \r";
+ cg_write_text("Undefined Behavior error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_BOOTSTRAP: {
- kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r";
- kcout << "*** WHAT: END OF CODE. *** \r";
+ cg_write_text("End of code.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_HANDSHAKE: {
- kcout << "*** CAUSE: RUNTIME_CHECK_HANDSHAKE *** \r";
- kcout << "*** WHAT: BAD HANDSHAKE. *** \r";
+ cg_write_text("Handshake error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_IPC: {
- kcout << "*** CAUSE: RUNTIME_CHECK_IPC *** \r";
- kcout << "*** WHAT: RICH CALL VIOLATION. *** \r";
+ cg_write_text("Kernel IPC error.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_INVALID_PRIVILEGE: {
- kcout << "*** CAUSE: RUNTIME_CHECK_INVALID_PRIVILEGE *** \r";
- kcout << "*** WHAT: HYPERVISOR POLICY VIOLATION. *** \r";
+ cg_write_text("Privilege violation.", start_y, x, panicTxt);
break;
case RUNTIME_CHECK_UNEXCPECTED: {
- kcout << "*** CAUSE: RUNTIME_CHECK_UNEXCPECTED *** \r";
- kcout << "*** WHAT: CATASROPHIC FAILURE! *** \r";
+ cg_write_text("Catasrophic failure.", start_y, x, panicTxt);
break;
}
case RUNTIME_CHECK_FAILED: {
- kcout << "*** CAUSE: RUNTIME_CHECK_FAILED *** \r";
- kcout << "*** WHAT: ASSERTION FAILED! *** \r";
+ cg_write_text("Assertion failed.", start_y, x, panicTxt);
break;
}
default: {
- kcout << "*** CAUSE: RUNTIME_CHECK_GENERIC *** \r";
+ cg_write_text("Unknown error.", start_y, x, panicTxt);
break;
}
}
};
RecoveryFactory::Recover();
-
}
-
+
Void RecoveryFactory::Recover() noexcept
- {
+ {
while (true)
{
- asm volatile ("cli; hlt");
+ asm volatile("cli; hlt");
}
}
-
void ke_runtime_check(bool expr, const char* file, const char* line)
{