summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
blob: b161f1db7d200af0e5368f4b0e87476cf01f8d79 (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
/*
 *	========================================================
 *
 *	HCore
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

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

static const char* kExceptionMessage[32] = {
    "Division by zero",
    "Debug Breakpoint",
    "Non-maskable interrupt",
    "Breakpoint",
    "Detected overflow",
    "Out-of-bounds",
    "Invalid opcode",
    "No coprocessor",
    "Double fault",
    "Coprocessor segment overrun",
    "Bad TSS",
    "Segment not found",
    "Stack error.",
    "General Protection Fault",
    "Page Fault",
    "Invalid interrupt",
    "Coprocessor fault",
    "Alignment check",
    "Machine check",
    "Reserved",
    "Reserved",
    "System Process Switch Issued",
    "System was interrupted by kernel",
    "System hang by kernel",
    "Reserved",
    "Reserved",
    "Reserved",
    "Reserved",
    "Reserved",
    "Reserved",
    "Reserved",
    "Reserved",
};

extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr& rsp) {
  HCore::HAL::rt_cli();

  HCore::HAL::StackFramePtr sf = (HCore::HAL::StackFramePtr)rsp;

  if (sf->IntNum == 0x21) {
    rt_syscall_handle(sf);
  }

  if (sf->IntNum < 32) {
    HCore::kcout << "Exception:" << kExceptionMessage[sf->IntNum] << "\n";
  }

  if (sf->IntNum >= 40) HCore::HAL::Out8(0x20, 0x20);  // ACK MASTER

  HCore::HAL::Out8(0xA0, 0x20);  // ACK SLAVE

  HCore::HAL::rt_sti();

  return rsp;
}