From 08e69a55cfda4722277d16ddb632669edde3580b Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 23 Oct 2024 10:08:05 +0200 Subject: IMP: Process scheduler timer interrupt have been implemented, fixes regarding interrupt API and use __TOOLCHAINKIT__ instead of __NDK__ Signed-off-by: Amlal --- dev/crt/defines.h | 8 +-- dev/sci/xpcom_core.h | 4 +- dev/zba/amd64-efi.make | 2 +- dev/zka/HALKit/AMD64/HalInterruptAPI.asm | 95 ++++++++++++++++++++++++++------ dev/zka/KernelKit/UserProcessScheduler.h | 1 + dev/zka/NewKit/CxxAbi.h | 2 +- dev/zka/src/ACPIFactoryInterface.cc | 13 +++-- dev/zka/src/UserProcessScheduler.cc | 16 +++++- 8 files changed, 106 insertions(+), 35 deletions(-) (limited to 'dev') diff --git a/dev/crt/defines.h b/dev/crt/defines.h index 38fe2b6c..ea821505 100644 --- a/dev/crt/defines.h +++ b/dev/crt/defines.h @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef __NDK_DEFINES_HXX__ -#define __NDK_DEFINES_HXX__ +#ifndef __TOOLCHAINKIT_DEFINES_HXX__ +#define __TOOLCHAINKIT_DEFINES_HXX__ #include #include @@ -25,7 +25,7 @@ typedef char* caddr_t; #ifdef __GNUC__ #include -#elif defined(__NDK__) +#elif defined(__TOOLCHAINKIT__) #define __alloca(sz) __ndk_alloca(sz) #endif @@ -103,4 +103,4 @@ namespace std } } // namespace std -#endif /* __NDK_DEFINES_HXX__ */ +#endif /* __TOOLCHAINKIT_DEFINES_HXX__ */ diff --git a/dev/sci/xpcom_core.h b/dev/sci/xpcom_core.h index c86210b5..45c13d1f 100644 --- a/dev/sci/xpcom_core.h +++ b/dev/sci/xpcom_core.h @@ -9,13 +9,13 @@ Purpose: Base code of XPCOM. /// @internal Reserved for internal definitions only. -#ifndef __NDK__ +#ifndef __TOOLCHAINKIT__ #define object class #define protocol class #define clsid(X) #warning ! You may be using the clang compiler, please be cautious that some features mayn't be present. ! -#endif // !__NDK__ +#endif // !__TOOLCHAINKIT__ protocol IUnknown; // Refrenced from an IDB entry. protocol ICLSID; // From the IDB, the constructor of the object, e.g: TextUCLSID. diff --git a/dev/zba/amd64-efi.make b/dev/zba/amd64-efi.make index 1af31f2e..24ffeb95 100644 --- a/dev/zba/amd64-efi.make +++ b/dev/zba/amd64-efi.make @@ -34,7 +34,7 @@ EMU_FLAGS=-net none -smp 4 -m 8G -M q35 \ file=fat:rw:src/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -serial stdio + -device ide-hd,drive=disk_2,bus=ahci.0 -d int LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/zka/HALKit/AMD64/HalInterruptAPI.asm b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm index e611fdf1..06066f41 100644 --- a/dev/zka/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm @@ -16,18 +16,26 @@ %macro IntExp 1 global __ZKA_INT_%1 __ZKA_INT_%1: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + sti o64 iret %endmacro %macro IntNormal 1 global __ZKA_INT_%1 __ZKA_INT_%1: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + sti o64 iret %endmacro @@ -56,24 +64,42 @@ IntNormal 5 ;; Invalid opcode interrupt __ZKA_INT_6: + cli + mov al, 0x20 out 0x20, al + out 0xA0, al + + push rax + mov rax, idt_handle_ud mov rcx, rsp - call idt_handle_ud + call rax + pop rax + + sti o64 iret IntNormal 7 ;; Invalid opcode interrupt __ZKA_INT_8: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + + push rax + mov rax, idt_handle_generic mov rcx, rsp - call idt_handle_generic + call rax + pop rax + + sti o64 iret IntNormal 9 @@ -83,21 +109,38 @@ IntExp 11 IntExp 12 __ZKA_INT_13: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + + push rax + mov rax, idt_handle_gpf mov rcx, rsp - call idt_handle_gpf + call rax + pop rax + + sti o64 iret __ZKA_INT_14: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + push rax + mov rax, idt_handle_pf mov rcx, rsp - call idt_handle_pf + call rax + pop rax + + sti o64 iret IntNormal 15 @@ -123,12 +166,19 @@ IntNormal 31 [extern idt_handle_scheduler] __ZKA_INT_32: + cli + mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + push rax mov rcx, rsp - call idt_handle_scheduler + mov rax, idt_handle_scheduler + call rax + pop rax + sti o64 iret IntNormal 33 @@ -159,12 +209,17 @@ __ZKA_INT_50: cli mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + + push rax + mov rax, hal_system_call_enter mov rcx, r8 mov rdx, r9 - jmp hal_system_call_enter + call rax + pop rax sti @@ -174,12 +229,17 @@ __ZKA_INT_51: cli mov al, 0x20 - out 0x21, al + out 0x20, al + out 0xA0, al + + push rax + mov rax, hal_kernel_call_enter mov rcx, r8 mov rdx, r9 - call hal_kernel_call_enter + call rax + pop rax sti @@ -229,10 +289,9 @@ extern hal_real_init hal_reload_segments: std ;; Write address of syscall handler. - - mov rdx, [mp_system_call_handler] + mov rdx, [mp_system_call_handler] shr rdx, 32 - mov rcx, 0xC0000082 + mov rcx, 0xC0000082 wrmsr ;; Set segments of syscall handler. diff --git a/dev/zka/KernelKit/UserProcessScheduler.h b/dev/zka/KernelKit/UserProcessScheduler.h index 92a698b6..5faafc0b 100644 --- a/dev/zka/KernelKit/UserProcessScheduler.h +++ b/dev/zka/KernelKit/UserProcessScheduler.h @@ -292,6 +292,7 @@ namespace Kernel private: UserProcessTeam mTeam; + }; /* diff --git a/dev/zka/NewKit/CxxAbi.h b/dev/zka/NewKit/CxxAbi.h index 36dcf0b3..c6408af1 100644 --- a/dev/zka/NewKit/CxxAbi.h +++ b/dev/zka/NewKit/CxxAbi.h @@ -7,7 +7,7 @@ #include -#ifndef __NDK__ +#ifndef __TOOLCHAINKIT__ #define kDSOMaxObjects (128) diff --git a/dev/zka/src/ACPIFactoryInterface.cc b/dev/zka/src/ACPIFactoryInterface.cc index c7d2914f..230b6ed6 100644 --- a/dev/zka/src/ACPIFactoryInterface.cc +++ b/dev/zka/src/ACPIFactoryInterface.cc @@ -29,11 +29,11 @@ namespace Kernel RSDT* xsdt = reinterpret_cast(rsp_ptr->RsdtAddress); - Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt32); + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(Int64); /*** - crucial to avoid - overflows. - */ + crucial to avoid underflows. + */ if (num < 1) { /// stop here, we should have entries... @@ -64,7 +64,8 @@ namespace Kernel if (signature_index == (cAcpiSignatureLength - 1)) { - kcout << "ACPI: Found the SDT" << endl; + kcout << "ACPI: SDT Signature: " << sdt->Signature << endl; + kcout << "ACPI: SDT OEM ID: " << sdt->OemId << endl; return ErrorOr(reinterpret_cast(xsdt->AddressArr[index])); } } @@ -74,10 +75,10 @@ namespace Kernel } /*** - @brief check SDT header + @brief Checksum on SDT header. @param checksum the header to checksum @param len the length of it. -*/ + */ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { if (len == 0) diff --git a/dev/zka/src/UserProcessScheduler.cc b/dev/zka/src/UserProcessScheduler.cc index bbe644dc..0081367a 100644 --- a/dev/zka/src/UserProcessScheduler.cc +++ b/dev/zka/src/UserProcessScheduler.cc @@ -423,6 +423,12 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. + if (mTeam.mProcessAmount < 1) + { + kcout << "UserProcessScheduler::Run(): This team doesn't have any process!\r"; + return 0; + } + for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { auto& process = mTeam.AsArray()[process_index]; @@ -430,9 +436,6 @@ namespace Kernel //! check if process needs to be scheduled. if (UserProcessHelper::CanBeScheduled(process)) { - // Set current process header. - this->CurrentProcess() = process; - process.PTime = static_cast(process.Affinity); UserProcessScheduler::The().CurrentProcess().Leak().Status = ProcessStatusKind::kFrozen; @@ -440,6 +443,9 @@ namespace Kernel kcout << "Switch to '" << process.Name << "'.\r"; + // Set current process header. + this->CurrentProcess() = process; + // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame, process.ProcessId)) @@ -494,6 +500,10 @@ namespace Kernel process.Status == ProcessStatusKind::kDead) return No; + if (process.Status == ProcessStatusKind::kStarting && + process.Image) + return Yes; + if (!process.Image && process.Kind == UserProcess::kExectuableKind) return No; -- cgit v1.2.3