summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp
blob: 6d831d3b94bf282a3b7a28aa709a1fb49751cdd3 (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
/* -------------------------------------------

	Copyright SoftwareLabs

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

#include <ArchKit/ArchKit.hpp>
#include <KernelKit/ProcessScheduler.hxx>
#include <NewKit/String.hpp>

/// @brief Handle GPF fault.
/// @param rsp
EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp)
{
	MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent());

	NewOS::kcout << "newoskrnl: Stack Pointer: "
				 << NewOS::StringBuilder::FromInt("rsp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: General Protection Fault, caused by "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName();

	NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash();
}

/// @brief Handle the scheduler interrupt, raised from the HPET timer.
/// @param rsp
EXTERN_C void idt_handle_scheduler(NewOS::UIntPtr rsp)
{
	NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: Will be scheduled back later "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName()
		<< NewOS::end_line();

	/// schedule another process.
	if (!NewOS::ProcessHelper::StartScheduling())
	{
		NewOS::kcout << "newoskrnl: Continue schedule this process...\r";
	}
}

/// @brief Handle page fault.
/// @param rsp
EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp)
{
	MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent());
	NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: Segmentation Fault, caused by "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName();

	NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash();
}

/// @brief Handle math fault.
/// @param rsp
EXTERN_C void idt_handle_math(NewOS::UIntPtr rsp)
{
	MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent());
	NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: Math error, caused by "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName();

	NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash();
}

/// @brief Handle any generic fault.
/// @param rsp
EXTERN_C void idt_handle_generic(NewOS::UIntPtr rsp)
{
	MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent());
	NewOS::kcout << NewOS::StringBuilder::FromInt("sp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: Execution error, caused by "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName();

	NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash();
}

/// @brief Handle #UD fault.
/// @param rsp
EXTERN_C void idt_handle_ud(NewOS::UIntPtr rsp)
{
	MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent());

	NewOS::kcout << "newoskrnl: Stack Pointer: "
				 << NewOS::StringBuilder::FromInt("rsp{%}", rsp);

	NewOS::kcout
		<< "newoskrnl: Invalid interrupt, caused by "
		<< NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName();

	NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash();
}