diff options
105 files changed, 994 insertions, 1347 deletions
@@ -12,6 +12,7 @@ cmake_install.cmake qtcsettings.cmake *.exec +*.rom NvVars 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/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/amd64-efi.make index 4bee19a2..37ac3704 100644 --- a/Boot/makefile +++ b/Boot/amd64-efi.make @@ -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), ) @@ -26,7 +28,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 -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/Boot/Sources/ovmf.ps1 b/Boot/download-ovmf.ps1 index 5a2c5f0e..5a2c5f0e 100644 --- a/Boot/Sources/ovmf.ps1 +++ b/Boot/download-ovmf.ps1 diff --git a/DDK/KernelCall.c b/DDK/KernelCall.c index c20a4894..7dc5761c 100644 --- a/DDK/KernelCall.c +++ b/DDK/KernelCall.c @@ -9,22 +9,18 @@ #include <DDK/KernelStd.h> #include <stdarg.h> -DK_EXTERN __attribute__((naked)) void __kernelDispatchCall(int32_t cnt, ...); +/// @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 -DK_EXTERN void* kernelCall(const char* kernelRpcName, int32_t cnt, ...) +/// @param +/// @return +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 <DDK/KernelDev.h> +#include <DDK/KernelString.h> /// @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..0486479c 100644 --- a/DDK/KernelStd.h +++ b/DDK/KernelStd.h @@ -19,4 +19,10 @@ #include <stdint.h> #include <stddef.h> -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/Usr/Sys/CoreSystem/Sources/CRTStartup.c b/Drv/GSMDrv/CheckStck.c index faefe9b7..3eb157ba 100644 --- a/Usr/Sys/CoreSystem/Sources/CRTStartup.c +++ b/Drv/GSMDrv/CheckStck.c @@ -1,12 +1,11 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include <Headers/Defines.h> - -VoidType __DllMainCRTStartup(VoidType) -{ - kSharedApplication = RtGetAppPointer(); -}
\ No newline at end of file +/* -------------------------------------------
+
+ 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..1b7cfed6 --- /dev/null +++ b/Drv/GSMDrv/GSMDrv.c @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include <DDK/KernelString.h> +#include <DDK/KernelPrint.h> + +/// @brief GSM entrypoint. +int __at_enter(void) +{ + kernelPrintStr("GSMDrv: Starting up...\r"); + + /// @brief activate SIM 0..n + + return 0; +} + +/// @brief GSM 'atexit' function. +int __at_exit(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/Usr/Sys/CoreSystem/Sources/Thread.c b/Drv/SampleDriver/CheckStck.c index 630787e1..3eb157ba 100644 --- a/Usr/Sys/CoreSystem/Sources/Thread.c +++ b/Drv/SampleDriver/CheckStck.c @@ -1,9 +1,11 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include <Headers/Thread.h> - -ThreadRef kMainThread = 0; +/* -------------------------------------------
+
+ 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/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..fc79d2a0 --- /dev/null +++ b/Drv/VideoDrv/VideoDrv.c @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include <DDK/KernelString.h> +#include <DDK/KernelPrint.h> + +#include <Builtins/GX/GX> + +int __at_enter(void) +{ + kernelPrintStr("VideoDrv: Starting up...\r"); + return 0; +} + +int __at_exit(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/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index 419f2c7a..c889c93c 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -79,12 +79,23 @@ namespace NewOS #define kKernelMaxSystemCalls (256) -typedef NewOS::Void (*rt_syscall_proc)(NewOS::HAL::StackFramePtr); +typedef NewOS::Void (*rt_syscall_proc)(NewOS::VoidPtr); -extern NewOS::Array<rt_syscall_proc, +struct RTSyscallInfoHdr final +{ + NewOS::Int64 fHash; + NewOS::Bool fHooked; + rt_syscall_proc fProc; +}; + +inline NewOS::Array<RTSyscallInfoHdr, kKernelMaxSystemCalls> kSyscalls; +inline NewOS::Array<RTSyscallInfoHdr, + kKernelMaxSystemCalls> + 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/Usr/Sys/CoreSystem/.gitkeep b/Kernel/Builtins/GPRS/.keepme index e69de29b..e69de29b 100644 --- a/Usr/Sys/CoreSystem/.gitkeep +++ b/Kernel/Builtins/GPRS/.keepme diff --git a/Usr/Sys/CoreSystem/ARM64/.gitkeep b/Kernel/Builtins/GSM/.keepme index e69de29b..e69de29b 100644 --- a/Usr/Sys/CoreSystem/ARM64/.gitkeep +++ b/Kernel/Builtins/GSM/.keepme 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 <NewKit/Defines.hpp>
+#include <NewKit/String.hpp>
+
+/// @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/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/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 <NewKit/Array.hpp> #include <NewKit/Defines.hpp> @@ -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 <SSizeT N> + template <SizeT N> using PropertyArray = Array<Property, N>; } // namespace NewOS -#endif // !_INC_PLIST_HPP__ +#endif // !__INC_PLIST_HPP__ diff --git a/Usr/Sys/CoreSystem/Headers/Rsrc.h b/Kernel/FSKit/FAT32.hxx index fafdcc7c..4aa0fc2b 100644 --- a/Usr/Sys/CoreSystem/Headers/Rsrc.h +++ b/Kernel/FSKit/FAT32.hxx @@ -1,12 +1,12 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include <Headers/Defines.h> - -/// @file Rsrc.h -/// @brief RXML forks.
\ No newline at end of file +/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hpp>
+
+/// @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..892083a2 100644 --- a/Kernel/FSKit/IndexableProperty.hxx +++ b/Kernel/FSKit/IndexableProperty.hxx @@ -24,19 +24,21 @@ namespace NewOS Char Path[kIndexerNodeNameLength]; }; + class IndexableProperty final : public Property { public: explicit IndexableProperty() - : Property(StringBuilder::Construct("IndexableProperty").Leak().Leak()) + : Property(StringBuilder::Construct("\\Filesystem\\IsIndexable?").Leak().Leak()) { } + ~IndexableProperty() override = default; NEWOS_COPY_DEFAULT(IndexableProperty); public: - IndexProperty& LeakProperty() noexcept; + IndexProperty& Leak() noexcept; public: void AddFlag(Int16 flag); 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/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 <FirmwareKit/EFI/EFI.hxx> + +/// @note this header is used to reference the EFI/EFI.hxx
\ No newline at end of file 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/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index 057ba61b..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) @@ -32,9 +31,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/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 5f64cc20..657ab622 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -12,90 +12,82 @@ /// @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(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); - 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"; - } + NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } /// @brief Handle page fault. /// @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(); + << 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. /// @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(); + << 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. /// @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(); + << 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. /// @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(); + << NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetName(); + + NewOS::ProcessScheduler::The().Leak().TheCurrent().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"; + + if (kSyscalls[rcx].Leak().Leak()->fHooked) + (kSyscalls[rcx].Leak().Leak()->fProc)((NewOS::VoidPtr)rdx); - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + 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 f15faf3c..4e9d2ff6 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -10,15 +10,13 @@ #include <ArchKit/ArchKit.hpp> #include <KernelKit/Semaphore.hpp> #include <KernelKit/ProcessScheduler.hxx> +#include <KernelKit/Timer.hpp> #define kAPIC_ICR_Low 0x300 #define kAPIC_ICR_High 0x310 #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); @@ -116,10 +114,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; @@ -159,23 +163,7 @@ namespace NewOS::HAL EXTERN_C Void hal_apic_acknowledge_cont(Void) { - kcout << "newoskrnl: finish kernel init... \r"; - - if (cProgramInitialized && - *cProgramInitialized) - { - *cProgramInitialized = false; - - kcout << "newoskrnl: putting thread to sleep...\r"; - - _hal_spin_core(); - } - else - { - KeMain(); - - _hal_spin_core(); - } + _hal_spin_core(); } EXTERN_C StackFramePtr _hal_leak_current_context(Void) @@ -196,16 +184,13 @@ namespace NewOS::HAL STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame) { Semaphore sem; - while (sem.IsLocked()) - { - } - sem.Lock(&ProcessScheduler::The().Leak().GetCurrent().Leak()); + sem.LockOrWait(&ProcessScheduler::The().Leak().TheCurrent().Leak(), Seconds(5)); 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(); } @@ -219,21 +204,23 @@ namespace NewOS::HAL if (kApicMadt != nullptr) { - MadtType* madt = (MadtType*)kApicMadt; + MadtType* madt = reinterpret_cast<MadtType*>(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; } } @@ -258,7 +245,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/HalHardwareMP.cpp b/Kernel/HALKit/AMD64/HalHart.cpp index 92e075aa..069f3767 100644 --- a/Kernel/HALKit/AMD64/HalHardwareMP.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/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/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index ef5a8319..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 @@ -195,15 +195,45 @@ 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 rcx + push rdx + push rax + + call hal_system_call_enter + + pop rax + pop rdx + pop rcx + + sti + iretq + +__NEW_INT_51: + cli + + push rcx + push rdx + push r8 + push r9 + push rax + + call hal_kernel_call_enter + + pop rax + pop r9 + pop r8 + pop rdx + pop rcx sti iretq -IntNormal 51 IntNormal 52 IntNormal 53 IntNormal 54 @@ -223,13 +253,19 @@ IntNormal 60 ;; this one is doing a POST for us. ;; testing interrupts. _ke_power_on_self_test: - int 0x32 - int 0x32 - int 0x32 + mov rcx, 0x10 + 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..8c4a05dc 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -14,6 +14,10 @@ #include <KernelKit/ProcessScheduler.hxx> #include <KernelKit/UserHeap.hpp> #include <NewKit/Json.hpp> +#include <KernelKit/CodeManager.hpp> + +/// @brief This symbol is the kernel main symbol. +EXTERN_C void KeMain(); EXTERN_C NewOS::VoidPtr kInterruptVectorTable[]; @@ -24,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 && @@ -35,29 +51,17 @@ EXTERN_C void hal_init_platform( return; } - /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = reinterpret_cast<NewOS::VoidPtr>( reinterpret_cast<NewOS::UIntPtr>(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<NewOS::UIntPtr>(&GDT); + gdtBase.Base = reinterpret_cast<NewOS::UIntPtr>(&cGdt); gdtBase.Limit = sizeof(NewOS::HAL::Detail::NewOSGDT) - 1; - /// Load GDT. - NewOS::HAL::GDTLoader gdt; gdt.Load(gdtBase); @@ -70,15 +74,70 @@ EXTERN_C void hal_init_platform( NewOS::HAL::IDTLoader idt; idt.Load(idtBase); - /// START POST + /* install basic syscalls. */ - NewOS::HAL::Detail::_ke_power_on_self_test(); + 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 - NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + kSyscalls[cSerialWriteInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void { + const char* msg = (const char*)rdx; + NewOS::kcout << "newoskrnl: " << msg << "\r"; + }; - NewOS::kcout << "newoskrnl: We're done here...\r"; + kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx)->void { + tls_check_syscall_impl(rdx); + }; - while (true) + 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 = reinterpret_cast<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 = reinterpret_cast<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 = reinterpret_cast<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(); + + /* Call generic kernel entrypoint. */ + + KeMain(); + + NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } 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 <KernelKit/Framebuffer.hpp> #include <NewKit/Defines.hpp> -// 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/HALKit/AMD64/PCI/Iterator.cxx b/Kernel/HALKit/AMD64/PCI/Iterator.cxx index 8675f171..d3167b46 100644 --- a/Kernel/HALKit/AMD64/PCI/Iterator.cxx +++ b/Kernel/HALKit/AMD64/PCI/Iterator.cxx @@ -7,8 +7,8 @@ #include <KernelKit/PCI/Iterator.hpp> #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/HALKit/ARM64/Hart.hxx b/Kernel/HALKit/ARM64/Hart.hxx new file mode 100644 index 00000000..1b16a072 --- /dev/null +++ b/Kernel/HALKit/ARM64/Hart.hxx @@ -0,0 +1,28 @@ +/* -------------------------------------------
+
+ Copyright Zeta Electronics Corporation
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hpp>
+
+/// @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);
+
+/// @brief Hart IPI enum
+enum {
+ cHartIpiTurnOn,
+ cHartIpiTurnOff,
+ cHartIpiStop,
+ cHartIpiResume,
+};
diff --git a/Usr/Sys/CoreSystem/RISCV/.gitkeep b/Kernel/HALKit/ARM64/MBCI/.keepme index e69de29b..e69de29b 100644 --- a/Usr/Sys/CoreSystem/RISCV/.gitkeep +++ b/Kernel/HALKit/ARM64/MBCI/.keepme diff --git a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp index ea0997ed..f308b0b5 100644 --- a/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp +++ b/Kernel/HALKit/AXP/CoreSyscallHandlerDEC.cpp @@ -5,16 +5,20 @@ ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> -#include <HALKit/Alpha/Processor.hpp> +#include <HALKit/AXP/Processor.hpp> -NewOS::Array<void (*)(NewOS::Int32 id, NewOS::HAL::StackFrame*), - kKernelMaxSystemCalls> - 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/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 <NewKit/Defines.hpp> 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 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 <NewKit/Defines.hpp> #include <NewKit/String.hpp> -#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/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/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index c6e090e4..8c470bb4 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 <ArchKit/ArchKit.hpp> #include <KernelKit/FileManager.hpp> @@ -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}; @@ -163,21 +162,13 @@ namespace NewOS enum { - kAppKind = 1, - kShLibKind = 2, - kDriverKind = 3, + kAppKind = 1, + kShLibKind = 2, kKindCount, }; - enum - { - kRingUserKind = 3, - kRingDriverKind = 0, - }; - ProcessTime PTime; PID ProcessId{kSchedInvalidPID}; - Int32 Ring{kRingDriverKind}; Int32 Kind{kAppKind}; public: @@ -240,7 +231,6 @@ namespace NewOS /// The main class which you call to schedule an app. class ProcessScheduler final { - private: explicit ProcessScheduler() = default; public: @@ -248,15 +238,8 @@ namespace NewOS 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(); @@ -266,7 +249,7 @@ namespace NewOS bool Remove(SizeT headerIndex); public: - Ref<ProcessHeader>& GetCurrent(); + Ref<ProcessHeader>& TheCurrent(); SizeT Run() noexcept; public: @@ -285,8 +268,8 @@ namespace NewOS public: static bool Switch(HAL::StackFrame* newStack, const PID& newPid); static bool CanBeScheduled(Ref<ProcessHeader>& process); - static PID& GetCurrentPID(); - static bool StartScheduling(); + static PID& TheCurrentPID(); + static SizeT StartScheduling(); }; const Int32& rt_get_exit_code() noexcept; @@ -300,4 +283,4 @@ namespace NewOS //////////////////////////////////////////////////// -#endif /* ifndef __PROCESS_SCHEDULER__ */ +#endif /* ifndef _INC_PROCESS_SCHEDULER_HXX_ */ diff --git a/Kernel/KernelKit/SMPManager.hpp b/Kernel/KernelKit/SMPManager.hpp index 985050f1..1840dd20 100644 --- a/Kernel/KernelKit/SMPManager.hpp +++ b/Kernel/KernelKit/SMPManager.hpp @@ -94,13 +94,13 @@ 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<HardwareThread> operator[](const SizeT& idx); - bool operator!() noexcept; - operator bool() noexcept; + Ref<HardwareThread*> operator[](const SizeT& idx); + bool operator!() noexcept; + operator bool() noexcept; public: /// @brief Shared instance of the SMP Manager. diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index eaae7991..75d29ced 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -15,19 +15,10 @@ #define kCookieMag1 'C' #define kCookieMag2 'R' -template <typename T> -T* tls_new_ptr(void); - -template <typename T> -bool tls_delete_ptr(T* ptr); - -template <typename T, typename... Args> -T* tls_new_class(Args&&... args); - -#define kTLSCookieLen 3 +#define kTLSCookieLen (3U) /// @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]; @@ -37,14 +28,27 @@ struct PACKED ThreadInformationBlock final NewOS::Int32 ThreadID; // Thread execution ID. }; -/// @brief TLS install TIB and PIB. -EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, NewOS::VoidPtr PIB); +typedef struct ThreadInformationBlock ProcessInformationBlock; ///! @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; +///! @brief new ptr syscall. +template <typename T> +T* tls_new_ptr(void); + +///! @brief delete ptr syscall. +template <typename T> +bool tls_delete_ptr(T* ptr); + +template <typename T, typename... Args> +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 <KernelKit/ThreadLocalStorage.inl> 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/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 <NewKit/Defines.hpp> -#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/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index d4cb366f..39b3070a 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" @@ -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/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/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx index a00fa98e..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 diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 49b142d5..9b251c2e 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -4,12 +4,14 @@ ------------------------------------------- */ -#ifndef __NETWORK_DEVICE__ -#define __NETWORK_DEVICE__ +#ifndef __INC_NETWORK_DEVICE_HPP__ +#define __INC_NETWORK_DEVICE_HPP__ #include <KernelKit/DeviceManager.hpp> #include <NetworkKit/IP.hpp> +/// @note Can either work with: Ethernet, GPRS, WiFi + namespace NewOS { struct NetworkDeviceCommand; @@ -33,12 +35,17 @@ namespace NewOS public: const char* Name() const override; + Boolean Name(const char* strView); private: - void (*fCleanup)(void); + static constexpr auto cNetworkNameLen = 512; + + Void (*fCleanup)(void); + Char fNetworkName[cNetworkNameLen]; + }; - struct PACKED NetworkDeviceCommand final + struct NetworkDeviceCommand final { UInt32 CommandName; UInt32 CommandType; @@ -58,8 +65,14 @@ namespace NewOS /// @brief IPCEP device. using IPCEPNetworkDevice = NetworkDevice; + + /// @brief GRPS device. + using GPRSNetworkDevice = NetworkDevice; + + /// @brief GSM device. + using GSMNetworkDevice = NetworkDevice; } // namespace NewOS #include <NetworkKit/NetworkDevice.inl> -#endif // !__NETWORK_DEVICE__ +#endif // !__INC_NETWORK_DEVICE_HPP__ diff --git a/Kernel/NewKit/Array.hpp b/Kernel/NewKit/Array.hpp index b8386c9a..b0b94584 100644 --- a/Kernel/NewKit/Array.hpp +++ b/Kernel/NewKit/Array.hpp @@ -21,13 +21,12 @@ namespace NewOS Array& operator=(const Array&) = default; Array(const Array&) = default; - ErrorOr<T> operator[](Size At) + ErrorOr<T*> operator[](Size At) { if (At > N) return {}; - kcout << "Returning element\r"; - return ErrorOr<T>(fArray[At]); + return ErrorOr<T*>(&fArray[At]); } Boolean Empty() const @@ -43,14 +42,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/NewKit/MutableArray.hpp b/Kernel/NewKit/MutableArray.hpp index f9c79301..6be9c15e 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<T>(); + iterationNode = fFirstNode; + } + MUST_PASS(iterationNode); while (iterationNode) 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/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<ProcessHeader> refProc = proc; return ProcessScheduler::The().Leak().Add(refProc); } -} // namespace NewOS
\ No newline at end of file +} // namespace NewOS 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/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<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast<NewCatalog*>(node), data, size, @@ -112,7 +112,7 @@ namespace NewOS NEWOS_UNUSED(flags); - auto dataForkName = "FileData"; + auto dataForkName = kNewFSDataFork; if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz, diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 937e983a..5ba02049 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/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 f4f9f44c..fb127271 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -28,18 +28,19 @@ 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: - explicit FilesystemWizard() + /// @brief wizard constructor. + explicit FilesystemInstaller() { if (NewOS::FilesystemManagerInterface::GetMounted()) { /// 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 +52,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\\", "\\Packages\\", + "\\Users\\", "\\Library\\", "\\Mount\\", "\\DCIM\\"}; for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { @@ -68,7 +69,7 @@ namespace NewOS::Detail } catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); + kNewFSCatalogKindDir); NewFork theFork{0}; @@ -92,9 +93,9 @@ namespace NewOS::Detail metadataFolder += "<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " - "system</p>\r<p>Volume Type: New OS Standard</p>\r"; + "system</p>\r<p>Volume Type: s10 Filesystem</p>\r"; - metadataFolder += "<p>File name: "; + metadataFolder += "<p>Path: "; metadataFolder += cDirStr[dirIndx]; metadataFolder += "</p>\r"; @@ -113,9 +114,9 @@ namespace NewOS::Detail } NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("/Mount/This Disk"); + this->fNewFS->GetParser()->GetCatalog("\\Mount\\C:\\"); - const NewOS::Char* cSrcName = "DiskInfo"; + const NewOS::Char* cSrcName = "DISK-INF"; if (catalogDisk) { @@ -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 += "<p>Kind: alias to disk</p>\r<p>Created by: system</p>\r<p>Edited " "by: " - "system</p>\r<p>Volume Type: New OS Standard</p>\r"; + "system</p>\r<p>Volume Type: s10 Filesystem</p>\r"; - diskFolder += "<p>Original Path: "; + diskFolder += "<p>Root: "; diskFolder += NewOS::NewFilesystemHelper::Root(); diskFolder += "</p>\r"; @@ -157,56 +158,50 @@ 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; } } } - ~FilesystemWizard() - { - delete fNewFS; - } + ~FilesystemInstaller() = default; - NEWOS_COPY_DEFAULT(FilesystemWizard); + NEWOS_COPY_DEFAULT(FilesystemInstaller); - /// 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 SystemLauncher_Main(NewOS::Void) + STATIC NewOS::Void ke_launch_srv(NewOS::Void) { - NewOS::PEFLoader lockScreen("/System/LockScreen"); + 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/StageBoard"); + 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); - - NewOS::kcout << "SystemLauncher: done, sleeping..."; - - while (true) {} } } // namespace NewOS::Detail @@ -216,13 +211,17 @@ 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::FilesystemInstaller installer; // automatic filesystem creation. - auto cLoaderName = "SystemLauncher"; - NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); + NewOS::Detail::ke_launch_srv(); + + // fetch system cores. + NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); - while (true) + // spin forever. + while (Yes) { - NewOS::ProcessScheduler::The().Leak().Run(); + // start scheduling. + NewOS::ProcessHelper::StartScheduling(); } } 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/Network/NetworkDevice.cxx b/Kernel/Sources/Network/NetworkDevice.cxx index 511246c7..027613ac 100644 --- a/Kernel/Sources/Network/NetworkDevice.cxx +++ b/Kernel/Sources/Network/NetworkDevice.cxx @@ -5,11 +5,31 @@ ------------------------------------------- */ #include <NetworkKit/NetworkDevice.hpp> +#include <NewKit/Utils.hpp> 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((VoidPtr)strView, + (VoidPtr)this->fNetworkName, rt_string_len(strView)); + + return true; } } // namespace NewOS 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 08a7971e..aae69386 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,14 +42,10 @@ 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) - { - MUST_PASS(ke_bug_check()); - } - this->Exit(kErrorProcessFault); } @@ -63,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; @@ -163,27 +161,11 @@ namespace NewOS void ProcessHeader::Exit(Int32 exit_code) { if (this->ProcessId != - ProcessScheduler::The().Leak().GetCurrent().Leak().ProcessId) - ke_stop(RUNTIME_CHECK_PROCESS); - - if (this->Ring == (Int32)ProcessSelector::kRingKernel && - ProcessScheduler::The().Leak().GetCurrent().Leak().Ring > 0) + ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId) 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); @@ -201,9 +183,6 @@ namespace NewOS /// @return SizeT ProcessScheduler::Add(Ref<ProcessHeader>& process) { - if (!process) - return -1; - if (!process.Leak().Image) { if (process.Leak().Kind != ProcessHeader::kShLibKind) @@ -212,7 +191,7 @@ namespace NewOS } } - if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) + if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r"; @@ -229,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; } @@ -255,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]; - - MUST_PASS(process); //! no need for a MUST_PASS(process.Leak());, it is - //! recursive because of the nature of the class; + 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(); @@ -278,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 { @@ -286,7 +266,7 @@ namespace NewOS } } - return processIndex; + return process_index; } /// @brief Gets the current scheduled team. @@ -306,17 +286,17 @@ namespace NewOS /// @brief Gets current running process. /// @return - Ref<ProcessHeader>& ProcessScheduler::GetCurrent() + Ref<ProcessHeader>& 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. @@ -349,26 +329,12 @@ namespace NewOS * @brief Spin scheduler class. */ - bool ProcessHelper::StartScheduling() + SizeT ProcessHelper::StartScheduling() { - if (ProcessHelper::CanBeScheduled( - ProcessScheduler::The().Leak().GetCurrent())) - { - --ProcessScheduler::The().Leak().GetCurrent().Leak().PTime; - return false; - } - - auto processRef = ProcessScheduler::The().Leak(); + auto& process_ref = ProcessScheduler::The().Leak(); + SizeT ret = process_ref.Run(); - if (!processRef) - return false; // we have nothing to schedule. simply return. - - SizeT ret = processRef.Run(); - - kcout << StringBuilder::FromInt( - "ProcessHelper::StartScheduling() Iterated over {%} jobs inside team.\r", ret); - - return true; + return ret; } /** @@ -384,30 +350,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); - ProcessHelper::GetCurrentPID() = new_pid; + SMPManager::The().Leak()[index].Leak()->Busy(true); + ProcessHelper::TheCurrentPID() = 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/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/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index f0b680ce..149b1334 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -85,39 +85,29 @@ 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->Exception = this->fID; + if (fStack) + { + delete fStack; + fStack = nullptr; } + + fStack = stack; rt_do_context_switch(fStack); - + return true; } @@ -143,12 +133,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; + ProcessHelper::TheCurrentPID() == + fThreadList[fCurrentThread].Leak().Leak()->fPID) + return fThreadList[fCurrentThread].Leak().Leak()->fStack; return nullptr; } @@ -163,35 +153,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::TheCurrentPID(); - fThreadList[idx].Leak().Leak().Busy(false); + fThreadList[idx].Leak().Leak()->Busy(false); return true; } @@ -204,19 +194,25 @@ namespace NewOS * @param idx the index * @return the reference to the hardware thread. */ - Ref<HardwareThread> SMPManager::operator[](const SizeT& idx) + Ref<HardwareThread*> 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}; } 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/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 ad3c4aa4..f20e30f8 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<Pmm>& Leak() { return s_Pmm; } - + STATIC Boolean& IsEnabled() { return s_PoolsAreEnabled; @@ -150,7 +150,7 @@ namespace NewOS { if (!poolHdr->fFree) { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); return; } diff --git a/Kernel/makefile b/Kernel/amd64-efi.make index 97804c20..b7ca45e9 100644 --- a/Kernel/makefile +++ b/Kernel/amd64-efi.make @@ -6,11 +6,12 @@ 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 + -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ ASM = nasm +DISKDRIVER = + ifneq ($(ATA_PIO_SUPPORT), ) DISKDRIVER = -D__ATA_PIO__ endif @@ -69,15 +70,17 @@ link-amd64-epm: .PHONY: all all: newos-amd64-epm link-amd64-epm + 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 new file mode 100644 index 00000000..ac7ccd2d --- /dev/null +++ b/Kernel/arm64-cb.make @@ -0,0 +1,69 @@ +################################################## +# (C) Zeta Electronics Corporation, all rights reserved. +# This is the microkernel makefile. +################################################## + +CC = arm-none-eabi-g++.exe +LD = arm-none-eabi-ld.exe +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 + +DISKDRIVER = -D__FLASH_MEM__ + +ifneq ($(SDCARD_SUPPORT), ) +DISKDRIVER = -D__SDCARD__ +endif + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +COPY = cp + +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.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 for EPM based disks." + @echo "newos-arm64-epm: Build kernel for EPM based disks." + +.PHONY: clean +clean: + rm -f $(LDOBJ) $(wildcard *.o) $(KERNEL) diff --git a/Meta/Zeta.pdf b/Meta/Zeta.pdf Binary files differnew file mode 100644 index 00000000..339651d5 --- /dev/null +++ b/Meta/Zeta.pdf @@ -1,4 +1,4 @@ -<!-- NuX OS --> +<!-- README --> <div align="center"> <img src="Meta/NewOS.svg"/> 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/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/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 <Headers/Defines.h> - -/// @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 2c04c3f1..00000000 --- a/Usr/Sys/CoreSystem/Headers/Defines.h +++ /dev/null @@ -1,241 +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 <Headers/Alert.h> - -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 <Headers/Hint.h> - -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<ApplicationInterfaceRef> - -template <SizeType N> -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 66bc6549..00000000 --- a/Usr/Sys/CoreSystem/Headers/File.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -#include <Headers/Defines.h> - -#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 <Headers/Defines.h> - -#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 c9eae306..00000000 --- a/Usr/Sys/CoreSystem/Headers/Intl.h +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#pragma once - -/// @brief Intlization primitives. - -#include <Headers/Defines.h> - -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 <Headers/Defines.h> - -/////////////////////////////////////////////////////////////////////// -/// 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/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 <Headers/Defines.h> - -#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 671621c8..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 <Headers/Defines.h> - -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 @@ -<SourceDeploy> - <File name="Headers/Hint.h" hidden="true"/> - <Directory name="Sources/" hidden="true"/> -</SourceDeploy>
\ No newline at end of file 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 <Headers/Defines.h> - -/// @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/File.c b/Usr/Sys/CoreSystem/Sources/File.c deleted file mode 100644 index 9f6b3b35..00000000 --- a/Usr/Sys/CoreSystem/Sources/File.c +++ /dev/null @@ -1,69 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - -------------------------------------------- */ - -#include <Headers/Defines.h> -#include <Headers/File.h> - -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 the file. -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 -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 -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 -/// @return -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 <Headers/Defines.h> -#include <Headers/Heap.h> - -/// @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 <Headers/Math.h> - -/// @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/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 diff --git a/newoskrnl.10x b/newoskrnl.10x index d232f112..4d9241c7 100644 --- a/newoskrnl.10x +++ b/newoskrnl.10x @@ -1,7 +1,7 @@ <?xml version="1.0"?>
<N10X>
<Workspace>
- <IncludeFilter>*.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,</IncludeFilter>
+ <IncludeFilter>*.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,</IncludeFilter>
<ExcludeFilter></ExcludeFilter>
<SyncFiles>true</SyncFiles>
<Recursive>true</Recursive>
|
