diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-06 08:50:56 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-06 08:50:56 +0100 |
| commit | dae34fe2db8827de776396c979c2bf79681edb9a (patch) | |
| tree | 3ef2d0bfab9883eef04f179ffb50157e5d6a59df /dev/ZKAKit | |
| parent | 78a639520307fef30e43ee7e2f1db058c3caba8a (diff) | |
IMP: A set of WiP for the process scheduler.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit')
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc | 12 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc | 28 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalDebugPort.cc | 10 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc | 14 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc | 10 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/PCI/Device.cc | 18 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/Processor.h | 12 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc | 50 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/ARM64/HalTimerARM64.cc (renamed from dev/ZKAKit/HALKit/ARM64/HalTimer.cc) | 0 | ||||
| -rw-r--r-- | dev/ZKAKit/KernelKit/PCI/IO-Impl-AMD64.inl | 12 | ||||
| -rw-r--r-- | dev/ZKAKit/KernelKit/UserProcessScheduler.h | 4 | ||||
| -rw-r--r-- | dev/ZKAKit/src/UserProcessScheduler.cc | 30 |
12 files changed, 109 insertions, 91 deletions
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc index fc1a6253..fb6b6e71 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCPUAMD64.cc @@ -17,7 +17,7 @@ namespace Kernel::HAL { - Void Out8(UInt16 port, UInt8 value) + Void rt_out8(UInt16 port, UInt8 value) { asm volatile("outb %%al, %1" : @@ -25,7 +25,7 @@ namespace Kernel::HAL : "memory"); } - Void Out16(UInt16 port, UInt16 value) + Void rt_out16(UInt16 port, UInt16 value) { asm volatile("outw %%ax, %1" : @@ -33,7 +33,7 @@ namespace Kernel::HAL : "memory"); } - Void Out32(UInt16 port, UInt32 value) + Void rt_out32(UInt16 port, UInt32 value) { asm volatile("outl %%eax, %1" : @@ -41,7 +41,7 @@ namespace Kernel::HAL : "memory"); } - UInt8 In8(UInt16 port) + UInt8 rt_in8(UInt16 port) { UInt8 value = 0UL; asm volatile("inb %1, %%al" @@ -52,7 +52,7 @@ namespace Kernel::HAL return value; } - UInt16 In16(UInt16 port) + UInt16 rt_in16(UInt16 port) { UInt16 value = 0UL; asm volatile("inw %1, %%ax" @@ -63,7 +63,7 @@ namespace Kernel::HAL return value; } - UInt32 In32(UInt16 port) + UInt32 rt_in32(UInt16 port) { UInt32 value = 0UL; asm volatile("inl %1, %%eax" diff --git a/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc b/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc index 7f55e64c..476106a5 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalDebugOutput.cc @@ -33,19 +33,19 @@ namespace Kernel if (kState == kStateReady || kState == kStateTransmit) return true; - HAL::Out8(PORT + 1, 0x00); // Disable all interrupts - HAL::Out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) - HAL::Out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud - HAL::Out8(PORT + 1, 0x00); // (hi byte) - HAL::Out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit - HAL::Out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold - HAL::Out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - HAL::Out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip - HAL::Out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if + HAL::rt_out8(PORT + 1, 0x00); // Disable all interrupts + HAL::rt_out8(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + HAL::rt_out8(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + HAL::rt_out8(PORT + 1, 0x00); // (hi byte) + HAL::rt_out8(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + HAL::rt_out8(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + HAL::rt_out8(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + HAL::rt_out8(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip + HAL::rt_out8(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if // serial returns same byte) // Check if serial is faulty (i.e: not same byte as sent) - if (HAL::In8(PORT) != 0xAE) + if (HAL::rt_in8(PORT) != 0xAE) { ke_stop(RUNTIME_CHECK_HANDSHAKE); } @@ -54,7 +54,7 @@ namespace Kernel // If serial is not faulty set it in normal operation mode // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) - HAL::Out8(Detail::PORT + 4, 0x0F); + HAL::rt_out8(Detail::PORT + 4, 0x0F); #endif // __DEBUG__ return true; @@ -82,9 +82,9 @@ namespace Kernel while (index < len) { if (bytes[index] == '\r') - HAL::Out8(Detail::PORT, '\r'); + HAL::rt_out8(Detail::PORT, '\r'); - HAL::Out8(Detail::PORT, bytes[index] == '\r' ? '\n' : bytes[index]); + HAL::rt_out8(Detail::PORT, bytes[index] == '\r' ? '\n' : bytes[index]); ++index; } @@ -107,7 +107,7 @@ namespace Kernel ///! TODO: Look on how to wait for the UART to complete. while (true) { - auto in = HAL::In8(Detail::PORT); + auto in = HAL::rt_in8(Detail::PORT); ///! If enter pressed then break. if (in == 0xD) diff --git a/dev/ZKAKit/HALKit/AMD64/HalDebugPort.cc b/dev/ZKAKit/HALKit/AMD64/HalDebugPort.cc index 4a4adae4..40541ee8 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalDebugPort.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalDebugPort.cc @@ -21,19 +21,19 @@ namespace Kernel for (UInt32 i = 0U; i < kDebugMaxPorts; ++i) { - HAL::Out16(theHook->fPort[i], kDebugMag0); + HAL::rt_out16(theHook->fPort[i], kDebugMag0); HAL::rt_wait_400ns(); - HAL::Out16(theHook->fPort[i], kDebugMag1); + HAL::rt_out16(theHook->fPort[i], kDebugMag1); HAL::rt_wait_400ns(); - HAL::Out16(theHook->fPort[i], kDebugMag2); + HAL::rt_out16(theHook->fPort[i], kDebugMag2); HAL::rt_wait_400ns(); - HAL::Out16(theHook->fPort[i], kDebugMag3); + HAL::rt_out16(theHook->fPort[i], kDebugMag3); HAL::rt_wait_400ns(); - if (HAL::In16(theHook->fPort[i] != kDebugUnboundPort)) + if (HAL::rt_in16(theHook->fPort[i] != kDebugUnboundPort)) ++theHook->fBoundCnt; } } diff --git a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc index 3d49c449..fe6491c6 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalDescriptorLoader.cc @@ -28,9 +28,9 @@ namespace Kernel::HAL UInt16 cCommonDivisor = kPITFrequency / ticks; // 100 Hz. - HAL::Out8(kPITControlPort, 0x36); // Command to PIT - HAL::Out8(kPITChannel0Port, cCommonDivisor & 0xFF); // Send low byte - HAL::Out8(kPITChannel0Port, (cCommonDivisor >> 8) & 0xFF); // Send high byte + HAL::rt_out8(kPITControlPort, 0x36); // Command to PIT + HAL::rt_out8(kPITChannel0Port, cCommonDivisor & 0xFF); // Send low byte + HAL::rt_out8(kPITChannel0Port, (cCommonDivisor >> 8) & 0xFF); // Send high byte hal_clear_irq_mask(32); } @@ -50,8 +50,8 @@ namespace Kernel::HAL irql -= 8; } - value = In8(port) | (1 << irql); - Out8(port, value); + value = rt_in8(port) | (1 << irql); + rt_out8(port, value); } STATIC void hal_clear_irq_mask(UInt8 irql) @@ -69,8 +69,8 @@ namespace Kernel::HAL irql -= 8; } - value = In8(port) & ~(1 << irql); - Out8(port, value); + value = rt_in8(port) & ~(1 << irql); + rt_out8(port, value); } } // namespace Detail diff --git a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc index 57d50fca..2e78a292 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc @@ -31,6 +31,11 @@ STATIC Kernel::Void hal_init_cxx_ctors() } } +namespace Kernel +{ + EXTERN ProcessID kProcessIDCounter; +} + /// @brief Kernel init procedure. EXTERN_C void hal_init_platform( Kernel::HEL::HANDOVER_INFO_HEADER* HandoverHeader) @@ -45,6 +50,8 @@ EXTERN_C void hal_init_platform( hal_init_cxx_ctors(); + Kernel::kProcessIDCounter = 0UL; + /************************************** */ /* INITIALIZE BIT MAP. */ /************************************** */ @@ -89,8 +96,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::rtl_create_process([]() -> void { while (Yes) ; - }, - "RtlProcess\0"); + }, "RtlProcess"); /* Start any cores. */ if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) diff --git a/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc b/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc index 7c8554a7..7d3a662e 100644 --- a/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc +++ b/dev/ZKAKit/HALKit/AMD64/PCI/Device.cc @@ -13,10 +13,10 @@ Kernel::UInt ZKA_PCIReadRaw(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | (bar & 0xFC); - Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, + Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, target); - return Kernel::HAL::In32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData); + return Kernel::HAL::rt_in32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigData); } void ZKA_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort dev, Kernel::UShort fun) @@ -25,7 +25,7 @@ void ZKA_PCISetCfgTarget(Kernel::UInt bar, Kernel::UShort bus, Kernel::UShort de ((Kernel::UInt)dev << 11) | ((Kernel::UInt)fun << 8) | (bar & ~3); - Kernel::HAL::Out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, + Kernel::HAL::rt_out32((Kernel::UShort)Kernel::PCI::PciConfigKind::ConfigAddress, target); } @@ -48,11 +48,11 @@ namespace Kernel::PCI ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction); if (sz == 4) - return HAL::In32((UShort)PciConfigKind::ConfigData + (bar & 3)); + return HAL::rt_in32((UShort)PciConfigKind::ConfigData + (bar & 3)); if (sz == 2) - return HAL::In16((UShort)PciConfigKind::ConfigData + (bar & 3)); + return HAL::rt_in16((UShort)PciConfigKind::ConfigData + (bar & 3)); if (sz == 1) - return HAL::In8((UShort)PciConfigKind::ConfigData + (bar & 3)); + return HAL::rt_in8((UShort)PciConfigKind::ConfigData + (bar & 3)); return 0xFFFF; } @@ -62,11 +62,11 @@ namespace Kernel::PCI ZKA_PCISetCfgTarget(bar, fBus, fDevice, fFunction); if (sz == 4) - HAL::Out32((UShort)PciConfigKind::ConfigData + (fBar & 3), (UInt)data); + HAL::rt_out32((UShort)PciConfigKind::ConfigData + (fBar & 3), (UInt)data); if (sz == 2) - HAL::Out16((UShort)PciConfigKind::ConfigData + (fBar & 3), (UShort)data); + HAL::rt_out16((UShort)PciConfigKind::ConfigData + (fBar & 3), (UShort)data); if (sz == 1) - HAL::Out8((UShort)PciConfigKind::ConfigData + (fBar & 3), (UChar)data); + HAL::rt_out8((UShort)PciConfigKind::ConfigData + (fBar & 3), (UChar)data); } UShort Device::DeviceId() diff --git a/dev/ZKAKit/HALKit/AMD64/Processor.h b/dev/ZKAKit/HALKit/AMD64/Processor.h index bd394e83..c854969b 100644 --- a/dev/ZKAKit/HALKit/AMD64/Processor.h +++ b/dev/ZKAKit/HALKit/AMD64/Processor.h @@ -285,13 +285,13 @@ namespace Kernel::HAL /// @return Status code of page manip. EXTERN_C Int32 mm_map_page(VoidPtr virt_addr, UInt32 flags); - EXTERN_C UChar In8(UInt16 port); - EXTERN_C UShort In16(UInt16 port); - EXTERN_C UInt In32(UInt16 port); + EXTERN_C UChar rt_in8(UInt16 port); + EXTERN_C UShort rt_in16(UInt16 port); + EXTERN_C UInt rt_in32(UInt16 port); - EXTERN_C void Out16(UShort port, UShort byte); - EXTERN_C void Out8(UShort port, UChar byte); - EXTERN_C void Out32(UShort port, UInt byte); + EXTERN_C void rt_out16(UShort port, UShort byte); + EXTERN_C void rt_out8(UShort port, UChar byte); + EXTERN_C void rt_out32(UShort port, UInt byte); EXTERN_C void rt_wait_400ns(); EXTERN_C void rt_halt(); diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc b/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc index 7cfe4acd..3e4fd553 100644 --- a/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc +++ b/dev/ZKAKit/HALKit/AMD64/Storage/ATA-PIO.cc @@ -34,16 +34,16 @@ STATIC Char kATAData[kATADataLen] = {0}; Boolean drv_std_wait_io(UInt16 IO) { for (int i = 0; i < 400; i++) - In8(IO + ATA_REG_STATUS); + rt_in8(IO + ATA_REG_STATUS); ATAWaitForIO_Retry: - auto statRdy = In8(IO + ATA_REG_STATUS); + auto statRdy = rt_in8(IO + ATA_REG_STATUS); if ((statRdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; ATAWaitForIO_Retry2: - statRdy = In8(IO + ATA_REG_STATUS); + statRdy = rt_in8(IO + ATA_REG_STATUS); if (statRdy & ATA_SR_ERR) return false; @@ -57,9 +57,9 @@ ATAWaitForIO_Retry2: Void drv_std_select(UInt16 Bus) { if (Bus == ATA_PRIMARY_IO) - Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); + rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); else - Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); + rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); } Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) @@ -70,11 +70,11 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) ATAInit_Retry: // Bus init, NEIN bit. - Out8(IO + ATA_REG_NEIN, 1); + rt_out8(IO + ATA_REG_NEIN, 1); // identify until it's good - auto statRdy = In8(IO + ATA_REG_STATUS); + auto statRdy = rt_in8(IO + ATA_REG_STATUS); if (statRdy & ATA_SR_ERR) { @@ -89,7 +89,7 @@ ATAInit_Retry: goto ATAInit_Retry; } - Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); /// fetch serial info /// model, speed, number of sectors... @@ -98,7 +98,7 @@ ATAInit_Retry: for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = In16(IO + ATA_REG_DATA); + kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); } OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; @@ -119,23 +119,23 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz drv_std_wait_io(IO); drv_std_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); + rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - Out8(IO + ATA_REG_LBA1, (Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); + rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); + rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); drv_std_wait_io(IO); for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { drv_std_wait_io(IO); - Buf[IndexOff] = In16(IO + ATA_REG_DATA); + Buf[IndexOff] = rt_in16(IO + ATA_REG_DATA); drv_std_wait_io(IO); } @@ -151,23 +151,23 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS drv_std_wait_io(IO); drv_std_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); + rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - Out8(IO + ATA_REG_LBA1, (Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); + rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); + rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); drv_std_wait_io(IO); for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { drv_std_wait_io(IO); - Out16(IO + ATA_REG_DATA, Buf[IndexOff]); + rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]); drv_std_wait_io(IO); } diff --git a/dev/ZKAKit/HALKit/ARM64/HalTimer.cc b/dev/ZKAKit/HALKit/ARM64/HalTimerARM64.cc index b1fe3bf2..b1fe3bf2 100644 --- a/dev/ZKAKit/HALKit/ARM64/HalTimer.cc +++ b/dev/ZKAKit/HALKit/ARM64/HalTimerARM64.cc diff --git a/dev/ZKAKit/KernelKit/PCI/IO-Impl-AMD64.inl b/dev/ZKAKit/KernelKit/PCI/IO-Impl-AMD64.inl index 8971810a..02d4fa27 100644 --- a/dev/ZKAKit/KernelKit/PCI/IO-Impl-AMD64.inl +++ b/dev/ZKAKit/KernelKit/PCI/IO-Impl-AMD64.inl @@ -22,11 +22,11 @@ namespace Kernel { #ifdef __ZKA_AMD64__ case 4: - return HAL::In32(fPorts[index].Leak()); + return HAL::rt_in32(fPorts[index].Leak()); case 2: - return HAL::In16(fPorts[index].Leak()); + return HAL::rt_in16(fPorts[index].Leak()); case 1: - return HAL::In8(fPorts[index].Leak()); + return HAL::rt_in8(fPorts[index].Leak()); #endif default: return 0xFFFF; @@ -41,11 +41,11 @@ namespace Kernel { #ifdef __ZKA_AMD64__ case 4: - HAL::Out32(fPorts[index].Leak(), value); + HAL::rt_out32(fPorts[index].Leak(), value); case 2: - HAL::Out16(fPorts[index].Leak(), value); + HAL::rt_out16(fPorts[index].Leak(), value); case 1: - HAL::Out8(fPorts[index].Leak(), value); + HAL::rt_out8(fPorts[index].Leak(), value); #endif default: break; diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h index 072dc0db..906a378b 100644 --- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h +++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h @@ -132,7 +132,9 @@ namespace Kernel class UserProcess final { public: - UserProcess(VoidPtr start_image = nullptr); + explicit UserProcess(VoidPtr start_image); + explicit UserProcess() = default; + ~UserProcess(); public: diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc index d503cae3..1a060041 100644 --- a/dev/ZKAKit/src/UserProcessScheduler.cc +++ b/dev/ZKAKit/src/UserProcessScheduler.cc @@ -287,9 +287,13 @@ namespace Kernel if (this->Code && mm_is_valid_heap(this->Code)) mm_delete_heap(this->Code); + if (this->ExecImg && mm_is_valid_heap(this->ExecImg)) + mm_delete_heap(this->ExecImg); + if (this->StackFrame && mm_is_valid_heap(this->StackFrame)) mm_delete_heap((VoidPtr)this->StackFrame); + this->ExecImg = nullptr; this->Code = nullptr; this->StackFrame = nullptr; @@ -298,19 +302,19 @@ namespace Kernel Bool success = false; rtl_fini_dll(this, this->PefDLLDelegate, &success); - if (success) + if (!success) { - this->PefDLLDelegate = nullptr; + ke_stop(RUNTIME_CHECK_PROCESS); } + + this->PefDLLDelegate = nullptr; } if (this->StackReserve) - delete[] this->StackReserve; + mm_delete_heap(reinterpret_cast<VoidPtr>(this->StackReserve)); this->ProcessId = 0; - - if (this->ProcessId > 0) - UserProcessScheduler::The().Remove(this->ProcessId); + --kProcessIDCounter; } /***********************************************************************************/ @@ -350,7 +354,13 @@ namespace Kernel process->PefDLLDelegate = rtl_init_dll(process); } - process->StackReserve = reinterpret_cast<UInt8*>(mm_new_heap(sizeof(UInt8) * process->StackSize, Yes, Yes)); + process->StackReserve = new UInt8[process->StackSize]; + + UInt32 flags = HAL::kMMFlagsPresent; + flags |= HAL::kMMFlagsWr; + flags |= HAL::kMMFlagsUser; + + HAL::mm_map_page((VoidPtr)process->StackReserve, flags); kcout << "Validate stack reserve: " << number((UIntPtr)process->StackReserve) << endl; @@ -360,7 +370,7 @@ namespace Kernel return -kErrorProcessFault; } - auto pid = 0UL; + auto pid = kProcessIDCounter; process->ProcessId = pid; process->Status = ProcessStatusKind::kRunning; @@ -371,7 +381,7 @@ namespace Kernel kcout << "Process Name: " << mTeam.AsArray()[pid].Name << endl; kcout << "PID: " << number(mTeam.AsArray()[pid].ProcessId) << endl; - BREAK_POINT(); + ++kProcessIDCounter; return pid; } @@ -401,7 +411,7 @@ namespace Kernel if (process_id > mTeam.mProcessList.Count()) return No; - --kProcessIDCounter; + mTeam.mProcessList[process_id].Exit(0); return Yes; } |
