summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-25 18:19:19 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-25 18:19:41 +0100
commit91c88797f7fa9dbb6cce12c14928a6fbd97d51b6 (patch)
tree9dd58ee1e796684e6ec15902d39836e45a1cf054 /Private/HALKit
parent2bd2e28868d50a2f3ced8b1bfea68216ed35622a (diff)
Kernel: Did progress on interrupts, moved kernel main to HAL, as the
code here is very specific. Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/HALKit')
-rw-r--r--Private/HALKit/AMD64/HalCoreInterruptHandler.cpp8
-rw-r--r--Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp5
-rw-r--r--Private/HALKit/AMD64/HalInterruptRouting.asm37
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx129
-rw-r--r--Private/HALKit/AMD64/HalNewBoot.asm27
-rw-r--r--Private/HALKit/AMD64/HalPlatformAMD64.cpp31
-rw-r--r--Private/HALKit/AMD64/HalRoutines.s12
-rw-r--r--Private/HALKit/AMD64/Processor.hpp4
-rw-r--r--Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp14
-rw-r--r--Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp5
10 files changed, 207 insertions, 65 deletions
diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
index a668a0e4..1e46e5af 100644
--- a/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
+++ b/Private/HALKit/AMD64/HalCoreInterruptHandler.cpp
@@ -16,10 +16,14 @@ extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr &rsp) {
HCore::HAL::StackFramePtr sf = (HCore::HAL::StackFramePtr)rsp;
- rt_syscall_handle(sf);
+ if (sf->IntNum == 0x21) {
+ rt_syscall_handle(sf);
+ }
- HCore::kcout << "Krnl\\rt_handle_interrupts: Done\r\n";
+ HCore::HAL::Out8(0x20, 0x20);
+ HCore::HAL::Out8(0xa0, 0x20);
HCore::HAL::rt_sti();
+
return rsp;
}
diff --git a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp
index 2e75b6cb..cacb66d8 100644
--- a/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp
+++ b/Private/HALKit/AMD64/HalCoreSyscallHandlerAMD64.cpp
@@ -11,12 +11,13 @@
#include <HALKit/AMD64/Processor.hpp>
#include <KernelKit/PermissionSelector.hxx>
-HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls>
+HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *),
+ kKernelMaxSystemCalls>
kSyscalls;
/// @brief Interrupt system call handler.
extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) {
- for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) {
+ for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) {
if (kSyscalls[index]) (kSyscalls[index].Leak().Leak())(stack->R15, stack);
}
}
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm
index 0f8ad89b..f50fb752 100644
--- a/Private/HALKit/AMD64/HalInterruptRouting.asm
+++ b/Private/HALKit/AMD64/HalInterruptRouting.asm
@@ -20,7 +20,6 @@ HCoreInterrupt%1:
cli
push %1
jmp ke_handle_irq
- iretq
%endmacro
%macro IntNormal 1
@@ -29,7 +28,6 @@ HCoreInterrupt%1:
push 0
push %1
jmp ke_handle_irq
- iretq
%endmacro
; This file handles the core interrupt table
@@ -78,7 +76,7 @@ ke_handle_irq:
pop rbx
pop rax
- retf
+ iretq
section .data
@@ -115,11 +113,7 @@ section .data
IntExp 30
IntNormal 31
- %assign i 32
- %rep 224
- IntNormal i
- %assign i i+1
- %endrep
+section .data
__EXEC_IVT:
%assign i 0
@@ -128,25 +122,10 @@ __EXEC_IVT:
%assign i i+1
%endrep
-section .text
-
-[bits 64]
-
-extern rt_load_gdt
-
-global Main
-extern RuntimeMain
-extern MainLong
-
-;; Just a simple setup, we'd also need to tell some before
-Main:
- push rcx
- jmp MainLong
+ %assign i 32
+ %rep 224
+ IntNormal i
+ %assign i i+1
+ %endrep
-MainLong:
- jmp RuntimeMain
- pop rcx
-L0:
- cli
- hlt
- jmp $
+ ret
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
new file mode 100644
index 00000000..b581f6de
--- /dev/null
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -0,0 +1,129 @@
+/*
+ * ========================================================
+ *
+ * HCore
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <ArchKit/ArchKit.hpp>
+#include <Drivers/PS2/Mouse.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/FileManager.hpp>
+#include <KernelKit/Framebuffer.hpp>
+#include <KernelKit/PEFCodeManager.hxx>
+#include <KernelKit/Rsrc/Award.hxx>
+#include <KernelKit/Rsrc/HCore.hxx>
+#include <KernelKit/Rsrc/Util.hxx>
+#include <NewKit/Json.hpp>
+#include <NewKit/KernelHeap.hpp>
+#include <NewKit/UserHeap.hpp>
+
+extern "C" HCore::UIntPtr __EXEC_IVT;
+
+namespace Detail {
+using namespace HCore;
+
+Void PowerOnSelfTest() {
+ kcout << "POST: Starting PowerOn-Self Test...\r\n";
+ asm("int $0x21");
+ kcout << "POST: Done\r\n";
+}
+
+struct PACKED HC_GDT_ENTRY final {
+ UInt16 Limit0;
+ UInt16 Base0;
+ UInt8 Base1;
+ UInt8 AccessByte;
+ UInt8 Limit1_Flags;
+ UInt8 Base2;
+};
+
+struct PACKED ALIGN(0x1000) HC_GDT final {
+ HC_GDT_ENTRY Null;
+ HC_GDT_ENTRY KernCode;
+ HC_GDT_ENTRY KernData;
+ HC_GDT_ENTRY UserNull;
+ HC_GDT_ENTRY UserCode;
+ HC_GDT_ENTRY UserData;
+};
+} // namespace Detail
+
+EXTERN_C void RuntimeMain(
+ HCore::HEL::HandoverInformationHeader* HandoverHeader) {
+ HCore::kcout << "HCoreKrnl: (R) Version 1.00, (C) MahroussLogic all rights "
+ "reserved.\n";
+
+ /// Setup kernel globals.
+ kKernelVirtualSize = HandoverHeader->f_VirtualSize;
+ kKernelVirtualStart = HandoverHeader->f_VirtualStart;
+
+ kKernelPhysicalSize = HandoverHeader->f_VirtualSize;
+ kKernelPhysicalStart = HandoverHeader->f_VirtualStart;
+
+ static Detail::HC_GDT GDT = {
+ {0, 0, 0, 0x00, 0x00, 0}, // null entry
+ {0, 0, 0, 0x9a, 0xa0, 0}, // kernel code
+ {0, 0, 0, 0x92, 0xa0, 0}, // kernel data
+ {0, 0, 0, 0x00, 0x00, 0}, // null entry
+ {0, 0, 0, 0x9a, 0xa0, 0}, // user code
+ {0, 0, 0, 0x92, 0xa0, 0}, // user data
+ };
+
+ HCore::HAL::Register64 gdtBase;
+
+ gdtBase.Base = (HCore::UIntPtr)&GDT;
+ gdtBase.Limit = sizeof(Detail::HC_GDT) - 1;
+
+ HCore::HAL::GDTLoader gdt;
+ gdt.Load(gdtBase);
+
+ HCore::VoidPtr IDT = new HCore::VoidPtr;
+
+ HCore::HAL::Register64 idtBase;
+ idtBase.Base = (HCore::UIntPtr)IDT;
+ idtBase.Limit = 0x0FFF;
+
+ HCore::HAL::IDTLoader idt;
+ idt.Load(idtBase);
+
+ if (HandoverHeader->f_Bootloader == 0xDD) {
+ /// Mount a New partition.
+ HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
+
+ // Open file from first hard-drive.
+ HCore::PEFLoader img("A:/System/HCoreServer.exe");
+
+ /// Run the shell.
+ if (!HCore::Utils::execute_from_image(img)) {
+ HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+ }
+ } else {
+ /**
+ ** This draws the background.
+ */
+
+ ResourceInit();
+
+ DrawResource(HCoreLogo, HandoverHeader, HCORELOGO_HEIGHT, HCORELOGO_WIDTH,
+ 10, 10);
+
+ ResourceClear();
+
+ DrawResource(PoweredByAward, HandoverHeader, POWEREDBYAWARD_HEIGHT,
+ POWEREDBYAWARD_WIDTH, POWEREDBYAWARD_WIDTH + 20, 10);
+
+ Detail::PowerOnSelfTest();
+
+ /**
+ ** This draws the HCore resource icon..
+ */
+
+ /**
+ This mounts the NewFS drive.
+ */
+
+ HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+ }
+}
diff --git a/Private/HALKit/AMD64/HalNewBoot.asm b/Private/HALKit/AMD64/HalNewBoot.asm
index 93456c89..8c7d7d1a 100644
--- a/Private/HALKit/AMD64/HalNewBoot.asm
+++ b/Private/HALKit/AMD64/HalNewBoot.asm
@@ -13,9 +13,6 @@
[global MainLong]
[global MainUnsupported]
-;; External symbols needed by this unit.
-[extern Main]
-
%define kTypeKernel 100
%define kArchAmd64 122
@@ -26,3 +23,27 @@ HandoverType: dw kTypeKernel
HandoverArch: dw kArchAmd64
;; This NewBootStart points to Main.
HandoverStart: dq Main
+
+section .text
+
+[bits 64]
+
+extern rt_load_gdt
+extern rt_load_ivt
+
+global Main
+extern RuntimeMain
+extern MainLong
+
+;; Just a simple setup, we'd also need to tell some before
+Main:
+ push rcx
+ jmp MainLong
+
+MainLong:
+ jmp RuntimeMain
+ pop rcx
+L0:
+ cli
+ hlt
+ jmp $
diff --git a/Private/HALKit/AMD64/HalPlatformAMD64.cpp b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
index e9e7fb82..b2e98004 100644
--- a/Private/HALKit/AMD64/HalPlatformAMD64.cpp
+++ b/Private/HALKit/AMD64/HalPlatformAMD64.cpp
@@ -10,21 +10,13 @@
#include <ArchKit/ArchKit.hpp>
namespace HCore::HAL {
-namespace Detail {
-struct PACKED RegisterAMD64 final {
- UIntPtr base;
- UShort limit;
-};
-} // namespace Detail
-
void GDTLoader::Load(Register64 &gdt) {
- Detail::RegisterAMD64 *gdtReg = new Detail::RegisterAMD64();
- MUST_PASS(gdtReg);
+ Register64 gdtReg;
- gdtReg->base = gdt.Base;
- gdtReg->limit = gdt.Limit;
+ gdtReg.Base = gdt.Base;
+ gdtReg.Limit = gdt.Limit;
- rt_load_gdt((VoidPtr)gdtReg);
+ rt_load_gdt(gdtReg);
}
namespace Detail::AMD64 {
@@ -49,15 +41,16 @@ struct InterruptDescriptorAMD64 final {
extern "C" HCore::UIntPtr rt_handle_interrupts(HCore::UIntPtr &rsp);
-static ALIGN(
- 0x10) Detail::AMD64::InterruptDescriptorAMD64 kIdtRegs[kMaxSyscalls];
+static ALIGN(0x10)
+ Detail::AMD64::InterruptDescriptorAMD64 kIdtRegs[kKernelMaxSystemCalls];
static HAL::Register64 kRegIdt;
void IDTLoader::Load(Register64 &idt) {
for (auto i = 0; i < 32; i++) {
kIdtRegs[i].Selector = kGdtSelector;
kIdtRegs[i].Ist = 0x00;
- kIdtRegs[i].TypeAttributes = kInterruptGate | kRing0 | kIdtPresent;
+ kIdtRegs[i].TypeAttributes =
+ kInterruptGate | kTrapGate | kRing0 | kIdtPresent;
kIdtRegs[i].OffsetLow = (((UIntPtr *)idt.Base)[i]) & 0xFFFF;
kIdtRegs[i].OffsetMid = (((UIntPtr *)idt.Base)[i] >> 16) & 0xFFFF;
kIdtRegs[i].OffsetHigh = (((UIntPtr *)idt.Base)[i] >> 32) & 0xFFFF;
@@ -75,9 +68,13 @@ void IDTLoader::Load(Register64 &idt) {
kRegIdt.Base = (UIntPtr)kIdtRegs;
kRegIdt.Limit = sizeof(Detail::AMD64::InterruptDescriptorAMD64) * idt.Limit;
- rt_load_idt((VoidPtr)&kRegIdt);
+ kcout << "HCoreKrnl: Installing Interrupt vector...\n";
+
+ rt_load_idt(kRegIdt);
+
+ asm volatile("sti");
- kcout << "Krnl: IDT loaded\n";
+ kcout << "HCoreKrnl: Interrupt Vector installed.\n";
}
void GDTLoader::Load(Ref<Register64> &gdt) { GDTLoader::Load(gdt.Leak()); }
diff --git a/Private/HALKit/AMD64/HalRoutines.s b/Private/HALKit/AMD64/HalRoutines.s
index 28833c47..d809541f 100644
--- a/Private/HALKit/AMD64/HalRoutines.s
+++ b/Private/HALKit/AMD64/HalRoutines.s
@@ -6,7 +6,17 @@
.section .text
rt_load_gdt:
lgdt (%rcx)
- ret
+ mov $0x10, %ax
+ mov %ax, %ds
+ mov %ax, %es
+ mov %ax, %fs
+ mov %ax, %gs
+ mov %ax, %ss
+ pop %rdi
+ mov $0x08, %rax
+ push %rax
+ push %rdi
+ retfq
rt_load_idt:
lidt (%rcx)
diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp
index a624b795..2ba98abf 100644
--- a/Private/HALKit/AMD64/Processor.hpp
+++ b/Private/HALKit/AMD64/Processor.hpp
@@ -138,5 +138,5 @@ extern "C" void idt_handle_gpf(HCore::UIntPtr rsp);
extern "C" void idt_handle_math(HCore::UIntPtr rsp);
extern "C" void idt_handle_pf(HCore::UIntPtr rsp);
-extern "C" void rt_load_idt(HCore::voidPtr ptr);
-extern "C" void rt_load_gdt(HCore::voidPtr ptr);
+extern "C" void rt_load_idt(HCore::HAL::Register64 ptr);
+extern "C" void rt_load_gdt(HCore::HAL::Register64 ptr);
diff --git a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp
index 5d1c6d2b..51b1fa0d 100644
--- a/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp
+++ b/Private/HALKit/AXP/CoreSyscallHandlerDEC.cpp
@@ -10,12 +10,12 @@
#include <ArchKit/ArchKit.hpp>
#include <HALKit/Alpha/Processor.hpp>
-HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls> kSyscalls;
+HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *),
+ kKernelMaxSystemCalls>
+ kSyscalls;
-extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack)
-{
- for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index)
- {
- (kSyscalls[index].Leak().Leak())(stack->ID, stack);
- }
+extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) {
+ for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) {
+ (kSyscalls[index].Leak().Leak())(stack->ID, stack);
+ }
}
diff --git a/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp b/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp
index c1672e68..71554dc4 100644
--- a/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp
+++ b/Private/HALKit/PowerPC/HalCoreSyscallHandlerPowerPC.cpp
@@ -10,11 +10,12 @@
#include <ArchKit/ArchKit.hpp>
#include <NewKit/Array.hpp>
-HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *), kMaxSyscalls>
+HCore::Array<void (*)(HCore::Int32 id, HCore::HAL::StackFrame *),
+ kKernelMaxSystemCalls>
kSyscalls;
extern "C" void rt_syscall_handle(HCore::HAL::StackFrame *stack) {
- for (HCore::SizeT index = 0UL; index < kMaxSyscalls; ++index) {
+ for (HCore::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) {
(kSyscalls[index].Leak().Leak())(stack->ID, stack);
}
}