summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-28 22:53:57 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-28 22:53:57 +0100
commit8b14d5db84ffe44e0092afd610c216a6f36d7058 (patch)
tree07d7da034be8b0da2dde1545000c0fc0fa2d3b20 /Private/HALKit
parenta71e1f4adc378ae69a001a9b7103c37ce1b1ee64 (diff)
HCoreKrnl: Interrupts are now working.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/HALKit')
-rw-r--r--Private/HALKit/AMD64/HalCoreInterruptHandler.cpp13
-rw-r--r--Private/HALKit/AMD64/HalDebugOutput.cxx2
-rw-r--r--Private/HALKit/AMD64/HalDescriptorLoader.cpp2
-rw-r--r--Private/HALKit/AMD64/HalInterruptRouting.asm69
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx4
5 files changed, 34 insertions, 56 deletions
diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
index 9f2e37d8..e568aa4d 100644
--- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
+++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
@@ -50,13 +50,18 @@ static const char* kExceptionMessages[32] = {
#define kKernelSyscallInterrupt (0x21)
EXTERN_C {
- HCore::Void rt_handle_interrupts(
- HCore::HAL::StackFramePtr stack) {
+ HCore::Void rt_handle_interrupts(HCore::HAL::StackFramePtr stack) {
+ HCore::kcout << "HCoreKrnl: Interrupting Hart...\r\n";
+
+ if (stack->IntNum < 32) {
+ HCore::kcout << "HCoreKrnl: " << kExceptionMessages[stack->IntNum] << HCore::end_line();
+ }
+
switch (stack->IntNum) {
case kKernelSyscallInterrupt: {
HCore::kcout << "HCoreKrnl: System call raised, checking.."
<< HCore::end_line();
- rt_syscall_handle(nullptr);
+ rt_syscall_handle(stack);
break;
}
@@ -65,9 +70,11 @@ EXTERN_C {
}
if ((stack->IntNum - 32) >= 12) {
+ HCore::kcout << "HCoreKrnl: EOI Master PIC...\r\n";
HCore::HAL::Out8(0xA0, 0x20);
}
+ HCore::kcout << "HCoreKrnl: EOI Slave PIC...\r\n";
HCore::HAL::Out8(0x20, 0x20);
}
} \ No newline at end of file
diff --git a/Private/HALKit/AMD64/HalDebugOutput.cxx b/Private/HALKit/AMD64/HalDebugOutput.cxx
index 91b8086a..4a949fc1 100644
--- a/Private/HALKit/AMD64/HalDebugOutput.cxx
+++ b/Private/HALKit/AMD64/HalDebugOutput.cxx
@@ -29,6 +29,8 @@ static int kState = kStateInvalid;
/// @return
bool serial_init() noexcept {
#ifdef __DEBUG__
+ if (kState == kStateReady) return true;
+
HAL::Out8(PORT + 1, 0x00); // Disable all interrupts
HAL::Out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
HAL::Out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
diff --git a/Private/HALKit/AMD64/HalDescriptorLoader.cpp b/Private/HALKit/AMD64/HalDescriptorLoader.cpp
index 3c84f151..fb41f654 100644
--- a/Private/HALKit/AMD64/HalDescriptorLoader.cpp
+++ b/Private/HALKit/AMD64/HalDescriptorLoader.cpp
@@ -55,7 +55,7 @@ void IDTLoader::Load(Register64 &idt) {
MUST_PASS(baseIdt[0]);
- for (UInt16 i = 0; i < 32; i++) {
+ for (UInt16 i = 0; i < kKernelIdtSize; i++) {
kInterruptVectorTable[i].Selector = kGdtCodeSelector;
kInterruptVectorTable[i].Ist = 0x0;
kInterruptVectorTable[i].TypeAttributes = kInterruptGate;
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm
index 8d10ed4f..cd3c8bcf 100644
--- a/Private/HALKit/AMD64/HalInterruptRouting.asm
+++ b/Private/HALKit/AMD64/HalInterruptRouting.asm
@@ -12,61 +12,20 @@
[bits 64]
%macro IntExp 1
+align 4
+global __HCR_INT_%1
__HCR_INT_%1:
- cli
-
- push 1
- push %1
-
- push rax
- push rcx
- push rdx
- push rbx
- push rbp
- push rsi
- push rdi
-
- jmp rt_handle_interrupts
-
- pop rdi
- pop rsi
- pop rbp
- pop rbx
- pop rdx
- pop rcx
- pop rax
-
- add rsp, 16
- sti
+ cld
+
iretq
%endmacro
%macro IntNormal 1
+align 4
+global __HCR_INT_%1
__HCR_INT_%1:
- cli
-
- push 0
- push %1
-
- push rax
- push rcx
- push rdx
- push rbx
- push rbp
- push rsi
- push rdi
-
- jmp rt_handle_interrupts
-
- pop rdi
- pop rsi
- pop rbp
- pop rbx
- pop rdx
- pop rcx
- pop rax
+ cld
- sti
iretq
%endmacro
@@ -113,11 +72,21 @@ IntNormal 29
IntExp 30
IntNormal 31
+%assign i 32
+%rep 224
+ IntNormal i
+%assign i i+1
+%endrep
+
;; this one is doing a POST for us.
;; testing interrupts.
_ke_power_on_self_test:
- mov rcx, 0x80
+ mov rcx, 0x00
mov rdx, 0x01
+
+ int 0x21
+ int 0x21
+ int 0x21
int 0x21
ret
@@ -148,7 +117,7 @@ rt_load_idt:
kInterruptVectorTable:
%assign i 0
- %rep 32
+ %rep 256
dq __HCR_INT_%+i
%assign i i+1
%endrep
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index a9e15820..df7ce91e 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -91,12 +91,12 @@ EXTERN_C void RuntimeMain(
idt.Load(idtBase);
KeInitRsrc();
- KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH, ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2.5), ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2.5));
+ KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH, ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2), ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2));
KeClearRsrc();
Detail::_ke_power_on_self_test();
- HCore::kcout << "HCoreKrnl: System Call issued, everything is OK...\r\n";
+ HCore::kcout << "HCoreKrnl: POST done, everything is OK...\r\n";
if (HandoverHeader->f_Bootloader == kInstalledMedia) {
/// Mounts a NewFS block.