summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/ARM64/HalKernelPanic.cc
blob: 4001b05f9a7458bce97939a1df371fc74d64a4cb (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
/* -------------------------------------------

	Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.

------------------------------------------- */

#include <NewKit/KernelPanic.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/CoreGfx/FBMgr.h>
#include <modules/CoreGfx/TextMgr.h>
#include <NewKit/Utils.h>

/* Each error code is attributed with an ID, which will prompt a string onto the
 * screen. Wait for debugger... */

namespace Kernel
{
	/// @brief Dumping factory class.
	class RecoveryFactory final
	{
	public:
		STATIC Void Recover() noexcept;
	};

	/***********************************************************************************/
	/// @brief Stops execution of the kernel.
	/// @param id kernel stop ID.
	/***********************************************************************************/
	Void ke_panic(const Kernel::Int32& id, const Char* message)
	{
		fb_init();

		auto panic_text = RGB(0xff, 0xff, 0xff);

		auto y = 10;
		auto x = 10;

		Char* message_apicid = new Char[128];
		rt_set_memory(message_apicid, 0, 128);

		rt_copy_memory((VoidPtr) "panic id: ", message_apicid, rt_string_len("panic id: "));
		rt_to_string(message_apicid + rt_string_len("panic id: "), (UIntPtr)id, 10);

		fb_render_string(message_apicid, y, x, panic_text);

		y += 10;

		fb_render_string((message ? message : "message: panic raised, going nowhere after this!"), y, x, panic_text);

		y += 10;

		fb_clear();

		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)
		{
			kout << "FAILED: FILE: " << file << kendl;
			kout << "FAILED: LINE: " << line << kendl;

			ke_panic(RUNTIME_CHECK_FAILED, file); // Runtime Check failed
		}
	}
} // namespace Kernel