summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-31 15:24:18 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-31 15:24:18 +0100
commit510c659355d9227d1b75edfe50c1b8691ea2f982 (patch)
tree56b5cc1b536555c5b313d4fb104410f9cf04fff0 /dev/Kernel/HALKit
parente48bf6e7af428f34bd85b733060554cfec6591d5 (diff)
IMPL: Better panic screen, fixing CUSA as in the gh issue.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit')
-rw-r--r--dev/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc10
-rw-r--r--dev/Kernel/HALKit/AMD64/HalCoreScheduler.cc10
-rw-r--r--dev/Kernel/HALKit/AMD64/HalInterruptAPI.asm135
-rw-r--r--dev/Kernel/HALKit/AMD64/HalKernelPanic.cc93
4 files changed, 182 insertions, 66 deletions
diff --git a/dev/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
index aa986635..771a1e33 100644
--- a/dev/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
+++ b/dev/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
@@ -29,8 +29,6 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
process.Leak().Status = Kernel::ProcessStatusKind::kFrozen;
process.Leak().Crash();
-
- Kernel::ke_panic(RUNTIME_CHECK_POINTER);
}
/// @brief Handle page fault.
@@ -54,8 +52,8 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp)
process.Leak().Status = Kernel::ProcessStatusKind::kFrozen;
process.Leak().Crash();
+
- Kernel::ke_panic(RUNTIME_CHECK_PAGE);
}
/// @brief Handle scheduler interrupt.
@@ -102,7 +100,7 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp)
process.Leak().Crash();
- Kernel::ke_panic(RUNTIME_CHECK_UNEXCPECTED);
+
}
/// @brief Handle any generic fault.
@@ -125,8 +123,8 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp)
process.Leak().Status = Kernel::ProcessStatusKind::kFrozen;
process.Leak().Crash();
+
- Kernel::ke_panic(RUNTIME_CHECK_UNEXCPECTED);
}
EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip)
@@ -170,7 +168,7 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp)
process.Leak().Crash();
- Kernel::ke_panic(RUNTIME_CHECK_UNEXCPECTED);
+
}
/// @brief Enter syscall from assembly.
diff --git a/dev/Kernel/HALKit/AMD64/HalCoreScheduler.cc b/dev/Kernel/HALKit/AMD64/HalCoreScheduler.cc
index f42787c3..c8556ddc 100644
--- a/dev/Kernel/HALKit/AMD64/HalCoreScheduler.cc
+++ b/dev/Kernel/HALKit/AMD64/HalCoreScheduler.cc
@@ -28,7 +28,7 @@
#define kAPIC_BASE_MSR_BSP 0x100
#define kAPIC_BASE_MSR_ENABLE 0x800
-#define cSMPMax (32U)
+#define kSMPMax (32U)
/// @note: _hal_switch_context is internal
@@ -48,8 +48,8 @@ namespace Kernel::HAL
STATIC Bool kSMPAware = false;
STATIC Int64 kSMPCount = 0;
- STATIC Int32 cSMPInterrupt = 0;
- STATIC UInt64 kAPICLocales[cSMPMax] = {0};
+ STATIC Int32 kSMPInterrupt = 0;
+ STATIC UInt64 kAPICLocales[kSMPMax] = {0};
STATIC VoidPtr kRawMADT = nullptr;
/// @brief Multiple APIC Descriptor Table.
@@ -194,7 +194,7 @@ namespace Kernel::HAL
// reset values.
- cSMPInterrupt = 0;
+ kSMPInterrupt = 0;
kSMPCount = 0;
kcout << "SMP: Probing Local APICs...\r";
@@ -204,7 +204,7 @@ namespace Kernel::HAL
while (Yes)
{
if (kMADTBlock->List[index].Type > 9 ||
- kSMPCount > cSMPMax)
+ kSMPCount > kSMPMax)
break;
switch (kMADTBlock->List[index].Type)
diff --git a/dev/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/dev/Kernel/HALKit/AMD64/HalInterruptAPI.asm
index d0dcc2a9..11deca52 100644
--- a/dev/Kernel/HALKit/AMD64/HalInterruptAPI.asm
+++ b/dev/Kernel/HALKit/AMD64/HalInterruptAPI.asm
@@ -19,8 +19,8 @@ __ZKA_INT_%1:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
sti
o64 iret
@@ -32,8 +32,8 @@ __ZKA_INT_%1:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
sti
o64 iret
@@ -54,17 +54,36 @@ extern idt_handle_breakpoint
section .text
-IntNormal 0
-IntNormal 1
-IntNormal 2
+__ZKA_INT_0:
+ cli
-section .data
+ mov al, 0x20
+ out 0x20, al
-__ZKA_INT_3_GET_RIP:
- dq 0
-__ZKA_INT_3_GET_RIP_END:
+ sti
+ o64 iret
-section .text
+__ZKA_INT_1:
+ cli
+
+ mov al, 0x20
+ out 0x20, al
+
+ sti
+ o64 iret
+
+__ZKA_INT_2:
+ cli
+
+ mov al, 0x20
+ out 0x20, al
+
+ push rcx
+ call idt_handle_generic
+ pop rcx
+
+ sti
+ o64 iret
;; @brief Triggers a breakpoint and freeze the process. RIP is also fetched.
__ZKA_INT_3:
@@ -72,23 +91,34 @@ __ZKA_INT_3:
mov al, 0x20
out 0x20, al
- out 0xA0, al
- push rax
- mov rax, idt_handle_breakpoint
+ push rcx
+ call idt_handle_generic
+ pop rcx
+ sti
+ o64 iret
- lea rcx, [rel __ZKA_INT_3_GET_RIP]
- sub rcx, 16
- mov [rcx], rcx
+__ZKA_INT_4:
+ cli
- call rax
- pop rax
+ mov al, 0x20
+ out 0x20, al
+
+ push rcx
+ call idt_handle_generic
+ pop rcx
sti
o64 iret
-IntNormal 4
-IntNormal 5
+__ZKA_INT_5:
+ cli
+
+ mov al, 0x20
+ out 0x20, al
+
+ sti
+ o64 iret
;; Invalid opcode interrupt
__ZKA_INT_6:
@@ -96,36 +126,38 @@ __ZKA_INT_6:
mov al, 0x20
out 0x20, al
- out 0xA0, al
- push rax
- mov rax, idt_handle_ud
+ push rcx
+ call idt_handle_generic
+ pop rcx
- mov rcx, rsp
+ sti
+ o64 iret
- call rax
- pop rax
+__ZKA_INT_7:
+ cli
+
+ mov al, 0x20
+ out 0x20, al
+
+ push rcx
+ call idt_handle_generic
+ pop rcx
sti
o64 iret
-IntNormal 7
-
;; Invalid opcode interrupt
__ZKA_INT_8:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
- push rax
- mov rax, idt_handle_generic
-
- mov rcx, rsp
-
- call rax
- pop rax
+ push rcx
+ call idt_handle_generic
+ pop rcx
sti
o64 iret
@@ -140,16 +172,12 @@ __ZKA_INT_13:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
- push rax
- mov rax, idt_handle_gpf
-
- mov rcx, rsp
-
- call rax
- pop rax
+ push rcx
+ call idt_handle_gpf
+ pop rcx
sti
o64 iret
@@ -158,15 +186,12 @@ __ZKA_INT_14:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
- push rax
- mov rax, idt_handle_pf
-
- mov rcx, rsp
+ out 0x20, al
- call rax
- pop rax
+ push rcx
+ call idt_handle_pf
+ pop rcx
sti
o64 iret
@@ -197,9 +222,9 @@ __ZKA_INT_32:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
-
+ out 0x20, al
+
push rax
mov rcx, rsp
call idt_handle_scheduler
@@ -236,8 +261,8 @@ __ZKA_INT_50:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
push rax
mov rax, hal_system_call_enter
@@ -256,8 +281,8 @@ __ZKA_INT_51:
cli
mov al, 0x20
- out 0x20, al
out 0xA0, al
+ out 0x20, al
push rax
mov rax, hal_kernel_call_enter
diff --git a/dev/Kernel/HALKit/AMD64/HalKernelPanic.cc b/dev/Kernel/HALKit/AMD64/HalKernelPanic.cc
new file mode 100644
index 00000000..ac41f7fa
--- /dev/null
+++ b/dev/Kernel/HALKit/AMD64/HalKernelPanic.cc
@@ -0,0 +1,93 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Theater Quality Corp, all rights reserved.
+
+------------------------------------------- */
+
+#include <NewKit/KernelPanic.h>
+#include <ArchKit/ArchKit.h>
+#include <KernelKit/Timer.h>
+#include <KernelKit/DebugOutput.h>
+#include <NewKit/KString.h>
+#include <FirmwareKit/Handover.h>
+#include <KernelKit/FileMgr.h>
+#include <Mod/GfxMgr/FBMgr.h>
+#include <Mod/GfxMgr/TextMgr.h>
+#include <NewKit/Utils.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() noexcept;
+ };
+
+ /***********************************************************************************/
+ /// @brief Stops execution of the kernel.
+ /// @param id kernel stop ID.
+ /***********************************************************************************/
+ Void ke_panic(const Kernel::Int32& id, const Char* message)
+ {
+ fb_init();
+
+ auto panic_text = RGB(0xff, 0xff, 0xff);
+
+ auto y = 10;
+ auto x = 10;
+
+ Char* message_apicid = new Char[128];
+ rt_set_memory(message_apicid, 0, 128);
+
+ rt_copy_memory((VoidPtr) "panic id: ", message_apicid, rt_string_len("panic id: "));
+ rt_to_string(message_apicid + rt_string_len("panic id: "), (UIntPtr)id, 10);
+
+ fb_render_string(message_apicid, y, x, panic_text);
+
+ y += 10;
+
+ fb_render_string((message ? message : "message: panic raised, going nowhere after this!"), y, x, panic_text);
+
+ y += 10;
+
+ Char* message_cr2 = new Char[128];
+ rt_set_memory(message_cr2, 0, 128);
+
+ rt_copy_memory((VoidPtr) "cr2: ", message_cr2, rt_string_len("cr2: "));
+ rt_to_string(message_cr2 + rt_string_len("cr2: "), (UIntPtr)hal_read_cr2(), 10);
+
+ fb_render_string(message_cr2, y, x, panic_text);
+
+ kcout << message_apicid;
+ kcout << message_cr2;
+
+ y += 10;
+
+ fb_clear();
+
+ RecoveryFactory::Recover();
+ }
+
+ Void RecoveryFactory::Recover() noexcept
+ {
+ while (YES)
+ {
+ HAL::rt_halt();
+ }
+ }
+
+ void ke_runtime_check(bool expr, const Char* file, const Char* line)
+ {
+ if (!expr)
+ {
+ kcout << "FAILED: FILE: " << file << endl;
+ kcout << "FAILED: LINE: " << line << endl;
+
+ ke_panic(RUNTIME_CHECK_FAILED, file); // Runtime Check failed
+ }
+ }
+} // namespace Kernel