summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources/KernelCheck.cxx
blob: 27519369bfa1823848a0c0fbaaefa76c6e92bf1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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