summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/src/Stop.cc
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:13 +0100
committerAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:45 +0100
commit610f91d87152cbe48d3054fcf437d8239da6ef35 (patch)
treea386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/src/Stop.cc
parent509fcca5986651c8ba712fb395f8498f2dea4109 (diff)
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src/Stop.cc')
-rw-r--r--dev/Kernel/src/Stop.cc130
1 files changed, 130 insertions, 0 deletions
diff --git a/dev/Kernel/src/Stop.cc b/dev/Kernel/src/Stop.cc
new file mode 100644
index 00000000..01820208
--- /dev/null
+++ b/dev/Kernel/src/Stop.cc
@@ -0,0 +1,130 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, TQ B.V, all rights reserved.
+
+------------------------------------------- */
+
+#include <NewKit/Stop.h>
+#include <ArchKit/ArchKit.h>
+#include <KernelKit/Timer.h>
+#include <KernelKit/DebugOutput.h>
+#include <NewKit/KString.h>
+#include <FirmwareKit/Handover.h>
+#include <KernelKit/FileMgr.h>
+#include <Modules/FB/FB.h>
+#include <Modules/FB/Text.h>
+
+#define kWebsiteURL "https://el-mahrouss-logic.com/products/help/"
+
+/* Each error code is attributed with an ID, which will prompt a string onto the
+ * screen. Wait for debugger... */
+
+namespace Kernel
+{
+ /***********************************************************************************/
+ /// @brief Stops execution of the kernel.
+ /// @param id kernel stop ID.
+ /***********************************************************************************/
+ Void ke_stop(const Kernel::Int32& id)
+ {
+ cg_init();
+
+ auto panic_text = RGB(0xff, 0xff, 0xff);
+
+ auto start_y = 50;
+ auto x = 10;
+
+ if (id != RUNTIME_CHECK_BOOTSTRAP)
+ CGDrawString("Kernel Panic!", start_y, x, panic_text);
+ else
+ CGDrawString("Kernel Bootstrap:", start_y, x, panic_text);
+
+ start_y += 10;
+
+ cg_fini();
+
+ // show text according to error id.
+
+ switch (id)
+ {
+ case RUNTIME_CHECK_PROCESS: {
+ CGDrawString("0x00000008: Invalid process behavior.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_ACPI: {
+ CGDrawString("0x00000006: ACPI configuration error.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_PAGE: {
+ CGDrawString("0x0000000B: Write/Read in non paged area.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_FILESYSTEM: {
+ CGDrawString("0x0000000A: Filesystem driver error.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_POINTER: {
+ CGDrawString("0x00000000: Kernel heap is corrupted.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_BAD_BEHAVIOR: {
+ CGDrawString("0x00000009: Bad behavior.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_BOOTSTRAP: {
+ CGDrawString("0x0000000A: Kernel has finished running, running OSLdr...", start_y, x, panic_text);
+ return;
+ }
+ case RUNTIME_CHECK_HANDSHAKE: {
+ CGDrawString("0x00000005: Handshake fault.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_IPC: {
+ CGDrawString("0x00000003: Bad LPC message.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_INVALID_PRIVILEGE: {
+ CGDrawString("0x00000007: Privilege access violation.", start_y, x, panic_text);
+ break;
+ case RUNTIME_CHECK_UNEXCPECTED: {
+ CGDrawString("0x0000000B: Unexpected violation.", start_y, x, panic_text);
+ break;
+ }
+ case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: {
+ CGDrawString("0x10000001: Out of virtual memory.", start_y, x, panic_text);
+
+ break;
+ }
+ case RUNTIME_CHECK_FAILED: {
+ CGDrawString("0x10000001: Kernel Bug check appears to have failed, a dump has been written to the storage.", start_y, x, panic_text);
+ break;
+ }
+ default: {
+ CGDrawString("0xFFFFFFFC: Unknown Kernel Error code.", start_y, x, panic_text);
+ break;
+ }
+ }
+ };
+
+ RecoveryFactory::Recover();
+ }
+
+ Void RecoveryFactory::Recover() noexcept
+ {
+ while (YES)
+ {
+ HAL::rt_halt();
+ }
+ }
+
+ void ke_runtime_check(bool expr, const Char* file, const Char* line)
+ {
+ if (!expr)
+ {
+ kcout << "FAILED: FILE: " << file << endl;
+ kcout << "FAILED: LINE: " << line << endl;
+
+ ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed
+ }
+ }
+} // namespace Kernel