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
|
/* -------------------------------------------
Copyright Zeta Electronics Corporation
------------------------------------------- */
#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 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();
}
/// @brief Enter syscall from assembly.
/// @param stack the stack pushed from assembly routine.
/// @return nothing.
EXTERN_C NewOS::Void hal_system_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx)
{
if (rcx <= (kSyscalls.Count() - 1))
{
NewOS::kcout << "newoskrnl: syscall: enter.\r";
NewOS::kcout << "rcx: " << NewOS::number(rcx) << NewOS::endl;
if (kSyscalls[rcx].Leak().Leak().fHooked)
(kSyscalls[rcx].Leak().Leak().fProc)((NewOS::HAL::StackFramePtr)rdx);
NewOS::kcout << "newoskrnl: syscall: exit.\r";
}
}
/// @brief Enter kernel call from assembly (DDK only).
/// @param stack the stack pushed from assembly routine.
/// @return nothing.
EXTERN_C NewOS::Void hal_kernel_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx,
NewOS::UIntPtr r8, NewOS::UIntPtr r9)
{
if (rcx != 0)
{
NewOS::kcout << "newoskrnl: kerncall: enter.\r";
NewOS::kcout << "newoskrnl: kerncall: exit.\r";
}
}
|