diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
| commit | f3d931aa7cfaf96baef8383b59a8938779541ee7 (patch) | |
| tree | fdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/Sources/KernelCheck.cxx | |
| parent | 86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff) | |
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/Sources/KernelCheck.cxx')
| -rw-r--r-- | dev/Kernel/Sources/KernelCheck.cxx | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/dev/Kernel/Sources/KernelCheck.cxx b/dev/Kernel/Sources/KernelCheck.cxx new file mode 100644 index 00000000..27519369 --- /dev/null +++ b/dev/Kernel/Sources/KernelCheck.cxx @@ -0,0 +1,136 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <ArchKit/ArchKit.hxx> +#include <KernelKit/DebugOutput.hxx> +#include <NewKit/KernelCheck.hxx> +#include <NewKit/String.hxx> +#include <FirmwareKit/Handover.hxx> +#include <Modules/ACPI/ACPIFactoryInterface.hxx> + +#include <Modules/CoreCG/Accessibility.hxx> +#include <Modules/CoreCG/FbRenderer.hxx> +#include <Modules/CoreCG/TextRenderer.hxx> + +#define SetMem(dst, byte, sz) Kernel::rt_set_memory((Kernel::VoidPtr)dst, byte, sz) +#define CopyMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz) +#define MoveMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz) + +#define cWebsiteMacro "https://zka.nl/help" + +#include <BootKit/Vendor/Qr.hxx> + +/* Each error code is attributed with an ID, which will prompt a string onto the + * screen. Wait for debugger... */ + +namespace Kernel +{ + void ke_stop(const Kernel::Int& id) + { + CGInit(); + + 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; + + 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); + + qr::Qr<cVer> encoder; + qr::QrDelegate encoderDelegate; + + encoder.encode(cInput, cInputLen, cECC, 0); // Manual mask 0 + + const auto cWhereStartX = (kHandoverHeader->f_GOP.f_Width - encoder.side_size()) - 20; + const auto cWhereStartY = (kHandoverHeader->f_GOP.f_Height - encoder.side_size()) / 2; + + // tell delegate to draw encoded QR now. + encoderDelegate.draw<cVer>(encoder, cWhereStartX, + cWhereStartY); + + start_y += 10; + + // show text according to error id. + + switch (id) + { + case RUNTIME_CHECK_PROCESS: { + cg_write_text("0x00000008 Process scheduler error (Catasrophic failure).", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_ACPI: { + cg_write_text("0x00000006 ACPI error.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_POINTER: { + cg_write_text("0x00000000 Kernel heap error.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_BAD_BEHAVIOR: { + cg_write_text("0x00000009 Undefined Behavior error.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_BOOTSTRAP: { + cg_write_text("0x0000000A End of code.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_HANDSHAKE: { + cg_write_text("0x00000005 Handshake error.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_IPC: { + cg_write_text("0x00000003 Kernel IPC error.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_INVALID_PRIVILEGE: { + cg_write_text("0x00000007 Kernel privilege violation.", start_y, x, panicTxt); + break; + case RUNTIME_CHECK_UNEXCPECTED: { + cg_write_text("0x0000000B Catasrophic failure.", start_y, x, panicTxt); + break; + } + case RUNTIME_CHECK_FAILED: { + cg_write_text("0x10000001 Assertion failed.", start_y, x, panicTxt); + break; + } + default: { + cg_write_text("0xFFFFFFFF Unknown error.", start_y, x, panicTxt); + break; + } + } + }; + + RecoveryFactory::Recover(); + } + + Void RecoveryFactory::Recover() noexcept + { + while (Yes) + { + asm volatile("cli; hlt"); + } + } + + void ke_runtime_check(bool expr, const char* file, const char* line) + { + if (!expr) + { + ke_stop(RUNTIME_CHECK_FAILED); // Runtime Check failed + } + } +} // namespace Kernel |
