From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/KernelKit/FileManager.hpp | 258 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 Kernel/KernelKit/FileManager.hpp (limited to 'Kernel/KernelKit/FileManager.hpp') diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp new file mode 100644 index 00000000..d0843a5e --- /dev/null +++ b/Kernel/KernelKit/FileManager.hpp @@ -0,0 +1,258 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +/* ------------------------------------------- + + Revision History: + + 31/01/24: Update documentation (amlel) + + ------------------------------------------- */ + +#pragma once + +#ifdef __FSKIT_NEWFS__ +#include +#endif // __FSKIT_NEWFS__ + +#include +#include +#include +#include + +/// @brief Filesystem abstraction manager. +/// Works like the VFS or IFS. + +#define kBootFolder "/Boot" +#define kBinFolder "/Applications" +#define kShLibsFolder "/Library" +#define kMountFolder "/Mount" + +/// refer to first enum. +#define kFileOpsCount 4 +#define kFileMimeGeneric "application-type/*" + +namespace NewOS +{ + enum + { + kFileWriteAll = 100, + kFileReadAll = 101, + kFileReadChunk = 102, + kFileWriteChunk = 103, + kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, + }; + + typedef VoidPtr NodePtr; + + /** + @brief Filesystem Manager Interface class + @brief Used to provide common I/O for a specific filesystem. +*/ + class FilesystemManagerInterface + { + public: + FilesystemManagerInterface() = default; + virtual ~FilesystemManagerInterface() = default; + + public: + NEWOS_COPY_DEFAULT(FilesystemManagerInterface); + + public: + /// @brief Mounts a new filesystem into an active state. + /// @param interface the filesystem interface + /// @return + static bool Mount(FilesystemManagerInterface* interface); + + /// @brief Unmounts the active filesystem + /// @return + static FilesystemManagerInterface* Unmount(); + + /// @brief Getter, gets the active filesystem. + /// @return + static FilesystemManagerInterface* GetMounted(); + + public: + virtual NodePtr Create(_Input const char* path) = 0; + virtual NodePtr CreateAlias(_Input const char* path) = 0; + virtual NodePtr CreateDirectory(_Input const char* path) = 0; + + public: + virtual bool Remove(_Input const char* path) = 0; + + public: + virtual NodePtr Open(_Input const char* path, _Input const char* r) = 0; + + public: + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; + virtual _Output VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) = 0; + + public: + virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; + + public: + virtual SizeT Tell(_Input NodePtr node) = 0; + virtual bool Rewind(_Input NodePtr node) = 0; + }; + +/** @brief invalid position. (n-pos) */ +#define kNPos (SizeT)(-1); + +#ifdef __FSKIT_NEWFS__ + /** + * @brief Based of FilesystemManagerInterface, takes care of managing NewFS + * disks. + */ + class NewFilesystemManager final : public FilesystemManagerInterface + { + public: + explicit NewFilesystemManager(); + ~NewFilesystemManager() override; + + public: + NEWOS_COPY_DEFAULT(NewFilesystemManager); + + public: + NodePtr Create(const char* path) override; + NodePtr CreateAlias(const char* path) override; + NodePtr CreateDirectory(const char* path) override; + + public: + bool Remove(const char* path) override; + NodePtr Open(const char* path, const char* r) override; + Void Write(NodePtr node, VoidPtr data, Int32 flags, SizeT sz) override; + VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override; + bool Seek(NodePtr node, SizeT off); + SizeT Tell(NodePtr node) override; + bool Rewind(NodePtr node) override; + + public: + void SetResourceFork(const char* forkName); + void SetDataFork(const char* forkName); + + NewFSParser* GetImpl() noexcept; + + private: + Char fDataFork[kNewFSForkNameLen] = {0}; + Char fRsrcFork[kNewFSForkNameLen] = {0}; + NewFSParser* fImpl{nullptr}; + }; + +#endif // ifdef __FSKIT_NEWFS__ + + /** + * Usable FileStream + * @tparam Encoding file encoding (char, wchar_t...) + * @tparam FSClass Filesystem contract who takes care of it. + */ + template + class FileStream final + { + public: + explicit FileStream(const Encoding* path, const Encoding* restrict_type); + ~FileStream(); + + public: + FileStream& operator=(const FileStream&); + FileStream(const FileStream&); + + public: + ErrorOr WriteAll(const VoidPtr data) noexcept + { + if (data == nullptr) + return ErrorOr(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fFile, data, kFileWriteAll); + return ErrorOr(0); + } + + return ErrorOr(kErrorInvalidData); + } + + VoidPtr Read() noexcept + { + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fFile, kFileReadAll, 0); + return ret; + } + + return nullptr; + } + + voidPtr Read(SizeT offset, SizeT sz) + { + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + auto ret = man->Read(fFile, kFileReadChunk, sz); + + return ret; + } + + return nullptr; + } + + Void Write(SizeT offset, voidPtr data, SizeT sz) + { + auto man = FSClass::GetMounted(); + + if (man) + { + man->Seek(fFile, offset); + man->Write(fFile, data, sz, kFileReadChunk); + } + } + + /// @brief Leak node pointer. + /// @return The node pointer. + NodePtr Leak() + { + return fFile; + } + + public: + char* MIME() noexcept + { + return const_cast(fMime); + } + + private: + NodePtr fFile; + const Char* fMime{kFileMimeGeneric}; + }; + +#define kRestrictR "r" +#define kRestrictRB "rb" +#define kRestrictW "w" +#define kRestrictRW "rw" + + using FileStreamUTF8 = FileStream; + using FileStreamUTF16 = FileStream; + + typedef UInt64 CursorType; + + template + FileStream::FileStream(const Encoding* path, + const Encoding* restrict_type) + : fFile(Class::GetMounted()->Open(path, restrict_type)) + { + } + + template + FileStream::~FileStream() = default; +} // namespace NewOS + +#define node_cast(PTR) reinterpret_cast(PTR) -- cgit v1.2.3 From 84b0e780dfd9272b177c32cc3bb99f37bb88304d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 10 May 2024 07:06:43 +0200 Subject: MHR-23: Getting SMP to work... Signed-off-by: Amlal El Mahrouss --- Boot/NetBoot/Module.cxx | 5 +- Boot/NetBoot/NetBoot.hxx | 12 +++ Boot/Source/BootloaderRsrc.rsrc | 2 +- Boot/Source/makefile | 106 -------------------- Boot/makefile | 110 +++++++++++++++++++++ Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 19 ++-- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 58 +++++------ Kernel/HALKit/AXP/README.TXT | 2 +- Kernel/KernelKit/DebugOutput.hpp | 2 +- Kernel/KernelKit/FileManager.hpp | 2 - Kernel/KernelKit/ProcessScheduler.hpp | 4 +- Kernel/KernelRsrc.rsrc | 2 +- Kernel/Linker/16x0.json | 2 +- Kernel/Linker/32x0.json | 2 +- Kernel/Linker/64x0.json | 2 +- Kernel/NewKit/Application.hxx | 31 ------ Kernel/NewKit/ApplicationInterface.hxx | 31 ++++++ Kernel/Source/AppMain.cxx | 39 ++++++-- Kernel/Source/FileManager.cxx | 22 +---- Kernel/Source/KernelCheck.cxx | 2 +- Kernel/Source/ProcessScheduler.cxx | 2 +- Kernel/Source/Variant.cxx | 5 - Kernel/makefile | 5 +- 23 files changed, 240 insertions(+), 227 deletions(-) create mode 100644 Boot/NetBoot/NetBoot.hxx delete mode 100644 Boot/Source/makefile create mode 100644 Boot/makefile delete mode 100644 Kernel/NewKit/Application.hxx create mode 100644 Kernel/NewKit/ApplicationInterface.hxx (limited to 'Kernel/KernelKit/FileManager.hpp') diff --git a/Boot/NetBoot/Module.cxx b/Boot/NetBoot/Module.cxx index c296903b..57841904 100644 --- a/Boot/NetBoot/Module.cxx +++ b/Boot/NetBoot/Module.cxx @@ -8,10 +8,11 @@ */ #include +#include -EXTERN_C Int32 EfiMain(Void) +EXTERN_C Int32 ModuleMain(Void) { - /// - Find a network drive called "/OnlineBoot" + /// - Find a network drive called "/Remote/NewOSKrnl" /// - Download our image /// - Boot from it. diff --git a/Boot/NetBoot/NetBoot.hxx b/Boot/NetBoot/NetBoot.hxx new file mode 100644 index 00000000..d45f1de1 --- /dev/null +++ b/Boot/NetBoot/NetBoot.hxx @@ -0,0 +1,12 @@ +/* + * ======================================================== + * + * NetBoot + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include diff --git a/Boot/Source/BootloaderRsrc.rsrc b/Boot/Source/BootloaderRsrc.rsrc index d79211e7..0282192b 100644 --- a/Boot/Source/BootloaderRsrc.rsrc +++ b/Boot/Source/BootloaderRsrc.rsrc @@ -15,7 +15,7 @@ BEGIN VALUE "FileVersion", BOOTLOADER_VERSION VALUE "InternalName", "NewBoot" VALUE "LegalCopyright", "Copyright SoftwareLabs, all rights reserved." - VALUE "OriginalFilename", "NewBoot.exe" + VALUE "OriginalFilename", "NewOSLdr.exe" VALUE "ProductName", "NewBoot" VALUE "ProductVersion", BOOTLOADER_VERSION END diff --git a/Boot/Source/makefile b/Boot/Source/makefile deleted file mode 100644 index 70fa7232..00000000 --- a/Boot/Source/makefile +++ /dev/null @@ -1,106 +0,0 @@ -################################################## -# (C) SoftwareLabs, all rights reserved. -# This is the bootloader makefile. -################################################## - -CC_GNU=x86_64-w64-mingw32-g++ -LD_GNU=x86_64-w64-mingw32-ld - -WINDRES=x86_64-w64-mingw32-windres - -ADD_FILE=touch -COPY=cp -HTTP_GET=wget - -ifeq ($(shell uname), Windows_NT) -EMU=qemu-system-x86_64w -else -EMU=qemu-system-x86_64 -endif - -ifeq ($(NEWS_MODEL), ) -NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" -endif - -IMG=epm.img -IMG_2=epm-slave.img - -EMU_FLAGS=-net none -smp 4 -m 8G -M q35 \ - -bios OVMF.fd -device piix3-ide,id=ide \ - -drive id=disk,file=$(IMG),format=raw,if=none \ - -device ide-hd,drive=disk,bus=ide.0 -drive \ - file=fat:rw:Root,index=2,format=raw -d int -hdd epm-slave.img - -LD_FLAGS=-e Main --subsystem=10 - -ifeq ($(NEWS_STANDLONE), ) -OBJ=*.o ../../Kernel/Objects/*.obj -else -RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o -STANDALONE_MACRO=-D__STANDALONE__ -OBJ=*.o -endif - -REM=rm -REM_FLAG=-f - -FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ - -DEFI_FUNCTION_WRAPPER -I../ -I../../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ - -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ - -BOOT_LOADER=NewBoot.exe -KERNEL=NewKernel.exe - -.PHONY: invalid-recipe -invalid-recipe: - @echo "invalid-recipe: Use make compile- instead." - -.PHONY: all -all: compile-amd64 - mkdir -p Root/EFI/BOOT - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(BOOT_LOADER) - $(COPY) $(BOOT_LOADER) Root/EFI/BOOT/BOOTX64.EFI - $(COPY) $(BOOT_LOADER) Root/EFI/BOOT/NEWBOOT.EFI - $(COPY) ../../Kernel/$(KERNEL) Root/$(KERNEL) - -ifneq ($(DEBUG_SUPPORT), ) -DEBUG = -D__DEBUG__ -endif - -.PHONY: compile-amd64 -compile-amd64: - $(RESCMD) - $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx) - -.PHONY: run-efi-amd64 -run-efi-amd64: - $(EMU) $(EMU_FLAGS) - -# img_2 is the rescue disk. img is the bootable disk, as provided by the NeWS. -.PHONY: epm-img -epm-img: - qemu-img create -f raw $(IMG) 10G - qemu-img create -f raw $(IMG_2) 512M - -.PHONY: download-edk -download-edk: - $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd - -BINS=*.bin -EXECUTABLES=NewBoot.exe NewKernel.exe OVMF.fd - -TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) - -.PHONY: clean -clean: - $(REM) $(TARGETS) - -.PHONY: help -help: - @echo "=== HELP ===" - @echo "epm-img: Format a disk using the Explicit Partition Map." - @echo "gpt-img: Format a disk using the Explicit Partition Map." - @echo "clean: clean bootloader." - @echo "bootloader-amd64: Build bootloader. (PC AMD64)" - @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Boot/makefile b/Boot/makefile new file mode 100644 index 00000000..878cee2a --- /dev/null +++ b/Boot/makefile @@ -0,0 +1,110 @@ +################################################## +# (C) SoftwareLabs, all rights reserved. +# This is the bootloader makefile. +################################################## + +CC_GNU=x86_64-w64-mingw32-g++ +LD_GNU=x86_64-w64-mingw32-ld + +WINDRES=x86_64-w64-mingw32-windres + +ADD_FILE=touch +COPY=cp +HTTP_GET=wget + +ifeq ($(shell uname), Windows_NT) +EMU=qemu-system-x86_64w +else +EMU=qemu-system-x86_64 +endif + +ifeq ($(NEWS_MODEL), ) +NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" +endif + +BIOS=OVMF.fd +IMG=epm.img +IMG_2=epm-slave.img + +EMU_FLAGS=-net none -smp 4,sockets=1,cores=4,threads=1 -m 8G -M q35 \ + -bios Source/$(BIOS) -device piix3-ide,id=ide \ + -drive id=disk,file=Source/$(IMG),format=raw,if=none \ + -device ide-hd,drive=disk,bus=ide.0 -drive \ + file=fat:rw:Source/Root,index=2,format=raw -d int -hdd Source/$(IMG_2) + +LD_FLAGS=-e Main --subsystem=10 + +ifeq ($(NEWS_STANDLONE), ) +OBJ=*.o ../Kernel/Objects/*.obj +else +RESCMD=$(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o +STANDALONE_MACRO=-D__STANDALONE__ +OBJ=*.o +endif + +REM=rm +REM_FLAG=-f + +FLAG_ASM=-f win64 +FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ \ + -DEFI_FUNCTION_WRAPPER -I./ -I../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ + -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ + +BOOT_LOADER=NewOSLdr.exe +KERNEL=NewOSKrnl.exe + +.PHONY: invalid-recipe +invalid-recipe: + @echo "invalid-recipe: Use make compile- instead." + +.PHONY: all +all: compile-amd64 + mkdir -p Root/EFI/BOOT + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Source/$(BOOT_LOADER) + $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/BOOTX64.EFI + $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/NEWBOOT.EFI + $(COPY) ../Kernel/$(KERNEL) Source/Root/$(KERNEL) + +ifneq ($(DEBUG_SUPPORT), ) +DEBUG = -D__DEBUG__ +endif + +.PHONY: compile-amd64 +compile-amd64: + $(RESCMD) + $(CC_GNU) $(NEWOS_MODEL) $(STANDALONE_MACRO) $(FLAG_GNU) $(DEBUG) \ + $(wildcard Source/HEL/AMD64/*.cxx) \ + $(wildcard Source/HEL/AMD64/*.S) + $(wildcard Source/*.cxx) + +.PHONY: run-efi-amd64 +run-efi-amd64: + $(EMU) $(EMU_FLAGS) + +# img_2 is the rescue disk. img is the bootable disk, as provided by the NeWS. +.PHONY: epm-img +epm-img: + qemu-img create -f raw $(IMG) 10G + qemu-img create -f raw $(IMG_2) 512M + +.PHONY: download-edk +download-edk: + $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd + +BINS=*.bin +EXECUTABLES=NewOSLdr.exe NewOSKrnl.exe OVMF.fd + +TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) + +.PHONY: clean +clean: + $(REM) $(TARGETS) + +.PHONY: help +help: + @echo "=== HELP ===" + @echo "epm-img: Format a disk using the Explicit Partition Map." + @echo "gpt-img: Format a disk using the Explicit Partition Map." + @echo "clean: clean bootloader." + @echo "bootloader-amd64: Build bootloader. (PC AMD64)" + @echo "run-efi-amd64: Run bootloader. (PC AMD64)" diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index f4c9226e..db82616e 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -75,7 +75,7 @@ namespace NewOS SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); - SizeT num = (xsdt->Length + sizeof(SDT)) / 8; + SizeT num = -(xsdt->Length - sizeof(SDT)) / 8; this->fEntries = num; @@ -83,22 +83,19 @@ namespace NewOS kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; constexpr short ACPI_SIGNATURE_LENGTH = 4; - SizeT offsetToAdd = 0UL; - - for (Size index = 0; index < num; ++index) + + for (Size index = 0; index < this->fEntries; ++index) { - SDT* sdt = &(xsdt[index]) + offsetToAdd; + SDT &sdt = xsdt[index]; - for (int signature_index = 0; signature_index < 4; signature_index++) + for (short signature_index = 0; signature_index < ACPI_SIGNATURE_LENGTH; ++signature_index) { - if (sdt->Signature[signature_index] != signature[signature_index]) + if (sdt.Signature[signature_index] != signature[signature_index]) break; - if (signature_index == 3) - return ErrorOr(reinterpret_cast(sdt)); + if (signature_index == 4) + return ErrorOr(reinterpret_cast(&sdt)); } - - offsetToAdd = sdt->Length; } return ErrorOr{nullptr}; diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index ec6d47da..470a3286 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -46,54 +46,54 @@ namespace NewOS::HAL STATIC voidPtr kApicMadt = nullptr; STATIC const char* kApicSignature = "APIC"; - /// @brief Multiple APIC descriptor table. + /// @brief Multiple APIC Descriptor Table. struct MadtType final : public SDT { struct MadtAddress final { - UInt32 fAddress; - UInt32 fFlags; // 1 = Dual Legacy PICs installed - - Char fType; - Char fRecLen; // record length - } fMadt[]; + Char RecordType; + Char RecordLen; // record length + + UInt32 Address; + UInt32 Flags; // 1 = Dual Legacy PICs installed + } MadtRecords[]; }; struct MadtProcessorLocalApic final { - Char fProcessorId; - Char fApicId; - UInt32 fFlags; + Char AcpiProcessorId; + Char Reserved; + UInt32 Flags; }; struct MadtIOApic final { - Char fApicId; - Char fReserved; - UInt32 fAddress; - UInt32 fSystemInterruptBase; + Char ApicId; + Char Reserved; + UInt32 Address; + UInt32 SystemInterruptBase; }; struct MadtInterruptSource final { - Char fBusSource; - Char fIrqSource; - UInt32 fGSI; - UInt16 fFlags; + Char BusSource; + Char IrqSource; + UInt32 GSI; + UInt16 Flags; }; struct MadtInterruptNmi final { - Char fNmiSource; - Char fReserved; - UInt16 fFlags; - UInt32 fGSI; + Char NmiSource; + Char Reserved; + UInt16 Flags; + UInt32 GSI; }; struct MadtLocalApicAddressOverride final { - UInt16 fResvered; - UIntPtr fAddress; + UInt16 Resvered; + UIntPtr Address; }; /////////////////////////////////////////////////////////////////////////////////////// @@ -109,17 +109,13 @@ namespace NewOS::HAL if (kApicMadt) { - kcout << "New OS: Successfuly fetched the cores!\r"; + kcout << "New OS: APIC is present...\r"; kApicInfoBlock = (MadtType*)kApicMadt; - - kcout << "New OS: Revision: "; - kcout.HexNumber(kApicInfoBlock->Revision).EndLine(); - - ke_stop(RUNTIME_CHECK_BOOTSTRAP); } else { - ke_stop(RUNTIME_CHECK_BOOTSTRAP); + kcout << "New OS: APIC is not present! it is a vital component.\r"; + ke_stop(RUNTIME_CHECK_FAILED); } } } // namespace NewOS::HAL diff --git a/Kernel/HALKit/AXP/README.TXT b/Kernel/HALKit/AXP/README.TXT index 03c2b816..d4ef257d 100644 --- a/Kernel/HALKit/AXP/README.TXT +++ b/Kernel/HALKit/AXP/README.TXT @@ -1 +1 @@ -A Toy HAL to test the Kernel portability. +An toy HAL to test the kernel portability. diff --git a/Kernel/KernelKit/DebugOutput.hpp b/Kernel/KernelKit/DebugOutput.hpp index 656fe7a9..c6eb4485 100644 --- a/Kernel/KernelKit/DebugOutput.hpp +++ b/Kernel/KernelKit/DebugOutput.hpp @@ -56,7 +56,7 @@ namespace NewOS TerminalDevice& HexNumber(const Long Data) noexcept { - number(Data); + hex_number(Data); return *this; } diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index d0843a5e..a5ac6a93 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -136,8 +136,6 @@ namespace NewOS NewFSParser* GetImpl() noexcept; private: - Char fDataFork[kNewFSForkNameLen] = {0}; - Char fRsrcFork[kNewFSForkNameLen] = {0}; NewFSParser* fImpl{nullptr}; }; diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp index ba34f9cb..243857ae 100644 --- a/Kernel/KernelKit/ProcessScheduler.hpp +++ b/Kernel/KernelKit/ProcessScheduler.hpp @@ -163,7 +163,7 @@ namespace NewOS enum { - kUserKind = 3, + kAppKind = 3, kLibKind = 3, kDriverKind = 0, kKindCount, @@ -178,7 +178,7 @@ namespace NewOS ProcessTime PTime; PID ProcessId{kSchedInvalidPID}; Int32 Ring{kRingDriverKind}; - Int32 Kind{kUserKind}; + Int32 Kind{kAppKind}; public: //! @brief boolean operator, check status. diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index d8fc6473..6689d10c 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -15,7 +15,7 @@ BEGIN VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "NewKernel" VALUE "LegalCopyright", "SoftwareLabs" - VALUE "OriginalFilename", "NewKernel.exe" + VALUE "OriginalFilename", "NewOSKrnl.exe" VALUE "ProductName", "NewKernel" VALUE "ProductVersion", KERNEL_VERSION END diff --git a/Kernel/Linker/16x0.json b/Kernel/Linker/16x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/16x0.json +++ b/Kernel/Linker/16x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/32x0.json b/Kernel/Linker/32x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/32x0.json +++ b/Kernel/Linker/32x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/64x0.json b/Kernel/Linker/64x0.json index 5851a2d3..40cee7c9 100644 --- a/Kernel/Linker/64x0.json +++ b/Kernel/Linker/64x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewKernel.exe", + "output_name": "NewOSKrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/NewKit/Application.hxx b/Kernel/NewKit/Application.hxx deleted file mode 100644 index 19a892d6..00000000 --- a/Kernel/NewKit/Application.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#pragma once - -/// -/// @brief Application object, given by the OS to the process. interact with the OS. -/// @file Application.hxx -/// @author Amlal EL Mahrouss -/// - -#include -#include - -/// \brief Application Interface. -/// \author Amlal El Mahrouss -typedef struct _ApplicationInterface final -{ - /// @brief Releases the object exit the process on main object. - NewOS::Void (*Release)(struct _Application* Self, NewOS::Int32 ExitCode); - /// @brief Invoke a function from the application object. - NewOS::IntPtr (*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...); - /// @brief Query a new application object from a GUID. - /// @note this doesn't query a process, it query a registered object withtin that app. - NewOS::Void (*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); -} ApplicationInterface, *ApplicationInterfaceRef; - -#define app_cast reinterpret_cast diff --git a/Kernel/NewKit/ApplicationInterface.hxx b/Kernel/NewKit/ApplicationInterface.hxx new file mode 100644 index 00000000..09d2c901 --- /dev/null +++ b/Kernel/NewKit/ApplicationInterface.hxx @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +/// +/// @brief Application object, given by the OS to the process. interact with the OS. +/// @file ApplicationInterface.hxx +/// @author Amlal EL Mahrouss +/// + +#include +#include + +/// \brief Application Interface. +/// \author Amlal El Mahrouss +typedef struct _ApplicationInterface final +{ + /// @brief Releases the object exit the process on main object. + NewOS::Void (*Release)(struct _Application* Self, NewOS::Int32 ExitCode); + /// @brief Invoke a function from the application object. + NewOS::IntPtr (*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...); + /// @brief Query a new application object from a GUID. + /// @note this doesn't query a process, it query a registered object withtin that app. + NewOS::Void (*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf); +} ApplicationInterface, *ApplicationInterfaceRef; + +#define app_cast reinterpret_cast diff --git a/Kernel/Source/AppMain.cxx b/Kernel/Source/AppMain.cxx index 4f5de11f..028e70e5 100644 --- a/Kernel/Source/AppMain.cxx +++ b/Kernel/Source/AppMain.cxx @@ -179,25 +179,50 @@ namespace Detail } }; - STATIC NewOS::Void AppWatchdogThread(NewOS::Void) + /// @brief System loader entrypoint. + /// @param void no parameters. + /// @return void no return value. + STATIC NewOS::Void AppSystemLoader(NewOS::Void) { - NewOS::kcout << "SystemSanityThread: Exiting process..."; + NewOS::PEFLoader coreGraphicsShLib("/System/CoreGraphics"); + + if (!coreGraphicsShLib.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(coreGraphicsShLib, + NewOS::ProcessHeader::kLibKind); + + NewOS::PEFLoader logonService("/System/Login"); + + if (!logonService.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(logonService, + NewOS::ProcessHeader::kAppKind); + + NewOS::kcout << "SystemLoader: Exiting process, we're done initializing stuff..."; + NewOS::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Exit(0); } } // namespace Detail -/// @file Main microkernel entrypoint. - +/// @brief Application entrypoint. +/// @param Void +/// @return Void EXTERN_C NewOS::Void AppMain(NewOS::Void) { /// Now run kernel loop, until no process are running. Detail::FilesystemWizard wizard; // automatic. - auto cWatchdogThreadName = "SystemSanityThread"; - NewOS::execute_from_image((NewOS::MainKind)Detail::AppWatchdogThread, cWatchdogThreadName); + auto cLoaderName = "SystemLoader"; + NewOS::execute_from_image(Detail::AppSystemLoader, cLoaderName); while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0) { - ; + NewOS::kcout << "New OS: sleeping...\r"; } } diff --git a/Kernel/Source/FileManager.cxx b/Kernel/Source/FileManager.cxx index 72ea15a1..ed90dab8 100644 --- a/Kernel/Source/FileManager.cxx +++ b/Kernel/Source/FileManager.cxx @@ -90,11 +90,11 @@ namespace NewOS NEWOS_UNUSED(flags); - const char* cReadAllFork = fDataFork; - + auto dataForkName = "FileData"; + if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast(node), data, size, - cReadAllFork); + dataForkName); } /// @brief Read from filesystem fork. @@ -112,11 +112,11 @@ namespace NewOS NEWOS_UNUSED(flags); - const char* cReadAllFork = fDataFork; + auto dataForkName = "FileData"; if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast(node), sz, - cReadAllFork); + dataForkName); return nullptr; } @@ -167,17 +167,5 @@ namespace NewOS { return fImpl; } - - void NewFilesystemManager::SetResourceFork(const char* forkName) - { - if (!forkName) return; - rt_copy_memory((VoidPtr)forkName, (VoidPtr)fRsrcFork, rt_string_len(forkName)); - } - - void NewFilesystemManager::SetDataFork(const char* forkName) - { - if (!forkName) return; - rt_copy_memory((VoidPtr)forkName, (VoidPtr)fDataFork, rt_string_len(forkName)); - } #endif // __FSKIT_NEWFS__ } // namespace NewOS diff --git a/Kernel/Source/KernelCheck.cxx b/Kernel/Source/KernelCheck.cxx index e7c43650..5df52248 100644 --- a/Kernel/Source/KernelCheck.cxx +++ b/Kernel/Source/KernelCheck.cxx @@ -26,7 +26,7 @@ namespace NewOS void ke_stop(const NewOS::Int& id) { kcout << "*** STOP *** \r"; - kcout << "*** NewKernel.exe has trigerred a runtime stop. *** \r"; + kcout << "*** Kernel has trigerred a runtime stop. *** \r"; switch (id) { diff --git a/Kernel/Source/ProcessScheduler.cxx b/Kernel/Source/ProcessScheduler.cxx index 859ce657..555dfe07 100644 --- a/Kernel/Source/ProcessScheduler.cxx +++ b/Kernel/Source/ProcessScheduler.cxx @@ -218,7 +218,7 @@ namespace NewOS kcout << "ProcessScheduler::Add(Ref& process)\r"; /// Create heap according to type of process. - if (process.Leak().Kind == ProcessHeader::kUserKind) + if (process.Leak().Kind == ProcessHeader::kAppKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); else if (process.Leak().Kind == ProcessHeader::kLibKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared); diff --git a/Kernel/Source/Variant.cxx b/Kernel/Source/Variant.cxx index afe66624..1a09718b 100644 --- a/Kernel/Source/Variant.cxx +++ b/Kernel/Source/Variant.cxx @@ -10,11 +10,6 @@ namespace NewOS { const Char* Variant::ToString() { - if (fPtr == nullptr) - { - return ("Memory:{Nullptr}"); - } - switch (fKind) { case VariantKind::kString: diff --git a/Kernel/makefile b/Kernel/makefile index 61eb9dfe..74365a60 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -37,10 +37,7 @@ LDFLAGS = -e __ImageStart --subsystem=17 LDOBJ = Objects/*.obj # This file is the kernel, responsible of task management and memory. -KERNEL = NewKernel.exe - -# The kernel entrypoint -SCRIPT = --script=Linker/Platforms/PC.lds +KERNEL = NewOSKrnl.exe .PHONY: error error: -- cgit v1.2.3