diff options
| author | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-12 18:09:07 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-12 18:09:07 +0200 |
| commit | 4b58295fb04c2430817301352fadce33178f94d4 (patch) | |
| tree | fb16edeb9d81ee475200bbbf9a5125822ea2a589 | |
| parent | 6a3b080067ff47f84c400987982cfa44927fe7e0 (diff) | |
MHR-30: initial commit.
Signed-off-by: Amlal EL Mahrouss <amlal@softwarelabs.com>
| -rw-r--r-- | Boot/Sources/HEL/AMD64/BootMain.cxx | 2 | ||||
| -rw-r--r-- | Boot/Sources/Root/SplashScreen.fmt | 4 | ||||
| -rw-r--r-- | Boot/makefile | 6 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 55 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalSMPCoreManager.asm | 42 | ||||
| -rw-r--r-- | Kernel/HALKit/POWER/ppc-cpu.h | 2 | ||||
| -rw-r--r-- | Kernel/Sources/KeMain.cxx (renamed from Kernel/Sources/AppMain.cxx) | 29 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessScheduler.cxx | 3 | ||||
| -rw-r--r-- | Kernel/Sources/SMPManager.cxx | 15 |
9 files changed, 120 insertions, 38 deletions
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx index feb05422..5ab7914a 100644 --- a/Boot/Sources/HEL/AMD64/BootMain.cxx +++ b/Boot/Sources/HEL/AMD64/BootMain.cxx @@ -19,7 +19,7 @@ /// make the compiler shut up. #ifndef kMachineModel -#define kMachineModel "NeWS HD" +#define kMachineModel "Zeta HD" #endif // !kMachineModel #ifndef cExpectedWidth diff --git a/Boot/Sources/Root/SplashScreen.fmt b/Boot/Sources/Root/SplashScreen.fmt index 57a5bf96..d7b03f8f 100644 --- a/Boot/Sources/Root/SplashScreen.fmt +++ b/Boot/Sources/Root/SplashScreen.fmt @@ -1,7 +1,7 @@ ================================================================== -Welcome to NeWS. +Welcome to RTKM1. Brought to you by: Amlal EL Mahrouss. * newosldr, newoskrnl: Amlal EL Mahrouss. -This copy can boot directly to newoskrnl (Unified System). +This copy can boot directly to newoskrnl (RTKM1). Copyright Zeta Electronics Corporation, all rights reserved. ================================================================== diff --git a/Boot/makefile b/Boot/makefile index 0c4f5854..e54b1aa8 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -19,14 +19,14 @@ EMU=qemu-system-x86_64w endif ifeq ($(NEWS_MODEL), ) -NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" +NEWOS_MODEL=-DkMachineModel="\"Generic Zeta HD\"" endif BIOS=OVMF.fd IMG=epm.img IMG_2=epm-slave.img -EMU_FLAGS=-net none -smp 4 -serial stdio -m 4G -M q35 \ +EMU_FLAGS=-net none -smp 4 -m 4G -M q35 \ -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ @@ -81,7 +81,7 @@ compile-amd64: run-efi-amd64: $(EMU) $(EMU_FLAGS) -# img_2 is the rescue disk. img is the bootable disk, as provided by the NeWS. +# img_2 is the rescue disk. img is the bootable disk, as provided by the Zeta. .PHONY: epm-img epm-img: qemu-img create -f raw $(IMG) 10G diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 2824b176..a395305c 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -8,13 +8,21 @@ #include <HALKit/AMD64/Processor.hpp> #include <NewKit/KernelCheck.hpp> #include <ArchKit/ArchKit.hpp> +#include <KernelKit/Semaphore.hpp> +#include <KernelKit/ProcessScheduler.hxx> #define kAPIC_ICR_Low 0x300 #define kAPIC_ICR_High 0x310 #define kAPIC_SIPI_Vector 0x00500 #define kAPIC_EIPI_Vector 0x00400 -EXTERN_C void AppMain(); +/// @brief This symbol is the kernel main symbol. +EXTERN_C void KeMain(); + +/// @brief assembly routine. internal use only. +EXTERN_C void _hal_enable_smp(void); + +/// @note: _hal_switch_context /////////////////////////////////////////////////////////////////////////////////////// @@ -104,6 +112,8 @@ namespace NewOS::HAL UIntPtr Address; }; + STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame); + /////////////////////////////////////////////////////////////////////////////////////// STATIC MadtType* kApicInfoBlock = nullptr; @@ -145,8 +155,7 @@ namespace NewOS::HAL NewOS::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector); } - /// @brief assembly routine. internal use only. - EXTERN_C Void _hal_enable_smp(Void); + STATIC HAL::StackFramePtr cFramePtr = nullptr; EXTERN_C Void hal_apic_acknowledge_cont(Void) { @@ -157,30 +166,46 @@ namespace NewOS::HAL { *cProgramInitialized = false; - AppMain(); - - while (true) - { + kcout << "newoskrnl: putting thread to sleep...\r"; - } + _hal_spin_core(); } else { - kcout << "newoskrnl: putting thread to sleep...\r"; - - AppMain(); + KeMain(); - while (true) - { - } + _hal_spin_core(); } } + EXTERN_C StackFramePtr _hal_leak_current_context(Void) { return cFramePtr; } + EXTERN_C Void hal_apic_acknowledge(Void) { hal_apic_acknowledge_cont(); } + EXTERN_C Void _hal_switch_context(HAL::StackFramePtr stackFrame) + { + hal_switch_context(stackFrame); + } + + STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame) + { + /// TODO: + Semaphore sem; + while (sem.IsLocked()) {} + + sem.Lock(&ProcessScheduler::The().Leak().GetCurrent().Leak()); + + cFramePtr = stackFrame; + + /// yes the exception field contains the core id. + hal_send_start_ipi(stackFrame->Exception, 0x40, cBaseAddressAPIC); + + sem.Unlock(); + } + Void hal_system_get_cores(voidPtr rsdPtr) { auto acpi = ACPIFactoryInterface(rsdPtr); @@ -194,7 +219,7 @@ namespace NewOS::HAL for (SizeT i = 2; i < cMaxProbableCores; ++i) { - if (madt->MadtRecords[i].Flags == 0x01) // if local apic. + if (madt->MadtRecords[i].Flags == kThreadLAPIC) // if local apic. { MadtType::MadtAddress& madtRecord = madt->MadtRecords[i]; // then register as a core for scheduler. diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm index 5ecc2370..c4042b50 100644 --- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm +++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm @@ -13,6 +13,8 @@ [global rt_do_context_switch] [global _hal_enable_smp] [global _hal_spin_core] +[extern _hal_switch_context] +[extern _hal_leak_current_context] section .text @@ -20,10 +22,50 @@ section .text ;; rcx: Stack Pointer ;; rdx: SMP core address. rt_do_context_switch: + push rax + push rcx + push rdx + push rbx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + + jmp _hal_switch_context + + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rbx + pop rdx + pop rcx + pop rax + + mov eax, 0 + retfq ;; gets the current stack frame. rt_get_current_context: + push rdx + jmp _hal_leak_current_context + mov rdx, rax + pop rdx retfq ;; @brief enables a smp core to run. diff --git a/Kernel/HALKit/POWER/ppc-cpu.h b/Kernel/HALKit/POWER/ppc-cpu.h index b7a96767..3855b85c 100644 --- a/Kernel/HALKit/POWER/ppc-cpu.h +++ b/Kernel/HALKit/POWER/ppc-cpu.h @@ -1,7 +1,7 @@ #ifndef __ASM_PPC_PROCESSOR_H #define __ASM_PPC_PROCESSOR_H -/// ! @note The NeWS cpu is based on the e500 with 64-bit extensions, much like the 970. +/// ! @note The Zeta cpu is based on the e500 with 64-bit extensions, much like the 970. /* * Default implementation of macro that returns current diff --git a/Kernel/Sources/AppMain.cxx b/Kernel/Sources/KeMain.cxx index 55b7f403..f4f9f44c 100644 --- a/Kernel/Sources/AppMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -2,7 +2,7 @@ Copyright Zeta Electronics Corporation - File: AppMain.cxx + File: KeMain.cxx Purpose: Kernel main loop. ------------------------------------------- */ @@ -182,29 +182,29 @@ namespace NewOS::Detail /// @brief System loader entrypoint. /// @param void no parameters. /// @return void no return value. - STATIC NewOS::Void AppSystem(NewOS::Void) + STATIC NewOS::Void SystemLauncher_Main(NewOS::Void) { - NewOS::PEFLoader wndServer("/System/WindowServer"); + NewOS::PEFLoader lockScreen("/System/LockScreen"); - if (!wndServer.IsLoaded()) + if (!lockScreen.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(wndServer, + NewOS::Utils::execute_from_image(lockScreen, NewOS::ProcessHeader::kAppKind); - NewOS::PEFLoader launchServer("/System/Launcher"); + NewOS::PEFLoader stageBoard("/System/StageBoard"); - if (!launchServer.IsLoaded()) + if (!stageBoard.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(launchServer, + NewOS::Utils::execute_from_image(stageBoard, NewOS::ProcessHeader::kAppKind); - NewOS::kcout << "System: done, sleeping..."; + NewOS::kcout << "SystemLauncher: done, sleeping..."; while (true) {} } @@ -213,13 +213,16 @@ namespace NewOS::Detail /// @brief Application entrypoint. /// @param Void /// @return Void -EXTERN_C NewOS::Void AppMain(NewOS::Void) +EXTERN_C NewOS::Void KeMain(NewOS::Void) { /// Now run kernel loop, until no process are running. NewOS::Detail::FilesystemWizard wizard; // automatic. - auto cLoaderName = "System"; - NewOS::execute_from_image(NewOS::Detail::AppSystem, cLoaderName); + auto cLoaderName = "SystemLauncher"; + NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); - while (NewOS::ProcessScheduler::The().Leak().Run() > 0) {} + while (true) + { + NewOS::ProcessScheduler::The().Leak().Run(); + } } diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 1a49af22..08a7971e 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -215,9 +215,6 @@ namespace NewOS if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; - if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) - return -1; - kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r"; /// Create heap according to type of process. diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index b2c3f488..f0b680ce 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -99,6 +99,21 @@ namespace NewOS fStack->Rsp = stack->Rsp; fStack->Fs = stack->Fs; fStack->Gs = stack->Gs; + + // save global registers. + + fStack->R15 = stack->R15; + fStack->R14 = stack->R14; + + fStack->R13 = stack->R13; + fStack->R12 = stack->R12; + fStack->R11 = stack->R11; + + fStack->R10 = stack->R10; + fStack->R9 = stack->R9; + fStack->R8 = stack->R8; + + fStack->Exception = this->fID; } rt_do_context_switch(fStack); |
