From 2f921f57ec48cc8c98882d7150a08c354b60bb72 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 13 Jun 2024 09:41:32 +0200 Subject: MHR-31: initial commit. Signed-off-by: Amlal El Mahrouss --- Boot/BootKit/BootKit.hxx | 2 +- Kernel/FSKit/NewFS.hxx | 4 ++-- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 4 ++-- Kernel/Sources/FS/NewFS.cxx | 2 ++ Kernel/Sources/KeMain.cxx | 24 +++++++++++----------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx index 3eab16cb..93b9986e 100644 --- a/Boot/BootKit/BootKit.hxx +++ b/Boot/BootKit/BootKit.hxx @@ -279,7 +279,7 @@ private: /// before going to forks, we must check for the catalog name first. if (blob->fKind == kNewFSCatalogKindDir && - blob->fFileName[strlen(blob->fFileName) - 1] != '/') + blob->fFileName[strlen(blob->fFileName) - 1] != kNewFSSeparator) { EFI::ThrowError(L"Developer-Error", L"This is caused by the developer of the bootloader."); } diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx index df4e7ea4..c400ff30 100644 --- a/Kernel/FSKit/NewFS.hxx +++ b/Kernel/FSKit/NewFS.hxx @@ -68,10 +68,10 @@ default. #define kNewFSCatalogKindDevice (9) #define kNewFSCatalogKindLock (10) -#define kNewFSSeparator '/' +#define kNewFSSeparator '\\' #define kNewFSUpDir ".." -#define kNewFSRoot "/" +#define kNewFSRoot "\\" #define kNewFSLF '\r' #define kNewFSEOF (-1) diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index f15faf3c..b70649ee 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -168,12 +168,12 @@ namespace NewOS::HAL kcout << "newoskrnl: putting thread to sleep...\r"; + KeMain(); + _hal_spin_core(); } else { - KeMain(); - _hal_spin_core(); } } diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index f015673d..2938c53f 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -593,6 +593,8 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; + kcout << "newoskrnl: start finding catalog...\r"; + Char* sectorBuf = new Char[sizeof(NewPartitionBlock)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index f4f9f44c..e2f41464 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -39,7 +39,7 @@ namespace NewOS::Detail { /// Mounted partition, cool! NewOS::kcout - << "New OS: No need to create for a NewFS partition here...\r"; + << "newoskrnl: No need to create for a NewFS partition here...\r"; } else { @@ -51,11 +51,11 @@ namespace NewOS::Detail if (fNewFS->GetParser()) { - constexpr auto cFolderInfo = "Metadata"; + constexpr auto cFolderInfo = "META-INF"; const auto cDirCount = 8; const char* cDirStr[cDirCount] = { - "/Boot/", "/System/", "/Support/", "/Applications/", - "/Users/", "/Library/", "/Mount/", "/Assistants/"}; + "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", + "\\Users\\", "\\Library\\", "\\Mount\\", "\\DCIM\\"}; for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { @@ -113,9 +113,9 @@ namespace NewOS::Detail } NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("/Mount/This Disk"); + this->fNewFS->GetParser()->GetCatalog("\\Mount\\This Disk"); - const NewOS::Char* cSrcName = "DiskInfo"; + const NewOS::Char* cSrcName = "DISK-INF"; if (catalogDisk) { @@ -128,14 +128,14 @@ namespace NewOS::Detail else { catalogDisk = - (NewCatalog*)this->Leak()->CreateAlias("/Mount/This Disk"); + (NewCatalog*)this->Leak()->CreateAlias("\\Mount\\This Disk"); NewOS::StringView diskFolder(kNewFSSectorSz); diskFolder += - "

Kind: alias to disk

\r

Created by: system

\r

Edited " + "

Kind: alias to disk

\r

Created by: newoskrnl

\r

Edited " "by: " - "system

\r

Volume Type: New OS Standard

\r"; + "N/A

\r

Volume Type: New OS Standard

\r"; diskFolder += "

Original Path: "; diskFolder += NewOS::NewFilesystemHelper::Root(); @@ -184,7 +184,7 @@ namespace NewOS::Detail /// @return void no return value. STATIC NewOS::Void SystemLauncher_Main(NewOS::Void) { - NewOS::PEFLoader lockScreen("/System/LockScreen"); + NewOS::PEFLoader lockScreen("\\System\\LockScreen"); if (!lockScreen.IsLoaded()) { @@ -194,7 +194,7 @@ namespace NewOS::Detail NewOS::Utils::execute_from_image(lockScreen, NewOS::ProcessHeader::kAppKind); - NewOS::PEFLoader stageBoard("/System/StageBoard"); + NewOS::PEFLoader stageBoard("\\System\\StageBoard"); if (!stageBoard.IsLoaded()) { @@ -221,7 +221,7 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) auto cLoaderName = "SystemLauncher"; NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); - while (true) + while (true) { NewOS::ProcessScheduler::The().Leak().Run(); } -- cgit v1.2.3 From 70ae21935c7c68ed8a380611481b553b94cee657 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Thu, 13 Jun 2024 15:52:14 +0200 Subject: MHR-31: common namespace, mahrouss api. Signed-off-by: Amlal EL Mahrouss --- Kernel/FirmwareKit/EFI.hxx | 2 ++ Kernel/NewKit/Defines.hpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Kernel/FirmwareKit/EFI.hxx b/Kernel/FirmwareKit/EFI.hxx index 4b230489..c83d62fe 100644 --- a/Kernel/FirmwareKit/EFI.hxx +++ b/Kernel/FirmwareKit/EFI.hxx @@ -5,3 +5,5 @@ ------------------------------------------- */ #include + +/// @note this header is used to reference the EFI/EFI.hxx \ No newline at end of file diff --git a/Kernel/NewKit/Defines.hpp b/Kernel/NewKit/Defines.hpp index 3210f1ef..96f13fd9 100644 --- a/Kernel/NewKit/Defines.hpp +++ b/Kernel/NewKit/Defines.hpp @@ -133,6 +133,12 @@ namespace NewOS }; } // namespace NewOS +/// @note this is for the purpose of having a common namespace alongside zeta's codebase. +namespace ma::zeta::kernel +{ + using namespace NewOS; +} + #define DEDUCE_ENDIAN(address, value) \ (((reinterpret_cast(address)[0]) == (value)) \ ? (NewOS::Endian::kEndianBig) \ -- cgit v1.2.3 From 349fe48baf941b2d1b571d3a5d0d796823bae312 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Thu, 13 Jun 2024 17:41:19 +0200 Subject: MHR-31: New systemcall/kernelcall architecture. Signed-off-by: Amlal EL Mahrouss --- Boot/makefile | 2 +- DDK/KernelCall.c | 11 ++-- DDK/KernelDev.c | 7 +-- DDK/KernelPrint.c | 2 +- DDK/KernelStd.h | 8 ++- DDK/KernelStdCxx.cc | 6 +-- Kernel/ArchKit/ArchKit.hpp | 13 ++++- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 50 +++++++++++------- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 22 ++------ Kernel/HALKit/AMD64/HalInterruptAPI.asm | 59 +++++++++++++++++++++- Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 20 +++++--- Kernel/NewKit/Array.hpp | 9 +--- Kernel/Sources/SMPManager.cxx | 2 +- 13 files changed, 139 insertions(+), 72 deletions(-) diff --git a/Boot/makefile b/Boot/makefile index 4bee19a2..e54b1aa8 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -26,7 +26,7 @@ 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 \ diff --git a/DDK/KernelCall.c b/DDK/KernelCall.c index c20a4894..a16a5278 100644 --- a/DDK/KernelCall.c +++ b/DDK/KernelCall.c @@ -9,22 +9,17 @@ #include #include -DK_EXTERN __attribute__((naked)) void __kernelDispatchCall(int32_t cnt, ...); +DK_EXTERN __attribute__((naked)) void* __kernelDispatchCall(const char* name, int32_t cnt, void* data, size_t sz); /// @brief Execute a function on the kernel. /// @param kernelRpcName the name of the function. /// @param cnt number of arguments. /// @param /// @return -DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, ...) +DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, void* data, size_t sz) { if (!kernelRpcName || cnt == 0) return NIL; - va_list arg; - va_start(arg, cnt); - - __kernelDispatchCall(cnt, arg); - - va_end(arg); + return __kernelDispatchCall(kernelRpcName, cnt, data, sz); } diff --git a/DDK/KernelDev.c b/DDK/KernelDev.c index f19f85c6..6a6aac99 100644 --- a/DDK/KernelDev.c +++ b/DDK/KernelDev.c @@ -7,6 +7,7 @@ ------------------------------------------- */ #include +#include /// @brief Open a new binary device from path. DK_EXTERN kernelDeviceRef kernelOpenBinaryDevice(const char* devicePath) @@ -14,7 +15,7 @@ DK_EXTERN kernelDeviceRef kernelOpenBinaryDevice(const char* devicePath) if (!devicePath) return NIL; - return kernelCall("OpenBinaryDevice", 1, devicePath); + return kernelCall("OpenBinaryDevice", 1, devicePath, kernelStringLength(devicePath)); } /// @brief Open a new character device from path. @@ -23,7 +24,7 @@ DK_EXTERN kernelDeviceRef kernelOpenCharDevice(const char* devicePath) if (!devicePath) return NIL; - return kernelCall("OpenCharDevice", 1, devicePath); + return kernelCall("OpenCharDevice", 1, devicePath, kernelStringLength(devicePath)); } /// @brief Close any device. @@ -33,5 +34,5 @@ DK_EXTERN void kernelCloseDevice(kernelDeviceRef device) if (!device) return; - kernelCall("CloseDevice", 1, device); + kernelCall("CloseDevice", 1, device, sizeof(kernelDevice)); } diff --git a/DDK/KernelPrint.c b/DDK/KernelPrint.c index b7513149..77f70280 100644 --- a/DDK/KernelPrint.c +++ b/DDK/KernelPrint.c @@ -10,7 +10,7 @@ DK_EXTERN void kernelPrintChar(const char ch) { - kernelCall("WriteCharacter", 1, ch); + kernelCall("WriteCharacter", 1, ch, 1); } /// @brief print string to UART. diff --git a/DDK/KernelStd.h b/DDK/KernelStd.h index 61bc23a9..63df4c2a 100644 --- a/DDK/KernelStd.h +++ b/DDK/KernelStd.h @@ -19,4 +19,10 @@ #include #include -DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, ...); +/// @brief Call kernel (interrupt 0x33) +/// @param kernelRpcName +/// @param cnt +/// @param dat +/// @param sz +/// @return +DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, void* dat, size_t sz); diff --git a/DDK/KernelStdCxx.cc b/DDK/KernelStdCxx.cc index b1d233fa..cdca85dc 100644 --- a/DDK/KernelStdCxx.cc +++ b/DDK/KernelStdCxx.cc @@ -11,8 +11,8 @@ void* operator new(size_t sz) { if (!sz) ++sz; - auto ptr = kernelCall("NewKernelHeap", 1, sz); - kernelCall("ProtectKernelHeap", 1, ptr); + auto ptr = kernelCall("NewKernelHeap", 1, &sz, sizeof(size_t)); + kernelCall("ProtectKernelHeap", 1, ptr, sz); return ptr; } @@ -20,5 +20,5 @@ void* operator new(size_t sz) { void operator delete(void* ptr) noexcept { if (!ptr) return; - kernelCall("DeleteKernelHeap", 1,ptr); + kernelCall("DeleteKernelHeap", 1, ptr, 0); } diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index 419f2c7a..c2e5a967 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -81,10 +81,21 @@ namespace NewOS typedef NewOS::Void (*rt_syscall_proc)(NewOS::HAL::StackFramePtr); -extern NewOS::Array kSyscalls; +inline NewOS::Array + kKerncalls; + EXTERN_C NewOS::HAL::StackFramePtr rt_get_current_context(); EXTERN_C NewOS::Void rt_do_context_switch(NewOS::HAL::StackFramePtr stackFrame); diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 5f64cc20..a21a4c47 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -24,24 +24,6 @@ EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp) NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); } -/// @brief Handle the scheduler interrupt, raised from the HPET timer. -/// @param rsp -EXTERN_C void idt_handle_scheduler(NewOS::UIntPtr rsp) -{ - NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); - - NewOS::kcout - << "newoskrnl: Will be scheduled back later " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName() - << NewOS::end_line(); - - /// schedule another process. - if (!NewOS::ProcessHelper::StartScheduling()) - { - NewOS::kcout << "newoskrnl: Continue schedule this process...\r"; - } -} - /// @brief Handle page fault. /// @param rsp EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp) @@ -99,3 +81,35 @@ EXTERN_C void idt_handle_ud(NewOS::UIntPtr rsp) NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); } + +/// @brief Enter syscall from assembly. +/// @param stack the stack pushed from assembly routine. +/// @return nothing. +EXTERN_C NewOS::Void hal_system_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx) +{ + if (rcx <= (kSyscalls.Count() - 1)) + { + NewOS::kcout << "newoskrnl: syscall: enter.\r"; + + NewOS::kcout << "rcx: " << NewOS::number(rcx) << NewOS::endl; + + if (kSyscalls[rcx].Leak().Leak().fHooked) + (kSyscalls[rcx].Leak().Leak().fProc)((NewOS::HAL::StackFramePtr)rdx); + + NewOS::kcout << "newoskrnl: syscall: exit.\r"; + } +} + +/// @brief Enter kernel call from assembly (DDK only). +/// @param stack the stack pushed from assembly routine. +/// @return nothing. +EXTERN_C NewOS::Void hal_kernel_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx, + NewOS::UIntPtr r8, NewOS::UIntPtr r9) +{ + if (rcx != 0) + { + NewOS::kcout << "newoskrnl: kerncall: enter.\r"; + + NewOS::kcout << "newoskrnl: kerncall: exit.\r"; + } +} diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index b70649ee..e2520332 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -159,23 +159,10 @@ namespace NewOS::HAL EXTERN_C Void hal_apic_acknowledge_cont(Void) { - kcout << "newoskrnl: finish kernel init... \r"; + /// TODO: better init code. + KeMain(); - if (cProgramInitialized && - *cProgramInitialized) - { - *cProgramInitialized = false; - - kcout << "newoskrnl: putting thread to sleep...\r"; - - KeMain(); - - _hal_spin_core(); - } - else - { - _hal_spin_core(); - } + _hal_spin_core(); } EXTERN_C StackFramePtr _hal_leak_current_context(Void) @@ -196,6 +183,7 @@ namespace NewOS::HAL STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame) { Semaphore sem; + while (sem.IsLocked()) { } @@ -205,7 +193,7 @@ namespace NewOS::HAL cFramePtr = stackFrame; /// yes the exception field contains the core id. - hal_send_start_ipi(stackFrame->Exception, 0x40, cBaseAddressAPIC); + hal_send_start_ipi(stackFrame->Rcx, 0x40, cBaseAddressAPIC); sem.Unlock(); } diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index ef5a8319..e88ffc0d 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -195,15 +195,69 @@ IntNormal 47 IntNormal 48 IntNormal 49 +[extern hal_system_call_enter] +[extern hal_kernel_call_enter] + __NEW_INT_50: cli - ;; todo handle system calls. + push rax + + call hal_system_call_enter + + pop rax + + sti + iretq + +__NEW_INT_51: + cli + + push 0 + push 51 + 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 + push gs + push fs + + mov rcx, rbp + + call hal_kernel_call_enter + + pop fs + pop gs + 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 sti iretq -IntNormal 51 IntNormal 52 IntNormal 53 IntNormal 54 @@ -223,6 +277,7 @@ IntNormal 60 ;; this one is doing a POST for us. ;; testing interrupts. _ke_power_on_self_test: + mov rcx, 0x10 int 0x32 int 0x32 int 0x32 diff --git a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp index ea0997ed..3217a660 100644 --- a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -5,16 +5,20 @@ ------------------------------------------- */ #include -#include +#include -NewOS::Array - kSyscalls; - -extern "C" void rt_syscall_handle(NewOS::HAL::StackFrame* stack) +/// @brief Internal call for syscall, to work with C++. +/// @param stack +/// @return nothing. +EXTERN_C void rt_syscall_handle(NewOS::HAL::StackFrame* stack) { - for (NewOS::SizeT index = 0UL; index < kKernelMaxSystemCalls; ++index) + if (stack->Rcx <= (kSyscalls.Count() - 1)) { - (kSyscalls[index].Leak().Leak())(stack->ID, stack); + NewOS::kcout << "newoskrnl: syscall: enter.\r"; + + if (kSyscalls[stack->Rcx].Leak().Leak().fHooked) + (kSyscalls[stack->Rcx].Leak().Leak().fProc)(stack); + + NewOS::kcout << "newoskrnl: syscall: exit.\r"; } } diff --git a/Kernel/NewKit/Array.hpp b/Kernel/NewKit/Array.hpp index b8386c9a..1c89f365 100644 --- a/Kernel/NewKit/Array.hpp +++ b/Kernel/NewKit/Array.hpp @@ -43,14 +43,7 @@ namespace NewOS SizeT Count() const { - SizeT cntElems = 0UL; - for (auto Val : fArray) - { - if (Val) - ++cntElems; - } - - return cntElems; + return N; } const T* CData() diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index f0b680ce..99a3b025 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -113,7 +113,7 @@ namespace NewOS fStack->R9 = stack->R9; fStack->R8 = stack->R8; - fStack->Exception = this->fID; + fStack->Rcx = this->fID; } rt_do_context_switch(fStack); -- cgit v1.2.3 From 7327f305efb1c6678722308cc5f9645dd39f451e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 13 Jun 2024 19:38:29 +0200 Subject: MHR-31: Lots of fixes and improvements regarding the kernel. Signed-off-by: Amlal El Mahrouss --- Boot/makefile | 2 +- Kernel/ArchKit/ArchKit.hpp | 4 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 25 +-------- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 7 +-- Kernel/HALKit/AMD64/HalHardwareMP.cpp | 30 ----------- Kernel/HALKit/AMD64/HalHart.cpp | 30 +++++++++++ Kernel/HALKit/AMD64/HalInterruptAPI.asm | 47 +++++------------ Kernel/HALKit/AMD64/HalKernelMain.cxx | 19 ++++++- Kernel/HALKit/AMD64/PCI/Iterator.cxx | 6 +-- Kernel/KernelKit/ProcessScheduler.hxx | 19 ++----- Kernel/KernelKit/SMPManager.hpp | 6 +-- Kernel/NewKit/Array.hpp | 4 +- Kernel/NewKit/MutableArray.hpp | 7 +++ Kernel/Sources/HError.cxx | 3 +- Kernel/Sources/KeMain.cxx | 5 -- Kernel/Sources/ProcessScheduler.cxx | 61 +++++++++++----------- Kernel/Sources/SMPManager.cxx | 46 +++++++++------- 17 files changed, 145 insertions(+), 176 deletions(-) delete mode 100644 Kernel/HALKit/AMD64/HalHardwareMP.cpp create mode 100644 Kernel/HALKit/AMD64/HalHart.cpp diff --git a/Boot/makefile b/Boot/makefile index e54b1aa8..4bee19a2 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -26,7 +26,7 @@ BIOS=OVMF.fd IMG=epm.img IMG_2=epm-slave.img -EMU_FLAGS=-net none -smp 4 -m 4G -M q35 \ +EMU_FLAGS=-net none -smp 4 -serial stdio -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 \ diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index c2e5a967..6407a0d8 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -79,7 +79,7 @@ namespace NewOS #define kKernelMaxSystemCalls (256) -typedef NewOS::Void (*rt_syscall_proc)(NewOS::HAL::StackFramePtr); +typedef NewOS::Void (*rt_syscall_proc)(NewOS::VoidPtr); struct RTSyscallInfoHdr final { @@ -95,7 +95,7 @@ inline NewOS::Array kKerncalls; - + EXTERN_C NewOS::HAL::StackFramePtr rt_get_current_context(); EXTERN_C NewOS::Void rt_do_context_switch(NewOS::HAL::StackFramePtr stackFrame); diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index a21a4c47..51570b86 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -12,11 +12,6 @@ /// @param rsp EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp) { - MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - - NewOS::kcout << "newoskrnl: Stack Pointer: " - << NewOS::StringBuilder::FromInt("rsp{%}", rsp); - NewOS::kcout << "newoskrnl: General Protection Fault, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); @@ -28,9 +23,6 @@ EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp) { - MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); - NewOS::kcout << "newoskrnl: Segmentation Fault, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); @@ -42,9 +34,6 @@ EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_math(NewOS::UIntPtr rsp) { - MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); - NewOS::kcout << "newoskrnl: Math error, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); @@ -56,9 +45,6 @@ EXTERN_C void idt_handle_math(NewOS::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_generic(NewOS::UIntPtr rsp) { - MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - NewOS::kcout << NewOS::StringBuilder::FromInt("sp{%}", rsp); - NewOS::kcout << "newoskrnl: Execution error, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); @@ -70,11 +56,6 @@ EXTERN_C void idt_handle_generic(NewOS::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_ud(NewOS::UIntPtr rsp) { - MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - - NewOS::kcout << "newoskrnl: Stack Pointer: " - << NewOS::StringBuilder::FromInt("rsp{%}", rsp); - NewOS::kcout << "newoskrnl: Invalid interrupt, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); @@ -91,10 +72,8 @@ EXTERN_C NewOS::Void hal_system_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rd { NewOS::kcout << "newoskrnl: syscall: enter.\r"; - NewOS::kcout << "rcx: " << NewOS::number(rcx) << NewOS::endl; - - if (kSyscalls[rcx].Leak().Leak().fHooked) - (kSyscalls[rcx].Leak().Leak().fProc)((NewOS::HAL::StackFramePtr)rdx); + if (kSyscalls[rcx].Leak().Leak()->fHooked) + (kSyscalls[rcx].Leak().Leak()->fProc)((NewOS::VoidPtr)rdx); NewOS::kcout << "newoskrnl: syscall: exit.\r"; } diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index e2520332..c15a7b55 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -16,9 +16,6 @@ #define kAPIC_SIPI_Vector 0x00500 #define kAPIC_EIPI_Vector 0x00400 -/// @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); @@ -159,9 +156,7 @@ namespace NewOS::HAL EXTERN_C Void hal_apic_acknowledge_cont(Void) { - /// TODO: better init code. - KeMain(); - + ProcessHelper::StartScheduling(); _hal_spin_core(); } diff --git a/Kernel/HALKit/AMD64/HalHardwareMP.cpp b/Kernel/HALKit/AMD64/HalHardwareMP.cpp deleted file mode 100644 index 92e075aa..00000000 --- a/Kernel/HALKit/AMD64/HalHardwareMP.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include - -// bugs = 0 - -namespace NewOS -{ - /// @brief wakes up thread. - /// wakes up thread from hang. - void rt_wakeup_thread(HAL::StackFrame* stack) - { - HAL::rt_cli(); - - HAL::rt_sti(); - } - - /// @brief makes thread sleep. - /// hooks and hangs thread to prevent code from executing. - void rt_hang_thread(HAL::StackFrame* stack) - { - HAL::rt_cli(); - - HAL::rt_sti(); - } -} // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cpp new file mode 100644 index 00000000..92e075aa --- /dev/null +++ b/Kernel/HALKit/AMD64/HalHart.cpp @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include + +// bugs = 0 + +namespace NewOS +{ + /// @brief wakes up thread. + /// wakes up thread from hang. + void rt_wakeup_thread(HAL::StackFrame* stack) + { + HAL::rt_cli(); + + HAL::rt_sti(); + } + + /// @brief makes thread sleep. + /// hooks and hangs thread to prevent code from executing. + void rt_hang_thread(HAL::StackFrame* stack) + { + HAL::rt_cli(); + + HAL::rt_sti(); + } +} // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index e88ffc0d..150cfc10 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -201,11 +201,15 @@ IntNormal 49 __NEW_INT_50: cli + push rcx + push rdx push rax call hal_system_call_enter pop rax + pop rdx + pop rcx sti iretq @@ -213,47 +217,19 @@ __NEW_INT_50: __NEW_INT_51: cli - push 0 - push 51 - 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 - push gs - push fs - - mov rcx, rbp + push rax call hal_kernel_call_enter - pop fs - pop gs - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 + pop rax pop r9 pop r8 - pop rdi - pop rsi - pop rbp - pop rbx pop rdx pop rcx - pop rax sti iretq @@ -278,13 +254,18 @@ IntNormal 60 ;; testing interrupts. _ke_power_on_self_test: mov rcx, 0x10 - int 0x32 - int 0x32 - int 0x32 + mov rdx, _ke_string_post + int 0x32 ret +section .data +_ke_string_post: + db "POST has been successful.", 0 + +section .text + [global hal_load_gdt] hal_load_gdt: diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 708004b3..6f01734e 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -14,6 +14,10 @@ #include #include #include +#include + +/// @brief This symbol is the kernel main symbol. +EXTERN_C void KeMain(); EXTERN_C NewOS::VoidPtr kInterruptVectorTable[]; @@ -72,13 +76,24 @@ EXTERN_C void hal_init_platform( /// START POST + constexpr auto cDummyInterrupt = 0x10; // 16 + + kSyscalls[cDummyInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr sf) -> void { + const char* msg = (const char*)sf; + NewOS::kcout << "newoskrnl: " << msg << "\r"; + }; + + kSyscalls[cDummyInterrupt].Leak().Leak()->fHooked = true; + NewOS::HAL::Detail::_ke_power_on_self_test(); + auto cLoaderName = "newoskrnl"; + NewOS::execute_from_image(KeMain, cLoaderName); + NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); NewOS::kcout << "newoskrnl: We're done here...\r"; while (true) - { - } + {} } diff --git a/Kernel/HALKit/AMD64/PCI/Iterator.cxx b/Kernel/HALKit/AMD64/PCI/Iterator.cxx index 8675f171..297aa89c 100644 --- a/Kernel/HALKit/AMD64/PCI/Iterator.cxx +++ b/Kernel/HALKit/AMD64/PCI/Iterator.cxx @@ -7,8 +7,8 @@ #include #define PCI_ITERATOR_FIND_AND_UNWRAP(DEV, SZ) \ - if (DEV.Leak()) \ - return DEV.Leak(); + if (DEV.Leak().Leak()) \ + return *DEV.Leak().Leak(); namespace NewOS::PCI { @@ -25,7 +25,7 @@ namespace NewOS::PCI if (dev.Class() == (UChar)type) { - fDevices[bus].Leak().Leak() = dev; + *fDevices[bus].Leak().Leak() = dev; } } } diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index c6e090e4..8c1971b0 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -17,7 +17,7 @@ #define kSchedMinMicroTime (AffinityKind::kHartStandard) #define kSchedInvalidPID (-1) -#define kSchedProcessLimitPerTeam (100U) +#define kSchedProcessLimitPerTeam (16U) //////////////////////////////////////////////////// @@ -134,7 +134,6 @@ namespace NewOS explicit ProcessHeader(VoidPtr startImage = nullptr) : Image(startImage) { - MUST_PASS(startImage); } ~ProcessHeader() = default; @@ -145,7 +144,7 @@ namespace NewOS void SetEntrypoint(UIntPtr& imageStart) noexcept; public: - Char Name[kProcessLen] = {"NewOS Process"}; + Char Name[kProcessLen] = {"Process"}; ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid}; ProcessSelector Selector{ProcessSelector::kRingUser}; HAL::StackFramePtr StackFrame{nullptr}; @@ -240,23 +239,15 @@ namespace NewOS /// The main class which you call to schedule an app. class ProcessScheduler final { - private: - explicit ProcessScheduler() = default; + explicit ProcessScheduler() = default; public: ~ProcessScheduler() = default; NEWOS_COPY_DEFAULT(ProcessScheduler) - operator bool() - { - return mTeam.AsArray().Count() > 0; - } - - bool operator!() - { - return mTeam.AsArray().Count() == 0; - } + operator bool(); + bool operator!(); public: ProcessTeam& CurrentTeam(); diff --git a/Kernel/KernelKit/SMPManager.hpp b/Kernel/KernelKit/SMPManager.hpp index 985050f1..ba706cf6 100644 --- a/Kernel/KernelKit/SMPManager.hpp +++ b/Kernel/KernelKit/SMPManager.hpp @@ -94,11 +94,11 @@ namespace NewOS NEWOS_COPY_DEFAULT(SMPManager); public: - bool Switch(HAL::StackFrame* the); - HAL::StackFramePtr GetStackFrame() noexcept; + bool Switch(HAL::StackFramePtr the); + HAL::StackFramePtr Leak() noexcept; public: - Ref operator[](const SizeT& idx); + Ref operator[](const SizeT& idx); bool operator!() noexcept; operator bool() noexcept; diff --git a/Kernel/NewKit/Array.hpp b/Kernel/NewKit/Array.hpp index 1c89f365..dca5c13f 100644 --- a/Kernel/NewKit/Array.hpp +++ b/Kernel/NewKit/Array.hpp @@ -21,13 +21,13 @@ namespace NewOS Array& operator=(const Array&) = default; Array(const Array&) = default; - ErrorOr operator[](Size At) + ErrorOr operator[](Size At) { if (At > N) return {}; kcout << "Returning element\r"; - return ErrorOr(fArray[At]); + return ErrorOr(&fArray[At]); } Boolean Empty() const diff --git a/Kernel/NewKit/MutableArray.hpp b/Kernel/NewKit/MutableArray.hpp index f9c79301..a3ad4cb1 100644 --- a/Kernel/NewKit/MutableArray.hpp +++ b/Kernel/NewKit/MutableArray.hpp @@ -170,6 +170,13 @@ namespace NewOS Boolean Add(const T val) { auto* iterationNode = fFirstNode; + + if (!iterationNode) + { + fFirstNode = new MutableLinkedList(); + iterationNode = fFirstNode; + } + MUST_PASS(iterationNode); while (iterationNode) diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 937e983a..1f36d020 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -13,6 +13,7 @@ namespace NewOS /// @return if error-free: true, otherwise false. Boolean ke_bug_check(void) noexcept { - return true; + /// TODO: + return false; } } // namespace NewOS diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index e2f41464..60494ee3 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -220,9 +220,4 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) auto cLoaderName = "SystemLauncher"; NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); - - while (true) - { - NewOS::ProcessScheduler::The().Leak().Run(); - } } diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 08a7971e..7008eafe 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -18,7 +18,7 @@ ///! BUGS: 0 /***********************************************************************************/ -/* This file handles the process scheduling. +/* This file handles the process scheduling. */ /***********************************************************************************/ namespace NewOS @@ -42,7 +42,8 @@ namespace NewOS void ProcessHeader::Crash() { - kcout << this->Name << ": crashed. (id = " << number(kErrorProcessFault); + kcout << (*this->Name == 0 ? "Unknown" : this->Name) << ": crashed. (id = "; + kcout.Number(kErrorProcessFault); kcout << ")\r"; if (this->Ring != kRingUserKind) @@ -201,9 +202,6 @@ namespace NewOS /// @return SizeT ProcessScheduler::Add(Ref& process) { - if (!process) - return -1; - if (!process.Leak().Image) { if (process.Leak().Kind != ProcessHeader::kShLibKind) @@ -212,7 +210,7 @@ namespace NewOS } } - if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) + if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; kcout << "ProcessScheduler::Add(Ref& process)\r"; @@ -262,8 +260,8 @@ namespace NewOS { auto process = mTeam.AsArray()[processIndex]; - MUST_PASS(process); //! no need for a MUST_PASS(process.Leak());, it is - //! recursive because of the nature of the class; + if (!process) + continue; //! run any process needed to be scheduled. if (ProcessHelper::CanBeScheduled(process.Leak())) @@ -351,22 +349,11 @@ namespace NewOS bool ProcessHelper::StartScheduling() { - if (ProcessHelper::CanBeScheduled( - ProcessScheduler::The().Leak().GetCurrent())) - { - --ProcessScheduler::The().Leak().GetCurrent().Leak().PTime; - return false; - } - - auto processRef = ProcessScheduler::The().Leak(); - - if (!processRef) - return false; // we have nothing to schedule. simply return. + auto& processRef = ProcessScheduler::The().Leak(); + SizeT ret = processRef.Run(); - SizeT ret = processRef.Run(); - - kcout << StringBuilder::FromInt( - "ProcessHelper::StartScheduling() Iterated over {%} jobs inside team.\r", ret); + kcout << "newoskrnl: Iterated over: " << number(ret); + kcout << " processes.\r"; return true; } @@ -384,30 +371,42 @@ namespace NewOS for (SizeT index = 0UL; index < SMPManager::The().Leak().Count(); ++index) { - if (SMPManager::The().Leak()[index].Leak().Kind() == kInvalidHart) + if (SMPManager::The().Leak()[index].Leak()->Kind() == kInvalidHart) continue; - if (SMPManager::The().Leak()[index].Leak().StackFrame() == the_stack) + if (SMPManager::The().Leak()[index].Leak()->StackFrame() == the_stack) { - SMPManager::The().Leak()[index].Leak().Busy(false); + SMPManager::The().Leak()[index].Leak()->Busy(false); continue; } - if (SMPManager::The().Leak()[index].Leak().IsBusy()) + if (SMPManager::The().Leak()[index].Leak()->IsBusy()) continue; - if (SMPManager::The().Leak()[index].Leak().Kind() != + if (SMPManager::The().Leak()[index].Leak()->Kind() != ThreadKind::kHartBoot && - SMPManager::The().Leak()[index].Leak().Kind() != + SMPManager::The().Leak()[index].Leak()->Kind() != ThreadKind::kHartSystemReserved) { - SMPManager::The().Leak()[index].Leak().Busy(true); + SMPManager::The().Leak()[index].Leak()->Busy(true); ProcessHelper::GetCurrentPID() = new_pid; - return SMPManager::The().Leak()[index].Leak().Switch(the_stack); + return SMPManager::The().Leak()[index].Leak()->Switch(the_stack); } } return false; } + + /// @brief this checks if any process is on the team. + ProcessScheduler::operator bool() + { + return mTeam.AsArray().Count() > 0; + } + + /// @brief this checks if no process is on the team. + bool ProcessScheduler::operator!() + { + return mTeam.AsArray().Count() == 0; + } } // namespace NewOS diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 99a3b025..683343ff 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -117,7 +117,7 @@ namespace NewOS } rt_do_context_switch(fStack); - + return true; } @@ -143,12 +143,12 @@ namespace NewOS } /// @brief Get Stack Frame of Core - HAL::StackFramePtr SMPManager::GetStackFrame() noexcept + HAL::StackFramePtr SMPManager::Leak() noexcept { if (fThreadList[fCurrentThread].Leak() && ProcessHelper::GetCurrentPID() == - fThreadList[fCurrentThread].Leak().Leak().fPID) - return fThreadList[fCurrentThread].Leak().Leak().fStack; + fThreadList[fCurrentThread].Leak().Leak()->fPID) + return fThreadList[fCurrentThread].Leak().Leak()->fStack; return nullptr; } @@ -163,35 +163,35 @@ namespace NewOS { // stack != nullptr -> if core is used, then continue. if (!fThreadList[idx].Leak() || - !fThreadList[idx].Leak().Leak().IsWakeup() || - fThreadList[idx].Leak().Leak().IsBusy()) + !fThreadList[idx].Leak().Leak()->IsWakeup() || + fThreadList[idx].Leak().Leak()->IsBusy()) continue; // to avoid any null deref. - if (!fThreadList[idx].Leak().Leak().fStack) + if (!fThreadList[idx].Leak().Leak()->fStack) continue; - if (fThreadList[idx].Leak().Leak().fStack->Rsp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->Rsp == 0) continue; - if (fThreadList[idx].Leak().Leak().fStack->Rbp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->Rbp == 0) continue; - fThreadList[idx].Leak().Leak().Busy(true); + fThreadList[idx].Leak().Leak()->Busy(true); - fThreadList[idx].Leak().Leak().fID = idx; + fThreadList[idx].Leak().Leak()->fID = idx; /// I figured out this: /// Allocate stack /// Set APIC base to stack /// Do stuff and relocate stack based on this code. /// - Amlel - rt_copy_memory(stack, fThreadList[idx].Leak().Leak().fStack, + rt_copy_memory(stack, fThreadList[idx].Leak().Leak()->fStack, sizeof(HAL::StackFrame)); - fThreadList[idx].Leak().Leak().Switch(fThreadList[idx].Leak().Leak().fStack); + fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack); - fThreadList[idx].Leak().Leak().fPID = ProcessHelper::GetCurrentPID(); + fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::GetCurrentPID(); - fThreadList[idx].Leak().Leak().Busy(false); + fThreadList[idx].Leak().Leak()->Busy(false); return true; } @@ -204,19 +204,25 @@ namespace NewOS * @param idx the index * @return the reference to the hardware thread. */ - Ref SMPManager::operator[](const SizeT& idx) + Ref SMPManager::operator[](const SizeT& idx) { if (idx == 0) { - if (fThreadList[idx].Leak().Leak().Kind() != kHartSystemReserved) + if (fThreadList[idx].Leak().Leak()->Kind() != kHartSystemReserved) { - fThreadList[idx].Leak().Leak().fKind = kHartBoot; + fThreadList[idx].Leak().Leak()->fKind = kHartBoot; } } else if (idx >= kMaxHarts) { - HardwareThread fakeThread; - fakeThread.fKind = kInvalidHart; + static HardwareThread* fakeThread = new HardwareThread(); + + if (!fakeThread) + { + fakeThread = new HardwareThread(); + } + + fakeThread->fKind = kInvalidHart; return {fakeThread}; } -- cgit v1.2.3 From 12126f9eebfa7fc6b2cd6148f13585ff71cf5425 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 13 Jun 2024 19:55:30 +0200 Subject: MHR-31: Rework scheduler, remove the concept of user driver and rings. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalKernelMain.cxx | 4 +--- Kernel/KernelKit/ProcessScheduler.hxx | 8 -------- Kernel/Sources/CodeManager.cxx | 4 ++-- Kernel/Sources/KeMain.cxx | 7 ++----- Kernel/Sources/ProcessScheduler.cxx | 24 ++---------------------- 5 files changed, 7 insertions(+), 40 deletions(-) diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 6f01734e..7064183b 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -87,13 +87,11 @@ EXTERN_C void hal_init_platform( NewOS::HAL::Detail::_ke_power_on_self_test(); - auto cLoaderName = "newoskrnl"; + auto cLoaderName = "LaunchDevil"; NewOS::execute_from_image(KeMain, cLoaderName); NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); - NewOS::kcout << "newoskrnl: We're done here...\r"; - while (true) {} } diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 8c1971b0..1ac19053 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -164,19 +164,11 @@ namespace NewOS { kAppKind = 1, kShLibKind = 2, - kDriverKind = 3, kKindCount, }; - enum - { - kRingUserKind = 3, - kRingDriverKind = 0, - }; - ProcessTime PTime; PID ProcessId{kSchedInvalidPID}; - Int32 Ring{kRingDriverKind}; Int32 Kind{kAppKind}; public: diff --git a/Kernel/Sources/CodeManager.cxx b/Kernel/Sources/CodeManager.cxx index 33121edf..9f374c18 100644 --- a/Kernel/Sources/CodeManager.cxx +++ b/Kernel/Sources/CodeManager.cxx @@ -20,11 +20,11 @@ namespace NewOS return false; ProcessHeader proc((VoidPtr)main); - proc.Kind = ProcessHeader::kDriverKind; + proc.Kind = ProcessHeader::kAppKind; rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(proc.Name)); Ref refProc = proc; return ProcessScheduler::The().Leak().Add(refProc); } -} // namespace NewOS \ No newline at end of file +} // namespace NewOS diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 60494ee3..9be8a026 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -204,9 +204,7 @@ namespace NewOS::Detail NewOS::Utils::execute_from_image(stageBoard, NewOS::ProcessHeader::kAppKind); - NewOS::kcout << "SystemLauncher: done, sleeping..."; - - while (true) {} + /// TODO: now jump to user mode using the HAL. } } // namespace NewOS::Detail @@ -218,6 +216,5 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) /// Now run kernel loop, until no process are running. NewOS::Detail::FilesystemWizard wizard; // automatic. - auto cLoaderName = "SystemLauncher"; - NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); + NewOS::Detail::SystemLauncher_Main(); } diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 7008eafe..d9d013c6 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -46,11 +46,6 @@ namespace NewOS kcout.Number(kErrorProcessFault); kcout << ")\r"; - if (this->Ring != kRingUserKind) - { - MUST_PASS(ke_bug_check()); - } - this->Exit(kErrorProcessFault); } @@ -167,24 +162,8 @@ namespace NewOS ProcessScheduler::The().Leak().GetCurrent().Leak().ProcessId) ke_stop(RUNTIME_CHECK_PROCESS); - if (this->Ring == (Int32)ProcessSelector::kRingKernel && - ProcessScheduler::The().Leak().GetCurrent().Leak().Ring > 0) - ke_stop(RUNTIME_CHECK_PROCESS); - kLastExitCode = exit_code; - if (this->Ring != (Int32)ProcessSelector::kRingDriver) - { - if (this->HeapPtr) - rt_free_heap(this->HeapPtr); - - this->HeapPtr = nullptr; - this->HeapCursor = nullptr; - - this->FreeMemory = 0UL; - this->UsedMemory = 0UL; - } - //! Delete image if not done already. if (this->Image) ke_delete_ke_heap(this->Image); @@ -352,7 +331,8 @@ namespace NewOS auto& processRef = ProcessScheduler::The().Leak(); SizeT ret = processRef.Run(); - kcout << "newoskrnl: Iterated over: " << number(ret); + kcout << "newoskrnl: Iterated over: "; + kcout.Number(ret); kcout << " processes.\r"; return true; -- cgit v1.2.3 From 67a14f5c12510e277911cbcf8ea5ce01f8b8fbb1 Mon Sep 17 00:00:00 2001 From: amlal Date: Thu, 13 Jun 2024 22:02:27 +0200 Subject: MHR-31: Detect all types of cores except the boot one. Signed-off-by: amlal --- Boot/NetBoot/NetBoot.hxx | 7 +++--- Boot/Sources/HEL/AMD64/BootMain.cxx | 10 ++++---- Boot/makefile | 2 +- DDK/KernelCall.c | 5 ++-- DDK/KernelStd.h | 10 ++++---- Kernel/ArchKit/ArchKit.hpp | 4 ++-- Kernel/FirmwareKit/EFI/API.hxx | 4 ++-- Kernel/FirmwareKit/EPM.hxx | 8 +++---- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 3 +-- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 27 ++++++++++++++-------- Kernel/HALKit/AMD64/HalKernelMain.cxx | 7 +++--- Kernel/HALKit/AMD64/PCI/Iterator.cxx | 2 +- Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp | 2 +- Kernel/KernelKit/DriveManager.hxx | 6 ++--- Kernel/KernelKit/FileManager.hpp | 2 +- Kernel/KernelKit/Framebuffer.hpp | 2 +- Kernel/KernelKit/KernelHeap.hpp | 8 +++---- Kernel/KernelKit/ProcessScheduler.hxx | 8 +++---- Kernel/KernelKit/SMPManager.hpp | 4 ++-- Kernel/KernelKit/XCOFF.hxx | 11 +++++---- Kernel/NetworkKit/IPCEP.hxx | 4 ++-- Kernel/NewKit/Array.hpp | 1 - Kernel/NewKit/MutableArray.hpp | 4 ++-- Kernel/Sources/HError.cxx | 2 +- Kernel/Sources/KeMain.cxx | 6 ++--- Kernel/Sources/KernelHeap.cxx | 4 ++-- Kernel/Sources/SMPManager.cxx | 6 ++--- Kernel/Sources/UserHeap.cxx | 8 +++---- Usr/Sys/CoreSystem/Headers/Defines.h | 19 ++++++++------- Usr/Sys/CoreSystem/Headers/File.h | 2 +- Usr/Sys/CoreSystem/Headers/Intl.h | 6 ++--- Usr/Sys/CoreSystem/Headers/Transport.h | 6 ++--- Usr/Sys/CoreSystem/Sources/CRTStartup.c | 2 +- Usr/Sys/CoreSystem/Sources/File.c | 18 +++++++-------- 34 files changed, 113 insertions(+), 107 deletions(-) diff --git a/Boot/NetBoot/NetBoot.hxx b/Boot/NetBoot/NetBoot.hxx index ccb43290..e3119c5f 100644 --- a/Boot/NetBoot/NetBoot.hxx +++ b/Boot/NetBoot/NetBoot.hxx @@ -19,9 +19,8 @@ typedef struct NetBootInternetHeader CharacterTypeUTF8 NB3; /// magic char 3 'T' CharacterTypeUTF8 NB4; /// magic char 4 'B' - CharacterTypeUTF8 PatchName[255]; /// example: ColdChoco - NewOS::Int32 PatchLength; /// the patch length. + CharacterTypeUTF8 PatchName[255]; /// example: ColdChoco + NewOS::Int32 PatchLength; /// the patch length. CharacterTypeUTF8 PatchTarget[255]; /// the target file. - NewOS::Boolean ImpliesROM; /// does it implies EEPROM patching? + NewOS::Boolean ImpliesROM; /// does it implies EEPROM patching? } NetBootInternetHeader; - diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx index 5ab7914a..fab212ee 100644 --- a/Boot/Sources/HEL/AMD64/BootMain.cxx +++ b/Boot/Sources/HEL/AMD64/BootMain.cxx @@ -81,8 +81,8 @@ STATIC Bool CheckBootDevice(BootDeviceATA& ataDev) EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { - InitEFI(SystemTable); ///! Init the EFI library. - InitVideoFB(); ///! Init the GOP. + InitEFI(SystemTable); ///! Init the EFI library. + InitVideoFB(); ///! Init the GOP. BTextWriter writer; @@ -146,13 +146,13 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, GXInit(); GXDraw(RGB(9d, 9d, 9d), handoverHdrPtr->f_GOP.f_Height, - handoverHdrPtr->f_GOP.f_Width, 0, 0); + handoverHdrPtr->f_GOP.f_Width, 0, 0); GXFini(); GXDrawImg(NewBoot, NEWBOOT_HEIGHT, NEWBOOT_WIDTH, - (handoverHdrPtr->f_GOP.f_Width - NEWBOOT_WIDTH) / 2, - (handoverHdrPtr->f_GOP.f_Height - NEWBOOT_HEIGHT) / 2); + (handoverHdrPtr->f_GOP.f_Width - NEWBOOT_WIDTH) / 2, + (handoverHdrPtr->f_GOP.f_Height - NEWBOOT_HEIGHT) / 2); GXFini(); diff --git a/Boot/makefile b/Boot/makefile index 4bee19a2..e54b1aa8 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -26,7 +26,7 @@ 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 \ diff --git a/DDK/KernelCall.c b/DDK/KernelCall.c index a16a5278..7dc5761c 100644 --- a/DDK/KernelCall.c +++ b/DDK/KernelCall.c @@ -9,13 +9,14 @@ #include #include +/// @brief this is an internal call, do not use it. DK_EXTERN __attribute__((naked)) void* __kernelDispatchCall(const char* name, int32_t cnt, void* data, size_t sz); /// @brief Execute a function on the kernel. /// @param kernelRpcName the name of the function. /// @param cnt number of arguments. -/// @param -/// @return +/// @param +/// @return DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, void* data, size_t sz) { if (!kernelRpcName || cnt == 0) diff --git a/DDK/KernelStd.h b/DDK/KernelStd.h index 63df4c2a..0486479c 100644 --- a/DDK/KernelStd.h +++ b/DDK/KernelStd.h @@ -20,9 +20,9 @@ #include /// @brief Call kernel (interrupt 0x33) -/// @param kernelRpcName -/// @param cnt -/// @param dat -/// @param sz -/// @return +/// @param kernelRpcName +/// @param cnt +/// @param dat +/// @param sz +/// @return DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, void* dat, size_t sz); diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index 6407a0d8..c889c93c 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -83,8 +83,8 @@ typedef NewOS::Void (*rt_syscall_proc)(NewOS::VoidPtr); struct RTSyscallInfoHdr final { - NewOS::Int64 fHash; - NewOS::Bool fHooked; + NewOS::Int64 fHash; + NewOS::Bool fHooked; rt_syscall_proc fProc; }; diff --git a/Kernel/FirmwareKit/EFI/API.hxx b/Kernel/FirmwareKit/EFI/API.hxx index c6d02a3e..0f7da5a4 100644 --- a/Kernel/FirmwareKit/EFI/API.hxx +++ b/Kernel/FirmwareKit/EFI/API.hxx @@ -92,8 +92,8 @@ Bascially frees everything we have in the EFI side. GXInit(); GXDrawImg(NewBootFatal, NEWBOOTFATAL_HEIGHT, NEWBOOTFATAL_WIDTH, - (kHandoverHeader->f_GOP.f_Width - NEWBOOTFATAL_WIDTH) / 2, - (kHandoverHeader->f_GOP.f_Height - NEWBOOTFATAL_HEIGHT) / 2); + (kHandoverHeader->f_GOP.f_Width - NEWBOOTFATAL_WIDTH) / 2, + (kHandoverHeader->f_GOP.f_Height - NEWBOOTFATAL_HEIGHT) / 2); GXFini(); diff --git a/Kernel/FirmwareKit/EPM.hxx b/Kernel/FirmwareKit/EPM.hxx index 7c4b37b6..93f4730e 100644 --- a/Kernel/FirmwareKit/EPM.hxx +++ b/Kernel/FirmwareKit/EPM.hxx @@ -117,16 +117,16 @@ typedef struct PartitionBlock PartitionBlockType; ///! @brief partition must start at this address. ///! Anything below is reserved for Data backup by the Main OS. -#define kEPMStartPartitionBlk (sizeof(BootBlock)) +#define kEPMStartPartitionBlk (sizeof(BootBlock)) ///! @brief Current EPM revision (2) -#define kEPMRevision (3) +#define kEPMRevision (3) ///! @brief Current EPM revision (2) -#define kEPMRevisionUEFI (0xF) +#define kEPMRevisionUEFI (0xF) /* @brief Maximum block count. */ -#define kEPMMaxBlks (128) +#define kEPMMaxBlks (128) /// END OF SPECS diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 51570b86..e9c0941c 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -82,8 +82,7 @@ EXTERN_C NewOS::Void hal_system_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rd /// @brief Enter kernel call from assembly (DDK only). /// @param stack the stack pushed from assembly routine. /// @return nothing. -EXTERN_C NewOS::Void hal_kernel_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx, - NewOS::UIntPtr r8, NewOS::UIntPtr r9) +EXTERN_C NewOS::Void hal_kernel_call_enter(NewOS::UIntPtr rcx, NewOS::UIntPtr rdx, NewOS::UIntPtr r8, NewOS::UIntPtr r9) { if (rcx != 0) { diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index c15a7b55..37a681ab 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -113,10 +113,16 @@ namespace NewOS::HAL /////////////////////////////////////////////////////////////////////////////////////// - STATIC MadtType* kApicInfoBlock = nullptr; - STATIC UIntPtr kApicMadtAddresses[255] = {0}; - STATIC SizeT kApicMadtAddressesCount = 0UL; - STATIC UIntPtr cBaseAddressAPIC = 0xFEE00000; + STATIC MadtType* kApicInfoBlock = nullptr; + + STATIC struct + { + UIntPtr fAddress{0}; + UInt32 fKind{0}; + } kApicMadtAddresses[255] = {}; + + STATIC SizeT kApicMadtAddressesCount = 0UL; + STATIC UIntPtr cBaseAddressAPIC = 0xFEE00000; /// @brief this will help us schedule our cores. STATIC Boolean* cProgramInitialized = nullptr; @@ -156,7 +162,6 @@ namespace NewOS::HAL EXTERN_C Void hal_apic_acknowledge_cont(Void) { - ProcessHelper::StartScheduling(); _hal_spin_core(); } @@ -202,21 +207,23 @@ namespace NewOS::HAL if (kApicMadt != nullptr) { - MadtType* madt = (MadtType*)kApicMadt; + MadtType* madt = reinterpret_cast(kApicMadt); constexpr auto cMaxProbableCores = 4; // the amount of cores we want. constexpr auto cStartAt = 0; // start here to avoid boot core. for (SizeT coreAt = cStartAt; coreAt < cMaxProbableCores; ++coreAt) { - if (madt->MadtRecords[coreAt].Flags == kThreadLAPIC) // if local apic. + if (madt->MadtRecords[coreAt].Flags != kThreadBoot) // if local apic. { MadtType::MadtAddress& madtRecord = madt->MadtRecords[coreAt]; // then register as a core for scheduler. - kcout << "newoskrnl: register core as scheduler thread.\r"; + kcout << "newoskrnl: Register Local APIC.\r"; + + kApicMadtAddresses[kApicMadtAddressesCount].fAddress = madtRecord.Address; + kApicMadtAddresses[kApicMadtAddressesCount].fKind = madt->MadtRecords[coreAt].Flags; - kApicMadtAddresses[kApicMadtAddressesCount] = madtRecord.Address; ++kApicMadtAddressesCount; } } @@ -241,7 +248,7 @@ namespace NewOS::HAL cProgramInitialized = new Boolean(true); constexpr auto cWhereToInterrupt = 0x40; - constexpr auto cWhatCore = 1; + constexpr auto cWhatCore = 1; hal_send_start_ipi(cWhatCore, cWhereToInterrupt, cBaseAddressAPIC); } diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 7064183b..9b605e1a 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -79,8 +79,8 @@ EXTERN_C void hal_init_platform( constexpr auto cDummyInterrupt = 0x10; // 16 kSyscalls[cDummyInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr sf) -> void { - const char* msg = (const char*)sf; - NewOS::kcout << "newoskrnl: " << msg << "\r"; + const char* msg = (const char*)sf; + NewOS::kcout << "newoskrnl: " << msg << "\r"; }; kSyscalls[cDummyInterrupt].Leak().Leak()->fHooked = true; @@ -93,5 +93,6 @@ EXTERN_C void hal_init_platform( NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); while (true) - {} + { + } } diff --git a/Kernel/HALKit/AMD64/PCI/Iterator.cxx b/Kernel/HALKit/AMD64/PCI/Iterator.cxx index 297aa89c..d3167b46 100644 --- a/Kernel/HALKit/AMD64/PCI/Iterator.cxx +++ b/Kernel/HALKit/AMD64/PCI/Iterator.cxx @@ -7,7 +7,7 @@ #include #define PCI_ITERATOR_FIND_AND_UNWRAP(DEV, SZ) \ - if (DEV.Leak().Leak()) \ + if (DEV.Leak().Leak()) \ return *DEV.Leak().Leak(); namespace NewOS::PCI diff --git a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp index 3217a660..f308b0b5 100644 --- a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -8,7 +8,7 @@ #include /// @brief Internal call for syscall, to work with C++. -/// @param stack +/// @param stack /// @return nothing. EXTERN_C void rt_syscall_handle(NewOS::HAL::StackFrame* stack) { diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx index e78c350e..df7d5f28 100644 --- a/Kernel/KernelKit/DriveManager.hxx +++ b/Kernel/KernelKit/DriveManager.hxx @@ -14,10 +14,10 @@ #include #include -#define kDriveManagerCount (4U) +#define kDriveManagerCount (4U) -#define kDriveInvalidID (-1) -#define kDriveNameLen (32) +#define kDriveInvalidID (-1) +#define kDriveNameLen (32) namespace NewOS { diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index 71f3cfd0..b06b926e 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -134,7 +134,7 @@ namespace NewOS void SetDataFork(const char* forkName); /// @brief Get internal parser. - /// @return + /// @return NewFSParser* GetParser() noexcept; private: diff --git a/Kernel/KernelKit/Framebuffer.hpp b/Kernel/KernelKit/Framebuffer.hpp index 3437fed1..ebe983c8 100644 --- a/Kernel/KernelKit/Framebuffer.hpp +++ b/Kernel/KernelKit/Framebuffer.hpp @@ -39,7 +39,7 @@ namespace NewOS : fFrameBufferAddr(addr) { } - + ~Framebuffer() { } diff --git a/Kernel/KernelKit/KernelHeap.hpp b/Kernel/KernelKit/KernelHeap.hpp index 7b8cbc7c..6be94a63 100644 --- a/Kernel/KernelKit/KernelHeap.hpp +++ b/Kernel/KernelKit/KernelHeap.hpp @@ -37,8 +37,8 @@ namespace NewOS /// @return if it valid: point has crc now., otherwise fail. Boolean ke_protect_ke_heap(VoidPtr heapPtr); - /// @brief Makes a kernel heap page. - /// @param heapPtr - /// @return - Int32 ke_make_ke_page(VoidPtr heapPtr); + /// @brief Makes a kernel heap page. + /// @param heapPtr + /// @return + Int32 ke_make_ke_page(VoidPtr heapPtr); } // namespace NewOS diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 1ac19053..637fc8c4 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -162,8 +162,8 @@ namespace NewOS enum { - kAppKind = 1, - kShLibKind = 2, + kAppKind = 1, + kShLibKind = 2, kKindCount, }; @@ -231,14 +231,14 @@ namespace NewOS /// The main class which you call to schedule an app. class ProcessScheduler final { - explicit ProcessScheduler() = default; + explicit ProcessScheduler() = default; public: ~ProcessScheduler() = default; NEWOS_COPY_DEFAULT(ProcessScheduler) - operator bool(); + operator bool(); bool operator!(); public: diff --git a/Kernel/KernelKit/SMPManager.hpp b/Kernel/KernelKit/SMPManager.hpp index ba706cf6..1840dd20 100644 --- a/Kernel/KernelKit/SMPManager.hpp +++ b/Kernel/KernelKit/SMPManager.hpp @@ -99,8 +99,8 @@ namespace NewOS public: Ref operator[](const SizeT& idx); - bool operator!() noexcept; - operator bool() noexcept; + bool operator!() noexcept; + operator bool() noexcept; public: /// @brief Shared instance of the SMP Manager. diff --git a/Kernel/KernelKit/XCOFF.hxx b/Kernel/KernelKit/XCOFF.hxx index 4574fcf7..0d74b3ef 100644 --- a/Kernel/KernelKit/XCOFF.hxx +++ b/Kernel/KernelKit/XCOFF.hxx @@ -16,7 +16,7 @@ #include -#define cXCOFF64Magic (0x01F7) +#define cXCOFF64Magic (0x01F7) #define cXCOFFRelFlg (0x0001) #define cXCOFFExecutable (0x0002) @@ -41,10 +41,11 @@ typedef struct XCoffFileHeader #define cForkNameLen (255) /// @brief This the executable manifest fork. -typedef struct XCoffForkHeader { - NewOS::Char fPropertiesXMLFork[cForkNameLen]; - NewOS::Char fDynamicLoaderFork[cForkNameLen]; - NewOS::Char fCodeSignFork[cForkNameLen]; +typedef struct XCoffForkHeader +{ + NewOS::Char fPropertiesXMLFork[cForkNameLen]; + NewOS::Char fDynamicLoaderFork[cForkNameLen]; + NewOS::Char fCodeSignFork[cForkNameLen]; } XCoffForkHeader; #endif // ifndef __XCOFF__ diff --git a/Kernel/NetworkKit/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx index a00fa98e..72efae73 100644 --- a/Kernel/NetworkKit/IPCEP.hxx +++ b/Kernel/NetworkKit/IPCEP.hxx @@ -50,8 +50,8 @@ namespace NewOS IPCEPAddressType IpcFrom; IPCEPAddressType IpcTo; UInt32 IpcCRC32; - UInt32 IpcMsg; - UInt32 IpcMsgSz; + UInt32 IpcMsg; + UInt32 IpcMsgSz; } PACKED IPCEPConnectionHeader; } // namespace NewOS diff --git a/Kernel/NewKit/Array.hpp b/Kernel/NewKit/Array.hpp index dca5c13f..b0b94584 100644 --- a/Kernel/NewKit/Array.hpp +++ b/Kernel/NewKit/Array.hpp @@ -26,7 +26,6 @@ namespace NewOS if (At > N) return {}; - kcout << "Returning element\r"; return ErrorOr(&fArray[At]); } diff --git a/Kernel/NewKit/MutableArray.hpp b/Kernel/NewKit/MutableArray.hpp index a3ad4cb1..6be9c15e 100644 --- a/Kernel/NewKit/MutableArray.hpp +++ b/Kernel/NewKit/MutableArray.hpp @@ -173,8 +173,8 @@ namespace NewOS if (!iterationNode) { - fFirstNode = new MutableLinkedList(); - iterationNode = fFirstNode; + fFirstNode = new MutableLinkedList(); + iterationNode = fFirstNode; } MUST_PASS(iterationNode); diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 1f36d020..5ba02049 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -13,7 +13,7 @@ namespace NewOS /// @return if error-free: true, otherwise false. Boolean ke_bug_check(void) noexcept { - /// TODO: + /// TODO: return false; } } // namespace NewOS diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 9be8a026..58c76dc4 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -68,7 +68,7 @@ namespace NewOS::Detail } catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); + kNewFSCatalogKindDir); NewFork theFork{0}; @@ -157,8 +157,8 @@ namespace NewOS::Detail fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); fNewFS->GetParser()->WriteCatalog(catalogDisk, - (NewOS::VoidPtr)diskFolder.CData(), - kNewFSSectorSz, cSrcName); + (NewOS::VoidPtr)diskFolder.CData(), + kNewFSSectorSz, cSrcName); delete catalogDisk; } diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/KernelHeap.cxx index 00dfce8c..c3e8e86b 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/KernelHeap.cxx @@ -76,8 +76,8 @@ namespace NewOS } /// @brief Makes a page heap. - /// @param heapPtr - /// @return + /// @param heapPtr + /// @return Int32 ke_make_ke_page(VoidPtr heapPtr) { if (kHeapCount < 1) diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 683343ff..5002e880 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -110,8 +110,8 @@ namespace NewOS fStack->R11 = stack->R11; fStack->R10 = stack->R10; - fStack->R9 = stack->R9; - fStack->R8 = stack->R8; + fStack->R9 = stack->R9; + fStack->R8 = stack->R8; fStack->Rcx = this->fID; } @@ -219,7 +219,7 @@ namespace NewOS if (!fakeThread) { - fakeThread = new HardwareThread(); + fakeThread = new HardwareThread(); } fakeThread->fKind = kInvalidHart; diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/UserHeap.cxx index ad3c4aa4..d1de13a6 100644 --- a/Kernel/Sources/UserHeap.cxx +++ b/Kernel/Sources/UserHeap.cxx @@ -37,8 +37,8 @@ namespace NewOS */ class UserHeapManager final { - UserHeapManager() = delete; - + UserHeapManager() = delete; + public: ~UserHeapManager() = default; @@ -47,12 +47,12 @@ namespace NewOS { return s_NumPools; } - + STATIC Ref& Leak() { return s_Pmm; } - + STATIC Boolean& IsEnabled() { return s_PoolsAreEnabled; diff --git a/Usr/Sys/CoreSystem/Headers/Defines.h b/Usr/Sys/CoreSystem/Headers/Defines.h index 2c04c3f1..f659fa76 100644 --- a/Usr/Sys/CoreSystem/Headers/Defines.h +++ b/Usr/Sys/CoreSystem/Headers/Defines.h @@ -11,12 +11,12 @@ #endif #ifdef _DEBUG -#define CS_MUST_PASS(e) \ - { \ - if (!e) \ - { \ +#define CS_MUST_PASS(e) \ + { \ + if (!e) \ + { \ UiAlert("Assertion failed.\nExpression :%s\nFile: %s\nLine: %i", #e, __FILE__, __LINE__) RtAssertTriggerInterrupt() \ - } \ + } \ } #else #define CS_MUST_PASS(e) CS_UNREFERENCED_PARAMETER(e) @@ -124,7 +124,7 @@ typedef CharacterTypeUTF8 BooleanType; #define CS_CONSTEXPR #endif // __cplusplus -enum +enum { kCallAllocPtr = 1, kCallFreePtr, @@ -173,8 +173,7 @@ typedef struct ApplicationInterface { VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); - VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, - SizeType SzDst, struct GUID* GuidOf); + VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); } ApplicationInterface, *ApplicationInterfaceRef; #ifdef __cplusplus @@ -214,12 +213,12 @@ CS_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); /// @brief Get argument count /// @param /// @return -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); /// @brief Get argument pointer. /// @param /// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); /// @brief Shared application interface. CS_EXTERN_C ApplicationInterfaceRef kSharedApplication; diff --git a/Usr/Sys/CoreSystem/Headers/File.h b/Usr/Sys/CoreSystem/Headers/File.h index 66bc6549..12dfb033 100644 --- a/Usr/Sys/CoreSystem/Headers/File.h +++ b/Usr/Sys/CoreSystem/Headers/File.h @@ -51,7 +51,7 @@ CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); /// @brief Flush file /// @param refCS the file reference. -/// @return +/// @return CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); /// END OF FILE diff --git a/Usr/Sys/CoreSystem/Headers/Intl.h b/Usr/Sys/CoreSystem/Headers/Intl.h index c9eae306..afc7431c 100644 --- a/Usr/Sys/CoreSystem/Headers/Intl.h +++ b/Usr/Sys/CoreSystem/Headers/Intl.h @@ -14,12 +14,12 @@ typedef UInt64Type IntlRef; /// @brief Get app locale. /// @param name locale name. -/// @return -IntlRef IntlGetLocale(const char* name); +/// @return +IntlRef IntlGetLocale(const char* name); /// @brief Set app locale. /// @param intl the locale -/// @return +/// @return BooleanType IntlSetLocale(const IntlRef intl); /// @brief locale helpers. diff --git a/Usr/Sys/CoreSystem/Headers/Transport.h b/Usr/Sys/CoreSystem/Headers/Transport.h index 671621c8..996e69cc 100644 --- a/Usr/Sys/CoreSystem/Headers/Transport.h +++ b/Usr/Sys/CoreSystem/Headers/Transport.h @@ -28,19 +28,19 @@ CS_EXTERN_C CS_CONST TptStreamType CSOpenSocket(UInt32Type afType, UInt32Type so /// @brief Close a STREAMS socket. /// @param streams The streams socket. -/// @return +/// @return CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TptStreamType streams); /// @brief Get OpenTransport version. /// @param void -/// @return +/// @return CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); enum { TrSocketProtoTCP, /// TCP socket TrSocketProtoUDP, /// UDP socket - TrSocketProtoUN, /// IPC socket + TrSocketProtoUN, /// IPC socket TrSocketProtoRaw, /// Raw socket TrSocketProtoCount, }; diff --git a/Usr/Sys/CoreSystem/Sources/CRTStartup.c b/Usr/Sys/CoreSystem/Sources/CRTStartup.c index faefe9b7..2dc9b1c4 100644 --- a/Usr/Sys/CoreSystem/Sources/CRTStartup.c +++ b/Usr/Sys/CoreSystem/Sources/CRTStartup.c @@ -8,5 +8,5 @@ VoidType __DllMainCRTStartup(VoidType) { - kSharedApplication = RtGetAppPointer(); + kSharedApplication = RtGetAppPointer(); } \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/File.c b/Usr/Sys/CoreSystem/Sources/File.c index 9f6b3b35..2e34d782 100644 --- a/Usr/Sys/CoreSystem/Sources/File.c +++ b/Usr/Sys/CoreSystem/Sources/File.c @@ -19,7 +19,7 @@ enum FileOp /// @brief Opens a new file. /// @param path where to find it. /// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. +/// @return FSRef file reference. CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* rest) { @@ -33,7 +33,7 @@ CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, /// @brief Closes the file and flushes it to the said file. /// @param refCS the filesystem reference. -/// @return +/// @return void CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) { CS_MUST_PASS(kSharedApplication); @@ -45,7 +45,7 @@ CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) /// @brief Flush file /// @param refCS the file reference. -/// @return +/// @return void CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) { CS_MUST_PASS(kSharedApplication); @@ -54,16 +54,16 @@ CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) } /// @brief Check if filesystem path is valid. -/// @param path -/// @return +/// @param path the filesystem path. +/// @return if the path is valid or not. CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) { CS_MUST_PASS(kSharedApplication); CS_MUST_PASS(path); return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); + kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); } \ No newline at end of file -- cgit v1.2.3 From 479ee6ad453401f5ae7f46d3d91136753f0839e7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 13 Jun 2024 23:29:26 +0200 Subject: MHR-31: update kernel icon. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelRsrc.rsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index d4cb366f..5c166c13 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -1,4 +1,4 @@ -1 ICON "../Icons/kernel-logo.ico" +1 ICON "../Icons/bonjour-logo.ico" #include "CompilerKit/Version.hxx" -- cgit v1.2.3 From dd7b72379108c10cd68853d2a8a0332784ebb8cb Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Fri, 14 Jun 2024 09:58:11 +0200 Subject: Kernel: Scheduler: ProcessHeader::New: do not get the pointer before allocating it! Kernel: HAL: AMD64: Two things. - Switching to an ARM HAL for our Zeta platform. - Fix return register when sending acknowledge on APIC, which was using the 32-bit eax instead of rax. Kernel: Boot: Update uname for Windows. Kernel: GDT: move as global (HalKenelMain.cxx) Signed-off-by: Amlal EL Mahrouss --- Boot/makefile | 6 +++-- Kernel/HALKit/AMD64/HalInterruptAPI.asm | 4 +-- Kernel/HALKit/AMD64/HalKernelMain.cxx | 37 +++++++++++++-------------- Kernel/Sources/KeMain.cxx | 11 ++++++-- Kernel/Sources/ProcessScheduler.cxx | 45 ++++++++++++++++++--------------- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/Boot/makefile b/Boot/makefile index e54b1aa8..98726bbe 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -12,10 +12,12 @@ ADD_FILE=touch COPY=cp HTTP_GET=wget -ifneq ($(shell uname), Windows_NT) +# Select this for UNIX distributions +ifneq ($(shell uname), CYGWIN_NT-10.0-19045) EMU=qemu-system-x86_64 else -EMU=qemu-system-x86_64w +# this for NT distributions +EMU=qemu-system-x86_64w.exe endif ifeq ($(NEWS_MODEL), ) diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index 150cfc10..4832ecf3 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -157,10 +157,10 @@ __NEW_INT_32: pop rcx pop rax - mov eax, 0 + mov rax, 0 ;; tell there local apic that we're done. - mov dword [0xFEE00000 + 0xB0], eax ; LAPIC_EOI + mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI iretq diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 9b605e1a..cafa6388 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -28,9 +28,21 @@ namespace NewOS::HAL extern void hal_system_get_cores(NewOS::voidPtr rsdPtr); } // namespace NewOS::HAL +/* GDT constant. */ +STATIC NewOS::HAL::Detail::NewOSGDT cGdt = { + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xaf, 0}, // kernel code + {0, 0, 0, 0x92, 0xaf, 0}, // kernel data + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xaf, 0}, // user code + {0, 0, 0, 0x92, 0xaf, 0}, // user data +}; + EXTERN_C void hal_init_platform( NewOS::HEL::HandoverInformationHeader* HandoverHeader) { + /* Setup globals. */ + kHandoverHeader = HandoverHeader; if (kHandoverHeader->f_Magic != kHandoverMagic && @@ -39,29 +51,17 @@ EXTERN_C void hal_init_platform( return; } - /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = reinterpret_cast( reinterpret_cast(HandoverHeader->f_VirtualStart) + kVirtualAddressStartOffset); kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; - STATIC NewOS::HAL::Detail::NewOSGDT GDT = { - {0, 0, 0, 0x00, 0x00, 0}, // null entry - {0, 0, 0, 0x9a, 0xaf, 0}, // kernel code - {0, 0, 0, 0x92, 0xaf, 0}, // kernel data - {0, 0, 0, 0x00, 0x00, 0}, // null entry - {0, 0, 0, 0x9a, 0xaf, 0}, // user code - {0, 0, 0, 0x92, 0xaf, 0}, // user data - }; - NewOS::HAL::RegisterGDT gdtBase; - gdtBase.Base = reinterpret_cast(&GDT); + gdtBase.Base = reinterpret_cast(&cGdt); gdtBase.Limit = sizeof(NewOS::HAL::Detail::NewOSGDT) - 1; - /// Load GDT. - NewOS::HAL::GDTLoader gdt; gdt.Load(gdtBase); @@ -74,7 +74,7 @@ EXTERN_C void hal_init_platform( NewOS::HAL::IDTLoader idt; idt.Load(idtBase); - /// START POST + /* install basic hooks. */ constexpr auto cDummyInterrupt = 0x10; // 16 @@ -87,12 +87,9 @@ EXTERN_C void hal_init_platform( NewOS::HAL::Detail::_ke_power_on_self_test(); - auto cLoaderName = "LaunchDevil"; - NewOS::execute_from_image(KeMain, cLoaderName); + /* Call generic kernel entrypoint. */ - NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + KeMain(); - while (true) - { - } + NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 58c76dc4..23e32c1d 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -203,8 +203,6 @@ namespace NewOS::Detail NewOS::Utils::execute_from_image(stageBoard, NewOS::ProcessHeader::kAppKind); - - /// TODO: now jump to user mode using the HAL. } } // namespace NewOS::Detail @@ -217,4 +215,13 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) NewOS::Detail::FilesystemWizard wizard; // automatic. NewOS::Detail::SystemLauncher_Main(); + + // fetch system cores. + NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + + while (true) + { + // start scheduling. + NewOS::ProcessHelper::StartScheduling(); + } } diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index d9d013c6..dc273cf6 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -59,18 +59,20 @@ namespace NewOS VoidPtr ProcessHeader::New(const SizeT& sz) { - if (this->FreeMemory < 1) + if (this->HeapCursor) { - DbgLastError() = kErrorHeapOutOfMemory; - this->Crash(); /// out of memory. + if (this->FreeMemory < 1) + { + DbgLastError() = kErrorHeapOutOfMemory; + + /* we're going out of memory */ + this->Crash(); - return nullptr; - } + return nullptr; + } - if (this->HeapCursor) - { - VoidPtr ptr = this->HeapCursor; this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); + VoidPtr ptr = this->HeapCursor; ++this->UsedMemory; --this->FreeMemory; @@ -206,12 +208,14 @@ namespace NewOS ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); MUST_PASS(process.Leak().StackFrame); + + process.Leak().Status = ProcessStatus::kRunning; - mTeam.AsArray().Add(process); - - process.Leak().ProcessId = mTeam.AsArray().Count() - 1; + process.Leak().ProcessId = (mTeam.AsArray().Count() - 1); process.Leak().HeapCursor = process.Leak().HeapPtr; + mTeam.AsArray().Add(process); + return mTeam.AsArray().Count() - 1; } @@ -232,17 +236,14 @@ namespace NewOS /// @return SizeT ProcessScheduler::Run() noexcept { - SizeT processIndex = 0; //! we store this guy to tell the scheduler how many + SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - for (; processIndex < mTeam.AsArray().Count(); ++processIndex) + for (; process_index < mTeam.AsArray().Count(); ++process_index) { - auto process = mTeam.AsArray()[processIndex]; - - if (!process) - continue; + auto process = mTeam.AsArray()[process_index]; - //! run any process needed to be scheduled. + //! check if process needs to be scheduled. if (ProcessHelper::CanBeScheduled(process.Leak())) { auto unwrapped_process = *process.Leak(); @@ -255,6 +256,8 @@ namespace NewOS // tell helper to find a core to schedule on. ProcessHelper::Switch(mTeam.AsRef().Leak().StackFrame, mTeam.AsRef().Leak().ProcessId); + + kcout << unwrapped_process.Name << ": process switched.\r"; } else { @@ -263,7 +266,7 @@ namespace NewOS } } - return processIndex; + return process_index; } /// @brief Gets the current scheduled team. @@ -328,8 +331,8 @@ namespace NewOS bool ProcessHelper::StartScheduling() { - auto& processRef = ProcessScheduler::The().Leak(); - SizeT ret = processRef.Run(); + auto& process_ref = ProcessScheduler::The().Leak(); + SizeT ret = process_ref.Run(); kcout << "newoskrnl: Iterated over: "; kcout.Number(ret); -- cgit v1.2.3 From f284646368823ffa88aa411d302f02421df2f5b2 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Fri, 14 Jun 2024 15:56:45 +0200 Subject: MHR-31: Focusing on ARM support for upcoming product. Signed-off-by: Amlal EL Mahrouss --- .gitignore | 1 + Drv/SampleDriver/CheckStck.c | 11 +++++++++++ Drv/SampleDriver/SampleDriver.c | 6 ------ Kernel/HALKit/ARM64/Hart.hxx | 7 +++++++ Kernel/makefile | 6 +++++- Meta/Zeta.pdf | Bin 0 -> 34775 bytes 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 Drv/SampleDriver/CheckStck.c create mode 100644 Kernel/HALKit/ARM64/Hart.hxx create mode 100644 Meta/Zeta.pdf diff --git a/.gitignore b/.gitignore index 13f452e4..c0f62932 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ cmake_install.cmake qtcsettings.cmake *.exec +*.rom NvVars diff --git a/Drv/SampleDriver/CheckStck.c b/Drv/SampleDriver/CheckStck.c new file mode 100644 index 00000000..3eb157ba --- /dev/null +++ b/Drv/SampleDriver/CheckStck.c @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +///! @brief Use this to check your stack, if using MinGW/MSVC/CodeTools. +void ___chkstk_ms(void) +{ + (void)0; +} diff --git a/Drv/SampleDriver/SampleDriver.c b/Drv/SampleDriver/SampleDriver.c index 94d5635b..85bd8d54 100644 --- a/Drv/SampleDriver/SampleDriver.c +++ b/Drv/SampleDriver/SampleDriver.c @@ -18,9 +18,3 @@ int __ImageEnd(void) kernelPrintStr("SampleDriver: Shutting down...\r"); return 0; } - -///! @brief Use this to check your stack, if using MinGW/MSVC. -void ___chkstk_ms(void) -{ - (void)0; -} diff --git a/Kernel/HALKit/ARM64/Hart.hxx b/Kernel/HALKit/ARM64/Hart.hxx new file mode 100644 index 00000000..0146ad8c --- /dev/null +++ b/Kernel/HALKit/ARM64/Hart.hxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#pragma once diff --git a/Kernel/makefile b/Kernel/makefile index 97804c20..16a36013 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -11,6 +11,8 @@ CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fn ASM = nasm +DISKDRIVER = -D__ATA_PIO__ + ifneq ($(ATA_PIO_SUPPORT), ) DISKDRIVER = -D__ATA_PIO__ endif @@ -23,7 +25,7 @@ ifneq ($(AHCI_SUPPORT), ) DISKDRIVER = -D__AHCI__ endif -ifneq ($(DEBUG_SUPPORT), ) +ifeq ($(RELEASE_SUPPORT), ) DEBUG = -D__DEBUG__ endif @@ -69,6 +71,8 @@ link-amd64-epm: .PHONY: all all: newos-amd64-epm link-amd64-epm + qemu-img create -f raw newoskrnl.rom 512K + dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc @echo "NewOSKrnl => OK." .PHONY: help diff --git a/Meta/Zeta.pdf b/Meta/Zeta.pdf new file mode 100644 index 00000000..2a4adfb9 Binary files /dev/null and b/Meta/Zeta.pdf differ -- cgit v1.2.3 From 058fec6d8ef07a0c1c5f4408ef84b92c6badf3ec Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Fri, 14 Jun 2024 16:03:54 +0200 Subject: MHR-31: Update PDF. Signed-off-by: Amlal EL Mahrouss --- Meta/Zeta.pdf | Bin 34775 -> 35727 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Meta/Zeta.pdf b/Meta/Zeta.pdf index 2a4adfb9..f29b5954 100644 Binary files a/Meta/Zeta.pdf and b/Meta/Zeta.pdf differ -- cgit v1.2.3 From a7091202dab1d4a3fcfa15ecb0f1f0b2c28d0957 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Fri, 14 Jun 2024 23:46:50 +0200 Subject: MHR-31: Working on SMP for ARM64, implementing HAL for ARM64 based Zeta machines. Signed-off-by: Amlal EL Mahrouss --- Kernel/FSKit/FAT32.hxx | 12 ++++++++++++ Kernel/FSKit/IndexableProperty.hxx | 3 ++- Kernel/HALKit/ARM64/Hart.hxx | 13 +++++++++++++ Kernel/HALKit/ARM64/MBCI/.keepme | 0 Kernel/HALKit/POWER/Hart.hxx | 6 ++++++ Kernel/HALKit/RISCV/Hart.hxx | 6 ++++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Kernel/FSKit/FAT32.hxx create mode 100644 Kernel/HALKit/ARM64/MBCI/.keepme diff --git a/Kernel/FSKit/FAT32.hxx b/Kernel/FSKit/FAT32.hxx new file mode 100644 index 00000000..4aa0fc2b --- /dev/null +++ b/Kernel/FSKit/FAT32.hxx @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#pragma once + +#include + +/// @file FAT32.hxx +/// @brief FAT32 support. \ No newline at end of file diff --git a/Kernel/FSKit/IndexableProperty.hxx b/Kernel/FSKit/IndexableProperty.hxx index ef742a8e..91b90903 100644 --- a/Kernel/FSKit/IndexableProperty.hxx +++ b/Kernel/FSKit/IndexableProperty.hxx @@ -28,9 +28,10 @@ namespace NewOS { public: explicit IndexableProperty() - : Property(StringBuilder::Construct("IndexableProperty").Leak().Leak()) + : Property(StringBuilder::Construct("Indexable").Leak().Leak()) { } + ~IndexableProperty() override = default; NEWOS_COPY_DEFAULT(IndexableProperty); diff --git a/Kernel/HALKit/ARM64/Hart.hxx b/Kernel/HALKit/ARM64/Hart.hxx index 0146ad8c..bc35c3f5 100644 --- a/Kernel/HALKit/ARM64/Hart.hxx +++ b/Kernel/HALKit/ARM64/Hart.hxx @@ -5,3 +5,16 @@ ------------------------------------------- */ #pragma once + +#include + +/// @file HALKit\ARM64\Hart.hxx +/// @brief ARM64 hardware thread concept. + +typedef NewOS::Int32 Arm64HartType; + +/// @brief Set PC to specific hart. +/// @param hart the hart +/// @param epc the pc. +/// @return +EXTERN_C NewOS::Void hal_switch_to_hart(Arm64HartType hart, NewOS::VoidPtr epc); \ No newline at end of file diff --git a/Kernel/HALKit/ARM64/MBCI/.keepme b/Kernel/HALKit/ARM64/MBCI/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/HALKit/POWER/Hart.hxx b/Kernel/HALKit/POWER/Hart.hxx index 4e4a281b..10066048 100644 --- a/Kernel/HALKit/POWER/Hart.hxx +++ b/Kernel/HALKit/POWER/Hart.hxx @@ -26,3 +26,9 @@ typedef struct HalHardwareThread NewOS::UInt32 fPageFlags; PPCHartType fIdentNumber; } HalHardwareThread; + +/// @brief Set PC to specific hart. +/// @param hart the hart +/// @param epc the pc. +/// @return +EXTERN_C NewOS::Void hal_switch_to_hart(HalHardwareThread* hart, NewOS::VoidPtr epc); \ No newline at end of file diff --git a/Kernel/HALKit/RISCV/Hart.hxx b/Kernel/HALKit/RISCV/Hart.hxx index 17ec84a1..ba56b7c9 100644 --- a/Kernel/HALKit/RISCV/Hart.hxx +++ b/Kernel/HALKit/RISCV/Hart.hxx @@ -16,3 +16,9 @@ #include typedef NewOS::Int32 Rv64HartType; + +/// @brief Set PC to specific hart. +/// @param hart the hart +/// @param epc the pc. +/// @return +EXTERN_C NewOS::Void hal_switch_to_hart(Rv64HartType hart, NewOS::VoidPtr epc); \ No newline at end of file -- cgit v1.2.3 From ce11c1a5252f7cbb52ebecff41522f3c4a30525a Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 15 Jun 2024 09:07:52 +0200 Subject: MHR-31: Updated PDF. Signed-off-by: Amlal EL Mahrouss --- Meta/Zeta.pdf | Bin 35727 -> 35543 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Meta/Zeta.pdf b/Meta/Zeta.pdf index f29b5954..238f6f78 100644 Binary files a/Meta/Zeta.pdf and b/Meta/Zeta.pdf differ -- cgit v1.2.3 From 1efed3cbec879134d55aee8e13c6bbc6da9b6ef6 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 15 Jun 2024 09:38:25 +0200 Subject: MHR-31: Changes related to ARM64/AMD64: This is the last commit regarding AMD64 support, focusing on ARM64 now. Signed-off-by: Amlal EL Mahrouss --- Boot/Sources/ovmf.ps1 | 4 -- Boot/download-ovmf.ps1 | 4 ++ .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 7 +--- Kernel/HALKit/AMD64/HalHart.cpp | 12 ++++-- Kernel/HALKit/AMD64/HalKernelMouse.cxx | 2 +- Kernel/HALKit/AMD64/HalSMPCoreManager.asm | 48 ++++++---------------- Kernel/KernelRsrc.rsrc | 2 +- ReadMe.md | 2 +- 8 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 Boot/Sources/ovmf.ps1 create mode 100644 Boot/download-ovmf.ps1 diff --git a/Boot/Sources/ovmf.ps1 b/Boot/Sources/ovmf.ps1 deleted file mode 100644 index 5a2c5f0e..00000000 --- a/Boot/Sources/ovmf.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -$client = new-object System.Net.WebClient -$output = "$PSScriptRoot\OVMF.fd" - -$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output) diff --git a/Boot/download-ovmf.ps1 b/Boot/download-ovmf.ps1 new file mode 100644 index 00000000..5a2c5f0e --- /dev/null +++ b/Boot/download-ovmf.ps1 @@ -0,0 +1,4 @@ +$client = new-object System.Net.WebClient +$output = "$PSScriptRoot\OVMF.fd" + +$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output) diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 37a681ab..26773640 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #define kAPIC_ICR_Low 0x300 #define kAPIC_ICR_High 0x310 @@ -184,11 +185,7 @@ namespace NewOS::HAL { Semaphore sem; - while (sem.IsLocked()) - { - } - - sem.Lock(&ProcessScheduler::The().Leak().GetCurrent().Leak()); + sem.LockOrWait(&ProcessScheduler::The().Leak().GetCurrent().Leak(), Seconds(5)); cFramePtr = stackFrame; diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cpp index 92e075aa..069f3767 100644 --- a/Kernel/HALKit/AMD64/HalHart.cpp +++ b/Kernel/HALKit/AMD64/HalHart.cpp @@ -16,15 +16,19 @@ namespace NewOS { HAL::rt_cli(); + rt_do_context_switch(stack); + HAL::rt_sti(); } - /// @brief makes thread sleep. + /// @brief makes the thread sleep on a loop. /// hooks and hangs thread to prevent code from executing. void rt_hang_thread(HAL::StackFrame* stack) { - HAL::rt_cli(); - - HAL::rt_sti(); + while (true) + { + /* nohing, code is spinning */ + } + } } // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalKernelMouse.cxx b/Kernel/HALKit/AMD64/HalKernelMouse.cxx index 8dbd328a..5d50e4f2 100644 --- a/Kernel/HALKit/AMD64/HalKernelMouse.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMouse.cxx @@ -10,7 +10,7 @@ #include #include -// forward decl. +/// @note forward decl. EXTERN_C NewOS::Boolean _hal_draw_mouse(); EXTERN_C NewOS::Void _hal_init_mouse(); diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm index c4042b50..320120a4 100644 --- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm +++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm @@ -22,59 +22,37 @@ 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 + push rax - jmp _hal_switch_context + call _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 + push rax + jmp _hal_leak_current_context - mov rdx, rax - pop rdx + + mov rax, r9 + pop rax + + mov r9, rax + retfq ;; @brief enables a smp core to run. _hal_enable_smp: -; Read the APIC base MSR + ; Read the APIC base MSR mov ecx, 0x1B ; IA32_APIC_BASE MSR rdmsr + ; Enable the APIC by setting bit 11 (APIC Global Enable) or rdx, 0x800 + ; Set the base address (0xFEE00000) mov eax, 0xFEE shl rax, 12 diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index 5c166c13..39b3070a 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -11,7 +11,7 @@ BEGIN BLOCK "080904E4" BEGIN VALUE "CompanyName", "Zeta Electronics Corporation" - VALUE "FileDescription", "NuX/OS kernel." + VALUE "FileDescription", "Zeta OS kernel." VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "NeXUS" VALUE "LegalCopyright", "Zeta Electronics Corporation" diff --git a/ReadMe.md b/ReadMe.md index df4685a9..1164bfb0 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,4 +1,4 @@ - +

-- cgit v1.2.3 From 999877265276c8a5ae78eb01c92d1d9928a13576 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 15 Jun 2024 11:07:19 +0200 Subject: MHR-31: ARM Support: Removing API from repository. Signed-off-by: Amlal EL Mahrouss --- Meta/Zeta.pdf | Bin 35543 -> 28882 bytes Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx | 6 +- Usr/Sys/CoreSystem/.gitkeep | 0 Usr/Sys/CoreSystem/AMD64/CoreAssembly.s | 28 --- Usr/Sys/CoreSystem/ARM64/.gitkeep | 0 Usr/Sys/CoreSystem/Headers/Alert.h | 25 --- Usr/Sys/CoreSystem/Headers/Defines.h | 240 -------------------------- Usr/Sys/CoreSystem/Headers/File.h | 57 ------ Usr/Sys/CoreSystem/Headers/Heap.h | 39 ----- Usr/Sys/CoreSystem/Headers/Hint.h | 20 --- Usr/Sys/CoreSystem/Headers/Intl.h | 29 ---- Usr/Sys/CoreSystem/Headers/Math.h | 27 --- Usr/Sys/CoreSystem/Headers/Rsrc.h | 12 -- Usr/Sys/CoreSystem/Headers/Thread.h | 47 ----- Usr/Sys/CoreSystem/Headers/Transport.h | 48 ------ Usr/Sys/CoreSystem/POWER/CoreAssembly.s | 23 --- Usr/Sys/CoreSystem/Private.xml | 4 - Usr/Sys/CoreSystem/RISCV/.gitkeep | 0 Usr/Sys/CoreSystem/ReadMe.md | 13 -- Usr/Sys/CoreSystem/Sources/App.c | 31 ---- Usr/Sys/CoreSystem/Sources/CRTStartup.c | 12 -- Usr/Sys/CoreSystem/Sources/File.c | 69 -------- Usr/Sys/CoreSystem/Sources/Heap.c | 54 ------ Usr/Sys/CoreSystem/Sources/Math.c | 14 -- Usr/Sys/CoreSystem/Sources/Thread.c | 9 - Usr/Sys/CoreSystem/amd64.mk | 22 --- Usr/Sys/CoreSystem/compile_flags.txt | 4 - 27 files changed, 3 insertions(+), 830 deletions(-) delete mode 100644 Usr/Sys/CoreSystem/.gitkeep delete mode 100644 Usr/Sys/CoreSystem/AMD64/CoreAssembly.s delete mode 100644 Usr/Sys/CoreSystem/ARM64/.gitkeep delete mode 100644 Usr/Sys/CoreSystem/Headers/Alert.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Defines.h delete mode 100644 Usr/Sys/CoreSystem/Headers/File.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Heap.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Hint.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Intl.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Math.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Rsrc.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Thread.h delete mode 100644 Usr/Sys/CoreSystem/Headers/Transport.h delete mode 100644 Usr/Sys/CoreSystem/POWER/CoreAssembly.s delete mode 100644 Usr/Sys/CoreSystem/Private.xml delete mode 100644 Usr/Sys/CoreSystem/RISCV/.gitkeep delete mode 100644 Usr/Sys/CoreSystem/ReadMe.md delete mode 100644 Usr/Sys/CoreSystem/Sources/App.c delete mode 100644 Usr/Sys/CoreSystem/Sources/CRTStartup.c delete mode 100644 Usr/Sys/CoreSystem/Sources/File.c delete mode 100644 Usr/Sys/CoreSystem/Sources/Heap.c delete mode 100644 Usr/Sys/CoreSystem/Sources/Math.c delete mode 100644 Usr/Sys/CoreSystem/Sources/Thread.c delete mode 100644 Usr/Sys/CoreSystem/amd64.mk delete mode 100644 Usr/Sys/CoreSystem/compile_flags.txt diff --git a/Meta/Zeta.pdf b/Meta/Zeta.pdf index 238f6f78..339651d5 100644 Binary files a/Meta/Zeta.pdf and b/Meta/Zeta.pdf differ diff --git a/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx b/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx index cd864c70..8941274a 100644 --- a/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx +++ b/Usr/Sys/CoreCxxRuntime/Sources/New+Delete.cxx @@ -13,7 +13,7 @@ void* operator new[](size_t sz) if (sz == 0) ++sz; - return RtHeapAllocate(sz, kStandardAllocation); + return CSAllocateHeap(sz, kStandardAllocation); } void* operator new(size_t sz) @@ -21,7 +21,7 @@ void* operator new(size_t sz) if (sz == 0) ++sz; - return RtHeapAllocate(sz, kArrayAllocation); + return CSAllocateHeap(sz, kArrayAllocation); } void operator delete[](void* ptr) @@ -29,5 +29,5 @@ void operator delete[](void* ptr) if (ptr == nullptr) return; - RtHeapFree(ptr); + CSFreeHeap(ptr); } \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/.gitkeep b/Usr/Sys/CoreSystem/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s b/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s deleted file mode 100644 index a2cf12f1..00000000 --- a/Usr/Sys/CoreSystem/AMD64/CoreAssembly.s +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - - Purpose: AMD64 low level I/O - -------------------------------------------- */ - -.text - -.globl RtGetAppPointer -.globl RtAssertTriggerInterrupt - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -RtGetAppPointer: - mov $0x10, %rcx /* sysGetProcessObject */ - int $0x32 - - /* rax gets saved and returned. */ - ret - -RtAssertTriggerInterrupt: - mov $0x11, %rcx /* sysTerminateCurrentProcess */ - int $0x32 - - ret - diff --git a/Usr/Sys/CoreSystem/ARM64/.gitkeep b/Usr/Sys/CoreSystem/ARM64/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Usr/Sys/CoreSystem/Headers/Alert.h b/Usr/Sys/CoreSystem/Headers/Alert.h deleted file mode 100644 index 3b2922d2..00000000 --- a/Usr/Sys/CoreSystem/Headers/Alert.h +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -/************************************************************* - * - * File: Alert.h - * Purpose: New OS alert dialog. - * Date: 3/26/24 - * - * Copyright Zeta Electronics Corporation, all rights reserved. - * - *************************************************************/ - -#pragma once - -#include - -/// @brief Shows an alert box, as provided by the OS. -/// @param fmt The alert formating. -/// @param -/// @return -CS_EXTERN_C VoidType UiAlert(const CharacterTypeUTF8* fmt, ...); diff --git a/Usr/Sys/CoreSystem/Headers/Defines.h b/Usr/Sys/CoreSystem/Headers/Defines.h deleted file mode 100644 index f659fa76..00000000 --- a/Usr/Sys/CoreSystem/Headers/Defines.h +++ /dev/null @@ -1,240 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#ifdef CS_MUST_PASS -#undef CS_MUST_PASS -#endif - -#ifdef _DEBUG -#define CS_MUST_PASS(e) \ - { \ - if (!e) \ - { \ - UiAlert("Assertion failed.\nExpression :%s\nFile: %s\nLine: %i", #e, __FILE__, __LINE__) RtAssertTriggerInterrupt() \ - } \ - } -#else -#define CS_MUST_PASS(e) CS_UNREFERENCED_PARAMETER(e) -#endif - -#ifdef __cplusplus - -#define CS_EXTERN_C extern "C" - -#else - -#define CS_EXTERN_C extern - -#endif - -#include - -struct ApplicationInterface; -struct GUID; - -CS_EXTERN_C void RtAssertTriggerInterrupt(void); - -#define CS_STDCALL __attribute__((stdcall)) -#define CS_CDECL __attribute__((cdecl)) -#define CS_MSCALL __attribute__((ms_abi)) - -#define PACKED __attribute__((packed)) - -#define CS_PASCAL CS_STDCALL - -#include - -typedef __UINT8_TYPE__ ByteType; -typedef __UINT16_TYPE__ WordType; -typedef __UINT32_TYPE__ DWordType; -typedef __UINT64_TYPE__ QWordType; -typedef __SIZE_TYPE__ SizeType; - -typedef char CharacterTypeUTF8; -typedef CharacterTypeUTF8* PtrCharacterType; - -typedef void* PtrVoidType; -typedef void VoidType; - -#ifdef __SINGLE_PRECISION__ -typedef float FloatType; -typedef float PositionType; -#else -typedef double FloatType; -typedef double PositionType; -#endif - -typedef __UINTPTR_TYPE__ UIntPtrType; -typedef __INTPTR_TYPE__ IntPtrType; -typedef __UINT64_TYPE__ UInt64Type; -typedef __INT64_TYPE__ Int64Type; -typedef __UINT32_TYPE__ UInt32Type; -typedef __INT32_TYPE__ Int32Type; - -typedef CharacterTypeUTF8 BooleanType; - -#define Yes 1 -#define No 0 - -#define CS_PTR * - -#define CS_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) - -#ifdef __x86_64__ - -#define CS_FAR __far -#define CS_NEAR __near - -#define _M_AMD64 2 -#else - -#define CS_FAR -#define CS_NEAR - -#endif - -#ifdef __aarch64__ -#define _M_AARCH64 3 -#endif - -#ifdef __powerpc64__ -#define _M_PPC64 4 -#endif - -#ifdef __64x0__ -#define _M_64000 5 -#endif - -#ifdef __riscv__ -#define _M_RISCV 6 -#endif - -#define CS_STATIC static -#define CS_INLINE inline -#define CS_CONST const - -#ifdef __cplusplus -#define CS_CONSTEXPR constexpr -#else -#define CS_CONSTEXPR -#endif // __cplusplus - -enum -{ - kCallAllocPtr = 1, - kCallFreePtr, - kCallSizePtr, - kCallCheckPtr, - kCallAllocStack, - /// @brief Open a specific handle - /// (can be used as sel to call methods related to it.) - kCallOpenFile, - kCallCloseFile, - kCallOpenDir, - kCallCloseDir, - kCallOpenDevice, - kCallCloseDevice, - kCallCreateWindow, - kCallCloseWindow, - kCallCreateMenu, - kCallCloseMenu, - kCallRandomNumberGenerator, - kCallGetArgsCount, - kCallGetArgsPtr, - kCallFileExists, - kCallDirectoryExists, - kCallSymlinkExists, - kCallDeviceExists, - kCallDriveExists, - /// @brief Number of process calls. - kCallCount, -}; - -/** - * @brief GUID type, something you can also find in CFKit. - * @author Amlal El Mahrouss - */ -typedef struct GUID -{ - DWordType Data1; - WordType Data2; - WordType Data3; - ByteType Data4[8]; -} GUIDType, *PtrGUIDType; - -/// \brief Application Interface. -/// \author Amlal El Mahrouss -typedef struct ApplicationInterface -{ - VoidType (*Release)(struct ApplicationInterface* Self, DWordType ExitCode); - IntPtrType (*Invoke)(struct ApplicationInterface* Self, DWordType Sel, ...); - VoidType (*Query)(struct ApplicationInterface* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); -} ApplicationInterface, *ApplicationInterfaceRef; - -#ifdef __cplusplus - -#define CS_COPY_DELETE(KLASS) \ - KLASS& operator=(const KLASS&) = delete; \ - KLASS(const KLASS&) = delete; - -#define CS_COPY_DEFAULT(KLASS) \ - KLASS& operator=(const KLASS&) = default; \ - KLASS(const KLASS&) = default; - -#define CS_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ - KLASS(KLASS&&) = delete; - -#define CS_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ - KLASS(KLASS&&) = default; - -#define app_cast reinterpret_cast - -template -using StrType = CharacterTypeUTF8[N]; - -#else - -#define app_cast(X) (ApplicationInterfaceRef)(X) - -#endif // ifdef C++ - -/// @brief Get app singleton. -/// @param -/// @return -CS_EXTERN_C ApplicationInterfaceRef RtGetAppPointer(VoidType); - -/// @brief Get argument count -/// @param -/// @return -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType); - -/// @brief Get argument pointer. -/// @param -/// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType); - -/// @brief Shared application interface. -CS_EXTERN_C ApplicationInterfaceRef kSharedApplication; - -/// @brief 255 length string type. -typedef CharacterTypeUTF8 StrType255[255]; - -#define True 1 -#define False 0 -#define Bool BooleanType - -#define NullPtr ((PtrVoidType)0) - -#ifndef kInvalidRef -#define kInvalidRef 0 -#endif - -/// @brief Result type. -typedef UInt64Type ResultType; diff --git a/Usr/Sys/CoreSystem/Headers/File.h b/Usr/Sys/CoreSystem/Headers/File.h deleted file mode 100644 index 12dfb033..00000000 --- a/Usr/Sys/CoreSystem/Headers/File.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include - -#define kMaxForkNameLength (256U) /* long fork names. */ - -struct _Fork; - -/// @brief Filesystem wrapper. - -typedef QWordType FSRef; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef the file. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS); - -/// @brief A fork information header. -typedef struct _Fork -{ - Int32Type forkFlags; - Int32Type forkKind; - CharacterTypeUTF8 forkName[kMaxForkNameLength]; - SizeType forkSize; - CharacterTypeUTF8 forkData[]; -} ForkType, ForkTypePtr; - -typedef ForkType* FSForkRef; - -/// @brief Gets the fork inside a file. -/// @param refCS the filesystem ref -/// @param forkName the fork's name -/// @return the fork data. -CS_EXTERN_C FSForkRef CSGetFork(FSRef refCS, const CharacterTypeUTF8* forkName); - -/// @brief Check if the filesystem path is valid. -/// @return if not return false, or true. -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path); - -/// @brief Flush file -/// @param refCS the file reference. -/// @return -CS_EXTERN_C VoidType CSFlushFile(FSRef refCS); - -/// END OF FILE diff --git a/Usr/Sys/CoreSystem/Headers/Heap.h b/Usr/Sys/CoreSystem/Headers/Heap.h deleted file mode 100644 index afb8e6e4..00000000 --- a/Usr/Sys/CoreSystem/Headers/Heap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include - -#define cAllocationKindCount (2U) - -enum CsAllocationKind -{ - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -/// @brief Allocates a new pointer from process pool. -/// @param sz the size -/// @param flags the allocation flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, - DWordType flags); - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr); - -/// @brief Gets the size of the process' pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr); - -/// @brief Frees the process pointer. -/// @param ptr the pointer to free. -/// @return -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr); diff --git a/Usr/Sys/CoreSystem/Headers/Hint.h b/Usr/Sys/CoreSystem/Headers/Hint.h deleted file mode 100644 index db582035..00000000 --- a/Usr/Sys/CoreSystem/Headers/Hint.h +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/Usr/Sys/CoreSystem/Headers/Intl.h b/Usr/Sys/CoreSystem/Headers/Intl.h deleted file mode 100644 index afc7431c..00000000 --- a/Usr/Sys/CoreSystem/Headers/Intl.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -/// @brief Intlization primitives. - -#include - -typedef UInt64Type IntlRef; - -/// @brief Get app locale. -/// @param name locale name. -/// @return -IntlRef IntlGetLocale(const char* name); - -/// @brief Set app locale. -/// @param intl the locale -/// @return -BooleanType IntlSetLocale(const IntlRef intl); - -/// @brief locale helpers. - -/// @brief translate a string from a locale. -const CharacterTypeUTF8* Intl(const CharacterTypeUTF8* input, - const IntlRef locale); diff --git a/Usr/Sys/CoreSystem/Headers/Math.h b/Usr/Sys/CoreSystem/Headers/Math.h deleted file mode 100644 index e3a203dc..00000000 --- a/Usr/Sys/CoreSystem/Headers/Math.h +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include - -/////////////////////////////////////////////////////////////////////// -/// Random number generators functions /// -/////////////////////////////////////////////////////////////////////// - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType); - -/////////////////////////////////////////////////////////////////////// -/// Mathematical functions /// -/////////////////////////////////////////////////////////////////////// - -CS_EXTERN_C FloatType Sqrt(FloatType number); - -CS_EXTERN_C FloatType Cosine(FloatType number); -CS_EXTERN_C FloatType Sine(FloatType number); -CS_EXTERN_C FloatType Tangent(FloatType number); \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Headers/Rsrc.h b/Usr/Sys/CoreSystem/Headers/Rsrc.h deleted file mode 100644 index fafdcc7c..00000000 --- a/Usr/Sys/CoreSystem/Headers/Rsrc.h +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Rsrc.h -/// @brief RXML forks. \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Headers/Thread.h b/Usr/Sys/CoreSystem/Headers/Thread.h deleted file mode 100644 index 26b6477f..00000000 --- a/Usr/Sys/CoreSystem/Headers/Thread.h +++ /dev/null @@ -1,47 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -// -// Created by Amlal on 3/18/24 -// - -#ifndef __THREAD__ -#define __THREAD__ - -#include - -#define kThreadErrorExit (-33) - -/// @brief Thread reference. -typedef QWordType ThreadRef; - -/// @brief Main application thread. -CS_EXTERN_C ThreadRef kMainThread; - -typedef VoidType (*ThreadEntrypointKind)(VoidType); - -/// @brief Creates a new thread, and runs the code. -/// @param threadName the thread's name. -/// @param threadStart where to start. -/// @return -CS_EXTERN_C ThreadRef CSThreadCreate(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); - -/// @brief Dispoes the thread, and exits with code kThreadErrorExit -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadRelease(ThreadRef ref); - -/// @brief Waits for the thread to complete. -/// @param ref the thread reference. -/// @return nothing. -CS_EXTERN_C VoidType CSThreadJoin(ThreadRef ref); - -/// @brief Yields the current thread. -/// @param ref the thead reference. -/// @return -CS_EXTERN_C VoidType CSThreadYield(ThreadRef ref); - -#endif // __THREAD__ diff --git a/Usr/Sys/CoreSystem/Headers/Transport.h b/Usr/Sys/CoreSystem/Headers/Transport.h deleted file mode 100644 index 996e69cc..00000000 --- a/Usr/Sys/CoreSystem/Headers/Transport.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -// -// Created by Amlal on 5/12/24 -// - -#ifndef __TRANSPORT__ -#define __TRANSPORT__ - -/// @file: Transport.h -/// @brief Open Transport Layer, an alternative to berkeley sockets. - -#include - -typedef QWordType TptStreamType; - -/// @brief Opens a new socket -/// @param afType address family -/// @param sockType type of socket -/// @param sockProto socket protocol. -/// @return The STREAMS socket. -/// @note return is const. -CS_EXTERN_C CS_CONST TptStreamType CSOpenSocket(UInt32Type afType, UInt32Type sockType, UInt32Type sockProto); - -/// @brief Close a STREAMS socket. -/// @param streams The streams socket. -/// @return -CS_EXTERN_C VoidType CSCloseSocket(CS_CONST TptStreamType streams); - -/// @brief Get OpenTransport version. -/// @param void -/// @return -CS_EXTERN_C CS_CONST Int32Type CSGetVersion(VoidType); - -enum -{ - TrSocketProtoTCP, /// TCP socket - TrSocketProtoUDP, /// UDP socket - TrSocketProtoUN, /// IPC socket - TrSocketProtoRaw, /// Raw socket - TrSocketProtoCount, -}; - -#endif // __TRANSPORT__ \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/POWER/CoreAssembly.s b/Usr/Sys/CoreSystem/POWER/CoreAssembly.s deleted file mode 100644 index 3262cbb4..00000000 --- a/Usr/Sys/CoreSystem/POWER/CoreAssembly.s +++ /dev/null @@ -1,23 +0,0 @@ -; /* ------------------------------------------- -; -; Copyright Zeta Electronics Corporation -; -; Purpose: POWER low level I/O -; -; ------------------------------------------- */ - -/* @brief Application getter */ -/* @throws: ApptError: appartement error. */ -export .code64 RtGetAppPointer: - mflr r3 - stw 0x10, 0(r3) /* sysGetProcessObject */ - sc - - blr - -export .code64 RtAssertTriggerInterrupt: - mflr r3 - stw 0x11, 0(r3) /* sysTerminateCurrentProcess */ - sc - - blr diff --git a/Usr/Sys/CoreSystem/Private.xml b/Usr/Sys/CoreSystem/Private.xml deleted file mode 100644 index 4be6c388..00000000 --- a/Usr/Sys/CoreSystem/Private.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/RISCV/.gitkeep b/Usr/Sys/CoreSystem/RISCV/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Usr/Sys/CoreSystem/ReadMe.md b/Usr/Sys/CoreSystem/ReadMe.md deleted file mode 100644 index ae5df339..00000000 --- a/Usr/Sys/CoreSystem/ReadMe.md +++ /dev/null @@ -1,13 +0,0 @@ -# CoreSystem -## Core System framework. - -Currently contains: - -- Heap API. -- File API. -- Data API. -- Threading API. - -Needs to have: -- Device API -- Drive API. \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/App.c b/Usr/Sys/CoreSystem/Sources/App.c deleted file mode 100644 index 3334dad4..00000000 --- a/Usr/Sys/CoreSystem/Sources/App.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include - -/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. -ApplicationInterfaceRef kSharedApplication = NullPtr; - -/// @brief Gets the app arguments count. -/// @param void no arguments. -/// @return The number of arguments given to the application. -CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); -} - -/// @brief Gets the app arguments pointer. -/// @param void no arguments. -/// @return -CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) -{ - CS_MUST_PASS(kSharedApplication); - - return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, - kCallGetArgsPtr); -} diff --git a/Usr/Sys/CoreSystem/Sources/CRTStartup.c b/Usr/Sys/CoreSystem/Sources/CRTStartup.c deleted file mode 100644 index 2dc9b1c4..00000000 --- a/Usr/Sys/CoreSystem/Sources/CRTStartup.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include - -VoidType __DllMainCRTStartup(VoidType) -{ - kSharedApplication = RtGetAppPointer(); -} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/File.c b/Usr/Sys/CoreSystem/Sources/File.c deleted file mode 100644 index 2e34d782..00000000 --- a/Usr/Sys/CoreSystem/Sources/File.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include -#include - -enum FileOp -{ - kFlushFile, - kReadFork, - kWriteFork, - kOpenFork, - kCloseFork, -}; - -/// @brief Opens a new file. -/// @param path where to find it. -/// @param rest the restrict (rw, rwe, r+, w+, r, w) -/// @return FSRef file reference. -CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, - const CharacterTypeUTF8* rest) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path && CSIsValidPath(path) == Yes); - CS_MUST_PASS(rest); - - return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, - rest); -} - -/// @brief Closes the file and flushes it to the said file. -/// @param refCS the filesystem reference. -/// @return void -CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) -{ - CS_MUST_PASS(kSharedApplication); - - CSFlushFile(refCS); - - kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); -} - -/// @brief Flush file -/// @param refCS the file reference. -/// @return void -CS_EXTERN_C VoidType CSFlushFile(FSRef refCS) -{ - CS_MUST_PASS(kSharedApplication); - - kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); -} - -/// @brief Check if filesystem path is valid. -/// @param path the filesystem path. -/// @return if the path is valid or not. -CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(path); - - return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || - kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); -} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/Heap.c b/Usr/Sys/CoreSystem/Sources/Heap.c deleted file mode 100644 index 1f96648d..00000000 --- a/Usr/Sys/CoreSystem/Sources/Heap.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include -#include - -/// @brief Allocate from the user's heap. -/// @param sz size of object. -/// @param flags flags. -/// @return -CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(sz); - CS_MUST_PASS(flags); - - return (PtrVoidType)kSharedApplication->Invoke(kSharedApplication, - kCallAllocPtr, sz, flags); -} - -/// @brief Free pointer from the user's heap. -/// @param ptr the pointer to free. -CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - - CS_UNREFERENCED_PARAMETER( - kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); -} - -/// @brief Get pointer size. -/// @param ptr the pointer to find. -/// @return the size. -CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - - CS_MUST_PASS(ptr); - return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); -} - -/// @brief Check if the pointer exists. -/// @param ptr the pointer to check. -/// @return if it exists -CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) -{ - CS_MUST_PASS(kSharedApplication); - CS_MUST_PASS(ptr); - return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); -} diff --git a/Usr/Sys/CoreSystem/Sources/Math.c b/Usr/Sys/CoreSystem/Sources/Math.c deleted file mode 100644 index 2d9536f6..00000000 --- a/Usr/Sys/CoreSystem/Sources/Math.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include - -/// @brief Number generator helper. -/// @return Random generated number. -CS_EXTERN_C SizeType MathRand(VoidType) -{ - return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); -} \ No newline at end of file diff --git a/Usr/Sys/CoreSystem/Sources/Thread.c b/Usr/Sys/CoreSystem/Sources/Thread.c deleted file mode 100644 index 630787e1..00000000 --- a/Usr/Sys/CoreSystem/Sources/Thread.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include - -ThreadRef kMainThread = 0; diff --git a/Usr/Sys/CoreSystem/amd64.mk b/Usr/Sys/CoreSystem/amd64.mk deleted file mode 100644 index 65642c2e..00000000 --- a/Usr/Sys/CoreSystem/amd64.mk +++ /dev/null @@ -1,22 +0,0 @@ -################################################## -# (C) Zeta Electronics Corporation, all rights reserved. -# This is the CoreSystem Makefile. -################################################## - -CC=x86_64-w64-mingw32-gcc -AR=x86_64-w64-mingw32-ar -CCINC=-I./ -CCFLAGS=-D__SINGLE_PRECISION__ -nostdlib -std=c17 -ffreestanding -Xlinker --subsystem=17 -e __DllMainCRTStartup -shared -OUTPUT=CoreSystem.lib - -.PHONY: all -all: build-core-amd64 - @echo "[CoreSystem.lib] Build done." - -.PHONY: build-core-amd64 -build-core-amd64: - $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard AMD64/*.s) -o $(OUTPUT) - -.PHONY: clean -clean: - rm -f $(wildcard *.lib) diff --git a/Usr/Sys/CoreSystem/compile_flags.txt b/Usr/Sys/CoreSystem/compile_flags.txt deleted file mode 100644 index 749a500e..00000000 --- a/Usr/Sys/CoreSystem/compile_flags.txt +++ /dev/null @@ -1,4 +0,0 @@ --I./ --I../ --I../../../Kernel --std=c17 -- cgit v1.2.3 From f05b598a1c1a8ca4f1bf0acca078f9c9e3c07991 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 15 Jun 2024 13:49:07 +0200 Subject: kernel: include assembly files as well in project. Signed-off-by: Amlal EL Mahrouss --- Kernel/CFKit/Property.hpp | 20 +++++++++----------- Kernel/FSKit/IndexableProperty.hxx | 5 +++-- Kernel/KernelKit/ProcessScheduler.hxx | 2 +- Kernel/Sources/IndexableProperty.cxx | 12 +++++++----- Kernel/Sources/KeMain.cxx | 10 +++++----- Kernel/Sources/ProcessScheduler.cxx | 8 ++------ Kernel/Sources/Property.cxx | 8 ++++++++ newoskrnl.10x | 2 +- 8 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Kernel/CFKit/Property.hpp b/Kernel/CFKit/Property.hpp index 7667194f..5c5aeb8f 100644 --- a/Kernel/CFKit/Property.hpp +++ b/Kernel/CFKit/Property.hpp @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef _INC_PLIST_HPP__ -#define _INC_PLIST_HPP__ +#ifndef __INC_PLIST_HPP__ +#define __INC_PLIST_HPP__ #include #include @@ -14,18 +14,16 @@ namespace NewOS { - using PropertyId = Int; + /// @brief handle to anything (number, ptr, string...) + using PropertyId = UIntPtr; /// @brief Kernel property class. + /// @example \Properties\SmpCores or \Properties\KernelVersion class Property { public: - explicit Property(const StringView& sw) - : fName(sw) - { - } - - virtual ~Property() = default; + explicit Property(const StringView& sw); + virtual ~Property(); public: Property& operator=(const Property&) = default; @@ -39,8 +37,8 @@ namespace NewOS PropertyId fAction; }; - template + template using PropertyArray = Array; } // namespace NewOS -#endif // !_INC_PLIST_HPP__ +#endif // !__INC_PLIST_HPP__ diff --git a/Kernel/FSKit/IndexableProperty.hxx b/Kernel/FSKit/IndexableProperty.hxx index 91b90903..892083a2 100644 --- a/Kernel/FSKit/IndexableProperty.hxx +++ b/Kernel/FSKit/IndexableProperty.hxx @@ -24,11 +24,12 @@ namespace NewOS Char Path[kIndexerNodeNameLength]; }; + class IndexableProperty final : public Property { public: explicit IndexableProperty() - : Property(StringBuilder::Construct("Indexable").Leak().Leak()) + : Property(StringBuilder::Construct("\\Filesystem\\IsIndexable?").Leak().Leak()) { } @@ -37,7 +38,7 @@ namespace NewOS NEWOS_COPY_DEFAULT(IndexableProperty); public: - IndexProperty& LeakProperty() noexcept; + IndexProperty& Leak() noexcept; public: void AddFlag(Int16 flag); diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 637fc8c4..f49292f1 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -269,7 +269,7 @@ namespace NewOS static bool Switch(HAL::StackFrame* newStack, const PID& newPid); static bool CanBeScheduled(Ref& process); static PID& GetCurrentPID(); - static bool StartScheduling(); + static SizeT StartScheduling(); }; const Int32& rt_get_exit_code() noexcept; diff --git a/Kernel/Sources/IndexableProperty.cxx b/Kernel/Sources/IndexableProperty.cxx index a687e0ec..457e2c53 100644 --- a/Kernel/Sources/IndexableProperty.cxx +++ b/Kernel/Sources/IndexableProperty.cxx @@ -20,19 +20,21 @@ namespace NewOS { namespace Indexer { - IndexProperty& IndexableProperty::LeakProperty() noexcept + IndexProperty& IndexableProperty::Leak() noexcept { return fIndex; } - void IndexableProperty::AddFlag(Int16 flag) + Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } - void IndexableProperty::RemoveFlag(Int16 flag) + + Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } + Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; @@ -48,9 +50,9 @@ namespace NewOS if (!indexer.HasFlag(kIndexerClaimed)) { indexer.AddFlag(kIndexerClaimed); - rt_copy_memory((VoidPtr)indexer.LeakProperty().Path, (VoidPtr)filename, filenameLen); + rt_copy_memory((VoidPtr)indexer.Leak().Path, (VoidPtr)filename, filenameLen); - kcout << "newoskrnl: FSKit: index new file: " << filename << endl; + kcout << "newoskrnl: filesystem: index new file: " << filename << endl; } } } // namespace Indexer diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 23e32c1d..e1b347b8 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -182,9 +182,9 @@ namespace NewOS::Detail /// @brief System loader entrypoint. /// @param void no parameters. /// @return void no return value. - STATIC NewOS::Void SystemLauncher_Main(NewOS::Void) + STATIC NewOS::Void ke_launch_srv(NewOS::Void) { - NewOS::PEFLoader lockScreen("\\System\\LockScreen"); + NewOS::PEFLoader lockScreen("\\System\\securesrv.exe"); if (!lockScreen.IsLoaded()) { @@ -194,7 +194,7 @@ namespace NewOS::Detail NewOS::Utils::execute_from_image(lockScreen, NewOS::ProcessHeader::kAppKind); - NewOS::PEFLoader stageBoard("\\System\\StageBoard"); + NewOS::PEFLoader stageBoard("\\System\\uisrv.exe"); if (!stageBoard.IsLoaded()) { @@ -212,9 +212,9 @@ namespace NewOS::Detail EXTERN_C NewOS::Void KeMain(NewOS::Void) { /// Now run kernel loop, until no process are running. - NewOS::Detail::FilesystemWizard wizard; // automatic. + NewOS::Detail::FilesystemWizard wizard; // automatic filesystem creation. - NewOS::Detail::SystemLauncher_Main(); + NewOS::Detail::ke_launch_srv(); // fetch system cores. NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index dc273cf6..d232c72e 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -329,16 +329,12 @@ namespace NewOS * @brief Spin scheduler class. */ - bool ProcessHelper::StartScheduling() + SizeT ProcessHelper::StartScheduling() { auto& process_ref = ProcessScheduler::The().Leak(); SizeT ret = process_ref.Run(); - kcout << "newoskrnl: Iterated over: "; - kcout.Number(ret); - kcout << " processes.\r"; - - return true; + return ret; } /** diff --git a/Kernel/Sources/Property.cxx b/Kernel/Sources/Property.cxx index dca34429..b58de469 100644 --- a/Kernel/Sources/Property.cxx +++ b/Kernel/Sources/Property.cxx @@ -8,6 +8,14 @@ namespace NewOS { + Property::Property(const StringView& sw) + : fName(sw) + { + kcout << "Property: created: " << sw.CData() << endl; + } + + Property::~Property() = default; + bool Property::StringEquals(StringView& name) { return fName && this->fName == name; diff --git a/newoskrnl.10x b/newoskrnl.10x index d232f112..4d9241c7 100644 --- a/newoskrnl.10x +++ b/newoskrnl.10x @@ -1,7 +1,7 @@ - *.c,*.cc,*.cpp,*.c++,*.cp,*.cxx,*.h,*.hh,*.hpp,*.h++,*.hp,*.hxx,*.inl,*.cs,*.rs,*.java,*.jav,*.js,*.jsc,*.jsx,*.json,*.cls,*.py,*.rpy,*.php,*.php3,*.phl,*.phtml,*.rhtml,*.tpl,*.phps,*.lua,*.html,*.html5,*.htm,*.xml,*.xaml,*.css,*.ssi,*.haml,*.yaml,*.bat,*.wbf,*.wbt,*.txt,*.cmake,*.make,*.makefile,*.mak,*.mk,*.sh,*.bash,*.csv,*.asp,*.pl,*.mac,*.ws,*.vbs,*.perl,*.src,*.rss,*.inc,*.f,*.go,*.prl,*.plx,*.rb,*.lsp,*.lpx,*.ps1,*.command,*.cbl,*.cob,*.qs,*.wxs,*.ph,*.msc,*.glsl,*.hlsl,*.fx,*.vert,*.tesc,*.tese,*.geom,*.frag,*.comp,*.pssl,*.scons,*.cu,*.jai, + *.s,*.asm,*.S,*.c,*.cc,*.cpp,*.c++,*.cp,*.cxx,*.h,*.hh,*.hpp,*.h++,*.hp,*.hxx,*.inl,*.cs,*.rs,*.java,*.jav,*.js,*.jsc,*.jsx,*.json,*.cls,*.py,*.rpy,*.php,*.php3,*.phl,*.phtml,*.rhtml,*.tpl,*.phps,*.lua,*.html,*.html5,*.htm,*.xml,*.xaml,*.css,*.ssi,*.haml,*.yaml,*.bat,*.wbf,*.wbt,*.txt,*.cmake,*.make,*.makefile,*.mak,*.mk,*.sh,*.bash,*.csv,*.asp,*.pl,*.mac,*.ws,*.vbs,*.perl,*.src,*.rss,*.inc,*.f,*.go,*.prl,*.plx,*.rb,*.lsp,*.lpx,*.ps1,*.command,*.cbl,*.cob,*.qs,*.wxs,*.ph,*.msc,*.glsl,*.hlsl,*.fx,*.vert,*.tesc,*.tese,*.geom,*.frag,*.comp,*.pssl,*.scons,*.cu,*.jai, true true -- cgit v1.2.3 From 84aea90cff9952dbafcf147b7741c1985622a8d2 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 16 Jun 2024 00:25:47 +0200 Subject: MHR-31: Add cHartIpi enum, improve ReadMe and fix FilesystemWizard. Signed-off-by: Amlal EL Mahrouss --- Kernel/Builtins/ReadMe.txt | 8 ++++---- Kernel/HALKit/ARM64/Hart.hxx | 10 +++++++++- Kernel/Sources/KeMain.cxx | 42 +++++++++++++++++++++--------------------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Kernel/Builtins/ReadMe.txt b/Kernel/Builtins/ReadMe.txt index b0a5a327..df63e0be 100644 --- a/Kernel/Builtins/ReadMe.txt +++ b/Kernel/Builtins/ReadMe.txt @@ -6,14 +6,14 @@ NewOS Builtins What are these? =============== -These are NewOS builtins device drivers. +These are like modules for the kernel. =================== Maintainers/Authors =================== -ACPIFactoryInterface: Amlal EL Mahrouss. +ACPI: Amlal EL Mahrouss. AHCI: Amlal EL Mahrouss. GX: Amlal EL Mahrouss. -PS2: Amlal EL Mahrouss -ATA: Amlal EL Mahrouss \ No newline at end of file +PS2: Amlal EL Mahrouss. +ATA: Amlal EL Mahrouss. \ No newline at end of file diff --git a/Kernel/HALKit/ARM64/Hart.hxx b/Kernel/HALKit/ARM64/Hart.hxx index bc35c3f5..1b16a072 100644 --- a/Kernel/HALKit/ARM64/Hart.hxx +++ b/Kernel/HALKit/ARM64/Hart.hxx @@ -17,4 +17,12 @@ typedef NewOS::Int32 Arm64HartType; /// @param hart the hart /// @param epc the pc. /// @return -EXTERN_C NewOS::Void hal_switch_to_hart(Arm64HartType hart, NewOS::VoidPtr epc); \ No newline at end of file +EXTERN_C NewOS::Void hal_switch_to_hart(Arm64HartType hart, NewOS::VoidPtr epc); + +/// @brief Hart IPI enum +enum { + cHartIpiTurnOn, + cHartIpiTurnOff, + cHartIpiStop, + cHartIpiResume, +}; diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index e1b347b8..83702d77 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -33,6 +33,7 @@ namespace NewOS::Detail NewOS::NewFilesystemManager* fNewFS{nullptr}; public: + /// @brief wizard constructor. explicit FilesystemWizard() { if (NewOS::FilesystemManagerInterface::GetMounted()) @@ -54,7 +55,7 @@ namespace NewOS::Detail constexpr auto cFolderInfo = "META-INF"; const auto cDirCount = 8; const char* cDirStr[cDirCount] = { - "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", + "\\Boot\\", "\\System\\", "\\Support\\", "\\Packages\\", "\\Users\\", "\\Library\\", "\\Mount\\", "\\DCIM\\"}; for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) @@ -92,9 +93,9 @@ namespace NewOS::Detail metadataFolder += "

Kind: folder

\r

Created by: system

\r

Edited by: " - "system

\r

Volume Type: New OS Standard

\r"; + "system

\r

Volume Type: s10 Filesystem

\r"; - metadataFolder += "

File name: "; + metadataFolder += "

Path: "; metadataFolder += cDirStr[dirIndx]; metadataFolder += "

\r"; @@ -113,7 +114,7 @@ namespace NewOS::Detail } NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("\\Mount\\This Disk"); + this->fNewFS->GetParser()->GetCatalog("\\Mount\\C:\\"); const NewOS::Char* cSrcName = "DISK-INF"; @@ -128,16 +129,16 @@ namespace NewOS::Detail else { catalogDisk = - (NewCatalog*)this->Leak()->CreateAlias("\\Mount\\This Disk"); + (NewCatalog*)this->Leak()->CreateAlias("\\Mount\\C:\\"); NewOS::StringView diskFolder(kNewFSSectorSz); diskFolder += - "

Kind: alias to disk

\r

Created by: newoskrnl

\r

Edited " + "

Kind: alias to disk

\r

Created by: system

\r

Edited " "by: " - "N/A

\r

Volume Type: New OS Standard

\r"; + "system

\r

Volume Type: s10 Filesystem

\r"; - diskFolder += "

Original Path: "; + diskFolder += "

Root: "; diskFolder += NewOS::NewFilesystemHelper::Root(); diskFolder += "

\r"; @@ -165,43 +166,41 @@ namespace NewOS::Detail } } - ~FilesystemWizard() - { - delete fNewFS; - } + ~FilesystemWizard() = default; NEWOS_COPY_DEFAULT(FilesystemWizard); - /// Grab the disk's NewFS reference. + /// @brief Grab the disk's NewFS reference. + /// @return NewFilesystemManager the filesystem interface NewOS::NewFilesystemManager* Leak() { return fNewFS; } }; - /// @brief System loader entrypoint. + /// @brief Loads necessary servers for the OS to work. /// @param void no parameters. /// @return void no return value. STATIC NewOS::Void ke_launch_srv(NewOS::Void) { - NewOS::PEFLoader lockScreen("\\System\\securesrv.exe"); + NewOS::PEFLoader secureSrv("\\System\\securesrv.exe"); - if (!lockScreen.IsLoaded()) + if (!secureSrv.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(lockScreen, + NewOS::Utils::execute_from_image(secureSrv, NewOS::ProcessHeader::kAppKind); - NewOS::PEFLoader stageBoard("\\System\\uisrv.exe"); + NewOS::PEFLoader uiSrv("\\System\\uisrv.exe"); - if (!stageBoard.IsLoaded()) + if (!uiSrv.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(stageBoard, + NewOS::Utils::execute_from_image(uiSrv, NewOS::ProcessHeader::kAppKind); } } // namespace NewOS::Detail @@ -219,7 +218,8 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) // fetch system cores. NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); - while (true) + // spin forever. + while (Yes) { // start scheduling. NewOS::ProcessHelper::StartScheduling(); -- cgit v1.2.3 From 684197d4bcb66e94c1dbf37591ed2a984792e51d Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 16 Jun 2024 12:32:15 +0200 Subject: MHR-31: Add ARM64 executable type for newoskrnl's PEF implementation. Signed-off-by: Amlal EL Mahrouss --- Boot/makefile | 2 +- Kernel/KernelKit/PEF.hpp | 1 + Kernel/NewKit/Defines.hpp | 6 ------ Kernel/NewKit/String.hpp | 2 +- Kernel/Sources/FileManager.cxx | 4 ++-- Kernel/Sources/String.cxx | 2 +- Kernel/makefile | 2 +- 7 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Boot/makefile b/Boot/makefile index 98726bbe..37ac3704 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -28,7 +28,7 @@ BIOS=OVMF.fd IMG=epm.img IMG_2=epm-slave.img -EMU_FLAGS=-net none -smp 4 -m 4G -M q35 \ +EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -d int \ -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 \ diff --git a/Kernel/KernelKit/PEF.hpp b/Kernel/KernelKit/PEF.hpp index 0713e7c5..005c7673 100644 --- a/Kernel/KernelKit/PEF.hpp +++ b/Kernel/KernelKit/PEF.hpp @@ -36,6 +36,7 @@ namespace NewOS kPefArch64x0, /* 64x0. ISA */ kPefArch32x0, /* 32x0. ISA */ kPefArchPowerPC, + kPefArchARM64, kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1, kPefArchInvalid = 0xFF, }; diff --git a/Kernel/NewKit/Defines.hpp b/Kernel/NewKit/Defines.hpp index 96f13fd9..3210f1ef 100644 --- a/Kernel/NewKit/Defines.hpp +++ b/Kernel/NewKit/Defines.hpp @@ -133,12 +133,6 @@ namespace NewOS }; } // namespace NewOS -/// @note this is for the purpose of having a common namespace alongside zeta's codebase. -namespace ma::zeta::kernel -{ - using namespace NewOS; -} - #define DEDUCE_ENDIAN(address, value) \ (((reinterpret_cast(address)[0]) == (value)) \ ? (NewOS::Endian::kEndianBig) \ diff --git a/Kernel/NewKit/String.hpp b/Kernel/NewKit/String.hpp index 644a1394..14286ca0 100644 --- a/Kernel/NewKit/String.hpp +++ b/Kernel/NewKit/String.hpp @@ -35,7 +35,7 @@ namespace NewOS StringView(const StringView&) = default; Char* Data(); - const Char* CData(); + const Char* CData() const; Size Length() const; bool operator==(const Char* rhs) const; diff --git a/Kernel/Sources/FileManager.cxx b/Kernel/Sources/FileManager.cxx index 6e61a65d..ee285ae1 100644 --- a/Kernel/Sources/FileManager.cxx +++ b/Kernel/Sources/FileManager.cxx @@ -90,7 +90,7 @@ namespace NewOS NEWOS_UNUSED(flags); - auto dataForkName = "FileData"; + auto dataForkName = kNewFSDataFork; if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast(node), data, size, @@ -112,7 +112,7 @@ namespace NewOS NEWOS_UNUSED(flags); - auto dataForkName = "FileData"; + auto dataForkName = kNewFSDataFork; if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast(node), sz, diff --git a/Kernel/Sources/String.cxx b/Kernel/Sources/String.cxx index 08ca1036..fab12226 100644 --- a/Kernel/Sources/String.cxx +++ b/Kernel/Sources/String.cxx @@ -15,7 +15,7 @@ namespace NewOS return fData; } - const Char* StringView::CData() + const Char* StringView::CData() const { return fData; } diff --git a/Kernel/makefile b/Kernel/makefile index 16a36013..1f749323 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -25,7 +25,7 @@ ifneq ($(AHCI_SUPPORT), ) DISKDRIVER = -D__AHCI__ endif -ifeq ($(RELEASE_SUPPORT), ) +ifneq ($(DEBUG_SUPPORT), ) DEBUG = -D__DEBUG__ endif -- cgit v1.2.3 From 30bcb0416e8acaf3fb7b224e18534e7f64df26af Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 16 Jun 2024 12:56:02 +0200 Subject: MHR-31: Work in progress ARM64 port of the kernel. - This is a very capable kernel, it has HAL capabilities. - We're going to make a timer to implmenent our scheduler. - We're going to support flash memoru and SD cards, alongside a SIM driver. Signed-off-by: Amlal EL Mahrouss --- Kernel/amd64-efi.make | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/arm64-cb.make | 73 ++++++++++++++++++++++++++++++++++++++++++ Kernel/makefile | 87 --------------------------------------------------- 3 files changed, 159 insertions(+), 87 deletions(-) create mode 100644 Kernel/amd64-efi.make create mode 100644 Kernel/arm64-cb.make delete mode 100644 Kernel/makefile diff --git a/Kernel/amd64-efi.make b/Kernel/amd64-efi.make new file mode 100644 index 00000000..7e076a8d --- /dev/null +++ b/Kernel/amd64-efi.make @@ -0,0 +1,86 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the microkernel makefile. +################################################## + +CC = x86_64-w64-mingw32-gcc +LD = x86_64-w64-mingw32-ld +CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ + -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./ + +ASM = nasm + +DISKDRIVER = + +ifneq ($(ATA_PIO_SUPPORT), ) +DISKDRIVER = -D__ATA_PIO__ +endif + +ifneq ($(ATA_DMA_SUPPORT), ) +DISKDRIVER = -D__ATA_DMA__ +endif + +ifneq ($(AHCI_SUPPORT), ) +DISKDRIVER = -D__AHCI__ +endif + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +COPY = cp + +# Add assembler, linker, and object files variables. +ASMFLAGS = -f win64 + +# NewOS subsystem is 17 and entrypoint is __ImageStart +LDFLAGS = -e __ImageStart --subsystem=17 +LDOBJ = Objects/*.obj + +# This file is the kernel, responsible of task management and memory. +KERNEL = newoskrnl.exe + +.PHONY: error +error: + @echo "=== ERROR ===" + @echo "=> Use a specific target." + +MOVEALL=./MoveAll.sh +WINDRES=x86_64-w64-mingw32-windres + +.PHONY: newos-amd64-epm +newos-amd64-epm: clean + $(WINDRES) KernelRsrc.rsrc -O coff -o KernelRsrc.obj + $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Sources/*.cxx) \ + $(wildcard Sources/FS/*.cxx) $(wildcard HALKit/AMD64/Storage/*.cxx) \ + $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Sources/Network/*.cxx) $(wildcard Sources/Storage/*.cxx) \ + $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) \ + $(wildcard HALKit/AMD64/*.s) + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInstallTIB.asm + $(MOVEALL) + +OBJCOPY=x86_64-w64-mingw32-objcopy + +.PHONY: link-amd64-epm +link-amd64-epm: + $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL) + +.PHONY: all +all: newos-amd64-epm link-amd64-epm + qemu-img create -f raw newoskrnl.rom 512K + dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc + @echo "NewOSKrnl => OK." + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "all: Build kernel and link it." + @echo "link-amd64-epm: Link kernel. (EPM AMD64)" + @echo "newos-amd64-epm: Build kernel. (EPM AMD64)" + +.PHONY: clean +clean: + rm -f $(LDOBJ) $(KERNEL) diff --git a/Kernel/arm64-cb.make b/Kernel/arm64-cb.make new file mode 100644 index 00000000..3b24bcdb --- /dev/null +++ b/Kernel/arm64-cb.make @@ -0,0 +1,73 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the microkernel makefile. +################################################## + +CC = arm-none-eabi-gcc.exe +LD = arm-none-eabi-ld.exe +CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_ARM64__ -fno-rtti -fno-exceptions -I../ -I./ \ + -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ + +ASM = arm-none-eabi-as.exe + +DISKDRIVER = -D__FLASH_MEM__ + +ifneq ($(SDCARD_SUPPORT), ) +DISKDRIVER = -D__SDCARD__ +endif + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +COPY = cp + +# Add assembler, linker, and object files variables. +ASMFLAGS = -f elf64 + +# NewOS subsystem is 17 and entrypoint is __ImageStart +LDFLAGS = -e __ImageStart +LDOBJ = Objects/*.obj + +# This file is the kernel, responsible of task management and memory. +KERNEL = newoskrnl.exe + +.PHONY: error +error: + @echo "=== ERROR ===" + @echo "=> Use a specific target." + +MOVEALL=./MoveAll.sh + +.PHONY: newos-arm64-epm +newos-arm64-epm: clean + $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Sources/*.cxx) \ + $(wildcard Sources/FS/*.cxx) $(wildcard HALKit/ARM64/Storage/*.cxx) \ + $(wildcard HALKit/ARM64/PCI/*.cxx) $(wildcard Sources/Network/*.cxx) $(wildcard Sources/Storage/*.cxx) \ + $(wildcard HALKit/ARM64/*.cxx) $(wildcard HALKit/ARM64/*.cpp) \ + $(wildcard HALKit/ARM64/*.s) + + $(MOVEALL) + +OBJCOPY=x86_64-w64-mingw32-objcopy + +.PHONY: link-arm64-epm +link-arm64-epm: + $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL) + +.PHONY: all +all: newos-arm64-epm link-arm64-epm + qemu-img create -f raw newoskrnl.rom 512K + dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc + @echo "NewOSKrnl => OK." + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "all: Build kernel and link it." + @echo "link-arm64-epm: Link kernel. (EPM AMD64)" + @echo "newos-arm64-epm: Build kernel. (EPM AMD64)" + +.PHONY: clean +clean: + rm -f $(LDOBJ) $(KERNEL) diff --git a/Kernel/makefile b/Kernel/makefile deleted file mode 100644 index 1f749323..00000000 --- a/Kernel/makefile +++ /dev/null @@ -1,87 +0,0 @@ -################################################## -# (C) Zeta Electronics Corporation, all rights reserved. -# This is the microkernel makefile. -################################################## - -CC = x86_64-w64-mingw32-gcc -LD = x86_64-w64-mingw32-ld -CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ - -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./ \ - -DBLEND2D_NO_STDCXX -DBLEND2D_NO_TLS -DBLEND2D_EMBED - -ASM = nasm - -DISKDRIVER = -D__ATA_PIO__ - -ifneq ($(ATA_PIO_SUPPORT), ) -DISKDRIVER = -D__ATA_PIO__ -endif - -ifneq ($(ATA_DMA_SUPPORT), ) -DISKDRIVER = -D__ATA_DMA__ -endif - -ifneq ($(AHCI_SUPPORT), ) -DISKDRIVER = -D__AHCI__ -endif - -ifneq ($(DEBUG_SUPPORT), ) -DEBUG = -D__DEBUG__ -endif - -COPY = cp - -# Add assembler, linker, and object files variables. -ASMFLAGS = -f win64 - -# NewOS subsystem is 17 and entrypoint is __ImageStart -LDFLAGS = -e __ImageStart --subsystem=17 -LDOBJ = Objects/*.obj - -# This file is the kernel, responsible of task management and memory. -KERNEL = newoskrnl.exe - -.PHONY: error -error: - @echo "=== ERROR ===" - @echo "=> Use a specific target." - -MOVEALL=./MoveAll.sh -WINDRES=x86_64-w64-mingw32-windres - -.PHONY: newos-amd64-epm -newos-amd64-epm: clean - $(WINDRES) KernelRsrc.rsrc -O coff -o KernelRsrc.obj - $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Sources/*.cxx) \ - $(wildcard Sources/FS/*.cxx) $(wildcard HALKit/AMD64/Storage/*.cxx) \ - $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Sources/Network/*.cxx) $(wildcard Sources/Storage/*.cxx) \ - $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) \ - $(wildcard HALKit/AMD64/*.s) - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInstallTIB.asm - $(MOVEALL) - -OBJCOPY=x86_64-w64-mingw32-objcopy - -.PHONY: link-amd64-epm -link-amd64-epm: - $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL) - -.PHONY: all -all: newos-amd64-epm link-amd64-epm - qemu-img create -f raw newoskrnl.rom 512K - dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc - @echo "NewOSKrnl => OK." - -.PHONY: help -help: - @echo "=== HELP ===" - @echo "all: Build kernel and link it." - @echo "link-amd64-epm: Link kernel. (EPM AMD64)" - @echo "newos-amd64-epm: Build kernel. (EPM AMD64)" - -.PHONY: clean -clean: - rm -f $(LDOBJ) $(KERNEL) -- cgit v1.2.3 From c4cbc986ac68dbfdc743efec58c72ebb74d3f3b0 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 16 Jun 2024 18:05:36 +0200 Subject: MHR-31: Start work on drivers for ARM64. Signed-off-by: Amlal EL Mahrouss --- Drv/GSMDrv/CheckStck.c | 11 ++++++++ Drv/GSMDrv/DriverRsrc.rsrc | 25 +++++++++++++++++ Drv/GSMDrv/GSMDrv.c | 23 ++++++++++++++++ Drv/GSMDrv/x86_64.make | 51 +++++++++++++++++++++++++++++++++++ Drv/VideoDrv/CheckStck.c | 11 ++++++++ Drv/VideoDrv/DriverRsrc.rsrc | 25 +++++++++++++++++ Drv/VideoDrv/VideoDrv.c | 22 +++++++++++++++ Drv/VideoDrv/x86_64.make | 51 +++++++++++++++++++++++++++++++++++ Kernel/Builtins/GPRS/.keepme | 0 Kernel/Builtins/GSM/.keepme | 0 Kernel/Builtins/GSM/IO.hxx | 29 ++++++++++++++++++++ Kernel/KernelKit/ProcessScheduler.hxx | 6 ++--- Kernel/NetworkKit/GSM.hxx | 2 +- Kernel/NetworkKit/NetworkDevice.hpp | 8 ++++++ 14 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 Drv/GSMDrv/CheckStck.c create mode 100644 Drv/GSMDrv/DriverRsrc.rsrc create mode 100644 Drv/GSMDrv/GSMDrv.c create mode 100644 Drv/GSMDrv/x86_64.make create mode 100644 Drv/VideoDrv/CheckStck.c create mode 100644 Drv/VideoDrv/DriverRsrc.rsrc create mode 100644 Drv/VideoDrv/VideoDrv.c create mode 100644 Drv/VideoDrv/x86_64.make create mode 100644 Kernel/Builtins/GPRS/.keepme create mode 100644 Kernel/Builtins/GSM/.keepme create mode 100644 Kernel/Builtins/GSM/IO.hxx diff --git a/Drv/GSMDrv/CheckStck.c b/Drv/GSMDrv/CheckStck.c new file mode 100644 index 00000000..3eb157ba --- /dev/null +++ b/Drv/GSMDrv/CheckStck.c @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +///! @brief Use this to check your stack, if using MinGW/MSVC/CodeTools. +void ___chkstk_ms(void) +{ + (void)0; +} diff --git a/Drv/GSMDrv/DriverRsrc.rsrc b/Drv/GSMDrv/DriverRsrc.rsrc new file mode 100644 index 00000000..f8e9c05f --- /dev/null +++ b/Drv/GSMDrv/DriverRsrc.rsrc @@ -0,0 +1,25 @@ +1 ICON "../../Icons/driver-logo.ico" + +1 VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "CompanyName", "Zeta Electronics Corporation" + VALUE "FileDescription", "New OS driver." + VALUE "FileVersion", "1.00" + VALUE "InternalName", "SampleDriver" + VALUE "LegalCopyright", "Copyright Zeta Electronics Corporation, all rights reserved." + VALUE "OriginalFilename", "SampleDriver.exe" + VALUE "ProductName", "SampleDriver" + VALUE "ProductVersion", "1.00" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 1252 + END +END diff --git a/Drv/GSMDrv/GSMDrv.c b/Drv/GSMDrv/GSMDrv.c new file mode 100644 index 00000000..791c0678 --- /dev/null +++ b/Drv/GSMDrv/GSMDrv.c @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include +#include + +int __ImageStart(void) +{ + kernelPrintStr("GSMDrv: Starting up...\r"); + + /// @brief activate SIM 0..n + + return 0; +} + +int __ImageEnd(void) +{ + kernelPrintStr("GSMDrv: Shutting down...\r"); + return 0; +} diff --git a/Drv/GSMDrv/x86_64.make b/Drv/GSMDrv/x86_64.make new file mode 100644 index 00000000..a47c40ae --- /dev/null +++ b/Drv/GSMDrv/x86_64.make @@ -0,0 +1,51 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the sample driver makefile. +################################################## + +CC_GNU=x86_64-w64-mingw32-gcc +LD_GNU=x86_64-w64-mingw32-ld + +WINDRES=x86_64-w64-mingw32-windres + +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + +LD_FLAGS=-e __ImageStart --subsystem=17 + +OBJ=*.o + + +REM=rm +REM_FLAG=-f + +FLAG_ASM=-f win64 +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -std=c17 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ + +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make all instead." + +.PHONY: all +all: compile-amd64 + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o GSMDrv.exe + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +.PHONY: compile-amd64 +compile-amd64: + $(WINDRES) DriverRsrc.rsrc -O coff -o DriverRsrc.o + $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DDK/*.c) $(wildcard ../../DDK/*.S) + +.PHONY: clean +clean: + $(REM) $(REM_FLAG) $(OBJ) GSMDrv.exe + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "clean: Clean driver." + @echo "compile-amd64: Build driver." diff --git a/Drv/VideoDrv/CheckStck.c b/Drv/VideoDrv/CheckStck.c new file mode 100644 index 00000000..3eb157ba --- /dev/null +++ b/Drv/VideoDrv/CheckStck.c @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +///! @brief Use this to check your stack, if using MinGW/MSVC/CodeTools. +void ___chkstk_ms(void) +{ + (void)0; +} diff --git a/Drv/VideoDrv/DriverRsrc.rsrc b/Drv/VideoDrv/DriverRsrc.rsrc new file mode 100644 index 00000000..f8e9c05f --- /dev/null +++ b/Drv/VideoDrv/DriverRsrc.rsrc @@ -0,0 +1,25 @@ +1 ICON "../../Icons/driver-logo.ico" + +1 VERSIONINFO +FILEVERSION 1,0,0,0 +PRODUCTVERSION 1,0,0,0 +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "080904E4" + BEGIN + VALUE "CompanyName", "Zeta Electronics Corporation" + VALUE "FileDescription", "New OS driver." + VALUE "FileVersion", "1.00" + VALUE "InternalName", "SampleDriver" + VALUE "LegalCopyright", "Copyright Zeta Electronics Corporation, all rights reserved." + VALUE "OriginalFilename", "SampleDriver.exe" + VALUE "ProductName", "SampleDriver" + VALUE "ProductVersion", "1.00" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x809, 1252 + END +END diff --git a/Drv/VideoDrv/VideoDrv.c b/Drv/VideoDrv/VideoDrv.c new file mode 100644 index 00000000..3ba104d6 --- /dev/null +++ b/Drv/VideoDrv/VideoDrv.c @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include +#include + +#include + +int __ImageStart(void) +{ + kernelPrintStr("VideoDrv: Starting up...\r"); + return 0; +} + +int __ImageEnd(void) +{ + kernelPrintStr("VideoDrv: Shutting down...\r"); + return 0; +} diff --git a/Drv/VideoDrv/x86_64.make b/Drv/VideoDrv/x86_64.make new file mode 100644 index 00000000..8ec42277 --- /dev/null +++ b/Drv/VideoDrv/x86_64.make @@ -0,0 +1,51 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the sample driver makefile. +################################################## + +CC_GNU=x86_64-w64-mingw32-gcc +LD_GNU=x86_64-w64-mingw32-ld + +WINDRES=x86_64-w64-mingw32-windres + +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + +LD_FLAGS=-e __ImageStart --subsystem=17 + +OBJ=*.o + + +REM=rm +REM_FLAG=-f + +FLAG_ASM=-f win64 +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -std=c17 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ + +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make all instead." + +.PHONY: all +all: compile-amd64 + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o VideoDrv.exe + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +.PHONY: compile-amd64 +compile-amd64: + $(WINDRES) DriverRsrc.rsrc -O coff -o DriverRsrc.o + $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DDK/*.c) $(wildcard ../../DDK/*.S) + +.PHONY: clean +clean: + $(REM) $(REM_FLAG) $(OBJ) VideoDrv.exe + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "clean: Clean driver." + @echo "compile-amd64: Build driver." diff --git a/Kernel/Builtins/GPRS/.keepme b/Kernel/Builtins/GPRS/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/Builtins/GSM/.keepme b/Kernel/Builtins/GSM/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/Builtins/GSM/IO.hxx b/Kernel/Builtins/GSM/IO.hxx new file mode 100644 index 00000000..39de1a0f --- /dev/null +++ b/Kernel/Builtins/GSM/IO.hxx @@ -0,0 +1,29 @@ +/* ------------------------------------------- + +Copyright Zeta Electronics Corporation. + +File: GSM\IO.hxx. +Purpose: GSM I/O. + +------------------------------------------- */ + +#ifndef _INC_NETWORK_GSM_IO_HXX_ +#define _INC_NETWORK_GSM_IO_HXX_ + +#include +#include + +/// @brief GSM I/O routines. + +/// @brief Turn on SIM slot. +NewOS::Boolean gsm_turn_on_slot(NewOS::Int32 slot); + +/// @brief Turn off SIM slot. +NewOS::Boolean gsm_turn_off_slot(NewOS::Int32 slot); + +/// @brief Send AT command. +NewOS::Boolean gsm_send_at_command(NewOS::Char* buf, + NewOS::Size bufSz); + + +#endif // ifndef _INC_NETWORK_GSM_IO_HXX_ diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index f49292f1..7c8f99be 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef __PROCESS_SCHEDULER__ -#define __PROCESS_SCHEDULER__ +#ifndef _INC_PROCESS_SCHEDULER_HXX_ +#define _INC_PROCESS_SCHEDULER_HXX_ #include #include @@ -283,4 +283,4 @@ namespace NewOS //////////////////////////////////////////////////// -#endif /* ifndef __PROCESS_SCHEDULER__ */ +#endif /* ifndef _INC_PROCESS_SCHEDULER_HXX_ */ diff --git a/Kernel/NetworkKit/GSM.hxx b/Kernel/NetworkKit/GSM.hxx index 9a785344..f4b040b3 100644 --- a/Kernel/NetworkKit/GSM.hxx +++ b/Kernel/NetworkKit/GSM.hxx @@ -3,7 +3,7 @@ Copyright Zeta Electronics Corporation. File: GSM.hxx. - Purpose: GSM protocol. + Purpose: GSM protocol classes. ------------------------------------------- */ diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 49b142d5..58b9a98b 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -10,6 +10,8 @@ #include #include +/// @note Can either work with: Ethernet, GPRS, WiFi + namespace NewOS { struct NetworkDeviceCommand; @@ -58,6 +60,12 @@ namespace NewOS /// @brief IPCEP device. using IPCEPNetworkDevice = NetworkDevice; + + /// @brief GRPS device. + using GPRSNetworkDevice = NetworkDevice; + + /// @brief GSM device. + using GSMNetworkDevice = NetworkDevice; } // namespace NewOS #include -- cgit v1.2.3 From 9a6367cd51f4a8544e2ee7c68f1cca401b4f0066 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Mon, 17 Jun 2024 08:55:10 +0200 Subject: MHR-31: Create makefiles according to targets. Signed-off-by: Amlal EL Mahrouss --- Boot/amd64-efi.make | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ Boot/makefile | 112 -------------------------------------------------- Kernel/amd64-efi.make | 12 +++--- Kernel/arm64-cb.make | 18 ++++---- 4 files changed, 125 insertions(+), 129 deletions(-) create mode 100644 Boot/amd64-efi.make delete mode 100644 Boot/makefile diff --git a/Boot/amd64-efi.make b/Boot/amd64-efi.make new file mode 100644 index 00000000..37ac3704 --- /dev/null +++ b/Boot/amd64-efi.make @@ -0,0 +1,112 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the bootloader makefile. +################################################## + +CC_GNU=x86_64-w64-mingw32-g++ +LD_GNU=x86_64-w64-mingw32-ld + +WINDRES=x86_64-w64-mingw32-windres + +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + +# Select this for UNIX distributions +ifneq ($(shell uname), CYGWIN_NT-10.0-19045) +EMU=qemu-system-x86_64 +else +# this for NT distributions +EMU=qemu-system-x86_64w.exe +endif + +ifeq ($(NEWS_MODEL), ) +NEWOS_MODEL=-DkMachineModel="\"Generic Zeta HD\"" +endif + +BIOS=OVMF.fd +IMG=epm.img +IMG_2=epm-slave.img + +EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -d int \ + -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 \ + file=fat:rw:Sources/Root,index=2,format=raw -d int -hdd $(IMG_2) + +LD_FLAGS=-e Main --subsystem=10 + +ifeq ($(NEWS_STANDLONE), ) +OBJ=*.o ../Kernel/Objects/*.obj +else +RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o +STANDALONE_MACRO=-D__STANDALONE__ +OBJ=*.o +endif + +REM=rm +REM_FLAG=-f + +FLAG_ASM=-f win64 +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ + -DEFI_FUNCTION_WRAPPER -I./ -I../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ + -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ + +BOOT_LOADER=newosldr.exe +KERNEL=newoskrnl.exe + +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make compile- instead." + +.PHONY: all +all: compile-amd64 + mkdir -p Sources/Root/EFI/BOOT + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Sources/$(BOOT_LOADER) + $(COPY) Sources/$(BOOT_LOADER) Sources/Root/EFI/BOOT/BOOTX64.EFI + $(COPY) Sources/$(BOOT_LOADER) Sources/Root/EFI/BOOT/NEWBOOT.EFI + $(COPY) ../Kernel/$(KERNEL) Sources/Root/$(KERNEL) + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +.PHONY: compile-amd64 +compile-amd64: + $(RESCMD) + $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) \ + $(wildcard Sources/HEL/AMD64/*.cxx) \ + $(wildcard Sources/HEL/AMD64/*.S) + $(wildcard Sources/*.cxx) + +.PHONY: run-efi-amd64 +run-efi-amd64: + $(EMU) $(EMU_FLAGS) + +# 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 + qemu-img create -f raw $(IMG_2) 512M + +.PHONY: download-edk +download-edk: + $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd + +BINS=*.bin +EXECUTABLES=newosldr.exe newoskrnl.exe OVMF.fd + +TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) + +.PHONY: clean +clean: + $(REM) $(TARGETS) + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "epm-img: Format a disk using the Explicit Partition Map." + @echo "gpt-img: Format a disk using the Explicit Partition Map." + @echo "clean: clean bootloader." + @echo "bootloader-amd64: Build bootloader. (PC AMD64)" + @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Boot/makefile b/Boot/makefile deleted file mode 100644 index 37ac3704..00000000 --- a/Boot/makefile +++ /dev/null @@ -1,112 +0,0 @@ -################################################## -# (C) Zeta Electronics Corporation, all rights reserved. -# This is the bootloader makefile. -################################################## - -CC_GNU=x86_64-w64-mingw32-g++ -LD_GNU=x86_64-w64-mingw32-ld - -WINDRES=x86_64-w64-mingw32-windres - -ADD_FILE=touch -COPY=cp -HTTP_GET=wget - -# Select this for UNIX distributions -ifneq ($(shell uname), CYGWIN_NT-10.0-19045) -EMU=qemu-system-x86_64 -else -# this for NT distributions -EMU=qemu-system-x86_64w.exe -endif - -ifeq ($(NEWS_MODEL), ) -NEWOS_MODEL=-DkMachineModel="\"Generic Zeta HD\"" -endif - -BIOS=OVMF.fd -IMG=epm.img -IMG_2=epm-slave.img - -EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -d int \ - -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 \ - file=fat:rw:Sources/Root,index=2,format=raw -d int -hdd $(IMG_2) - -LD_FLAGS=-e Main --subsystem=10 - -ifeq ($(NEWS_STANDLONE), ) -OBJ=*.o ../Kernel/Objects/*.obj -else -RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o -STANDALONE_MACRO=-D__STANDALONE__ -OBJ=*.o -endif - -REM=rm -REM_FLAG=-f - -FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ - -DEFI_FUNCTION_WRAPPER -I./ -I../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ - -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ - -BOOT_LOADER=newosldr.exe -KERNEL=newoskrnl.exe - -.PHONY: invalid-recipe -invalid-recipe: - @echo "invalid-recipe: Use make compile- instead." - -.PHONY: all -all: compile-amd64 - mkdir -p Sources/Root/EFI/BOOT - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Sources/$(BOOT_LOADER) - $(COPY) Sources/$(BOOT_LOADER) Sources/Root/EFI/BOOT/BOOTX64.EFI - $(COPY) Sources/$(BOOT_LOADER) Sources/Root/EFI/BOOT/NEWBOOT.EFI - $(COPY) ../Kernel/$(KERNEL) Sources/Root/$(KERNEL) - -ifneq ($(DEBUG_SUPPORT), ) -DEBUG = -D__DEBUG__ -endif - -.PHONY: compile-amd64 -compile-amd64: - $(RESCMD) - $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) \ - $(wildcard Sources/HEL/AMD64/*.cxx) \ - $(wildcard Sources/HEL/AMD64/*.S) - $(wildcard Sources/*.cxx) - -.PHONY: run-efi-amd64 -run-efi-amd64: - $(EMU) $(EMU_FLAGS) - -# 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 - qemu-img create -f raw $(IMG_2) 512M - -.PHONY: download-edk -download-edk: - $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - -BINS=*.bin -EXECUTABLES=newosldr.exe newoskrnl.exe OVMF.fd - -TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) - -.PHONY: clean -clean: - $(REM) $(TARGETS) - -.PHONY: help -help: - @echo "=== HELP ===" - @echo "epm-img: Format a disk using the Explicit Partition Map." - @echo "gpt-img: Format a disk using the Explicit Partition Map." - @echo "clean: clean bootloader." - @echo "bootloader-amd64: Build bootloader. (PC AMD64)" - @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Kernel/amd64-efi.make b/Kernel/amd64-efi.make index 7e076a8d..b7ca45e9 100644 --- a/Kernel/amd64-efi.make +++ b/Kernel/amd64-efi.make @@ -6,7 +6,7 @@ CC = x86_64-w64-mingw32-gcc LD = x86_64-w64-mingw32-ld CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ - -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I../ -I./ + -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ ASM = nasm @@ -70,17 +70,17 @@ link-amd64-epm: .PHONY: all all: newos-amd64-epm link-amd64-epm - qemu-img create -f raw newoskrnl.rom 512K - dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc + qemu-img create -f raw newoskrnl.512k.exe 512K + dd if=newoskrnl.exe of=newoskrnl.512k.exe bs=1 seek=0 conv=notrunc @echo "NewOSKrnl => OK." .PHONY: help help: @echo "=== HELP ===" @echo "all: Build kernel and link it." - @echo "link-amd64-epm: Link kernel. (EPM AMD64)" - @echo "newos-amd64-epm: Build kernel. (EPM AMD64)" + @echo "link-amd64-epm: Link kernel for EPM based disks." + @echo "newos-amd64-epm: Build kernel for EPM based disks." .PHONY: clean clean: - rm -f $(LDOBJ) $(KERNEL) + rm -f $(LDOBJ) $(wildcard *.o) $(KERNEL) diff --git a/Kernel/arm64-cb.make b/Kernel/arm64-cb.make index 3b24bcdb..ac7ccd2d 100644 --- a/Kernel/arm64-cb.make +++ b/Kernel/arm64-cb.make @@ -3,9 +3,9 @@ # This is the microkernel makefile. ################################################## -CC = arm-none-eabi-gcc.exe +CC = arm-none-eabi-g++.exe LD = arm-none-eabi-ld.exe -CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_ARM64__ -fno-rtti -fno-exceptions -I../ -I./ \ +CCFLAGS = -c -fPIC -ffreestanding -D__NEWOS_ARM64__ -fno-rtti -fno-exceptions -I./ \ -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ ASM = arm-none-eabi-as.exe @@ -22,10 +22,6 @@ endif COPY = cp -# Add assembler, linker, and object files variables. -ASMFLAGS = -f elf64 - -# NewOS subsystem is 17 and entrypoint is __ImageStart LDFLAGS = -e __ImageStart LDOBJ = Objects/*.obj @@ -57,17 +53,17 @@ link-arm64-epm: .PHONY: all all: newos-arm64-epm link-arm64-epm - qemu-img create -f raw newoskrnl.rom 512K - dd if=newoskrnl.exe of=newoskrnl.rom bs=1 seek=0 conv=notrunc + qemu-img create -f raw newoskrnl.512k.exe 512K + dd if=newoskrnl.exe of=newoskrnl.512k.exe bs=1 seek=0 conv=notrunc @echo "NewOSKrnl => OK." .PHONY: help help: @echo "=== HELP ===" @echo "all: Build kernel and link it." - @echo "link-arm64-epm: Link kernel. (EPM AMD64)" - @echo "newos-arm64-epm: Build kernel. (EPM AMD64)" + @echo "link-arm64-epm: Link kernel for EPM based disks." + @echo "newos-arm64-epm: Build kernel for EPM based disks." .PHONY: clean clean: - rm -f $(LDOBJ) $(KERNEL) + rm -f $(LDOBJ) $(wildcard *.o) $(KERNEL) -- cgit v1.2.3 From e8f7e653364e4a2d48529c07b8325a8f147cf3e9 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Mon, 17 Jun 2024 15:31:00 +0200 Subject: MHR-31: Will add 'Profiles' for phone/laptop models. Signed-off-by: Amlal EL Mahrouss --- Kernel/NetworkKit/NetworkDevice.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 58b9a98b..20c2a66a 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef __NETWORK_DEVICE__ -#define __NETWORK_DEVICE__ +#ifndef __INC_NETWORK_DEVICE_HPP__ +#define __INC_NETWORK_DEVICE_HPP__ #include #include @@ -70,4 +70,4 @@ namespace NewOS #include -#endif // !__NETWORK_DEVICE__ +#endif // !__INC_NETWORK_DEVICE_HPP__ -- cgit v1.2.3 From 8051ad2bd4af1f226a9751288957ee6af7e787d7 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Mon, 17 Jun 2024 18:55:38 +0200 Subject: MHR-31: IMP: Add setter for Name. Signed-off-by: Amlal EL Mahrouss --- Drv/GSMDrv/GSMDrv.c | 6 ++++-- Drv/VideoDrv/VideoDrv.c | 4 ++-- Kernel/NetworkKit/NetworkDevice.hpp | 9 +++++++-- Kernel/Sources/Network/NetworkDevice.cxx | 20 +++++++++++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Drv/GSMDrv/GSMDrv.c b/Drv/GSMDrv/GSMDrv.c index 791c0678..1b7cfed6 100644 --- a/Drv/GSMDrv/GSMDrv.c +++ b/Drv/GSMDrv/GSMDrv.c @@ -7,7 +7,8 @@ #include #include -int __ImageStart(void) +/// @brief GSM entrypoint. +int __at_enter(void) { kernelPrintStr("GSMDrv: Starting up...\r"); @@ -16,7 +17,8 @@ int __ImageStart(void) return 0; } -int __ImageEnd(void) +/// @brief GSM 'atexit' function. +int __at_exit(void) { kernelPrintStr("GSMDrv: Shutting down...\r"); return 0; diff --git a/Drv/VideoDrv/VideoDrv.c b/Drv/VideoDrv/VideoDrv.c index 3ba104d6..fc79d2a0 100644 --- a/Drv/VideoDrv/VideoDrv.c +++ b/Drv/VideoDrv/VideoDrv.c @@ -9,13 +9,13 @@ #include -int __ImageStart(void) +int __at_enter(void) { kernelPrintStr("VideoDrv: Starting up...\r"); return 0; } -int __ImageEnd(void) +int __at_exit(void) { kernelPrintStr("VideoDrv: Shutting down...\r"); return 0; diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 20c2a66a..4ea98e4f 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -35,12 +35,17 @@ namespace NewOS public: const char* Name() const override; + Boolean Name(const char* strView); private: - void (*fCleanup)(void); + constexpr auto cNetworkNameLen = 512; + + Void (*fCleanup)(void); + Char fNetworkName[cNetworkNameLen]; + }; - struct PACKED NetworkDeviceCommand final + struct NetworkDeviceCommand final { UInt32 CommandName; UInt32 CommandType; diff --git a/Kernel/Sources/Network/NetworkDevice.cxx b/Kernel/Sources/Network/NetworkDevice.cxx index 511246c7..e1994baa 100644 --- a/Kernel/Sources/Network/NetworkDevice.cxx +++ b/Kernel/Sources/Network/NetworkDevice.cxx @@ -8,8 +8,26 @@ namespace NewOS { + /// \brief Getter for fNetworkName. const char* NetworkDevice::Name() const { - return "NetworkDevice"; + return this->fNetworkName; + } + + /// \brief Setter for fNetworkName. + Boolean NetworkDevice::Name(const char* strView) + { + if (strView == nullptr) + return false; + + if (*strView == 0) + return false; + + if (rt_string_len(strView) > cNetworkNameLen) + return false; + + rt_copy_memory(strView, this->fNetworkName, rt_string_len(strView)); + + return true; } } // namespace NewOS -- cgit v1.2.3 From 596268586bb4c8248a8ec106b8cdea12b9ab926a Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 18 Jun 2024 10:39:00 +0200 Subject: IMP: TLS syscall, serial write syscall. FIX: SMP manager writes to stack frame directly, check if we also want to free the stack. Signed-off-by: Amlal EL Mahrouss --- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 20 +++++----- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 2 +- Kernel/HALKit/AMD64/HalKernelMain.cxx | 14 +++++-- Kernel/KernelKit/ProcessScheduler.hxx | 4 +- Kernel/KernelKit/ThreadLocalStorage.hxx | 6 ++- Kernel/KernelKit/ThreadLocalStorage.inl | 8 ++-- Kernel/NetworkKit/NetworkDevice.hpp | 2 +- Kernel/Sources/KeMain.cxx | 10 ++--- Kernel/Sources/Network/NetworkDevice.cxx | 4 +- Kernel/Sources/PEFSharedObject.cxx | 10 ++--- Kernel/Sources/ProcessScheduler.cxx | 12 +++--- Kernel/Sources/SMPManager.cxx | 44 +++++++++------------- Kernel/Sources/ThreadLocalStorage.cxx | 8 ++-- Kernel/Sources/UserHeap.cxx | 2 +- 14 files changed, 74 insertions(+), 72 deletions(-) diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index e9c0941c..657ab622 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -14,9 +14,9 @@ EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp) { NewOS::kcout << "newoskrnl: General Protection Fault, caused by " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Handle page fault. @@ -25,9 +25,9 @@ EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp) { NewOS::kcout << "newoskrnl: Segmentation Fault, caused by " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Handle math fault. @@ -36,9 +36,9 @@ EXTERN_C void idt_handle_math(NewOS::UIntPtr rsp) { NewOS::kcout << "newoskrnl: Math error, caused by " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Handle any generic fault. @@ -47,9 +47,9 @@ EXTERN_C void idt_handle_generic(NewOS::UIntPtr rsp) { NewOS::kcout << "newoskrnl: Execution error, caused by " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Handle #UD fault. @@ -58,9 +58,9 @@ EXTERN_C void idt_handle_ud(NewOS::UIntPtr rsp) { NewOS::kcout << "newoskrnl: Invalid interrupt, caused by " - << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Enter syscall from assembly. diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 26773640..4e9d2ff6 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -185,7 +185,7 @@ namespace NewOS::HAL { Semaphore sem; - sem.LockOrWait(&ProcessScheduler::The().Leak().GetCurrent().Leak(), Seconds(5)); + sem.LockOrWait(&ProcessScheduler::The().Leak().TheCurrent().Leak(), Seconds(5)); cFramePtr = stackFrame; diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index cafa6388..3fac40ca 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -76,14 +76,20 @@ EXTERN_C void hal_init_platform( /* install basic hooks. */ - constexpr auto cDummyInterrupt = 0x10; // 16 + constexpr auto cSerialWriteInterrupt = 0x10; // 16 + constexpr auto cTlsInterrupt = 0x11; // 17 - kSyscalls[cDummyInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr sf) -> void { - const char* msg = (const char*)sf; + kSyscalls[cSerialWriteInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void { + const char* msg = (const char*)rdx; NewOS::kcout << "newoskrnl: " << msg << "\r"; }; - kSyscalls[cDummyInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { + tls_check_syscall_impl(rdx); + }; + + kSyscalls[cSerialWriteInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cTlsInterrupt].Leak().Leak()->fHooked = true; NewOS::HAL::Detail::_ke_power_on_self_test(); diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 7c8f99be..8c470bb4 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -249,7 +249,7 @@ namespace NewOS bool Remove(SizeT headerIndex); public: - Ref& GetCurrent(); + Ref& TheCurrent(); SizeT Run() noexcept; public: @@ -268,7 +268,7 @@ namespace NewOS public: static bool Switch(HAL::StackFrame* newStack, const PID& newPid); static bool CanBeScheduled(Ref& process); - static PID& GetCurrentPID(); + static PID& TheCurrentPID(); static SizeT StartScheduling(); }; diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index eaae7991..432cc9ac 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -37,14 +37,16 @@ struct PACKED ThreadInformationBlock final NewOS::Int32 ThreadID; // Thread execution ID. }; +typedef struct ThreadInformationBlock ProcessInformationBlock; + /// @brief TLS install TIB and PIB. -EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, NewOS::VoidPtr PIB); +EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, ThreadInformationBlock* PIB); ///! @brief Cookie Sanity check. NewOS::Boolean tls_check_tib(ThreadInformationBlock* Ptr); /// @brief TLS check system call -EXTERN_C NewOS::Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr StackPtr) noexcept; +EXTERN_C NewOS::Void tls_check_syscall_impl(NewOS::VoidPtr TIB) noexcept; #include diff --git a/Kernel/KernelKit/ThreadLocalStorage.inl b/Kernel/KernelKit/ThreadLocalStorage.inl index 1df825a3..6dbff3a1 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.inl +++ b/Kernel/KernelKit/ThreadLocalStorage.inl @@ -15,9 +15,9 @@ inline T* tls_new_ptr(void) { using namespace NewOS; - MUST_PASS(ProcessScheduler::The().Leak().GetCurrent()); + MUST_PASS(ProcessScheduler::The().Leak().TheCurrent()); - auto ref_process = ProcessScheduler::The().Leak().GetCurrent(); + auto ref_process = ProcessScheduler::The().Leak().TheCurrent(); T* pointer = (T*)ref_process.Leak().New(sizeof(T)); return pointer; @@ -32,9 +32,9 @@ inline bool tls_delete_ptr(T* ptr) using namespace NewOS; - MUST_PASS(ProcessScheduler::The().Leak().GetCurrent()); + MUST_PASS(ProcessScheduler::The().Leak().TheCurrent()); - auto ref_process = ProcessScheduler::The().Leak().GetCurrent(); + auto ref_process = ProcessScheduler::The().Leak().TheCurrent(); return ref_process.Leak().Delete(ptr, sizeof(T)); } diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 4ea98e4f..9b251c2e 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -38,7 +38,7 @@ namespace NewOS Boolean Name(const char* strView); private: - constexpr auto cNetworkNameLen = 512; + static constexpr auto cNetworkNameLen = 512; Void (*fCleanup)(void); Char fNetworkName[cNetworkNameLen]; diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 83702d77..fb127271 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -28,13 +28,13 @@ namespace NewOS::Detail { /// @brief Filesystem auto mounter, additional checks are also done by the /// class. - class FilesystemWizard final + class FilesystemInstaller final { NewOS::NewFilesystemManager* fNewFS{nullptr}; public: /// @brief wizard constructor. - explicit FilesystemWizard() + explicit FilesystemInstaller() { if (NewOS::FilesystemManagerInterface::GetMounted()) { @@ -166,9 +166,9 @@ namespace NewOS::Detail } } - ~FilesystemWizard() = default; + ~FilesystemInstaller() = default; - NEWOS_COPY_DEFAULT(FilesystemWizard); + NEWOS_COPY_DEFAULT(FilesystemInstaller); /// @brief Grab the disk's NewFS reference. /// @return NewFilesystemManager the filesystem interface @@ -211,7 +211,7 @@ namespace NewOS::Detail EXTERN_C NewOS::Void KeMain(NewOS::Void) { /// Now run kernel loop, until no process are running. - NewOS::Detail::FilesystemWizard wizard; // automatic filesystem creation. + NewOS::Detail::FilesystemInstaller installer; // automatic filesystem creation. NewOS::Detail::ke_launch_srv(); diff --git a/Kernel/Sources/Network/NetworkDevice.cxx b/Kernel/Sources/Network/NetworkDevice.cxx index e1994baa..027613ac 100644 --- a/Kernel/Sources/Network/NetworkDevice.cxx +++ b/Kernel/Sources/Network/NetworkDevice.cxx @@ -5,6 +5,7 @@ ------------------------------------------- */ #include +#include namespace NewOS { @@ -26,7 +27,8 @@ namespace NewOS if (rt_string_len(strView) > cNetworkNameLen) return false; - rt_copy_memory(strView, this->fNetworkName, rt_string_len(strView)); + rt_copy_memory((VoidPtr)strView, + (VoidPtr)this->fNetworkName, rt_string_len(strView)); return true; } diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx index 5103e075..0d5949f1 100644 --- a/Kernel/Sources/PEFSharedObject.cxx +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -41,7 +41,7 @@ EXTERN_C SharedObjectPtr rt_library_init(void) if (!library) { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } @@ -50,17 +50,17 @@ EXTERN_C SharedObjectPtr rt_library_init(void) if (!library->Get()) { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } library->Get()->fImageObject = - ProcessScheduler::The().Leak().GetCurrent().Leak().Image; + ProcessScheduler::The().Leak().TheCurrent().Leak().Image; if (!library->Get()->fImageObject) { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return nullptr; } @@ -85,7 +85,7 @@ EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) if (lib == nullptr) { *successful = false; - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } delete lib->Get(); diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index d232c72e..aae69386 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -161,7 +161,7 @@ namespace NewOS void ProcessHeader::Exit(Int32 exit_code) { if (this->ProcessId != - ProcessScheduler::The().Leak().GetCurrent().Leak().ProcessId) + ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) ke_stop(RUNTIME_CHECK_PROCESS); kLastExitCode = exit_code; @@ -286,17 +286,17 @@ namespace NewOS /// @brief Gets current running process. /// @return - Ref& ProcessScheduler::GetCurrent() + Ref& ProcessScheduler::TheCurrent() { return mTeam.AsRef(); } /// @brief Current proccess id getter. /// @return Process ID integer. - PID& ProcessHelper::GetCurrentPID() + PID& ProcessHelper::TheCurrentPID() { - kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r"; - return ProcessScheduler::The().Leak().GetCurrent().Leak().ProcessId; + kcout << "ProcessHelper::TheCurrentPID: Leaking ProcessId...\r"; + return ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId; } /// @brief Check if process can be schedulded. @@ -368,7 +368,7 @@ namespace NewOS ThreadKind::kHartSystemReserved) { SMPManager::The().Leak()[index].Leak()->Busy(true); - ProcessHelper::GetCurrentPID() = new_pid; + ProcessHelper::TheCurrentPID() = new_pid; return SMPManager::The().Leak()[index].Leak()->Switch(the_stack); } diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 5002e880..149b1334 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -85,36 +85,26 @@ namespace NewOS bool HardwareThread::Switch(HAL::StackFramePtr stack) { if (!rt_check_stack(stack)) - return false; - - if (!fStack) - { - fStack = stack; - } - else { - /// Keep the arguments, switch the base pointer, stack pointer - /// fs and gs registers. - fStack->Rbp = stack->Rbp; - fStack->Rsp = stack->Rsp; - fStack->Fs = stack->Fs; - fStack->Gs = stack->Gs; - - // save global registers. - - fStack->R15 = stack->R15; - fStack->R14 = stack->R14; + /// provide 'nullptr' to free the stack frame. + if (stack == nullptr) + { + delete fStack; + fStack = nullptr; - fStack->R13 = stack->R13; - fStack->R12 = stack->R12; - fStack->R11 = stack->R11; + return true; + } - fStack->R10 = stack->R10; - fStack->R9 = stack->R9; - fStack->R8 = stack->R8; + return false; + } - fStack->Rcx = this->fID; + if (fStack) + { + delete fStack; + fStack = nullptr; } + + fStack = stack; rt_do_context_switch(fStack); @@ -146,7 +136,7 @@ namespace NewOS HAL::StackFramePtr SMPManager::Leak() noexcept { if (fThreadList[fCurrentThread].Leak() && - ProcessHelper::GetCurrentPID() == + ProcessHelper::TheCurrentPID() == fThreadList[fCurrentThread].Leak().Leak()->fPID) return fThreadList[fCurrentThread].Leak().Leak()->fStack; @@ -189,7 +179,7 @@ namespace NewOS fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack); - fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::GetCurrentPID(); + fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::TheCurrentPID(); fThreadList[idx].Leak().Leak()->Busy(false); diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index c292d078..4d6fec14 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -44,14 +44,16 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr stackPtr) noexcept +EXTERN_C Void tls_check_syscall_impl(NewOS::VoidPtr TIB) noexcept { - ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs; + if (!TIB) return; + + ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB; if (!tls_check_tib(tib)) { kcout << "newoskrnl: Verification failed, Crashing...\r"; - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/UserHeap.cxx index d1de13a6..f20e30f8 100644 --- a/Kernel/Sources/UserHeap.cxx +++ b/Kernel/Sources/UserHeap.cxx @@ -150,7 +150,7 @@ namespace NewOS { if (!poolHdr->fFree) { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return; } -- cgit v1.2.3 From 1a3b924f62346cc76bd183883825c5541834c90c Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 18 Jun 2024 12:40:05 +0200 Subject: MHR-31: TLS.hxx: FIX: Dont specify a virtual address for **every** architecture. Signed-off-by: Amlal EL Mahrouss --- Kernel/KernelKit/ThreadLocalStorage.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index 432cc9ac..9d5473a2 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -27,7 +27,7 @@ T* tls_new_class(Args&&... args); #define kTLSCookieLen 3 /// @brief Thread Information Block for Local Storage. -/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) +/// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) struct PACKED ThreadInformationBlock final { NewOS::Char Cookie[kTLSCookieLen]; -- cgit v1.2.3 From 90faf32f29b5482b52ab90f416528ed8f4e8f130 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 18 Jun 2024 13:04:01 +0200 Subject: MHR-31 IMP: Add TLS, a new/delete syscall. TODO: File I/O and network syscalls as well. Signed-off-by: Amlal EL Mahrouss --- Kernel/HALKit/AMD64/HalInstallTIB.asm | 2 ++ Kernel/HALKit/AMD64/HalKernelMain.cxx | 44 ++++++++++++++++++++++++++++++++- Kernel/KernelKit/ThreadLocalStorage.hxx | 30 +++++++++++----------- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/Kernel/HALKit/AMD64/HalInstallTIB.asm b/Kernel/HALKit/AMD64/HalInstallTIB.asm index f53fb14e..9111c835 100644 --- a/Kernel/HALKit/AMD64/HalInstallTIB.asm +++ b/Kernel/HALKit/AMD64/HalInstallTIB.asm @@ -11,6 +11,8 @@ [global rt_install_tib] +section .text + ;; changed: rs, fs ;; expected: rcx, rdx diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 3fac40ca..701439f1 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -74,10 +74,13 @@ EXTERN_C void hal_init_platform( NewOS::HAL::IDTLoader idt; idt.Load(idtBase); - /* install basic hooks. */ + /* install basic syscalls. */ constexpr auto cSerialWriteInterrupt = 0x10; // 16 constexpr auto cTlsInterrupt = 0x11; // 17 + constexpr auto cTlsInstallInterrupt = 0x12; // 18 + constexpr auto cNewInterrupt = 0x13; // 19 + constexpr auto cDeleteInterrupt = 0x14; // 20 kSyscalls[cSerialWriteInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void { const char* msg = (const char*)rdx; @@ -88,8 +91,47 @@ EXTERN_C void hal_init_platform( tls_check_syscall_impl(rdx); }; + struct PACKED HeapAllocInfo final + { + NewOS::VoidPtr fThe; + NewOS::Size fTheSz; + }; + + struct PACKED ProcessBlockInfo final + { + ThreadInformationBlock* fTIB; + ThreadInformationBlock* fPIB; + }; + + kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { + + /// get HAC struct. + HeapAllocInfo* rdxInf = (HeapAllocInfo*)rdx; + + /// assign the fThe field with the pointer. + rdxInf->fThe = NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz); + }; + + kSyscalls[cDeleteInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { + /// get HAC struct. + HeapAllocInfo* rdxInf = (HeapAllocInfo*)rdx; + + /// delete ptr with sz in mind. + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz); + }; + + kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { + ProcessBlockInfo* rdxPb = (ProcessBlockInfo*)rdx; + + /// install the process's fTIB and fPIB. + rt_install_tib(rdxPb->fTIB, rdxPb->fPIB); + }; + kSyscalls[cSerialWriteInterrupt].Leak().Leak()->fHooked = true; kSyscalls[cTlsInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cDeleteInterrupt].Leak().Leak()->fHooked = true; + kSyscalls[cNewInterrupt].Leak().Leak()->fHooked = true; NewOS::HAL::Detail::_ke_power_on_self_test(); diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index 9d5473a2..75d29ced 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -15,16 +15,7 @@ #define kCookieMag1 'C' #define kCookieMag2 'R' -template -T* tls_new_ptr(void); - -template -bool tls_delete_ptr(T* ptr); - -template -T* tls_new_class(Args&&... args); - -#define kTLSCookieLen 3 +#define kTLSCookieLen (3U) /// @brief Thread Information Block for Local Storage. /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) @@ -39,13 +30,24 @@ struct PACKED ThreadInformationBlock final typedef struct ThreadInformationBlock ProcessInformationBlock; -/// @brief TLS install TIB and PIB. -EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, ThreadInformationBlock* PIB); - ///! @brief Cookie Sanity check. NewOS::Boolean tls_check_tib(ThreadInformationBlock* Ptr); -/// @brief TLS check system call +///! @brief new ptr syscall. +template +T* tls_new_ptr(void); + +///! @brief delete ptr syscall. +template +bool tls_delete_ptr(T* ptr); + +template +T* tls_new_class(Args&&... args); + +/// @brief TLS install TIB and PIB. (syscall) +EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, ThreadInformationBlock* PIB); + +/// @brief TLS check (syscall) EXTERN_C NewOS::Void tls_check_syscall_impl(NewOS::VoidPtr TIB) noexcept; #include -- cgit v1.2.3 From b5ea4be45949b4592879ae35bd15cc3b35ac9ff5 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 18 Jun 2024 23:21:07 +0200 Subject: MHR-31: Fix code quality. Signed-off-by: Amlal EL Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 7 ++++++- Kernel/HALKit/AMD64/HalKernelMain.cxx | 6 +++--- Kernel/NetworkKit/IPCEP.hxx | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index 057ba61b..a8d0d8d7 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -32,9 +32,14 @@ namespace NewOS /// You have to parse the MADT! - ACPIFactoryInterface::ACPIFactoryInterface(voidPtr rsdPtr) + ACPIFactoryInterface::ACPIFactoryInterface(VoidPtr rsdPtr) : fRsdp(rsdPtr), fEntries(0) { +#ifdef __DEBUG__ + kcout << "newoskrnl: ACPI: init interface.\r"; +#else + +#endif } Void ACPIFactoryInterface::Shutdown() diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 701439f1..8c4a05dc 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -106,7 +106,7 @@ EXTERN_C void hal_init_platform( kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { /// get HAC struct. - HeapAllocInfo* rdxInf = (HeapAllocInfo*)rdx; + HeapAllocInfo* rdxInf = reinterpret_cast(rdx); /// assign the fThe field with the pointer. rdxInf->fThe = NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().New(rdxInf->fTheSz); @@ -114,14 +114,14 @@ EXTERN_C void hal_init_platform( kSyscalls[cDeleteInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { /// get HAC struct. - HeapAllocInfo* rdxInf = (HeapAllocInfo*)rdx; + HeapAllocInfo* rdxInf = reinterpret_cast(rdx); /// delete ptr with sz in mind. NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Delete(rdxInf->fThe, rdxInf->fTheSz); }; kSyscalls[cTlsInstallInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { - ProcessBlockInfo* rdxPb = (ProcessBlockInfo*)rdx; + ProcessBlockInfo* rdxPb = reinterpret_cast(rdx); /// install the process's fTIB and fPIB. rt_install_tib(rdxPb->fTIB, rdxPb->fPIB); diff --git a/Kernel/NetworkKit/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx index 72efae73..6c7578b3 100644 --- a/Kernel/NetworkKit/IPCEP.hxx +++ b/Kernel/NetworkKit/IPCEP.hxx @@ -27,7 +27,7 @@ namespace NewOS { /// @brief 96-bit number to represent the domain and namespace - struct PACKED IPCEPAddress + struct PACKED IPCEPAddress final { UInt32 RemoteAddress; UInt64 RemoteNamespace; @@ -41,17 +41,20 @@ namespace NewOS eIPCEPBigEndian = 1 }; - /// @brief IPCEP connection header + /// @brief IPCEP connection header, must be the same on + /// user side as well. + typedef struct IPCEPConnectionHeader { - UInt32 IpcHeader; // cRemoteHeaderMagic - UInt8 IpcEndianess; // 0 : LE, 1 : BE - SizeT IpcPacketSize; + UInt32 IpcHeader; // cRemoteHeaderMagic + UInt8 IpcEndianess; // 0 : LE, 1 : BE + SizeT IpcPacketSize; IPCEPAddressType IpcFrom; IPCEPAddressType IpcTo; - UInt32 IpcCRC32; - UInt32 IpcMsg; - UInt32 IpcMsgSz; + UInt32 IpcCRC32; + UInt32 IpcMsg; + UInt32 IpcMsgSz; + UInt8 IpcData[]; } PACKED IPCEPConnectionHeader; } // namespace NewOS -- cgit v1.2.3 From 6735570c44516661260546dadb81f0f5c238d1db Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Wed, 19 Jun 2024 09:57:48 +0200 Subject: MHR-31: Final commit. Signed-off-by: Amlal EL Mahrouss --- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index a8d0d8d7..c9b1cb1f 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -12,7 +12,6 @@ namespace NewOS { - /// Custom to the virtual machine, you'll need to parse the MADT instead. void rt_shutdown_acpi_qemu_20(void) -- cgit v1.2.3