summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-27 19:37:29 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-27 19:37:29 +0200
commitc9e0e4b6058f833f39c2193e217dc38f4edd8b82 (patch)
tree7eadd57a88b51fc70ffd2668c7adc29386650e91 /dev
parentfdbcbba07cac3dbf9ef377f2f5248dd662f6babd (diff)
[WIP] Finishing SMP support, and then working on system driver and
loader. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootJump.S8
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootMain.cxx2
-rw-r--r--dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx116
-rw-r--r--dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx25
-rw-r--r--dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx4
-rw-r--r--dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm16
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMouse.cxx190
-rw-r--r--dev/ZKA/HALKit/AMD64/HalTimer.cxx55
-rw-r--r--dev/ZKA/KernelKit/FileManager.hxx2
-rw-r--r--dev/ZKA/KernelKit/MP.hxx4
-rw-r--r--dev/ZKA/KernelKit/Timer.hxx3
-rw-r--r--dev/ZKA/Modules/ACPI/ACPI.hxx4
-rw-r--r--dev/ZKA/Modules/ACPI/ACPIFactoryInterface.hxx4
-rw-r--r--dev/ZKA/Modules/PS2/PS2MouseInterface.hxx115
-rw-r--r--dev/ZKA/NewKit/Macros.hxx4
-rw-r--r--dev/ZKA/Sources/DLLMain.cxx33
-rw-r--r--dev/ZKA/Sources/KernelCheck.cxx34
-rw-r--r--dev/ZKA/Sources/NewFS+FileManager.cxx8
-rw-r--r--dev/ZKA/Sources/ProcessScheduler.cxx4
19 files changed, 215 insertions, 416 deletions
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootJump.S b/dev/ZBA/Sources/HEL/AMD64/BootJump.S
index de474c96..f9943ecf 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootJump.S
+++ b/dev/ZBA/Sources/HEL/AMD64/BootJump.S
@@ -21,8 +21,6 @@ rt_jump_to_address:
ret
-.code16
-
rt_reset_hardware:
/* dont raise any interrupts. (except ofc NMIs.) */
cli
@@ -41,9 +39,9 @@ wait_gate2:
mov al,0x0FE
out 0x60,al
- /* trigger triple fault */
+ /* trigger triple fault, by writing to cr4 */
- xor eax,eax
- mov cr3,eax
+ xor rax,rax
+ mov cr4,rax
reset_wait:
jmp reset_wait
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
index 6925a05a..c8cbe6a7 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx
@@ -222,7 +222,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
checkPart.Format("ZKA (A:)", &root, 1);
- EFI::Stop();
+ rt_reset_hardware();
}
// ---------------------------------------------------- //
diff --git a/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx b/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx
index 28b26223..37b1375f 100644
--- a/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalACPIFactoryInterface.cxx
@@ -12,53 +12,101 @@
namespace Kernel
{
- /// Custom to the virtual machine, you'll need to parse the MADT instead.
-
- void rt_shutdown_acpi_qemu_20(void)
+ namespace Detail
{
- HAL::Out16(0xb004, 0x2000);
- }
-
- void rt_shutdown_acpi_qemu_30_plus(void)
- {
- HAL::Out16(0x604, 0x2000);
- }
-
- void rt_shutdown_acpi_virtualbox(void)
- {
- HAL::Out16(0x4004, 0x3400);
- }
-
- /// You have to parse the MADT!
+ struct FADT final : public SDT
+ {
+ UInt32 FirmwareCtrl;
+ UInt32 Dsdt;
+
+ // field used in ACPI 1.0; no longer in use, for compatibility only
+ UInt8 Reserved;
+
+ UInt8 PreferredPowerManagementProfile;
+ UInt16 SCI_Interrupt;
+ UInt32 SMI_CommandPort;
+ UInt8 AcpiEnable;
+ UInt8 AcpiDisable;
+ UInt8 S4BIOS_REQ;
+ UInt8 PSTATE_Control;
+ UInt32 PM1aEventBlock;
+ UInt32 PM1bEventBlock;
+ UInt32 PM1aControlBlock;
+ UInt32 PM1bControlBlock;
+ UInt32 PM2ControlBlock;
+ UInt32 PMTimerBlock;
+ UInt32 GPE0Block;
+ UInt32 GPE1Block;
+ UInt8 PM1EventLength;
+ UInt8 PM1ControlLength;
+ UInt8 PM2ControlLength;
+ UInt8 PMTimerLength;
+ UInt8 GPE0Length;
+ UInt8 GPE1Length;
+ UInt8 GPE1Base;
+ UInt8 CStateControl;
+ UInt16 WorstC2Latency;
+ UInt16 WorstC3Latency;
+ UInt16 FlushSize;
+ UInt16 FlushStride;
+ UInt8 DutyOffset;
+ UInt8 DutyWidth;
+ UInt8 DayAlarm;
+ UInt8 MonthAlarm;
+ UInt8 Century;
+
+ // reserved in ACPI 1.0; used since ACPI 2.0+
+ UInt16 BootArchitectureFlags;
+
+ UInt8 Reserved2;
+ UInt32 Flags;
+
+ // 12 byte structure; see below for details
+ ACPI_ADDRESS ResetReg;
+
+ UInt8 ResetValue;
+ UInt8 Reserved3[3];
+
+ // 64bit pointers - Available on ACPI 2.0+
+ UInt64 X_FirmwareControl;
+ UInt64 X_Dsdt;
+
+ ACPI_ADDRESS X_PM1aEventBlock;
+ ACPI_ADDRESS X_PM1bEventBlock;
+ ACPI_ADDRESS X_PM1aControlBlock;
+ ACPI_ADDRESS X_PM1bControlBlock;
+ ACPI_ADDRESS X_PM2ControlBlock;
+ ACPI_ADDRESS X_PMTimerBlock;
+ ACPI_ADDRESS X_GPE0Block;
+ ACPI_ADDRESS X_GPE1Block;
+ };
+ } // namespace Detail
ACPIFactoryInterface::ACPIFactoryInterface(VoidPtr rsdPtr)
: fRsdp(rsdPtr), fEntries(0)
{
-#ifdef __DEBUG__
- kcout << "newoskrnl: ACPI: init interface.\r";
-#else
-
-#endif
}
Void ACPIFactoryInterface::Shutdown()
{
-#ifdef __DEBUG__
- rt_shutdown_acpi_qemu_30_plus();
-#else
-
-#endif
+ failed_to_shutdown:
+ // in case no acpi mode, or it's not available.
+ while (Yes)
+ {
+ asm volatile("cli; hlt");
+ }
}
- /// @brief Reboot (shutdowns on qemu.)
- /// @return
+ /// @brief Reboot machine in either ACPI or by triple faulting.
+ /// @return nothing it's a reboot.
Void ACPIFactoryInterface::Reboot()
{
-#ifdef __DEBUG__
- rt_shutdown_acpi_qemu_30_plus();
-#else
-
-#endif
+ failed_to_reboot:
+ // in case no acpi mode, or it's not available.
+ while (Yes)
+ {
+ asm volatile("cli; hlt");
+ }
}
/// @brief Finds a descriptor table inside ACPI XSDT.
diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
index d11d1c8c..512ee483 100644
--- a/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalCoreMultiProcessingAMD64.cxx
@@ -12,6 +12,8 @@
#include <KernelKit/ProcessScheduler.hxx>
#include <KernelKit/Timer.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+
// Needed for SMP. //
#include <KernelKit/MP.hxx>
@@ -45,7 +47,7 @@ namespace Kernel::HAL
STATIC Void hal_switch_context(HAL::StackFramePtr stack_frame);
- STATIC MADT_TABLE* kMADTBlock = nullptr;
+ STATIC struct MADT_TABLE* kMADTBlock = nullptr;
STATIC Bool kSMPAware = false;
STATIC Int64 kSMPCount = 0;
@@ -114,7 +116,7 @@ namespace Kernel::HAL
/// @param targetAddress
/// @return
/***********************************************************************************/
-
+
Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress)
{
Kernel::ke_dma_write(targetAddress, kAPIC_ICR_High, (apicId << 24));
@@ -130,13 +132,14 @@ namespace Kernel::HAL
/***********************************************************************************/
Void hal_send_end_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_EIPI_Vector | vector);
}
/// @internal
EXTERN_C Void hal_ap_startup(Void)
{
+ CGDrawString("100", 10, 50, RGB(0x00, 0x00, 0x00));
ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
@@ -200,6 +203,8 @@ namespace Kernel::HAL
kcout << "newoskrnl: Probing MADT cores...\r";
+ UIntPtr madt_address = kMADTBlock->Address;
+
while (Yes)
{
if (kMADTBlock->List[index].Type == 0 ||
@@ -210,14 +215,21 @@ namespace Kernel::HAL
{
case 0x01: {
cSMPCores[index] = kMADTBlock->List[index].IOAPIC.IoID;
+ kcout << "newoskrnl: Core ID: " << number(cSMPCores[index]) << endl;
++kSMPCount;
break;
}
case 0x02: {
cSMPCores[index] = kMADTBlock->List[index].LAPIC.ProcessorID;
+ kcout << "newoskrnl: Core ID: " << number(cSMPCores[index]) << endl;
++kSMPCount;
break;
}
+ case 0x05: {
+ madt_address = kMADTBlock->List[index].LAPIC_ADDRESS_OVERRIDE.Address;
+ kcout << "newoskrnl: Address: " << number(madt_address) << endl;
+ break;
+ }
}
++index;
@@ -226,7 +238,14 @@ namespace Kernel::HAL
kcout << "newoskrnl: # of cores: " << number(kSMPCount) << endl;
kcout << "newoskrnl: First core ID: " << number(cSMPCores[0]) << endl;
+ // Kernel is now SMP aware.
+ // That means that the scheduler is now available (on MP kernels)
+
kSMPAware = true;
+
+ // This is used to start the
+ hal_send_end_ipi(cSMPCores[0], 0x34, madt_address);
+ hal_send_start_ipi(cSMPCores[0], 0x34, madt_address);
}
}
} // namespace Kernel::HAL
diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx
index 678b0896..11f9f249 100644
--- a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx
@@ -55,8 +55,6 @@ namespace Kernel::HAL
MUST_PASS(baseIdt);
- Detail::hal_remap_intel_pic_ctrl();
-
for (UInt16 i = 0; i < kKernelIdtSize; ++i)
{
MUST_PASS(baseIdt[i]);
@@ -77,6 +75,8 @@ namespace Kernel::HAL
(kKernelIdtSize - 1);
hal_load_idt(Detail::kRegIdt);
+
+ Detail::hal_remap_intel_pic_ctrl();
}
void GDTLoader::Load(Ref<RegisterGDT>& gdt)
diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm
index 0c79be81..9a637b8a 100644
--- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm
+++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm
@@ -35,7 +35,6 @@ __NEW_INT_%1:
global ke_handle_irq
global kInterruptVectorTable
-extern hal_handle_mouse
extern idt_handle_gpf
extern idt_handle_pf
extern ke_io_write
@@ -107,7 +106,9 @@ IntNormal 18
IntNormal 19
IntNormal 20
IntNormal 21
+
IntNormal 22
+
IntNormal 23
IntNormal 24
IntNormal 25
@@ -115,7 +116,8 @@ IntNormal 26
IntNormal 27
IntNormal 28
IntNormal 29
-IntExp 30
+
+IntExp 30
IntNormal 31
@@ -132,15 +134,7 @@ IntNormal 40
IntNormal 41
IntNormal 42
IntNormal 43
-
-__NEW_INT_44:
- cli
-
- call hal_handle_mouse
-
- sti
- iretq
-
+IntNormal 44
IntNormal 45
IntNormal 46
IntNormal 47
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMouse.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMouse.cxx
deleted file mode 100644
index 06cdc81b..00000000
--- a/dev/ZKA/HALKit/AMD64/HalKernelMouse.cxx
+++ /dev/null
@@ -1,190 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#include <Modules/PS2/PS2MouseInterface.hxx>
-#include <Modules/CoreCG/FbRenderer.hxx>
-#include <Modules/CoreCG/Rsrc/Cursor.rsrc>
-#include <KernelKit/Framebuffer.hxx>
-#include <NewKit/Defines.hxx>
-
-/// @note forward decl.
-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 kMouseCycle = 0;
-STATIC Kernel::Char kMousePacket[4] = {};
-STATIC Kernel::Boolean kMousePacketReady = false;
-
-STATIC CGInit();
-
-#define kPS2Leftbutton 0b00000001
-#define kPS2Middlebutton 0b00000010
-#define kPS2Rightbutton 0b00000100
-#define kPS2XSign 0b00010000
-#define kPS2YSign 0b00100000
-#define kPS2XOverflow 0b01000000
-#define kPS2YOverflow 0b10000000
-
-using namespace Kernel;
-
-EXTERN_C Void hal_handle_mouse()
-{
- Kernel::UInt8 data = HAL::In8(0x60);
-
- switch (kMouseCycle)
- {
- case 0:
- if (kMousePacketReady)
- break;
- if ((data & 0b00001000) == 0)
- break;
- kMousePacket[0] = data;
- kMouseCycle++;
- break;
- case 1:
- if (kMousePacketReady)
- break;
- kMousePacket[1] = data;
- kMouseCycle++;
- break;
- case 2:
- if (kMousePacketReady)
- break;
- kMousePacket[2] = data;
- kMousePacketReady = true;
- kMouseCycle = 0;
- break;
- }
-
- // Notify PIC controller that we're done with it's interrupt.
-
- Kernel::HAL::Out8(0x20, 0x20);
- Kernel::HAL::Out8(0xA0, 0x20);
-}
-
-EXTERN_C Boolean _hal_left_button_pressed()
-{
- return kMousePacket[0] & kPS2Leftbutton;
-}
-EXTERN_C Boolean _hal_right_button_pressed()
-{
- return kMousePacket[0] & kPS2Rightbutton;
-}
-EXTERN_C Boolean _hal_middle_button_pressed()
-{
- return kMousePacket[0] & kPS2Middlebutton;
-}
-
-/// @brief Draws the kernel's mouse.
-EXTERN_C Boolean _hal_draw_mouse()
-{
- if (!kMousePacketReady)
- return false;
-
- bool xNegative, yNegative, xOverflow, yOverflow;
-
- if (kMousePacket[0] & kPS2XSign)
- {
- xNegative = true;
- }
- else
- xNegative = false;
-
- if (kMousePacket[0] & kPS2YSign)
- {
- yNegative = true;
- }
- else
- yNegative = false;
-
- if (kMousePacket[0] & kPS2XOverflow)
- {
- xOverflow = true;
- }
- else
- xOverflow = false;
-
- if (kMousePacket[0] & kPS2YOverflow)
- {
- yOverflow = true;
- }
- else
- yOverflow = false;
-
- if (!xNegative)
- {
- kX += kMousePacket[1];
- if (xOverflow)
- {
- kX += 255;
- }
- }
- else
- {
- kMousePacket[1] = 256 - kMousePacket[1];
- kX -= kMousePacket[1];
- if (xOverflow)
- {
- kX -= 255;
- }
- }
-
- if (!yNegative)
- {
- kY -= kMousePacket[2];
- if (yOverflow)
- {
- kY -= 255;
- }
- }
- else
- {
- kMousePacket[2] = 256 - kMousePacket[2];
- kY += kMousePacket[2];
- if (yOverflow)
- {
- kY += 255;
- }
- }
-
- if (kX < 0)
- kX = 0;
- if (kX > kHandoverHeader->f_GOP.f_Width - 8)
- kX = kHandoverHeader->f_GOP.f_Width - 8;
-
- if (kY < 0)
- kY = 0;
- if (kY > kHandoverHeader->f_GOP.f_Height - 16)
- kY = kHandoverHeader->f_GOP.f_Height - 16;
-
- /// Draw mouse here.
-
- kPrevX = kX;
- kPrevY = kY;
-
- CGDrawBitMapInRegionA(Cursor, cCurHeight, cCurWidth, kY, kX);
-
- kMousePacketReady = false;
- return true;
-}
-
-/// @brief Init kernel mouse.
-EXTERN_C Void _hal_init_mouse()
-{
- kPrevX = 10;
- kPrevY = 10;
- kX = 10;
- kY = 10;
- kMouseCycle = 0;
- kMousePacketReady = false;
-
- Kernel::PS2MouseInterface ps2_mouse;
- ps2_mouse.Init();
-}
diff --git a/dev/ZKA/HALKit/AMD64/HalTimer.cxx b/dev/ZKA/HALKit/AMD64/HalTimer.cxx
index e6e21a67..33b0e00f 100644
--- a/dev/ZKA/HALKit/AMD64/HalTimer.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalTimer.cxx
@@ -15,25 +15,31 @@
#include <ArchKit/ArchKit.hxx>
#include <KernelKit/Timer.hxx>
+// timer slot 0
+
+#define cHPETCounterValue (0x0f0 * 0x20)
+#define cHPETConfigValue (0x010 * 0x20)
+#define cHPETCompValue (0x108 * 0x20)
+
///! BUGS: 0
///! @file HalTimer.cxx
-///! @brief Hardware Timer.
+///! @brief Hardware Timer (HPET)
namespace Kernel::Detail
{
struct HPET_BLOCK : public Kernel::SDT
{
- Kernel::UInt8 hardware_rev_id;
- Kernel::UInt8 comparator_count : 5;
- Kernel::UInt8 counter_size : 1;
- Kernel::UInt8 reserved : 1;
- Kernel::UInt8 legacy_replacement : 1;
- Kernel::UInt16 pci_vendor_id;
- Kernel::ACPI_ADDRESS address;
- Kernel::UInt8 hpet_number;
- Kernel::UInt16 minimum_tick;
- Kernel::UInt8 page_protection;
- } __attribute__((packed));
+ Kernel::UInt8 hardware_rev_id;
+ Kernel::UInt8 comparator_count : 5;
+ Kernel::UInt8 counter_size : 1;
+ Kernel::UInt8 reserved : 1;
+ Kernel::UInt8 legacy_replacement : 1;
+ Kernel::UInt16 pci_vendor_id;
+ ACPI_ADDRESS address;
+ Kernel::UInt8 hpet_number;
+ Kernel::UInt16 minimum_tick;
+ Kernel::UInt8 page_protection;
+ } PACKED;
} // namespace Kernel::Detail
using namespace Kernel;
@@ -43,9 +49,10 @@ HardwareTimer::HardwareTimer(Int64 ms)
{
auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr);
- auto hpet = (Detail::HPET_BLOCK*)power.Find("HPET").Leak().Leak();
+ auto hpet = (Detail::HPET_BLOCK*)power.Find("HPET").Leak().Leak();
+ MUST_PASS(hpet);
+
fDigitalTimer = (IntPtr*)hpet->address.Address;
- MUST_PASS(fDigitalTimer);
}
HardwareTimer::~HardwareTimer()
@@ -59,19 +66,21 @@ Int32 HardwareTimer::Wait() noexcept
if (fWaitFor < 1)
return -1;
- UInt32 minimum_tick = *(fDigitalTimer) >> 32;
-
- const UInt64 cLimitVal = 0x10000000000000;
+ // if not enabled yet.
+ if (!(*(fDigitalTimer + cHPETConfigValue) & (1 << 0)))
+ {
+ *(fDigitalTimer + cHPETConfigValue) |= (1 << 0); // enable it
+ *(fDigitalTimer + cHPETConfigValue) |= (1 << 3); // one shot conf
+ }
- UInt64 microsecond = fWaitFor / minimum_tick;
+ UInt64 ticks = fWaitFor / ((*(fDigitalTimer) >> 32) & __UINT32_MAX__);
- *(fDigitalTimer + 0x0f0) = cLimitVal - microsecond;
- *(fDigitalTimer + 0x010) = 0x1;
+ auto prev = *(fDigitalTimer + cHPETCounterValue);
- kcout << "MS: " << number(microsecond) << endl;
+ *(fDigitalTimer + cHPETCompValue) = prev + ticks;
- while (*(fDigitalTimer + 0x0f0) <= cLimitVal)
- ;
+ while (*(fDigitalTimer + cHPETCounterValue) < (ticks))
+ kcout << "MS: " << number(*(fDigitalTimer + cHPETCounterValue)) << endl;
return 0;
}
diff --git a/dev/ZKA/KernelKit/FileManager.hxx b/dev/ZKA/KernelKit/FileManager.hxx
index af33208a..67f2f501 100644
--- a/dev/ZKA/KernelKit/FileManager.hxx
+++ b/dev/ZKA/KernelKit/FileManager.hxx
@@ -98,6 +98,7 @@ namespace Kernel
virtual NodePtr Create(_Input const Char* path) = 0;
virtual NodePtr CreateAlias(_Input const Char* path) = 0;
virtual NodePtr CreateDirectory(_Input const Char* path) = 0;
+ virtual NodePtr CreateSwapFile(const Char* path) = 0;
public:
virtual bool Remove(_Input const Char* path) = 0;
@@ -149,6 +150,7 @@ namespace Kernel
NodePtr Create(const Char* path) override;
NodePtr CreateAlias(const Char* path) override;
NodePtr CreateDirectory(const Char* path) override;
+ NodePtr CreateSwapFile(const Char* path) override;
public:
bool Remove(const Char* path) override;
diff --git a/dev/ZKA/KernelKit/MP.hxx b/dev/ZKA/KernelKit/MP.hxx
index 0194e8dd..d2704b23 100644
--- a/dev/ZKA/KernelKit/MP.hxx
+++ b/dev/ZKA/KernelKit/MP.hxx
@@ -34,8 +34,8 @@ namespace Kernel
kHartCount,
};
- typedef enum ThreadKind SmThreadKind;
- typedef ThreadID SmThreadID;
+ typedef enum ThreadKind ThreadKind;
+ typedef ThreadID ThreadID;
///
/// \name HardwareThread
diff --git a/dev/ZKA/KernelKit/Timer.hxx b/dev/ZKA/KernelKit/Timer.hxx
index ba598975..3d997848 100644
--- a/dev/ZKA/KernelKit/Timer.hxx
+++ b/dev/ZKA/KernelKit/Timer.hxx
@@ -68,7 +68,8 @@ namespace Kernel
if (time < 0)
return 0;
- return 1000 * time;
+ // TODO: nanoseconds maybe?
+ return 1000 * 1000 * time;
}
inline Int64 Seconds(Int64 time)
diff --git a/dev/ZKA/Modules/ACPI/ACPI.hxx b/dev/ZKA/Modules/ACPI/ACPI.hxx
index 44e9fa1b..c959d6c1 100644
--- a/dev/ZKA/Modules/ACPI/ACPI.hxx
+++ b/dev/ZKA/Modules/ACPI/ACPI.hxx
@@ -48,7 +48,7 @@ namespace Kernel
UInt32 Reserved;
};
- enum class ACPI_ADDRESS_SPACE_KIND : UInt8
+ enum ACPI_ADDRESS_SPACE_KIND : UInt8
{
eSystemMemory = 0,
eSystemIO = 1,
@@ -62,7 +62,7 @@ namespace Kernel
class PACKED ACPI_ADDRESS final
{
public:
- ACPI_ADDRESS_SPACE_KIND AddressSpaceId;
+ UInt8 AddressSpaceId;
UInt8 RegisterBitWidth;
UInt8 RegisterBitOffset;
UInt8 Reserved;
diff --git a/dev/ZKA/Modules/ACPI/ACPIFactoryInterface.hxx b/dev/ZKA/Modules/ACPI/ACPIFactoryInterface.hxx
index a8f22c10..0d724f3b 100644
--- a/dev/ZKA/Modules/ACPI/ACPIFactoryInterface.hxx
+++ b/dev/ZKA/Modules/ACPI/ACPIFactoryInterface.hxx
@@ -29,8 +29,8 @@ namespace Kernel
ACPIFactoryInterface(const ACPIFactoryInterface&) = default;
public:
- void Shutdown(); // shutdown
- void Reboot(); // soft-reboot
+ Void Shutdown(); // shutdown
+ Void Reboot(); // soft-reboot
public:
/// @brief Descriptor find factory.
diff --git a/dev/ZKA/Modules/PS2/PS2MouseInterface.hxx b/dev/ZKA/Modules/PS2/PS2MouseInterface.hxx
deleted file mode 100644
index ec57b134..00000000
--- a/dev/ZKA/Modules/PS2/PS2MouseInterface.hxx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
- File: PS2MouseInterface.hxx
- Purpose: PS/2 mouse.
-
- Revision History:
-
- 03/02/24: Added file (amlel)
-
-------------------------------------------- */
-
-#pragma once
-
-#include <ArchKit/ArchKit.hxx>
-#include <CompilerKit/CompilerKit.hxx>
-#include <NewKit/Defines.hxx>
-
-namespace Kernel
-{
- /// @brief PS/2 Mouse driver interface
- class PS2MouseInterface final
- {
- public:
- explicit PS2MouseInterface() = default;
- ~PS2MouseInterface() = default;
-
- ZKA_COPY_DEFAULT(PS2MouseInterface);
-
- public:
- /// @brief Enables PS2 mouse for kernel.
- /// @return
- Void Init() noexcept
- {
- HAL::Out8(0x64, 0xA8); // enabling the auxiliary device - mouse
-
- this->Wait();
-
- HAL::Out8(0x64, 0x20); // tells the keyboard controller that we want to send a command to the mouse
-
- this->Wait();
-
- UInt8 status = HAL::In8(0x60);
- status |= 0x02;
-
- HAL::Out8(0x64, 0x60);
- HAL::Out8(0x60, status); // setting the correct bit is the "compaq" status byte
-
- HAL::Out8(0x64, 0xD4);
- HAL::Out8(0x60, 0xFA); // setting the correct bit is the "compaq" status byte
-
- this->Read();
-
- // Unmask mouse IRQ.
-
- // get slave PIC.
- UInt8 old_pic = HAL::In8(0x21);
-
- // enable mosue interrupts
- HAL::Out8(0x21, old_pic & (~0b00000100));
- }
-
- public:
- Bool WaitInput() noexcept
- {
- UInt64 timeout = 100000;
-
- while (timeout)
- {
- if ((HAL::In8(0x64) & 0x1))
- {
- return true;
- }
-
- --timeout;
- } // wait until we can read
-
- // return the ack bit.
- return false;
- }
-
- Bool Wait() noexcept
- {
- UInt64 timeout = 100000;
-
- while (timeout)
- {
- if ((HAL::In8(0x64) & 0b10) == 0)
- {
- return true;
- }
-
- --timeout;
- } // wait until we can read
-
- // return the ack bit.
- return false;
- }
-
- Void Write(UInt8 val)
- {
- HAL::Out8(0x64, 0xD4);
- this->Wait();
- HAL::Out8(0x60, val);
- this->Wait();
- }
-
- UInt8 Read()
- {
- this->WaitInput();
- return HAL::In8(0x60);
- }
- };
-} // namespace Kernel
diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx
index fae68334..db9d6ad9 100644
--- a/dev/ZKA/NewKit/Macros.hxx
+++ b/dev/ZKA/NewKit/Macros.hxx
@@ -114,4 +114,8 @@
#define RGB(R, G, B) (Kernel::UInt32)(R | G << 0x8 | B << 0x10)
#endif // !RGB
+/// @brief The system page file.
#define kSysPage "\\System\\syspage.sys"
+
+/// @brief The main system driver.
+#define kSysDrv "\\System\\sysdrv.sys"
diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx
index 8166a702..412f9bdd 100644
--- a/dev/ZKA/Sources/DLLMain.cxx
+++ b/dev/ZKA/Sources/DLLMain.cxx
@@ -34,12 +34,9 @@
EXTERN Kernel::Property cKernelVersion;
/***********************************************************************************/
-/* This is an external C symbol. */
+/* This is an external C symbol, to draw the mouse. */
/***********************************************************************************/
-EXTERN_C Kernel::Void _hal_init_mouse();
-EXTERN_C Kernel::Boolean _hal_draw_mouse();
-
STATIC CG::UI_WINDOW_STRUCT* cKernelWnd = nullptr;
namespace Kernel::Detail
@@ -55,12 +52,12 @@ namespace Kernel::Detail
{
if (Kernel::FilesystemManagerInterface::GetMounted())
{
- CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: NewFS filesystem already mounted...", 10, 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: NewFS already mounted by HAL...", 10, 10, RGB(0, 0, 0));
fNewFS = reinterpret_cast<Kernel::NewFilesystemManager*>(Kernel::FilesystemManagerInterface::GetMounted());
}
else
{
- CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Mounting a NewFS filesystem...", 10, 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Mounted NewFS filesystem...", 10, 10, RGB(0, 0, 0));
// Mounts a NewFS from main drive.
fNewFS = new Kernel::NewFilesystemManager();
@@ -84,8 +81,8 @@ namespace Kernel::Detail
{
Kernel::kcout << "newoskrnl: Already exists.\r";
- CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0));
- CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog already exists: ")), RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog directory already exists: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog directory already exists: ")), RGB(0, 0, 0));
delete catalogDir;
continue;
@@ -108,19 +105,19 @@ namespace Kernel::Detail
if (catalogDisk)
{
- CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog file exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0));
- CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog file exists: ")), RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog swap file already exists: ")), RGB(0, 0, 0));
delete catalogDisk;
}
else
{
- CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog has been created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0));
- CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog has been created: ")), RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("NewOSKrnl: Catalog swap file created: ")), RGB(0, 0, 0));
catalogDisk =
- (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias(kSysPage);
+ (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(kSysPage);
NFS_FORK_STRUCT theDiskFork{0};
@@ -172,7 +169,7 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
cKernelWnd = nullptr;
cKernelWnd = CG::CGCreateWindow(CG::cWndFlagWindow, "ZKA Operating System Kernel Log", "Window", 20, 20, CG::UIAccessibilty::The().Height() - 20, CG::UIAccessibilty::The().Width() - 20);
- cKernelWnd->w_sub_type = CG::cWndFlagCloseControlSelect;
+ cKernelWnd->w_sub_type = 0;
cKernelWnd->w_x = 10;
cKernelWnd->w_y = 10;
@@ -183,6 +180,14 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
/// Now run kernel loop, until no process are running.
Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation.
+ cKernelWnd->w_sub_type = CG::cWndFlagCloseControlSelect;
+ cKernelWnd->w_needs_repaint = Yes;
+
+ CG::CGDrawWindowList(&cKernelWnd, 1);
+
+ CG::CGDrawStringToWnd(cKernelWnd, "NewOSKrnl: Booting: ", 10, 10, RGB(0, 0, 0));
+ CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("NewOSKrnl: Booting: ")), RGB(0, 0, 0));
+
/// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though.
Kernel::cProcessScheduler = nullptr;
diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx
index a5389b39..3057fe65 100644
--- a/dev/ZKA/Sources/KernelCheck.cxx
+++ b/dev/ZKA/Sources/KernelCheck.cxx
@@ -5,6 +5,7 @@
------------------------------------------- */
#include <ArchKit/ArchKit.hxx>
+#include <KernelKit/Timer.hxx>
#include <KernelKit/DebugOutput.hxx>
#include <NewKit/KernelCheck.hxx>
#include <NewKit/String.hxx>
@@ -20,7 +21,7 @@
#define CopyMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz)
#define MoveMem(dst, src, sz) Kernel::rt_copy_memory((Kernel::VoidPtr)src, (Kernel::VoidPtr)dst, sz)
-#define cWebsiteMacro "https://zka.nl/help"
+#define cWebsiteMacro "https://help.el-mahrouss-logic.com/"
/* Each error code is attributed with an ID, which will prompt a string onto the
* screen. Wait for debugger... */
@@ -31,7 +32,7 @@ namespace Kernel
{
CGInit();
- auto panicTxt = RGB(0xff, 0xff, 0xff);
+ auto panicTxt = RGB(0xff, 0xff, 0xff);
CG::CGDrawBackground();
@@ -39,6 +40,11 @@ namespace Kernel
auto x = 10;
CGDrawString("newoskrnl.dll Stopped working properly so it had to stop.", start_y, x, panicTxt);
+ start_y += 10;
+
+ // simply offset from previous string and then write the website.
+ CGDrawString("Please visit: ", start_y, x, panicTxt);
+ CGDrawString(cWebsiteMacro, start_y, x + (FONT_SIZE_X * rt_string_len("Please visit: ")), panicTxt);
CGFini();
@@ -54,34 +60,42 @@ namespace Kernel
}
case RUNTIME_CHECK_ACPI: {
CGDrawString("0x00000006 ACPI configuration error.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_FILESYSTEM: {
CGDrawString("0x0000000A Filesystem corruption error.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_POINTER: {
CGDrawString("0x00000000 Kernel heap pointer error, surely corrupted.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_BAD_BEHAVIOR: {
CGDrawString("0x00000009 Undefined behavior error, image had to stop.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_BOOTSTRAP: {
CGDrawString("0x0000000A End of boot code, but nothing to continue.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_HANDSHAKE: {
CGDrawString("0x00000005 Bad handshake error.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_IPC: {
CGDrawString("0x00000003 Bad kernel IPC error.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
case RUNTIME_CHECK_INVALID_PRIVILEGE: {
CGDrawString("0x00000007 Kernel privilege violation.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
case RUNTIME_CHECK_UNEXCPECTED: {
CGDrawString("0x0000000B Catasrophic kernel failure.", start_y, x, panicTxt);
@@ -89,24 +103,30 @@ namespace Kernel
}
case RUNTIME_CHECK_FAILED: {
CGDrawString("0x10000001 Assertion failed.", start_y, x, panicTxt);
+ RecoveryFactory::Recover();
break;
}
default: {
+ RecoveryFactory::Recover();
CGDrawString("0xFFFFFFFC Unknown kernel error.", start_y, x, panicTxt);
break;
}
}
};
- RecoveryFactory::Recover();
+ while (Yes)
+ ;
}
Void RecoveryFactory::Recover() noexcept
{
- while (Yes)
- {
- asm volatile("cli; hlt");
- }
+ const auto cMaxSeconds = Seconds(4);
+
+ HardwareTimer timer(cMaxSeconds);
+ timer.Wait();
+
+ PowerFactoryInterface power(nullptr);
+ power.Reboot();
}
void ke_runtime_check(bool expr, const Char* file, const Char* line)
diff --git a/dev/ZKA/Sources/NewFS+FileManager.cxx b/dev/ZKA/Sources/NewFS+FileManager.cxx
index e40e98aa..6f50733f 100644
--- a/dev/ZKA/Sources/NewFS+FileManager.cxx
+++ b/dev/ZKA/Sources/NewFS+FileManager.cxx
@@ -68,6 +68,14 @@ namespace Kernel
return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias));
}
+ /// @brief Creates a node with is a page file.
+ /// @param path The filename path.
+ /// @return The Node pointer.
+ NodePtr NewFilesystemManager::CreateSwapFile(const Char* path)
+ {
+ return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage));
+ }
+
/// @brief Gets the root directory.
/// @return
const Char* NewFilesystemHelper::Root()
diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx
index 965c5eb1..4186808e 100644
--- a/dev/ZKA/Sources/ProcessScheduler.cxx
+++ b/dev/ZKA/Sources/ProcessScheduler.cxx
@@ -314,8 +314,6 @@ namespace Kernel
/// @return
SizeT ProcessScheduler::Run() noexcept
{
- kcout << "newoskrnl: Entering scheduler control..\r";
-
SizeT process_index = 0; //! we store this guy to tell the scheduler how many
//! things we have scheduled.
@@ -352,8 +350,6 @@ namespace Kernel
}
}
- kcout << "newoskrnl: Exiting scheduler control..\r";
-
return process_index;
}