summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/AMD64
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/HALKit/AMD64')
-rw-r--r--Kernel/HALKit/AMD64/CPUID.hxx2
-rw-r--r--Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx9
-rw-r--r--Kernel/HALKit/AMD64/HalAPIC.cxx36
-rw-r--r--Kernel/HALKit/AMD64/HalBoot.asm (renamed from Kernel/HALKit/AMD64/HalNewBoot.asm)2
-rw-r--r--Kernel/HALKit/AMD64/HalControlRegister.s2
-rw-r--r--Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx (renamed from Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp)12
-rw-r--r--Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx (renamed from Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp)107
-rw-r--r--Kernel/HALKit/AMD64/HalDebugOutput.cxx13
-rw-r--r--Kernel/HALKit/AMD64/HalDebugPort.cxx2
-rw-r--r--Kernel/HALKit/AMD64/HalDescriptorLoader.cxx (renamed from Kernel/HALKit/AMD64/HalDescriptorLoader.cpp)11
-rw-r--r--Kernel/HALKit/AMD64/HalHart.cxx (renamed from Kernel/HALKit/AMD64/HalHart.cpp)2
-rw-r--r--Kernel/HALKit/AMD64/HalInstallTIB.asm24
-rw-r--r--Kernel/HALKit/AMD64/HalInterruptAPI.asm47
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx71
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMouse.cxx14
-rw-r--r--Kernel/HALKit/AMD64/HalPageAlloc.hxx (renamed from Kernel/HALKit/AMD64/HalPageAlloc.hpp)20
-rw-r--r--Kernel/HALKit/AMD64/HalProcessor.cxx (renamed from Kernel/HALKit/AMD64/HalProcessor.cpp)20
-rw-r--r--Kernel/HALKit/AMD64/HalSMPCoreManager.asm2
-rw-r--r--Kernel/HALKit/AMD64/HalScheduler.cxx (renamed from Kernel/HALKit/AMD64/HalSMPCore.cxx)8
-rw-r--r--Kernel/HALKit/AMD64/HalTimer.cxx14
-rw-r--r--Kernel/HALKit/AMD64/HalUtils.asm49
-rw-r--r--Kernel/HALKit/AMD64/Hypervisor.hpp3
-rw-r--r--Kernel/HALKit/AMD64/PCI/Database.cxx2
-rw-r--r--Kernel/HALKit/AMD64/PCI/Device.cxx14
-rw-r--r--Kernel/HALKit/AMD64/PCI/Dma.cxx2
-rw-r--r--Kernel/HALKit/AMD64/PCI/Express.cxx2
-rw-r--r--Kernel/HALKit/AMD64/PCI/IO.cxx2
-rw-r--r--Kernel/HALKit/AMD64/PCI/Iterator.cxx2
-rw-r--r--Kernel/HALKit/AMD64/PCI/PCI.cxx4
-rw-r--r--Kernel/HALKit/AMD64/Processor.hxx (renamed from Kernel/HALKit/AMD64/Processor.hpp)121
-rw-r--r--Kernel/HALKit/AMD64/Storage/AHCI.cxx4
-rw-r--r--Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx4
-rw-r--r--Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx4
33 files changed, 376 insertions, 255 deletions
diff --git a/Kernel/HALKit/AMD64/CPUID.hxx b/Kernel/HALKit/AMD64/CPUID.hxx
index 602b2466..5c05277e 100644
--- a/Kernel/HALKit/AMD64/CPUID.hxx
+++ b/Kernel/HALKit/AMD64/CPUID.hxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
File: CPUID.hxx
Purpose: CPUID flags.
diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx
index ca6a7417..6f66ae5b 100644
--- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx
+++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx
@@ -1,14 +1,14 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
#include <Modules/ACPI/ACPIFactoryInterface.hxx>
-#include <HALKit/AMD64/Processor.hpp>
+#include <HALKit/AMD64/Processor.hxx>
#include <NewKit/String.hpp>
#include <ArchKit/ArchKit.hpp>
-#include <KernelKit/KernelHeap.hpp>
+#include <KernelKit/Heap.hxx>
namespace Kernel
{
@@ -104,7 +104,8 @@ namespace Kernel
{
SDT& sdt = *reinterpret_cast<SDT*>(xsdt->AddressArr[index]);
- kcout << "ACPI: Revision: " << number(sdt.CreatorID) << endl;
+ kcout << "ACPI: Checksum: " << number(sdt.Checksum) << endl;
+ kcout << "ACPI: Revision: " << number(sdt.Revision) << endl;
for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index)
{
diff --git a/Kernel/HALKit/AMD64/HalAPIC.cxx b/Kernel/HALKit/AMD64/HalAPIC.cxx
new file mode 100644
index 00000000..34ec7494
--- /dev/null
+++ b/Kernel/HALKit/AMD64/HalAPIC.cxx
@@ -0,0 +1,36 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <HALKit/AMD64/Processor.hxx>
+
+namespace Kernel::HAL
+{
+ /// @brief Read from APIC controller.
+ /// @param reg register.
+ UInt32 APICController::Read(UInt32 reg) noexcept
+ {
+ MUST_PASS(this->fApic);
+
+ UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic;
+ ioapic[0] = (reg & 0xff);
+
+ return ioapic[4];
+ }
+
+ /// @brief Write to APIC controller.
+ /// @param reg register.
+ /// @param value value.
+ Void APICController::Write(UInt32 reg, UInt32 value) noexcept
+ {
+ MUST_PASS(this->fApic);
+
+ UInt32 volatile* ioapic = (UInt32 volatile*)this->fApic;
+
+ ioapic[0] = (reg & 0xFF);
+ ioapic[4] = value;
+ }
+} // namespace Kernel::HAL
diff --git a/Kernel/HALKit/AMD64/HalNewBoot.asm b/Kernel/HALKit/AMD64/HalBoot.asm
index 5f0342a3..ab8273a1 100644
--- a/Kernel/HALKit/AMD64/HalNewBoot.asm
+++ b/Kernel/HALKit/AMD64/HalBoot.asm
@@ -2,7 +2,7 @@
;; * ========================================================
;; *
;; * Kernel
-;; * Copyright Zeta Electronics Corporation, all rights reserved.
+;; * Copyright ZKA Technologies, all rights reserved.
;; *
;; * ========================================================
;; */
diff --git a/Kernel/HALKit/AMD64/HalControlRegister.s b/Kernel/HALKit/AMD64/HalControlRegister.s
index 20eda96f..34b3da90 100644
--- a/Kernel/HALKit/AMD64/HalControlRegister.s
+++ b/Kernel/HALKit/AMD64/HalControlRegister.s
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
index f41ee55e..29c0f3c7 100644
--- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp
+++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -14,7 +14,7 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
{
Kernel::kcout
<< "newoskrnl: General Protection Fault, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName();
+ << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
@@ -25,7 +25,7 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp)
{
Kernel::kcout
<< "newoskrnl: Segmentation Fault, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName();
+ << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
@@ -36,7 +36,7 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp)
{
Kernel::kcout
<< "newoskrnl: Math error, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName();
+ << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
@@ -47,7 +47,7 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp)
{
Kernel::kcout
<< "newoskrnl: Execution error, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName();
+ << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
@@ -58,7 +58,7 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp)
{
Kernel::kcout
<< "newoskrnl: Invalid interrupt, caused by "
- << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName();
+ << Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetProcessName();
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
index 94fe68ad..48d737fe 100644
--- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp
+++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
@@ -1,11 +1,11 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
#include <Modules/ACPI/ACPIFactoryInterface.hxx>
-#include <HALKit/AMD64/Processor.hpp>
+#include <HALKit/AMD64/Processor.hxx>
#include <NewKit/KernelCheck.hpp>
#include <ArchKit/ArchKit.hpp>
#include <KernelKit/Semaphore.hpp>
@@ -17,10 +17,14 @@
#define kAPIC_SIPI_Vector 0x00500
#define kAPIC_EIPI_Vector 0x00400
+#define kAPIC_BASE_MSR 0x1B
+#define kAPIC_BASE_MSR_BSP 0x100
+#define kAPIC_BASE_MSR_ENABLE 0x800
+
/// @brief assembly routine. internal use only.
EXTERN_C void _hal_enable_smp(void);
-/// @note: _hal_switch_context
+/// @note: _hal_switch_context is internal
///////////////////////////////////////////////////////////////////////////////////////
@@ -57,8 +61,8 @@ namespace Kernel::HAL
} Selector;
};
- STATIC voidPtr kApicMadt = nullptr;
- STATIC const char* kApicSignature = "APIC";
+ STATIC VoidPtr kApicMadt = nullptr;
+ STATIC const Char* kApicSignature = "APIC";
/// @brief Multiple APIC Descriptor Table.
struct MadtType final : public SDT
@@ -122,11 +126,7 @@ namespace Kernel::HAL
UInt32 fKind{0};
} kApicMadtAddresses[255] = {};
- STATIC SizeT kApicMadtAddressesCount = 0UL;
- STATIC UIntPtr cBaseAddressAPIC = 0xFEE00000;
-
- /// @brief this will help us schedule our cores.
- STATIC Boolean* cProgramInitialized = nullptr;
+ STATIC SizeT kApicMadtAddressesCount = 0UL;
enum
{
@@ -142,7 +142,7 @@ namespace Kernel::HAL
/// @return
Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress)
{
- Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, apicId << 24);
+ Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24));
Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_SIPI_Vector | vector);
}
@@ -159,25 +159,23 @@ namespace Kernel::HAL
Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector);
}
- STATIC HAL::StackFramePtr cFramePtr = nullptr;
- STATIC Int32 cSMPInterrupt = 0x40;
-
- EXTERN_C Void hal_apic_acknowledge_cont(Void)
- {
- kcout << "newoskrnl: stopping core...\r";
- ke_stop(RUNTIME_CHECK_BOOTSTRAP);
- }
+ STATIC HAL::StackFramePtr cFramePtr = nullptr;
+ STATIC Int32 cSMPInterrupt = 34;
+ /// @brief Current context getter.
+ /// @retval StackFramePtr the current context.
EXTERN_C StackFramePtr _hal_leak_current_context(Void)
{
return cFramePtr;
}
+ /// @internal
EXTERN_C Void hal_apic_acknowledge(Void)
{
- hal_apic_acknowledge_cont();
+ kcout << "newoskrnl: acknowledge APIC.\r";
}
+ /// @internal
EXTERN_C Void _hal_switch_context(HAL::StackFramePtr stackFrame)
{
hal_switch_context(stackFrame);
@@ -187,17 +185,37 @@ namespace Kernel::HAL
{
Semaphore sem;
- HardwareTimer timer(Seconds(5));
+ constexpr auto cSeconds = 1U;
+
+ HardwareTimer timer(Seconds(cSeconds));
sem.LockOrWait(&ProcessScheduler::The().Leak().TheCurrent().Leak(), &timer);
cFramePtr = stackFrame;
- /// yes the exception field contains the core id.
- hal_send_start_ipi(stackFrame->Rcx, cSMPInterrupt, cBaseAddressAPIC);
-
sem.Unlock();
}
+ STATIC auto cAPICAddress = 0x0FEC00000;
+
+ STATIC Void cpu_set_apic_base(UIntPtr apic)
+ {
+ UInt32 edx = 0;
+ UInt32 eax = (apic & 0xfffff0000) | kAPIC_BASE_MSR_ENABLE;
+
+ edx = (apic >> 32) & 0x0f;
+
+ hal_set_msr(kAPIC_BASE_MSR, eax, edx);
+ }
+
+ STATIC UIntPtr cpu_get_apic_base(Void)
+ {
+ UInt32 eax, edx;
+
+ hal_get_msr(kAPIC_BASE_MSR, &eax, &edx);
+
+ return (eax & 0xfffff000) | ((UIntPtr)(edx & 0x0f) << 32);
+ }
+
/// @brief Fetch and enable cores inside main CPU.
/// @param rsdPtr RSD PTR structure.
Void hal_system_get_cores(voidPtr rsdPtr)
@@ -209,47 +227,14 @@ namespace Kernel::HAL
{
MadtType* madt = reinterpret_cast<MadtType*>(kApicMadt);
- constexpr auto cMaxProbableCores = 4; // the amount of cores we want.
- constexpr auto cStartAt = 0; // start here to avoid boot core.
-
- for (SizeT coreAt = cStartAt; coreAt < cMaxProbableCores; ++coreAt)
- {
- if (madt->MadtRecords[coreAt].Flags < kThreadBoot) // if local apic.
- {
- MadtType::MadtAddress& madtRecord = madt->MadtRecords[coreAt];
-
- // then register as a core for scheduler.
- kcout << "newoskrnl: Register APIC.\r";
-
- kApicMadtAddresses[kApicMadtAddressesCount].fAddress = madtRecord.Address;
- kApicMadtAddresses[kApicMadtAddressesCount].fKind = madt->MadtRecords[coreAt].Flags;
+ cpu_set_apic_base(cpu_get_apic_base());
- ++kApicMadtAddressesCount;
- }
- }
+ // set SVR register to bit 8 to start recieve interrupts.
- ///////////////////////////////////////////////////////////////////////////
- /// Start local APIC now.
- ///////////////////////////////////////////////////////////////////////////
-
- auto flagsSet = Kernel::ke_dma_read(cBaseAddressAPIC, 0xF0); // SVR register.
-
- // enable APIC.
+ auto flagsSet = Kernel::ke_dma_read(cAPICAddress, 0xF0); // SVR register.
flagsSet |= 0x100;
- Kernel::ke_dma_write(cBaseAddressAPIC, 0xF0, flagsSet);
-
- /// Set sprurious interrupt vector.
- Kernel::ke_dma_write(cBaseAddressAPIC, 0xF0, 0x100 | 0xFF);
-
- // highest task priority. for our realtime kernel.
- Kernel::ke_dma_write(cBaseAddressAPIC, 0x21, 0);
-
- cProgramInitialized = new Boolean(true);
-
- constexpr auto cWhatCore = 1;
-
- hal_send_start_ipi(cWhatCore, cSMPInterrupt, cBaseAddressAPIC);
+ Kernel::ke_dma_write(cAPICAddress, 0xF0, flagsSet | 0x100);
}
else
{
diff --git a/Kernel/HALKit/AMD64/HalDebugOutput.cxx b/Kernel/HALKit/AMD64/HalDebugOutput.cxx
index 3dd70dc6..36ae96b0 100644
--- a/Kernel/HALKit/AMD64/HalDebugOutput.cxx
+++ b/Kernel/HALKit/AMD64/HalDebugOutput.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -27,7 +27,7 @@ namespace Kernel
/// @brief Init COM1.
/// @return
- bool serial_init() noexcept
+ bool hal_serial_init() noexcept
{
#ifdef __DEBUG__
if (kState == kStateReady || kState == kStateTransmit)
@@ -64,7 +64,7 @@ namespace Kernel
EXTERN_C void ke_io_write(const char* bytes)
{
#ifdef __DEBUG__
- Detail::serial_init();
+ Detail::hal_serial_init();
if (!bytes || Detail::kState != kStateReady)
return;
@@ -74,7 +74,10 @@ namespace Kernel
Detail::kState = kStateTransmit;
SizeT index = 0;
- SizeT len = rt_string_len(bytes, 256);
+ SizeT len = 0;
+
+ index = 0;
+ len = rt_string_len(bytes, 255);
while (index < len)
{
@@ -92,7 +95,7 @@ namespace Kernel
EXTERN_C void ke_io_read(const char* bytes)
{
#ifdef __DEBUG__
- Detail::serial_init();
+ Detail::hal_serial_init();
if (!bytes || Detail::kState != kStateReady)
return;
diff --git a/Kernel/HALKit/AMD64/HalDebugPort.cxx b/Kernel/HALKit/AMD64/HalDebugPort.cxx
index a29a8129..8a161cc7 100644
--- a/Kernel/HALKit/AMD64/HalDebugPort.cxx
+++ b/Kernel/HALKit/AMD64/HalDebugPort.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/HalDescriptorLoader.cpp b/Kernel/HALKit/AMD64/HalDescriptorLoader.cxx
index 964b402a..7ded9259 100644
--- a/Kernel/HALKit/AMD64/HalDescriptorLoader.cpp
+++ b/Kernel/HALKit/AMD64/HalDescriptorLoader.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -61,13 +61,14 @@ namespace Kernel::HAL
{
MUST_PASS(baseIdt[i]);
- Detail::kInterruptVectorTable[i].Selector = kGdtCodeSelector;
+ Detail::kInterruptVectorTable[i].Selector = (i == kSyscallRoute) ? ((3 * 8) | 3) : kGdtCodeSelector;
Detail::kInterruptVectorTable[i].Ist = 0x0;
Detail::kInterruptVectorTable[i].TypeAttributes = kInterruptGate;
- Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & 0xFFFF);
- Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & 0xFFFF);
+ Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & __INT16_MAX__);
+ Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & __INT16_MAX__);
Detail::kInterruptVectorTable[i].OffsetHigh =
- (((UIntPtr)baseIdt[i] >> 32) & 0xFFFFFFFF);
+ (((UIntPtr)baseIdt[i] >> 32) & __INT32_MAX__);
+
Detail::kInterruptVectorTable[i].Zero = 0x0;
}
diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cxx
index 2a12ec50..adbf148c 100644
--- a/Kernel/HALKit/AMD64/HalHart.cpp
+++ b/Kernel/HALKit/AMD64/HalHart.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/HalInstallTIB.asm b/Kernel/HALKit/AMD64/HalInstallTIB.asm
deleted file mode 100644
index aad5d6d0..00000000
--- a/Kernel/HALKit/AMD64/HalInstallTIB.asm
+++ /dev/null
@@ -1,24 +0,0 @@
-;; /*
-;; * ========================================================
-;; *
-;; * Kernel
-;; * Copyright Zeta Electronics Corporation, all rights reserved.
-;; *
-;; * ========================================================
-;; */
-
-[bits 64]
-
-[global rt_install_tib]
-
-section .text
-
-;; changed: rs, fs
-;; expected: rcx, rdx
-
-rt_install_tib:
- mov rcx, gs ;; TIB -> Thread Information Block
- mov rdx, fs ;; PIB -> Process Information Block
- ret
-
-;; //////////////////////////////////////////////////// ;;
diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm
index 016c9cd8..c09d5a06 100644
--- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm
+++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm
@@ -1,7 +1,7 @@
;; /*
;; * ---------------------------------------------------
;; *
-;; * Copyright Zeta Electronics Corporation, all rights reserved.
+;; * Copyright ZKA Technologies, all rights reserved.
;; *
;; * File: HalInterruptAPI.asm
;; * Purpose: Interrupt routing, redirect raw interrupts into their handlers.
@@ -121,53 +121,16 @@ IntNormal 31
[extern hal_apic_acknowledge]
-__NEW_INT_32:
-;; make this active, SMP works again.
-%if 0
+__NEW_INT_34:
push rax
- push rcx
- push rdx
- push rbx
- push rbp
- push rsi
- push rdi
- push r8
- push r9
- push r10
- push r11
- push r12
- push r13
- push r14
- push r15
-
- jmp hal_apic_acknowledge
-
- pop r15
- pop r14
- pop r13
- pop r12
- pop r11
- pop r10
- pop r9
- pop r8
- pop rdi
- pop rsi
- pop rbp
- pop rbx
- pop rdx
- pop rcx
+ call hal_apic_acknowledge
pop rax
- mov rax, 0
-
- ;; tell there local apic that we're done.
- mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI
-%endif
iretq
-IntNormal 33
+IntNormal 32
-IntNormal 34
+IntNormal 33
IntNormal 35
IntNormal 36
IntNormal 37
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 628314b5..1628e5e9 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -9,21 +9,26 @@
#include <FirmwareKit/Handover.hxx>
#include <KernelKit/FileManager.hpp>
#include <KernelKit/Framebuffer.hpp>
-#include <KernelKit/KernelHeap.hpp>
+#include <KernelKit/Heap.hxx>
#include <KernelKit/PEFCodeManager.hxx>
#include <KernelKit/ProcessScheduler.hxx>
-#include <KernelKit/UserHeap.hpp>
-#include <NewKit/Json.hpp>
+#include <KernelKit/ProcessHeap.hxx>
+#include <NewKit/Json.hxx>
#include <Modules/CoreCG/Accessibility.hxx>
#include <KernelKit/CodeManager.hpp>
#include <Modules/ACPI/ACPIFactoryInterface.hxx>
#include <NetworkKit/IPCEP.hxx>
+#include <CFKit/Property.hpp>
-#define KERNEL_INIT(X) X; \
+#define mInitKernel(X) \
+ X; \
Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
+Kernel::Property cKernelVersion;
+Kernel::Property cAutoFormatDisk;
+
/// @brief This symbol is the kernel main symbol.
EXTERN_C void KeMain();
@@ -32,7 +37,7 @@ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[];
struct PACKED HeapAllocInfo final
{
Kernel::VoidPtr fThe;
- Kernel::Size fTheSz;
+ Kernel::Size fTheSz;
};
struct PACKED ProcessBlockInfo final
@@ -46,7 +51,7 @@ struct PACKED ProcessExitInfo final
STATIC constexpr auto cReasonLen = 512;
Kernel::Int64 fCode;
- Kernel::Char fReason[cReasonLen];
+ Kernel::Char fReason[cReasonLen];
};
namespace Kernel::HAL
@@ -121,9 +126,9 @@ EXTERN_C void hal_init_platform(
constexpr auto cCatalogCreate = 0x22;
constexpr auto cRebootInterrupt = 0x23;
constexpr auto cShutdownInterrupt = 0x24;
- constexpr auto cLPCSendMsg = 0x25;
- constexpr auto cLPCOpenMsg = 0x26;
- constexpr auto cLPCCloseMsg = 0x27;
+ constexpr auto cLPCSendMsg = 0x25;
+ constexpr auto cLPCOpenMsg = 0x26;
+ constexpr auto cLPCCloseMsg = 0x27;
constexpr auto cLPCSanitizeMsg = 0x28;
kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
@@ -142,8 +147,9 @@ EXTERN_C void hal_init_platform(
kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
// get HAC struct.
HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx);
-
- if (!rdxInf) return;
+
+ if (!rdxInf)
+ return;
// assign the fThe field with the pointer.
rdxInf->fThe = Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz);
@@ -153,7 +159,8 @@ EXTERN_C void hal_init_platform(
// get HAC struct.
HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx);
- if (!rdxInf) return;
+ if (!rdxInf)
+ return;
// delete ptr with sz in mind.
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz);
@@ -161,8 +168,9 @@ EXTERN_C void hal_init_platform(
kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
ProcessBlockInfo* rdxPb = reinterpret_cast<ProcessBlockInfo*>(rdx);
-
- if (!rdxPb) return;
+
+ if (!rdxPb)
+ return;
// install the fTIB and fPIB.
rt_install_tib(rdxPb->fTIB, rdxPb->fPIB);
@@ -170,8 +178,9 @@ EXTERN_C void hal_init_platform(
kSyscalls[cExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx);
-
- if (!rdxEi) return;
+
+ if (!rdxEi)
+ return;
Kernel::kcout << "newoskrnl: " << rdxEi->fReason << "\r";
Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Exit(rdxEi->fCode);
@@ -179,19 +188,20 @@ EXTERN_C void hal_init_platform(
kSyscalls[cLastExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
ProcessExitInfo* rdxEi = reinterpret_cast<ProcessExitInfo*>(rdx);
-
- if (!rdxEi) return;
- rdxEi->fCode = Kernel::rt_get_exit_code();
+ if (!rdxEi)
+ return;
+
+ rdxEi->fCode = Kernel::rt_get_exit_code();
};
kSyscalls[cRebootInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
- Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_RsdPtr);
+ Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr);
acpi.Reboot();
};
kSyscalls[cShutdownInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void {
- Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_RsdPtr);
+ Kernel::ACPIFactoryInterface acpi(kHandoverHeader->f_HardwareTables.f_VendorPtr);
acpi.Shutdown();
};
@@ -206,7 +216,20 @@ EXTERN_C void hal_init_platform(
kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fHooked = true;
- Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr);
+ // newoskrnl version 1.00
+ Kernel::StringView strVer(cMaxPropLen);
+ strVer += "\\Properties\\KernelVersion";
+
+ cKernelVersion.GetKey() = strVer;
+ cKernelVersion.GetValue() = __MAHROUSS__;
+
+ Kernel::StringView strAutoMount(cMaxPropLen);
+ strAutoMount += "\\Properties\\AutoMountFS?";
+
+ cAutoFormatDisk.GetKey() = strAutoMount;
+ cAutoFormatDisk.GetValue() = Yes;
+
+ Kernel::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
- KERNEL_INIT(KeMain());
+ mInitKernel(KeMain());
}
diff --git a/Kernel/HALKit/AMD64/HalKernelMouse.cxx b/Kernel/HALKit/AMD64/HalKernelMouse.cxx
index 9cad6d35..9b3467fa 100644
--- a/Kernel/HALKit/AMD64/HalKernelMouse.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMouse.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -14,16 +14,16 @@
EXTERN_C Kernel::Boolean _hal_draw_mouse();
EXTERN_C Kernel::Void _hal_init_mouse();
-STATIC Kernel::Int32 kPrevX = 10;
-STATIC Kernel::Int32 kPrevY = 10;
-STATIC Kernel::Int32 kX = 10;
-STATIC Kernel::Int32 kY = 10;
+STATIC Kernel::Int32 kPrevX = 10;
+STATIC Kernel::Int32 kPrevY = 10;
+STATIC Kernel::Int32 kX = 10;
+STATIC Kernel::Int32 kY = 10;
STATIC Kernel::Int32 kMouseCycle = 0;
STATIC Kernel::PS2MouseInterface kMousePS2;
-STATIC Kernel::Char kMousePacket[4] = {};
+STATIC Kernel::Char kMousePacket[4] = {};
STATIC Kernel::Boolean kMousePacketReady = false;
-STATIC GXInit();
+STATIC CGInit();
#define kPS2Leftbutton 0b00000001
#define kPS2Middlebutton 0b00000010
diff --git a/Kernel/HALKit/AMD64/HalPageAlloc.hpp b/Kernel/HALKit/AMD64/HalPageAlloc.hxx
index 55193686..6e05e58e 100644
--- a/Kernel/HALKit/AMD64/HalPageAlloc.hpp
+++ b/Kernel/HALKit/AMD64/HalPageAlloc.hxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -26,6 +26,10 @@
#define kPTESize (0x1000)
#endif // !kPTESize
+#ifndef kAlign
+#define kAlign __BIGGEST_ALIGNMENT__
+#endif // !kAlign
+
EXTERN_C void hal_flush_tlb();
EXTERN_C void hal_write_cr3(Kernel::UIntPtr pde);
EXTERN_C void hal_write_cr0(Kernel::UIntPtr bit);
@@ -38,16 +42,16 @@ namespace Kernel::HAL
{
struct PACKED PageTable64 final
{
- bool Present : 1;
- bool Rw : 1;
- bool User : 1;
- bool Wt : 1;
- bool Cache : 1;
- bool Accessed : 1;
+ bool Present : 1;
+ bool Rw : 1;
+ bool User : 1;
+ bool Wt : 1;
+ bool Cache : 1;
+ bool Accessed : 1;
Kernel::Int32 Reserved : 6;
Kernel::UInt64 PhysicalAddress : 36;
Kernel::Int32 Reserved1 : 15;
- bool ExecDisable : 1;
+ bool ExecDisable : 1;
};
namespace Detail
diff --git a/Kernel/HALKit/AMD64/HalProcessor.cpp b/Kernel/HALKit/AMD64/HalProcessor.cxx
index 01f3879a..2eb2d693 100644
--- a/Kernel/HALKit/AMD64/HalProcessor.cpp
+++ b/Kernel/HALKit/AMD64/HalProcessor.cxx
@@ -1,10 +1,10 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
-#include <HALKit/AMD64/Processor.hpp>
+#include <HALKit/AMD64/Processor.hxx>
/**
* @file Processor.cpp
@@ -13,7 +13,7 @@
namespace Kernel::HAL
{
- void Out8(UInt16 port, UInt8 value)
+ Void Out8(UInt16 port, UInt8 value)
{
asm volatile("outb %%al, %1"
:
@@ -21,7 +21,7 @@ namespace Kernel::HAL
: "memory");
}
- void Out16(UInt16 port, UInt16 value)
+ Void Out16(UInt16 port, UInt16 value)
{
asm volatile("outw %%ax, %1"
:
@@ -29,7 +29,7 @@ namespace Kernel::HAL
: "memory");
}
- void Out32(UInt16 port, UInt32 value)
+ Void Out32(UInt16 port, UInt32 value)
{
asm volatile("outl %%eax, %1"
:
@@ -70,27 +70,27 @@ namespace Kernel::HAL
return value;
}
- void rt_halt()
+ Void rt_halt()
{
asm volatile("hlt");
}
- void rt_cli()
+ Void rt_cli()
{
asm volatile("cli");
}
- void rt_sti()
+ Void rt_sti()
{
asm volatile("sti");
}
- void rt_cld()
+ Void rt_cld()
{
asm volatile("cld");
}
- void rt_std()
+ Void rt_std()
{
asm volatile("std");
}
diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
index 7b0926bb..7f6aa26a 100644
--- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
+++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
@@ -2,7 +2,7 @@
;; * ========================================================
;; *
;; * Kernel
-;; * Copyright Zeta Electronics Corporation, all rights reserved.
+;; * Copyright ZKA Technologies, all rights reserved.
;; *
;; * ========================================================
;; */
diff --git a/Kernel/HALKit/AMD64/HalSMPCore.cxx b/Kernel/HALKit/AMD64/HalScheduler.cxx
index 4cb87542..791361b5 100644
--- a/Kernel/HALKit/AMD64/HalSMPCore.cxx
+++ b/Kernel/HALKit/AMD64/HalScheduler.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -12,8 +12,8 @@ Void ProcessHeader::SetEntrypoint(UIntPtr& imageStart) noexcept
if (imageStart == 0)
this->Crash();
- this->StackFrame->Rbp = imageStart;
- this->StackFrame->Rsp = this->StackFrame->Rbp;
+ this->StackFrame->BP = imageStart;
+ this->StackFrame->SP = this->StackFrame->BP;
}
namespace Kernel
@@ -22,7 +22,7 @@ namespace Kernel
{
if (!stackPtr)
return false;
- if (stackPtr->Rbp == 0 || stackPtr->Rsp == 0)
+ if (stackPtr->BP == 0 || stackPtr->SP == 0)
return false;
return true;
diff --git a/Kernel/HALKit/AMD64/HalTimer.cxx b/Kernel/HALKit/AMD64/HalTimer.cxx
index e69de29b..e893198f 100644
--- a/Kernel/HALKit/AMD64/HalTimer.cxx
+++ b/Kernel/HALKit/AMD64/HalTimer.cxx
@@ -0,0 +1,14 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+ File: HalTimer.cxx
+ Purpose: HAL timer
+
+ Revision History:
+
+ 07/07/24: Added file (amlel)
+
+------------------------------------------- */
+
+#include <ArchKit/ArchKit.hpp> \ No newline at end of file
diff --git a/Kernel/HALKit/AMD64/HalUtils.asm b/Kernel/HALKit/AMD64/HalUtils.asm
new file mode 100644
index 00000000..6681a692
--- /dev/null
+++ b/Kernel/HALKit/AMD64/HalUtils.asm
@@ -0,0 +1,49 @@
+;; /*
+;; * ========================================================
+;; *
+;; * Kernel
+;; * Copyright ZKA Technologies, all rights reserved.
+;; *
+;; * ========================================================
+;; */
+
+[bits 64]
+
+[global rt_install_tib]
+
+section .text
+
+;; changed: rs, fs
+;; expected: rcx, rdx
+
+rt_install_tib:
+ mov rcx, gs ;; TIB -> Thread Information Block
+ mov rdx, fs ;; PIB -> Process Information Block
+ ret
+
+;; //////////////////////////////////////////////////// ;;
+
+[global rt_jump_user_mode]
+
+;; @used rcx, address to jump on.
+;; @note adjusted for long mode.
+rt_jump_user_mode:
+ cmp rcx, 0
+ je rt_jump_user_mode_failed
+
+ mov ax, (6 * 8) | 3 ; user data segment with RPL 3
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax ; SS is handled by iret
+
+ mov rax, rsp
+ push (6 * 8) | 3
+ push rax
+ pushf
+ push (5 * 8) | 3 ; user code segment with RPL 3
+ push rcx
+ iretq
+ ;; we just failed to validate the rcx, fallback and return to previous pc.
+rt_jump_user_mode_failed:
+ ret \ No newline at end of file
diff --git a/Kernel/HALKit/AMD64/Hypervisor.hpp b/Kernel/HALKit/AMD64/Hypervisor.hpp
index 1ab69ef4..b5fe48c2 100644
--- a/Kernel/HALKit/AMD64/Hypervisor.hpp
+++ b/Kernel/HALKit/AMD64/Hypervisor.hpp
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -21,6 +21,5 @@ namespace Kernel
ENUM_STRING(ParallelsAlt, " lrpepyh vr ");
ENUM_STRING(Bhyve, "bhyve bhyve ");
ENUM_STRING(Qnx, " QNXQVMBSQG ");
-
END_STRING_ENUM()
} // namespace Kernel
diff --git a/Kernel/HALKit/AMD64/PCI/Database.cxx b/Kernel/HALKit/AMD64/PCI/Database.cxx
index 65ec307e..67ebc6df 100644
--- a/Kernel/HALKit/AMD64/PCI/Database.cxx
+++ b/Kernel/HALKit/AMD64/PCI/Database.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/PCI/Device.cxx b/Kernel/HALKit/AMD64/PCI/Device.cxx
index c1fdc401..bec401d9 100644
--- a/Kernel/HALKit/AMD64/PCI/Device.cxx
+++ b/Kernel/HALKit/AMD64/PCI/Device.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -10,11 +10,11 @@
Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
- ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
- (bar & 0xFC);
+ ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
+ (bar & 0xFC);
Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
- target);
+ target);
return Kernel::HAL::In32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData);
}
@@ -22,11 +22,11 @@ Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShor
void NewOSPCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun)
{
Kernel::UInt target = 0x80000000 | ((Kernel::UInt)bus << 16) |
- ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
- (bar & ~3);
+ ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) |
+ (bar & ~3);
Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress,
- target);
+ target);
}
namespace Kernel::PCI
diff --git a/Kernel/HALKit/AMD64/PCI/Dma.cxx b/Kernel/HALKit/AMD64/PCI/Dma.cxx
index 3e6319e3..65bf7e72 100644
--- a/Kernel/HALKit/AMD64/PCI/Dma.cxx
+++ b/Kernel/HALKit/AMD64/PCI/Dma.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/PCI/Express.cxx b/Kernel/HALKit/AMD64/PCI/Express.cxx
index 2b88f312..cb999fe0 100644
--- a/Kernel/HALKit/AMD64/PCI/Express.cxx
+++ b/Kernel/HALKit/AMD64/PCI/Express.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/PCI/IO.cxx b/Kernel/HALKit/AMD64/PCI/IO.cxx
index 24ee05b3..8da2b21e 100644
--- a/Kernel/HALKit/AMD64/PCI/IO.cxx
+++ b/Kernel/HALKit/AMD64/PCI/IO.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/PCI/Iterator.cxx b/Kernel/HALKit/AMD64/PCI/Iterator.cxx
index 0f766111..df593f7a 100644
--- a/Kernel/HALKit/AMD64/PCI/Iterator.cxx
+++ b/Kernel/HALKit/AMD64/PCI/Iterator.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
diff --git a/Kernel/HALKit/AMD64/PCI/PCI.cxx b/Kernel/HALKit/AMD64/PCI/PCI.cxx
index eaf7f20a..d15b1b9a 100644
--- a/Kernel/HALKit/AMD64/PCI/PCI.cxx
+++ b/Kernel/HALKit/AMD64/PCI/PCI.cxx
@@ -1,7 +1,7 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
-#include <KernelKit/PCI/PCI.hpp>
+#include <KernelKit/PCI/PCI.hxx>
diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hxx
index 756c5770..92b91c70 100644
--- a/Kernel/HALKit/AMD64/Processor.hpp
+++ b/Kernel/HALKit/AMD64/Processor.hxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
File: Prcoessor.hxx
Purpose: AMD64 processor abstraction.
@@ -17,7 +17,12 @@
#include <NewKit/Defines.hpp>
#include <NewKit/Utils.hpp>
#include <FirmwareKit/Handover.hxx>
-#include <HALKit/AMD64/HalPageAlloc.hpp>
+#include <HALKit/AMD64/HalPageAlloc.hxx>
+
+EXTERN_C
+{
+#include <cpuid.h>
+}
#ifdef kCPUBackendName
#undef kCPUBackendName
@@ -25,6 +30,8 @@
#define kCPUBackendName "AMD64"
+#define kSyscallRoute 0x32
+
#define IsActiveLow(FLG) (FLG & 2)
#define IsLevelTriggered(FLG) (FLG & 8)
@@ -32,6 +39,7 @@
#define kTrapGate (0xEF)
#define kTaskGate (0b10001100)
#define kGdtCodeSelector (0x08)
+#define kGdtUserCodeSelector (0x10)
#define cHeapStartOffset (0x10000000)
namespace Kernel
@@ -71,16 +79,17 @@ namespace Kernel::HAL
{
UInt16 pml4_index = (virt_addr >> 39) & 0x1FF;
- if (!pde->Pte[pml4_index].Present)
+ if (pde && !pde->Pte[pml4_index].Present)
{
pde->Pte[pml4_index].Present = true;
- kcout << "PM is present now.\r";
pde->Pte[pml4_index].PhysicalAddress = phys_addr;
pde->Pte[pml4_index].Rw = flags & eFlagsRw;
pde->Pte[pml4_index].User = flags & eFlagsUser;
pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable;
+ kcout << "PTE is present now.\r";
+
return 0;
}
else
@@ -90,13 +99,13 @@ namespace Kernel::HAL
kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress);
kcout << "\r";
- kcout << "User: " << (pde->Pte[pml4_index].User ? "YES" : "NO") << "\r";
- kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "YES" : "NO") << "\r";
+ kcout << "User: " << (pde->Pte[pml4_index].User ? "true" : "false") << "\r";
+ kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "true" : "false") << "\r";
- return 1;
+ return 0;
}
- return 0;
+ return 1;
}
/// @brief Map address to PDE.
@@ -104,7 +113,7 @@ namespace Kernel::HAL
/// @param phys_addr
/// @param virt_addr
/// @param flags
- inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags)
+ inline Void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags)
{
UInt16 pml4_index = (virt_addr >> 39) & 0x1FF;
@@ -152,10 +161,11 @@ namespace Kernel::HAL
typedef UIntPtr Reg;
+ /// @brief Stack frame (as retrieved from assembly.)
struct PACKED StackFrame final
{
Reg IntNum, Exception;
- Reg Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
+ Reg A0, A2, BP, SP, A3, A4, A5, A6;
Reg R8, R9, R10, R11, R12, R13, R14, R15;
Reg Gs, Fs;
};
@@ -200,11 +210,12 @@ namespace Kernel::HAL
class SegmentDescriptorComparator final
{
public:
- bool IsValid(SegmentDescriptor& seg)
+ Bool IsValid(SegmentDescriptor& seg)
{
return seg.Base > seg.Limit;
}
- bool Equals(SegmentDescriptor& seg, SegmentDescriptor& segRight)
+
+ Bool Equals(SegmentDescriptor& seg, SegmentDescriptor& segRight)
{
return seg.Base == segRight.Base && seg.Limit == segRight.Limit;
}
@@ -215,29 +226,65 @@ namespace Kernel::HAL
class GDTLoader final
{
public:
- static void Load(RegisterGDT& gdt);
- static void Load(Ref<RegisterGDT>& gdt);
+ static Void Load(RegisterGDT& gdt);
+ static Void Load(Ref<RegisterGDT>& gdt);
};
class IDTLoader final
{
public:
- static void Load(Register64& idt);
- static void Load(Ref<Register64>& idt);
+ static Void Load(Register64& idt);
+ static Void Load(Ref<Register64>& idt);
};
Void hal_system_get_cores(VoidPtr rsdPtr);
Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
- /// @brief Processor specific structures.
- namespace Detail
+ /// @brief Do a cpuid to check if MSR exists on CPU.
+ /// @retval true it does exists.
+ /// @retval false it doesn't.
+ inline Bool hal_has_msr() noexcept
+ {
+ static UInt32 eax, unused, edx; // eax, edx
+
+ __get_cpuid(1, &eax, &unused, &unused, &edx);
+
+ // edx returns the flag for MSR (which is 1 shifted to 5.)
+ return edx & (1 << 5);
+ }
+
+ /// @brief Get Model-specific register.
+ /// @param msr MSR
+ /// @param lo low byte
+ /// @param hi high byte
+ inline Void hal_get_msr(UInt32 msr, UInt32* lo, UInt32* hi) noexcept
+ {
+ if (!lo || !hi)
+ return;
+
+ asm volatile("rdmsr"
+ : "=a"(*lo), "=d"(*hi)
+ : "c"(msr));
+ }
+
+ /// @brief Set Model-specific register.
+ /// @param msr MSR
+ /// @param lo low byte
+ /// @param hi high byte
+ inline Void hal_set_msr(UInt32 msr, UInt32 lo, UInt32 hi) noexcept
{
- EXTERN_C void _ke_power_on_self_test(void);
+ asm volatile("wrmsr"
+ :
+ : "a"(lo), "d"(hi), "c"(msr));
+ }
+ /// @brief Processor specific namespace.
+ namespace Detail
+ {
/**
- @brief Global descriptor table entry, either null, code or data.
-*/
+ @brief Global descriptor table entry, either null, code or data.
+ */
struct PACKED NewOSGDTRecord final
{
@@ -259,15 +306,35 @@ namespace Kernel::HAL
NewOSGDTRecord UserData;
};
} // namespace Detail
+
+ class APICController
+ {
+ public:
+ explicit APICController(VoidPtr base)
+ : fApic(base)
+ {
+ }
+
+ ~APICController() = default;
+
+ NEWOS_COPY_DEFAULT(APICController);
+
+ public:
+ UInt32 Read(UInt32 reg) noexcept;
+ Void Write(UInt32 reg, UInt32 value) noexcept;
+
+ private:
+ VoidPtr fApic{nullptr};
+ };
} // namespace Kernel::HAL
-EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp);
-EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp);
-EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp);
-EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_generic(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_math(Kernel::UIntPtr rsp);
+EXTERN_C Kernel::Void idt_handle_pf(Kernel::UIntPtr rsp);
-EXTERN_C void hal_load_idt(Kernel::HAL::Register64 ptr);
-EXTERN_C void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
+EXTERN_C Kernel::Void hal_load_idt(Kernel::HAL::Register64 ptr);
+EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
/// @brief Maximum size of the IDT.
#define kKernelIdtSize 0x100
diff --git a/Kernel/HALKit/AMD64/Storage/AHCI.cxx b/Kernel/HALKit/AMD64/Storage/AHCI.cxx
index 51153417..7a83b836 100644
--- a/Kernel/HALKit/AMD64/Storage/AHCI.cxx
+++ b/Kernel/HALKit/AMD64/Storage/AHCI.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -11,7 +11,7 @@
* @version 0.1
* @date 2024-02-02
*
- * @copyright Copyright (c) Zeta Electronics Corporation
+ * @copyright Copyright (c) ZKA Technologies
*
*/
diff --git a/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx b/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx
index 33e6bc31..bcba23e1 100644
--- a/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx
+++ b/Kernel/HALKit/AMD64/Storage/ATA-DMA.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -11,7 +11,7 @@
* @version 0.1
* @date 2024-02-02
*
- * @copyright Copyright (c) Zeta Electronics Corporation
+ * @copyright Copyright (c) ZKA Technologies
*
*/
diff --git a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx
index 1a8e78c3..fa64294d 100644
--- a/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx
+++ b/Kernel/HALKit/AMD64/Storage/ATA-PIO.cxx
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright Zeta Electronics Corporation
+ Copyright ZKA Technologies
------------------------------------------- */
@@ -11,7 +11,7 @@
* @version 0.1
* @date 2024-02-02
*
- * @copyright Copyright (c) Zeta Electronics Corporation
+ * @copyright Copyright (c) ZKA Technologies
*
*/