summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKAKit/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-07 18:07:22 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-07 18:07:22 +0100
commit4c7ea58f5d5e495e8da6cfc7e1d52a3dfcf5a893 (patch)
tree40c91fce5ac9e622e49515608033f8c98af5a8f1 /dev/ZKAKit/HALKit
parent63be0a396d95db7b629ffe64dcc543e251936b36 (diff)
IMPL: New I/O functions from assembly, still working on #8 issue.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/HALKit')
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc12
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalCommonAPI.asm45
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc28
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm3
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc2
-rw-r--r--dev/ZKAKit/HALKit/AMD64/HalRoutineWait.s2
-rw-r--r--dev/ZKAKit/HALKit/AMD64/Processor.h6
-rw-r--r--dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc2
-rw-r--r--dev/ZKAKit/HALKit/POWER/HalDebugOutput.cc (renamed from dev/ZKAKit/HALKit/POWER/HalSerialPort.cc)0
9 files changed, 80 insertions, 20 deletions
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc
index 275f630d..52ba46aa 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc
@@ -17,7 +17,7 @@
namespace Kernel::HAL
{
- Void rt_out8(UInt16 port, UInt8 value)
+ Void lrt_out8(UInt16 port, UInt8 value)
{
asm volatile("outb %%al, %1"
:
@@ -25,7 +25,7 @@ namespace Kernel::HAL
: "memory");
}
- Void rt_out16(UInt16 port, UInt16 value)
+ Void lrt_out16(UInt16 port, UInt16 value)
{
asm volatile("outw %%ax, %1"
:
@@ -33,7 +33,7 @@ namespace Kernel::HAL
: "memory");
}
- Void rt_out32(UInt16 port, UInt32 value)
+ Void lrt_out32(UInt16 port, UInt32 value)
{
asm volatile("outl %%eax, %1"
:
@@ -41,7 +41,7 @@ namespace Kernel::HAL
: "memory");
}
- UInt8 rt_in8(UInt16 port)
+ UInt8 lrt_in8(UInt16 port)
{
UInt8 value = 0UL;
asm volatile("inb %1, %%al"
@@ -52,7 +52,7 @@ namespace Kernel::HAL
return value;
}
- UInt16 rt_in16(UInt16 port)
+ UInt16 lrt_in16(UInt16 port)
{
UInt16 value = 0UL;
asm volatile("inw %1, %%ax"
@@ -63,7 +63,7 @@ namespace Kernel::HAL
return value;
}
- UInt32 rt_in32(UInt16 port)
+ UInt32 lrt_in32(UInt16 port)
{
UInt32 value = 0UL;
asm volatile("inl %1, %%eax"
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCommonAPI.asm b/dev/ZKAKit/HALKit/AMD64/HalCommonAPI.asm
index 77931d0e..6e463e98 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalCommonAPI.asm
+++ b/dev/ZKAKit/HALKit/AMD64/HalCommonAPI.asm
@@ -7,4 +7,47 @@
;; * ========================================================
;; */
-section .text \ No newline at end of file
+section .text
+
+extern rt_wait_400ns
+
+global rt_out8
+global rt_out16
+global rt_out32
+
+global rt_in8
+global rt_in16
+global rt_in32
+
+rt_out8:
+ mov al, dl
+ mov dx, cx
+ out dx, al
+ ret
+
+rt_out16:
+ mov ax, dx
+ mov dx, cx
+ out dx, ax
+ ret
+
+rt_out32:
+ mov eax, edx
+ mov edx, ecx
+ out dx, eax
+ ret
+
+rt_in8:
+ mov dx, cx
+ in al, dx
+ ret
+
+rt_in16:
+ mov edx, ecx
+ in ax, dx
+ ret
+
+rt_in32:
+ mov rdx, rcx
+ in eax, dx
+ ret
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
index e40ef071..aaf80c9a 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
@@ -17,6 +17,9 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+
process.Leak().ProcessSignal.SignalIP = 0UL;
process.Leak().ProcessSignal.SignalID = SIGKILL;
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
@@ -35,11 +38,13 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp)
EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp)
{
kcout << "Kernel: Page Fault.\r";
-
kcout << "Kernel: SIGKILL set.\r";
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+
process.Leak().ProcessSignal.SignalIP = 0UL;
process.Leak().ProcessSignal.SignalID = SIGKILL;
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
@@ -68,7 +73,7 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp)
}
try_count_before_brute = 100000UL;
- is_scheduling = YES;
+ is_scheduling = YES;
kcout << "Kernel: Timer IRQ (Scheduler Notification).\r";
Kernel::UserProcessHelper::StartScheduling();
@@ -84,6 +89,9 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp)
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+
process.Leak().ProcessSignal.SignalIP = 0UL;
process.Leak().ProcessSignal.SignalID = SIGKILL;
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
@@ -105,6 +113,9 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp)
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+
process.Leak().ProcessSignal.SignalIP = 0UL;
process.Leak().ProcessSignal.SignalID = SIGKILL;
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
@@ -122,13 +133,15 @@ EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip)
{
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
- kcout << "Kernel: Process RIP: " << Kernel::hex_number(rip) << endl;
- kcout << "Kernel: Process Name: " << process.Leak().Name << endl;
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+ kcout << "Kernel: Process RIP: " << Kernel::hex_number(rip) << endl;
kcout << "Kernel: SIGTRAP set.\r";
- process.Leak().ProcessSignal.SignalIP = rip;
- process.Leak().ProcessSignal.SignalID = SIGTRAP;
+ process.Leak().ProcessSignal.SignalIP = rip;
+ process.Leak().ProcessSignal.SignalID = SIGTRAP;
+
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
kcout << "Kernel: PRCFROZE status set..\r";
@@ -144,6 +157,9 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp)
auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess();
+ if (!process)
+ Kernel::ke_stop(RUNTIME_CHECK_PAGE);
+
process.Leak().ProcessSignal.SignalIP = 0UL;
process.Leak().ProcessSignal.SignalID = SIGKILL;
process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status;
diff --git a/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm
index 66dd34f0..7aafa079 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm
+++ b/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm
@@ -202,8 +202,7 @@ __ZKA_INT_32:
push rax
mov rcx, rsp
- mov rax, idt_handle_scheduler
- call rax
+ call idt_handle_scheduler
pop rax
sti
diff --git a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
index 3cff28d2..47a38ca1 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc
@@ -83,7 +83,7 @@ EXTERN_C void hal_init_platform(
EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept
{
- Kernel::rtl_create_process(ke_dll_entrypoint, "Kernel System");
+ Kernel::rtl_create_process(ke_dll_entrypoint, "Kernel System");
/* Initialize filesystem. */
Kernel::NeFileSystemMgr::Mount(new Kernel::NeFileSystemMgr());
diff --git a/dev/ZKAKit/HALKit/AMD64/HalRoutineWait.s b/dev/ZKAKit/HALKit/AMD64/HalRoutineWait.s
index d794882d..89051ba4 100644
--- a/dev/ZKAKit/HALKit/AMD64/HalRoutineWait.s
+++ b/dev/ZKAKit/HALKit/AMD64/HalRoutineWait.s
@@ -3,7 +3,9 @@
.section .text
rt_wait_400ns:
jmp .loop
+ pause
.loop:
jmp .loop2
+ pause
.loop2:
ret
diff --git a/dev/ZKAKit/HALKit/AMD64/Processor.h b/dev/ZKAKit/HALKit/AMD64/Processor.h
index b0580f3c..02c621bc 100644
--- a/dev/ZKAKit/HALKit/AMD64/Processor.h
+++ b/dev/ZKAKit/HALKit/AMD64/Processor.h
@@ -303,9 +303,9 @@ namespace Kernel::HAL
/// @return Status code of page manip.
EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags);
- EXTERN_C UChar rt_in8(UInt16 port);
- EXTERN_C UShort rt_in16(UInt16 port);
- EXTERN_C UInt rt_in32(UInt16 port);
+ EXTERN_C UInt8 rt_in8(UInt16 port);
+ EXTERN_C UInt16 rt_in16(UInt16 port);
+ EXTERN_C UInt32 rt_in32(UInt16 port);
EXTERN_C void rt_out16(UShort port, UShort byte);
EXTERN_C void rt_out8(UShort port, UChar byte);
diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
index 106a06b1..6b6d4ee5 100644
--- a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
+++ b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc
@@ -52,7 +52,7 @@ enum
};
STATIC Kernel::PCI::Device kAhciDevice;
-STATIC HbaPort* kAhciPort = nullptr;
+STATIC HbaPort* kAhciPort = nullptr;
STATIC Kernel::Lba kCurrentDiskSectorCount = 0UL;
Kernel::Void drv_calculate_disk_geometry()
diff --git a/dev/ZKAKit/HALKit/POWER/HalSerialPort.cc b/dev/ZKAKit/HALKit/POWER/HalDebugOutput.cc
index 91805d87..91805d87 100644
--- a/dev/ZKAKit/HALKit/POWER/HalSerialPort.cc
+++ b/dev/ZKAKit/HALKit/POWER/HalDebugOutput.cc