From 6ed8a39c1bd3083297b41e981a2bf4bdbe2abd1f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 21 Nov 2024 08:50:57 +0100 Subject: IMP: Add UserProcessImage structure to hold the code/entrypoint of the process. IMP: Use IDLLObject instead of IPEFDLLObject. IMP: Refactor DeviceInterface to IDeviceObject. ADD: rt_jump_to_address when you want to use a custom stack. Signed-off-by: Amlal El Mahrouss --- dev/ZBAKit/BootKit/Thread.h | 6 ++- dev/ZBAKit/amd64-efi.make | 4 +- dev/ZBAKit/src/BootThread.cc | 20 ++++++++-- dev/ZBAKit/src/HEL/AMD64/BootAPI.S | 8 ++++ dev/ZBAKit/src/HEL/AMD64/BootMain.cc | 4 +- dev/ZKAKit/CompilerKit/Version.h | 4 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 2 +- dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc | 11 ------ dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc | 15 ++++---- dev/ZKAKit/KernelKit/DebugOutput.h | 2 +- dev/ZKAKit/KernelKit/DeviceMgr.h | 20 +++++----- dev/ZKAKit/KernelKit/UserProcessScheduler.h | 37 ++++++++++++------ dev/ZKAKit/NetworkKit/NetworkDevice.h | 2 +- dev/ZKAKit/NetworkKit/NetworkDevice.inl | 2 +- dev/ZKAKit/NewKit/Macros.h | 8 ++-- dev/ZKAKit/StorageKit/AHCI.h | 2 +- dev/ZKAKit/StorageKit/ATA.h | 2 +- dev/ZKAKit/StorageKit/StorageKit.h | 2 +- dev/ZKAKit/src/CodeMgr.cc | 14 +++---- dev/ZKAKit/src/DriveMgr.cc | 5 +-- dev/ZKAKit/src/IPEFDLLObject.cc | 2 +- dev/ZKAKit/src/KString.cc | 6 +-- dev/ZKAKit/src/PEFCodeMgr.cc | 6 +-- dev/ZKAKit/src/Stop.cc | 4 +- dev/ZKAKit/src/Storage/AHCIDeviceInterface.cc | 2 +- dev/ZKAKit/src/Storage/ATADeviceInterface.cc | 6 +-- dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc | 2 +- dev/ZKAKit/src/UserProcessScheduler.cc | 45 ++++++++-------------- 28 files changed, 123 insertions(+), 120 deletions(-) (limited to 'dev') diff --git a/dev/ZBAKit/BootKit/Thread.h b/dev/ZBAKit/BootKit/Thread.h index e7f4d4f1..e7c6763f 100644 --- a/dev/ZBAKit/BootKit/Thread.h +++ b/dev/ZBAKit/BootKit/Thread.h @@ -29,14 +29,16 @@ namespace Boot BThread& operator=(const BThread&) = default; BThread(const BThread&) = default; - void Start(HEL::HANDOVER_INFO_HEADER* handover); - const char* GetName(); + void Start(HEL::HANDOVER_INFO_HEADER* handover, BOOL is_own_stack); void SetName(const char* name); + const char* GetName(); bool IsValid(); private: Char fBlobName[255] = {"BootThread"}; VoidPtr fStartAddress{nullptr}; VoidPtr fBlob{nullptr}; + UInt8* fStack{nullptr}; + HEL::HANDOVER_INFO_HEADER* fHandover{nullptr}; }; } // namespace Boot diff --git a/dev/ZBAKit/amd64-efi.make b/dev/ZBAKit/amd64-efi.make index 254a1ffc..9831b7ab 100644 --- a/dev/ZBAKit/amd64-efi.make +++ b/dev/ZBAKit/amd64-efi.make @@ -45,9 +45,7 @@ REM_FLAG=-f FLAG_ASM=-f win64 FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__NEWOSKRNL__ -D__NEWOSLDR__ \ -DEFI_FUNCTION_WRAPPER -I./ -I../ZKAKit -I../ -c -nostdlib -fno-rtti -fno-exceptions \ - -std=c++20 -D__HAVE_ZKA_APIS__ -DZBA_USE_FB -D__ZKA_AMD64__ -D__ZKA__ - -# -DZKA_AUTO_FORMAT + -std=c++20 -D__HAVE_ZKA_APIS__ -DZBA_USE_FB -D__ZKA_AMD64__ -D__ZKA__ -DZKA_AUTO_FORMAT BOOTLOADER=zbaosldr.exe KERNEL=minoskrnl.exe diff --git a/dev/ZBAKit/src/BootThread.cc b/dev/ZBAKit/src/BootThread.cc index 2ff8f7df..6ce14877 100644 --- a/dev/ZBAKit/src/BootThread.cc +++ b/dev/ZBAKit/src/BootThread.cc @@ -15,13 +15,15 @@ #include #include -// External boot services symbol. +/// @brief External boot services symbol. EXTERN EfiBootServices* BS; /// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. namespace Boot { + EXTERN_C Void rt_jump_to_address(VoidPtr code, HEL::HANDOVER_INFO_HEADER* handover, UInt8* stack); + BThread::BThread(VoidPtr blob) : fBlob(blob), fStartAddress(nullptr) { @@ -158,12 +160,14 @@ namespace Boot } else { - writer.Write("ZBA: Invalid executable.\r"); + writer.Write("ZBA: INVALID EXECUTABLE.\r"); } + + fStack = new UInt8[mib_cast(8)]; } /// @note handover header has to be valid! - Void BThread::Start(HEL::HANDOVER_INFO_HEADER* handover) + Void BThread::Start(HEL::HANDOVER_INFO_HEADER* handover, Bool own_stack) { HEL::HandoverProc err_fn = [](HEL::HANDOVER_INFO_HEADER* rcx) -> void { CGDrawString("ZBA: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); @@ -175,7 +179,15 @@ namespace Boot err_fn(handover); } - reinterpret_cast(fStartAddress)(handover); + fHandover = handover; + + if (own_stack) + rt_jump_to_address(fStartAddress, fHandover, &fStack[mib_cast(8) - 1]); + else + { + delete [] fStack; + reinterpret_cast(fStartAddress)(fHandover); + } } const Char* BThread::GetName() diff --git a/dev/ZBAKit/src/HEL/AMD64/BootAPI.S b/dev/ZBAKit/src/HEL/AMD64/BootAPI.S index 47f250f1..963ef46a 100644 --- a/dev/ZBAKit/src/HEL/AMD64/BootAPI.S +++ b/dev/ZBAKit/src/HEL/AMD64/BootAPI.S @@ -11,8 +11,16 @@ rt_jump_to_address: mov rbx, rcx mov rcx, rdx + push rbx + push rdx + mov rsp, r8 + push rax jmp rbx + pop rdx + pop rbx + pop rax + ret rt_reset_hardware: diff --git a/dev/ZBAKit/src/HEL/AMD64/BootMain.cc b/dev/ZBAKit/src/HEL/AMD64/BootMain.cc index cfc02837..404d8e3b 100644 --- a/dev/ZBAKit/src/HEL/AMD64/BootMain.cc +++ b/dev/ZBAKit/src/HEL/AMD64/BootMain.cc @@ -246,7 +246,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, syschk_thread->SetName("System Check (ZBA EFI Driver)"); } - syschk_thread->Start(handover_hdr); + syschk_thread->Start(handover_hdr, NO); // nullify these fields, to avoid being reused later. @@ -324,7 +324,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, // Finally load the OS kernel. // ---------------------------------------------------- // - kernel_thread->Start(handover_hdr); + kernel_thread->Start(handover_hdr, YES); CANT_REACH(); } diff --git a/dev/ZKAKit/CompilerKit/Version.h b/dev/ZKAKit/CompilerKit/Version.h index 3f7a726b..07f09055 100644 --- a/dev/ZKAKit/CompilerKit/Version.h +++ b/dev/ZKAKit/CompilerKit/Version.h @@ -3,5 +3,5 @@ #pragma once /// .. -#define BOOTLOADER_VERSION "1040.2024.110" -#define KERNEL_VERSION "1040.2024.110" +#define BOOTLOADER_VERSION "1104.2024.110" +#define KERNEL_VERSION "1104.2024.110" diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index 149f2391..71e6f037 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -174,6 +174,6 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, kcout << "kerncall: Kernel call isn't hooked at all! (is set to false)\r"; } - kcout << "kerncall: Exit Kernel Calls.\r"; + kcout << "kerncall: Exit Kernel Call List.\r"; } } diff --git a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc index 9ceefbc2..79dbf4ad 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalKernelMain.cc @@ -83,17 +83,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { /* Initialize filesystem. */ Kernel::NeFileSystemMgr::Mount(new Kernel::NeFileSystemMgr()); - Kernel::UserProcessHelper::InitScheduler(); - - const Kernel::Char process_name[] = "Kernel"; - - Kernel::rtl_create_process([]() -> void { - while (Yes) - { - kcout << "Scheduling...\r"; - } - }, - process_name); /* Load interrupts and start SMP. */ diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc index 06ba1c6f..4341da04 100644 --- a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc +++ b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc @@ -23,8 +23,9 @@ #ifdef __AHCI__ -#define kAhciCmdTblBase mib_cast(1) // 4M +#define AHCI_START_ADDRESS mib_cast(4) // 4M +#define HBA_ERR_TFE (1 << 30) #define HBA_PxCMD_ST 0x0001 #define HBA_PxCMD_FRE 0x0010 #define HBA_PxCMD_FR 0x4000 @@ -52,7 +53,7 @@ STATIC Kernel::Lba kCurrentDiskSectorCount = 0UL; Kernel::Void drv_calculate_disk_geometry() { kCurrentDiskSectorCount = 0UL; - kcout << "Max LBA: " << Kernel::number(kCurrentDiskSectorCount) << endl; + kcout << "Highest AHCI LBA (48-bit): " << Kernel::number(kCurrentDiskSectorCount) << endl; } /// @brief Initializes an AHCI disk. @@ -124,13 +125,13 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) // do in-between - kAhciPort->Clb = kAhciCmdTblBase + (ahci_index << 10); + kAhciPort->Clb = AHCI_START_ADDRESS + (ahci_index << 10); kAhciPort->Clbu = 0; rt_set_memory((void*)(kAhciPort->Clb), 0, 1024); // FIS offset: 32K+256*ahci_index // FIS entry size = 256 bytes per port - kAhciPort->Fb = kAhciCmdTblBase + (32 << 10) + (ahci_index << 8); + kAhciPort->Fb = AHCI_START_ADDRESS + (32 << 10) + (ahci_index << 8); kAhciPort->Fbu = 0; rt_set_memory((void*)(kAhciPort->Fb), 0, 256); @@ -143,7 +144,7 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) cmdheader[i].Prdtl = 8; // 8 prdt entries per command table // 256 bytes per command table, 64+16+48+16*8 // Command table offset: 40K + 8K*ahci_index + cmdheader_index*256 - cmdheader[i].Ctba = kAhciCmdTblBase + (40 << 10) + (ahci_index << 13) + (i << 8); + cmdheader[i].Ctba = AHCI_START_ADDRESS + (40 << 10) + (ahci_index << 13) + (i << 8); cmdheader[i].Ctbau = 0; rt_set_memory((void*)cmdheader[i].Ctba, 0, 256); @@ -268,7 +269,7 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size // in the PxIS port field as well (1 << 5) if ((kAhciPort->Ci & (1 << port)) == 0) break; - if (kAhciPort->Is & (1 << 30)) // Task file error + if (kAhciPort->Is & HBA_ERR_TFE) // Task file error { kcout << ("Read disk error\r"); return; @@ -276,7 +277,7 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size } // Check again for the last time. - if (kAhciPort->Is & (1 << 30)) // task file error status + if (kAhciPort->Is & HBA_ERR_TFE) // task file error status { kcout << ("Read disk error\r"); *buffer = 0; diff --git a/dev/ZKAKit/KernelKit/DebugOutput.h b/dev/ZKAKit/KernelKit/DebugOutput.h index b268d874..da37d3a0 100644 --- a/dev/ZKAKit/KernelKit/DebugOutput.h +++ b/dev/ZKAKit/KernelKit/DebugOutput.h @@ -39,7 +39,7 @@ namespace Kernel { public: TerminalDevice(void (*print)(const Char*), void (*get)(const Char*)) - : DeviceInterface(print, get) + : IDeviceObject(print, get) { } diff --git a/dev/ZKAKit/KernelKit/DeviceMgr.h b/dev/ZKAKit/KernelKit/DeviceMgr.h index cbdfb542..a7b7a2d0 100644 --- a/dev/ZKAKit/KernelKit/DeviceMgr.h +++ b/dev/ZKAKit/KernelKit/DeviceMgr.h @@ -24,39 +24,39 @@ #define kDeviceMgrRootDirPath "/Devices/" -#define ZKA_DEVICE : public ::Kernel::DeviceInterface +#define ZKA_DEVICE : public ::Kernel::IDeviceObject // Last Rev: Wed, Apr 3, 2024 9:09:41 AM namespace Kernel { template - class DeviceInterface; + class IDeviceObject; /***********************************************************************************/ /// @brief Device contract interface, represents an HW device. /***********************************************************************************/ template - class DeviceInterface + class IDeviceObject { public: - explicit DeviceInterface(void (*Out)(T), void (*In)(T)) + explicit IDeviceObject(void (*Out)(T), void (*In)(T)) : fOut(Out), fIn(In) {} - virtual ~DeviceInterface() = default; + virtual ~IDeviceObject() = default; public: - DeviceInterface& operator=(const DeviceInterface&) = default; - DeviceInterface(const DeviceInterface&) = default; + IDeviceObject& operator=(const IDeviceObject&) = default; + IDeviceObject(const IDeviceObject&) = default; public: - virtual DeviceInterface& operator<<(T Data) + virtual IDeviceObject& operator<<(T Data) { fOut(Data); return *this; } - virtual DeviceInterface& operator>>(T Data) + virtual IDeviceObject& operator>>(T Data) { fIn(Data); return *this; @@ -64,7 +64,7 @@ namespace Kernel virtual const char* Name() const { - return "DeviceInterface"; + return "IDeviceObject"; } operator bool() diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h index 1c9f4a94..808a8457 100644 --- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h +++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h @@ -27,10 +27,10 @@ namespace Kernel { - //! @note Forward declarations. + //! @note Forward class declarations. class UserProcess; - class IPEFDLLObject; + class IDLLObject; class UserProcessTeam; class UserProcessScheduler; class UserProcessHelper; @@ -39,7 +39,8 @@ namespace Kernel typedef Int64 ProcessID; //! @brief Local Process name length. - inline constexpr SizeT kProcessNameLen = 129U; + inline constexpr SizeT kProcessNameLen = 128U; + inline constexpr ProcessID kProcessInvalidID = -1; //! @brief Local Process status enum. enum class ProcessStatusKind : Int32 @@ -123,18 +124,32 @@ namespace Kernel kRingCount = 5, }; - // Helper types. + /// @brief Helper type to describe a code image. using ImagePtr = VoidPtr; + struct UserProcessImage + { + ImagePtr fCode; + ImagePtr fBlob; + + operator bool() + { + return this->fCode; + } + + Bool HasImage() + { + return this->fBlob != nullptr; + } + }; + /// @name UserProcess - /// @brief User process header. + /// @brief User process class. /// Holds information about the running process/thread. class UserProcess final { public: - explicit UserProcess(VoidPtr start_image); - explicit UserProcess() = default; - + explicit UserProcess(); ~UserProcess(); public: @@ -148,10 +163,9 @@ namespace Kernel AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatusKind Status{ProcessStatusKind::kDead}; UInt8* StackReserve{nullptr}; - ImagePtr Code{nullptr}; - ImagePtr ExecImg{nullptr}; + UserProcessImage Image; SizeT StackSize{kSchedMaxStackSz}; - IPEFDLLObject* PefDLLDelegate{nullptr}; + IDLLObject* PefDLLDelegate{nullptr}; SizeT MemoryCursor{0}; SizeT MemoryLimit{kSchedMaxMemoryLimit}; @@ -306,7 +320,6 @@ namespace Kernel STATIC Bool CanBeScheduled(const UserProcess& process); STATIC ErrorOr TheCurrentPID(); STATIC SizeT StartScheduling(); - STATIC Void InitScheduler(); }; const UInt32& sched_get_exit_code(void) noexcept; diff --git a/dev/ZKAKit/NetworkKit/NetworkDevice.h b/dev/ZKAKit/NetworkKit/NetworkDevice.h index 878030b1..6d119114 100644 --- a/dev/ZKAKit/NetworkKit/NetworkDevice.h +++ b/dev/ZKAKit/NetworkKit/NetworkDevice.h @@ -20,7 +20,7 @@ namespace Kernel /** * \brief Network device interface, establishes a connection to the NIC. */ - class NetworkDevice final : public DeviceInterface + class NetworkDevice final : public IDeviceObject { public: NetworkDevice(void (*out)(NetworkDeviceCommand), diff --git a/dev/ZKAKit/NetworkKit/NetworkDevice.inl b/dev/ZKAKit/NetworkKit/NetworkDevice.inl index 837750c6..d4ba2c1b 100644 --- a/dev/ZKAKit/NetworkKit/NetworkDevice.inl +++ b/dev/ZKAKit/NetworkKit/NetworkDevice.inl @@ -13,7 +13,7 @@ namespace Kernel NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), void (*in)(NetworkDeviceCommand), void (*on_cleanup)(void)) - : DeviceInterface(out, in), fCleanup(on_cleanup) + : IDeviceObject(out, in), fCleanup(on_cleanup) { kcout << "NetworkDevice initialized.\r"; diff --git a/dev/ZKAKit/NewKit/Macros.h b/dev/ZKAKit/NewKit/Macros.h index afde877e..2bc53491 100644 --- a/dev/ZKAKit/NewKit/Macros.h +++ b/dev/ZKAKit/NewKit/Macros.h @@ -44,6 +44,8 @@ (static_cast(!(sizeof(a) % sizeof(*(a))))))) #endif +#define DEPRECATED ATTRIBUTE(deprecated) + #ifndef ALIGN #define ALIGN(X) __attribute__((aligned(X))) #endif // #ifndef ALIGN @@ -90,9 +92,9 @@ #define END_STRING_ENUM() } #endif -#ifndef cAlloca -#define cAlloca(Sz) __builtin_alloca(Sz) -#endif // #ifndef cAlloca +#ifndef rtl_alloca +#define rtl_alloca(sz) __builtin_alloca(sz) +#endif // #ifndef rtl_alloca #ifndef CANT_REACH #define CANT_REACH() __builtin_unreachable() diff --git a/dev/ZKAKit/StorageKit/AHCI.h b/dev/ZKAKit/StorageKit/AHCI.h index a718dae7..f4c1d565 100644 --- a/dev/ZKAKit/StorageKit/AHCI.h +++ b/dev/ZKAKit/StorageKit/AHCI.h @@ -12,7 +12,7 @@ namespace Kernel { - class AHCIDeviceInterface : public DeviceInterface + class AHCIDeviceInterface ZKA_DEVICE { public: explicit AHCIDeviceInterface(void (*Out)(MountpointInterface* outpacket), diff --git a/dev/ZKAKit/StorageKit/ATA.h b/dev/ZKAKit/StorageKit/ATA.h index d70bc506..4c1aa632 100644 --- a/dev/ZKAKit/StorageKit/ATA.h +++ b/dev/ZKAKit/StorageKit/ATA.h @@ -14,7 +14,7 @@ namespace Kernel { /// @brief ATA device interface type. - class ATADeviceInterface : public DeviceInterface + class ATADeviceInterface : public IDeviceObject { public: explicit ATADeviceInterface(void (*Out)(MountpointInterface* outpacket), diff --git a/dev/ZKAKit/StorageKit/StorageKit.h b/dev/ZKAKit/StorageKit/StorageKit.h index 4b8b2411..34f8d47e 100644 --- a/dev/ZKAKit/StorageKit/StorageKit.h +++ b/dev/ZKAKit/StorageKit/StorageKit.h @@ -13,7 +13,7 @@ namespace Kernel { template - class DeviceInterface; + class IDeviceObject; class NVMEDeviceInterface; class AHCIDeviceInterface; diff --git a/dev/ZKAKit/src/CodeMgr.cc b/dev/ZKAKit/src/CodeMgr.cc index 5b5d471b..a4502f58 100644 --- a/dev/ZKAKit/src/CodeMgr.cc +++ b/dev/ZKAKit/src/CodeMgr.cc @@ -16,16 +16,14 @@ namespace Kernel /// @return if the process was started or not. ProcessID rtl_create_process(MainKind main, const Char* process_name) noexcept { - kcout << "Validating process header...\r"; - - if (!main) - return No; + if (!main || + !process_name || + *process_name == 0) + return kProcessInvalidID; UserProcess* process_hdr = new UserProcess(); - kcout << "Setting-up process data...\r"; - - process_hdr->Code = reinterpret_cast(main); + process_hdr->Image.fCode = reinterpret_cast(main); process_hdr->Kind = UserProcess::kExectuableKind; process_hdr->StackSize = kib_cast(16); @@ -33,8 +31,6 @@ namespace Kernel ProcessID id = UserProcessScheduler::The().Spawn(process_hdr); - delete process_hdr; - return id; } } // namespace Kernel diff --git a/dev/ZKAKit/src/DriveMgr.cc b/dev/ZKAKit/src/DriveMgr.cc index 024d1d76..b609c2f7 100644 --- a/dev/ZKAKit/src/DriveMgr.cc +++ b/dev/ZKAKit/src/DriveMgr.cc @@ -145,7 +145,7 @@ namespace Kernel trait.fInit = io_drv_unimplemented; trait.fDriveKind = io_drv_kind; - kcout << "Construct: " << trait.fName << ".\r"; + kcout << "Construct: " << trait.fName << "\r"; return trait; } @@ -206,9 +206,6 @@ namespace Kernel Detail::ioi_detect_drive(&trait); - while (YES) - ; - return trait; } } // namespace Kernel diff --git a/dev/ZKAKit/src/IPEFDLLObject.cc b/dev/ZKAKit/src/IPEFDLLObject.cc index fb9ef7f0..b72421d8 100644 --- a/dev/ZKAKit/src/IPEFDLLObject.cc +++ b/dev/ZKAKit/src/IPEFDLLObject.cc @@ -60,7 +60,7 @@ EXTERN_C IDLL rtl_init_dll(UserProcess* header) } dll_obj->Get()->fImageObject = - header->ExecImg; + header->Image.fBlob; if (!dll_obj->Get()->fImageObject) { diff --git a/dev/ZKAKit/src/KString.cc b/dev/ZKAKit/src/KString.cc index aa287f15..767bf4c2 100644 --- a/dev/ZKAKit/src/KString.cc +++ b/dev/ZKAKit/src/KString.cc @@ -100,7 +100,7 @@ namespace Kernel return ("?"); const Char* boolean_expr = i ? "YES" : "NO"; - char* ret = (char*)cAlloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); + Char* ret = (Char*)rtl_alloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); if (!ret) return ("?"); @@ -159,8 +159,8 @@ namespace Kernel if (!fmt || !fmt2) return ("?"); - char* ret = - (char*)cAlloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt)); + Char* ret = + (Char*)rtl_alloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt)); if (!ret) return ("?"); diff --git a/dev/ZKAKit/src/PEFCodeMgr.cc b/dev/ZKAKit/src/PEFCodeMgr.cc index 0568b998..0a787e57 100644 --- a/dev/ZKAKit/src/PEFCodeMgr.cc +++ b/dev/ZKAKit/src/PEFCodeMgr.cc @@ -251,13 +251,13 @@ namespace Kernel auto errOrStart = exec.FindStart(); if (errOrStart.Error() != kErrorSuccess) - return No; + return kProcessInvalidID; STATIC UserProcess proc; proc.Kind = procKind; - proc.ExecImg = errOrStart.Leak().Leak(); - proc.ExecImg = exec.GetBlob().Leak().Leak(); + proc.Image.fCode = errOrStart.Leak().Leak(); + proc.Image.fBlob = exec.GetBlob().Leak().Leak(); proc.StackSize = *(UIntPtr*)exec.FindSymbol(kPefStackSizeSymbol, kPefData); proc.MemoryLimit = *(UIntPtr*)exec.FindSymbol(kPefHeapSizeSymbol, kPefData); proc.PTime = 0UL; diff --git a/dev/ZKAKit/src/Stop.cc b/dev/ZKAKit/src/Stop.cc index 1374c842..391449d6 100644 --- a/dev/ZKAKit/src/Stop.cc +++ b/dev/ZKAKit/src/Stop.cc @@ -14,7 +14,7 @@ #include #include -#define kWebsiteURL "https://www.el-mahrouss-logic.com/zka-os/help/" +#define kWebsiteURL "https://www.el-mahrouss-logic.com/metal-os/help/" /* Each error code is attributed with an ID, which will prompt a string onto the * screen. Wait for debugger... */ @@ -31,7 +31,7 @@ namespace Kernel auto panic_text = RGB(0xff, 0xff, 0xff); - auto start_y = 30; + auto start_y = 50; auto x = 10; CGDrawString("Kernel Panic!", start_y, x, panic_text); diff --git a/dev/ZKAKit/src/Storage/AHCIDeviceInterface.cc b/dev/ZKAKit/src/Storage/AHCIDeviceInterface.cc index 9a591aaf..34b436e7 100644 --- a/dev/ZKAKit/src/Storage/AHCIDeviceInterface.cc +++ b/dev/ZKAKit/src/Storage/AHCIDeviceInterface.cc @@ -15,7 +15,7 @@ using namespace Kernel; AHCIDeviceInterface::AHCIDeviceInterface(void (*Out)(MountpointInterface* outpacket), void (*In)(MountpointInterface* inpacket), void (*Cleanup)(void)) - : DeviceInterface(Out, In), fCleanup(Cleanup) + : IDeviceObject(Out, In), fCleanup(Cleanup) { } diff --git a/dev/ZKAKit/src/Storage/ATADeviceInterface.cc b/dev/ZKAKit/src/Storage/ATADeviceInterface.cc index 9d23894d..e80dd533 100644 --- a/dev/ZKAKit/src/Storage/ATADeviceInterface.cc +++ b/dev/ZKAKit/src/Storage/ATADeviceInterface.cc @@ -16,7 +16,7 @@ ATADeviceInterface::ATADeviceInterface( void (*Out)(MountpointInterface* outpacket), void (*In)(MountpointInterface* inpacket), void (*Cleanup)(void)) - : DeviceInterface(Out, In), fCleanup(Cleanup) + : IDeviceObject(Out, In), fCleanup(Cleanup) { } @@ -57,7 +57,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) } } - return (ATADeviceInterface&)DeviceInterface::operator<<( + return (ATADeviceInterface&)IDeviceObject::operator<<( Data); } @@ -83,6 +83,6 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) } } - return (ATADeviceInterface&)DeviceInterface::operator>>( + return (ATADeviceInterface&)IDeviceObject::operator>>( Data); } diff --git a/dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc b/dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc index 89ce4fb2..860c0a95 100644 --- a/dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc +++ b/dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc @@ -11,7 +11,7 @@ namespace Kernel NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(MountpointInterface* outpacket), void (*in)(MountpointInterface* inpacket), void (*cleanup)(void)) - : DeviceInterface(out, in), fCleanup(cleanup) + : IDeviceObject(out, in), fCleanup(cleanup) { } diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc index 8694b449..79e07385 100644 --- a/dev/ZKAKit/src/UserProcessScheduler.cc +++ b/dev/ZKAKit/src/UserProcessScheduler.cc @@ -40,11 +40,7 @@ namespace Kernel STATIC UserProcessScheduler kProcessScheduler; - UserProcess::UserProcess(VoidPtr start_image) - : Code(start_image) - { - } - + UserProcess::UserProcess() = default; UserProcess::~UserProcess() = default; /// @brief Gets the last exit code. @@ -278,23 +274,24 @@ namespace Kernel HAL::mm_free_bitmap(this->VMRegister); //! Delete image if not done already. - if (this->Code && mm_is_valid_heap(this->Code)) - mm_delete_heap(this->Code); + if (this->Image.fCode && mm_is_valid_heap(this->Image.fCode)) + mm_delete_heap(this->Image.fCode); - if (this->ExecImg && mm_is_valid_heap(this->ExecImg)) - mm_delete_heap(this->ExecImg); + if (this->Image.fBlob && mm_is_valid_heap(this->Image.fBlob)) + mm_delete_heap(this->Image.fBlob); if (this->StackFrame && mm_is_valid_heap(this->StackFrame)) mm_delete_heap((VoidPtr)this->StackFrame); - this->ExecImg = nullptr; - this->Code = nullptr; + this->Image.fBlob = nullptr; + this->Image.fCode = nullptr; this->StackFrame = nullptr; if (this->Kind == kExectuableDLLKind) { Bool success = false; - rtl_fini_dll(this, this->PefDLLDelegate, &success); + + rtl_fini_dll(this, reinterpret_cast(this->PefDLLDelegate), &success); if (!success) { @@ -318,10 +315,10 @@ namespace Kernel ProcessID UserProcessScheduler::Spawn(UserProcess* process) { - if (*process->Name == 0) + if (!process || + *process->Name == 0) { - Char process_name[] = "Process (Unnamed)"; - rt_copy_memory((VoidPtr)process_name, process->Name, rt_string_len(process_name)); + return kProcessInvalidID; } #ifdef __ZKA_AMD64__ @@ -391,7 +388,6 @@ namespace Kernel UserProcessScheduler& UserProcessScheduler::The() { - kcout << "Return user scheduler object.\r"; return kProcessScheduler; } @@ -466,7 +462,7 @@ namespace Kernel kcout << "Switch to '" << process.Name << "'.\r"; // tell helper to find a core to schedule on. - if (!UserProcessHelper::Switch(process.Code, &process.StackReserve[process.StackSize - 1], process.StackFrame, + if (!UserProcessHelper::Switch(process.Image.fCode, &process.StackReserve[process.StackSize - 1], process.StackFrame, process.ProcessId)) { process.Crash(); @@ -522,7 +518,7 @@ namespace Kernel if (process.Status == ProcessStatusKind::kInvalid) return No; - if (!process.Code) + if (!process.Image.fCode) return No; return process.PTime < 1; @@ -537,17 +533,7 @@ namespace Kernel { return kProcessScheduler.Run(); } - - /***********************************************************************************/ - /** - * @brief Initializes the scheduler. - */ - /***********************************************************************************/ - Void UserProcessHelper::InitScheduler() - { - /// TODO: code to init scheduler here. - } - + /***********************************************************************************/ /** * \brief Does a context switch in a CPU. @@ -588,7 +574,6 @@ namespace Kernel //////////////////////////////////////////////////////////// /// Rollback on fail. /// //////////////////////////////////////////////////////////// - /// if (!ret) { HardwareThreadScheduler::The()[index].Leak()->fPTime = prev_ptime; -- cgit v1.2.3