blob: 827bc5c32d4e0f447ceff443e09962f1a1ec6992 (
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
|
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel
#include <ArchKit/ArchKit.h>
#include <FirmwareKit/Handover.h>
#include <KernelKit/DebugOutput.h>
#include <KernelKit/FileMgr.h>
#include <KernelKit/Timer.h>
#include <NeKit/KString.h>
#include <NeKit/KernelPanic.h>
#include <NeKit/Utils.h>
#include <modules/CoreGfx/CoreGfx.h>
#include <modules/CoreGfx/TextGfx.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();
};
/***********************************************************************************/
/// @brief Stops execution of the kernel.
/// @param id kernel stop ID.
/***********************************************************************************/
Void ke_panic(const Kernel::Int32& id, const Char* message) {
(Void)(kout << "*** STOP ***\r");
(Void)(kout << "Kernel_Panic_MSG: " << message << kendl);
(Void)(kout << "Kernel_Panic_ID: " << hex_number(id) << kendl);
(Void)(kout << "Kernel_Panic_CR2: " << hex_number((UIntPtr) hal_read_cr2()) << kendl);
RecoveryFactory::Recover();
}
Void RecoveryFactory::Recover() {
STATIC BOOL alreadyDumped = NO;
#if defined(__FSKIT_INCLUDES_OPENHEFS__)
if (alreadyDumped) {
HAL::rt_cli();
HAL::rt_halt();
}
alreadyDumped = YES;
HeFileSystemMgr mgr;
auto node = mgr.Open("/system/dump.dmp", "wb");
if (node && hal_read_cr2()) mgr.Write(node, hal_read_cr2(), 0, 0x100);
if (node) mm_free_ptr(node);
node = nullptr;
#endif
while (YES) {
HAL::rt_cli();
HAL::rt_halt();
}
}
void ke_runtime_check(bool expr, const Char* file, const Char* line) {
if (!expr) {
(Void)(kout << "*** CHECK ***\r");
(Void)(kout << "Kernel_Panic_FILE: " << file << kendl);
(Void)(kout << "Kernel_Panic_LINE: " << line << kendl);
ke_panic(RUNTIME_CHECK_FAILED, file); // Runtime Check failed
}
}
} // namespace Kernel
|