summaryrefslogtreecommitdiffhomepage
path: root/HALKit/AMD64/CoreInterruptHandlerAMD64.cpp
blob: fd037c5fe6b3e298c2b8ce97cee1823c284ba048 (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
/*
 *	========================================================
 *
 *	hCore
 * 	Copyright 2024 Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#include <ArchKit/Arch.hpp>
#include <NewKit/String.hpp>
#include <KernelKit/ProcessManager.hpp>

extern "C" void idt_handle_system_call(hCore::UIntPtr rsp)
{
    hCore::HAL::StackFrame *sf = reinterpret_cast<hCore::HAL::StackFrame*>(rsp);
    rt_syscall_handle(sf);

    hCore::kcout << "System Call with ID: " << hCore::StringBuilder::FromInt("syscall{%}", sf->SID);
}

extern "C" void idt_handle_gpf(hCore::UIntPtr rsp)
{
    MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent());

    hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp);

    hCore::kcout << "General Protection Fault, Caused by "
                   << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();

    hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}

extern "C" void idt_handle_scheduler(hCore::UIntPtr rsp)
{
    hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp);

    hCore::kcout << "Will be scheduled back later "
                   << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();

    /// schedule another process.
    if (!hCore::ProcessHelper::StartScheduling())
    {
        hCore::kcout << "Let's continue schedule this process...\r\n";
    }
}

extern "C" void idt_handle_pf(hCore::UIntPtr rsp)
{
    hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp);

    MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent());

    hCore::kcout << "Segmentation Fault, Caused by "
                   << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();

    hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}

extern "C" void idt_handle_math(hCore::UIntPtr rsp)
{
    hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp);

    MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent());

    hCore::kcout << "Math error, Caused by "
                   << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();

    hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}

extern "C" void idt_handle_generic(hCore::UIntPtr rsp)
{
    hCore::kcout << hCore::StringBuilder::FromInt("sp{%}", rsp);

    MUST_PASS(hCore::ProcessManager::Shared().Leak().GetCurrent());

    hCore::kcout << "Processor error, Caused by "
                   << hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName();

    hCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}