From 4b58295fb04c2430817301352fadce33178f94d4 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Wed, 12 Jun 2024 18:09:07 +0200 Subject: MHR-30: initial commit. Signed-off-by: Amlal EL Mahrouss --- Kernel/Sources/AppMain.cxx | 225 ----------------------------------- Kernel/Sources/KeMain.cxx | 228 ++++++++++++++++++++++++++++++++++++ Kernel/Sources/ProcessScheduler.cxx | 3 - Kernel/Sources/SMPManager.cxx | 15 +++ 4 files changed, 243 insertions(+), 228 deletions(-) delete mode 100644 Kernel/Sources/AppMain.cxx create mode 100644 Kernel/Sources/KeMain.cxx (limited to 'Kernel/Sources') diff --git a/Kernel/Sources/AppMain.cxx b/Kernel/Sources/AppMain.cxx deleted file mode 100644 index 55b7f403..00000000 --- a/Kernel/Sources/AppMain.cxx +++ /dev/null @@ -1,225 +0,0 @@ -/* ------------------------------------------- - - Copyright Zeta Electronics Corporation - - File: AppMain.cxx - Purpose: Kernel main loop. - -------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace NewOS::Detail -{ - /// @brief Filesystem auto mounter, additional checks are also done by the - /// class. - class FilesystemWizard final - { - NewOS::NewFilesystemManager* fNewFS{nullptr}; - - public: - explicit FilesystemWizard() - { - if (NewOS::FilesystemManagerInterface::GetMounted()) - { - /// Mounted partition, cool! - NewOS::kcout - << "New OS: No need to create for a NewFS partition here...\r"; - } - else - { - /// Not mounted partition, auto-mount. - ///! Mounts a NewFS block. - fNewFS = new NewOS::NewFilesystemManager(); - - NewOS::FilesystemManagerInterface::Mount(fNewFS); - - if (fNewFS->GetParser()) - { - constexpr auto cFolderInfo = "Metadata"; - const auto cDirCount = 8; - const char* cDirStr[cDirCount] = { - "/Boot/", "/System/", "/Support/", "/Applications/", - "/Users/", "/Library/", "/Mount/", "/Assistants/"}; - - for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) - { - auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); - - if (catalogDir) - { - delete catalogDir; - continue; - } - - catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); - - NewFork theFork{0}; - - const NewOS::Char* cSrcName = cFolderInfo; - - NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theFork.ForkName, - NewOS::rt_string_len(cSrcName)); - - NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDir->Name), - theFork.CatalogName, - NewOS::rt_string_len(catalogDir->Name)); - - delete catalogDir; - - theFork.DataSize = kNewFSForkSize; - theFork.ResourceId = 0; - theFork.ResourceKind = NewOS::kNewFSRsrcForkKind; - theFork.Kind = NewOS::kNewFSDataForkKind; - - NewOS::StringView metadataFolder(kNewFSSectorSz); - - metadataFolder += - "

Kind: folder

\r

Created by: system

\r

Edited by: " - "system

\r

Volume Type: New OS Standard

\r"; - - metadataFolder += "

File name: "; - metadataFolder += cDirStr[dirIndx]; - metadataFolder += "

\r"; - - const NewOS::SizeT metadataSz = kNewFSSectorSz; - - auto catalogSystem = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); - - fNewFS->GetParser()->CreateFork(catalogSystem, theFork); - - fNewFS->GetParser()->WriteCatalog( - catalogSystem, (NewOS::VoidPtr)(metadataFolder.CData()), - metadataSz, cFolderInfo); - - delete catalogSystem; - } - } - - NewCatalog* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("/Mount/This Disk"); - - const NewOS::Char* cSrcName = "DiskInfo"; - - if (catalogDisk) - { - auto bufferInfoDisk = (NewOS::Char*)this->fNewFS->GetParser()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); - NewOS::kcout << bufferInfoDisk << NewOS::end_line(); - - delete bufferInfoDisk; - delete catalogDisk; - } - else - { - catalogDisk = - (NewCatalog*)this->Leak()->CreateAlias("/Mount/This Disk"); - - NewOS::StringView diskFolder(kNewFSSectorSz); - - diskFolder += - "

Kind: alias to disk

\r

Created by: system

\r

Edited " - "by: " - "system

\r

Volume Type: New OS Standard

\r"; - - diskFolder += "

Original Path: "; - diskFolder += NewOS::NewFilesystemHelper::Root(); - diskFolder += "

\r"; - - NewFork theDiskFork{0}; - - NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theDiskFork.ForkName, - NewOS::rt_string_len(cSrcName)); - - NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - NewOS::rt_string_len(catalogDisk->Name)); - - theDiskFork.DataSize = kNewFSForkSize; - theDiskFork.ResourceId = 0; - theDiskFork.ResourceKind = NewOS::kNewFSRsrcForkKind; - theDiskFork.Kind = NewOS::kNewFSDataForkKind; - - fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); - fNewFS->GetParser()->WriteCatalog(catalogDisk, - (NewOS::VoidPtr)diskFolder.CData(), - kNewFSSectorSz, cSrcName); - - delete catalogDisk; - } - } - } - - ~FilesystemWizard() - { - delete fNewFS; - } - - NEWOS_COPY_DEFAULT(FilesystemWizard); - - /// Grab the disk's NewFS reference. - NewOS::NewFilesystemManager* Leak() - { - return fNewFS; - } - }; - - /// @brief System loader entrypoint. - /// @param void no parameters. - /// @return void no return value. - STATIC NewOS::Void AppSystem(NewOS::Void) - { - NewOS::PEFLoader wndServer("/System/WindowServer"); - - if (!wndServer.IsLoaded()) - { - NewOS::ke_stop(RUNTIME_CHECK_FAILED); - } - - NewOS::Utils::execute_from_image(wndServer, - NewOS::ProcessHeader::kAppKind); - - NewOS::PEFLoader launchServer("/System/Launcher"); - - if (!launchServer.IsLoaded()) - { - NewOS::ke_stop(RUNTIME_CHECK_FAILED); - } - - NewOS::Utils::execute_from_image(launchServer, - NewOS::ProcessHeader::kAppKind); - - NewOS::kcout << "System: done, sleeping..."; - - while (true) {} - } -} // namespace NewOS::Detail - -/// @brief Application entrypoint. -/// @param Void -/// @return Void -EXTERN_C NewOS::Void AppMain(NewOS::Void) -{ - /// Now run kernel loop, until no process are running. - NewOS::Detail::FilesystemWizard wizard; // automatic. - - auto cLoaderName = "System"; - NewOS::execute_from_image(NewOS::Detail::AppSystem, cLoaderName); - - while (NewOS::ProcessScheduler::The().Leak().Run() > 0) {} -} diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx new file mode 100644 index 00000000..f4f9f44c --- /dev/null +++ b/Kernel/Sources/KeMain.cxx @@ -0,0 +1,228 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + + File: KeMain.cxx + Purpose: Kernel main loop. + +------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace NewOS::Detail +{ + /// @brief Filesystem auto mounter, additional checks are also done by the + /// class. + class FilesystemWizard final + { + NewOS::NewFilesystemManager* fNewFS{nullptr}; + + public: + explicit FilesystemWizard() + { + if (NewOS::FilesystemManagerInterface::GetMounted()) + { + /// Mounted partition, cool! + NewOS::kcout + << "New OS: No need to create for a NewFS partition here...\r"; + } + else + { + /// Not mounted partition, auto-mount. + ///! Mounts a NewFS block. + fNewFS = new NewOS::NewFilesystemManager(); + + NewOS::FilesystemManagerInterface::Mount(fNewFS); + + if (fNewFS->GetParser()) + { + constexpr auto cFolderInfo = "Metadata"; + const auto cDirCount = 8; + const char* cDirStr[cDirCount] = { + "/Boot/", "/System/", "/Support/", "/Applications/", + "/Users/", "/Library/", "/Mount/", "/Assistants/"}; + + for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) + { + auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + + if (catalogDir) + { + delete catalogDir; + continue; + } + + catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, + kNewFSCatalogKindDir); + + NewFork theFork{0}; + + const NewOS::Char* cSrcName = cFolderInfo; + + NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theFork.ForkName, + NewOS::rt_string_len(cSrcName)); + + NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDir->Name), + theFork.CatalogName, + NewOS::rt_string_len(catalogDir->Name)); + + delete catalogDir; + + theFork.DataSize = kNewFSForkSize; + theFork.ResourceId = 0; + theFork.ResourceKind = NewOS::kNewFSRsrcForkKind; + theFork.Kind = NewOS::kNewFSDataForkKind; + + NewOS::StringView metadataFolder(kNewFSSectorSz); + + metadataFolder += + "

Kind: folder

\r

Created by: system

\r

Edited by: " + "system

\r

Volume Type: New OS Standard

\r"; + + metadataFolder += "

File name: "; + metadataFolder += cDirStr[dirIndx]; + metadataFolder += "

\r"; + + const NewOS::SizeT metadataSz = kNewFSSectorSz; + + auto catalogSystem = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + + fNewFS->GetParser()->CreateFork(catalogSystem, theFork); + + fNewFS->GetParser()->WriteCatalog( + catalogSystem, (NewOS::VoidPtr)(metadataFolder.CData()), + metadataSz, cFolderInfo); + + delete catalogSystem; + } + } + + NewCatalog* catalogDisk = + this->fNewFS->GetParser()->GetCatalog("/Mount/This Disk"); + + const NewOS::Char* cSrcName = "DiskInfo"; + + if (catalogDisk) + { + auto bufferInfoDisk = (NewOS::Char*)this->fNewFS->GetParser()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); + NewOS::kcout << bufferInfoDisk << NewOS::end_line(); + + delete bufferInfoDisk; + delete catalogDisk; + } + else + { + catalogDisk = + (NewCatalog*)this->Leak()->CreateAlias("/Mount/This Disk"); + + NewOS::StringView diskFolder(kNewFSSectorSz); + + diskFolder += + "

Kind: alias to disk

\r

Created by: system

\r

Edited " + "by: " + "system

\r

Volume Type: New OS Standard

\r"; + + diskFolder += "

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

\r"; + + NewFork theDiskFork{0}; + + NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theDiskFork.ForkName, + NewOS::rt_string_len(cSrcName)); + + NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDisk->Name), + theDiskFork.CatalogName, + NewOS::rt_string_len(catalogDisk->Name)); + + theDiskFork.DataSize = kNewFSForkSize; + theDiskFork.ResourceId = 0; + theDiskFork.ResourceKind = NewOS::kNewFSRsrcForkKind; + theDiskFork.Kind = NewOS::kNewFSDataForkKind; + + fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); + fNewFS->GetParser()->WriteCatalog(catalogDisk, + (NewOS::VoidPtr)diskFolder.CData(), + kNewFSSectorSz, cSrcName); + + delete catalogDisk; + } + } + } + + ~FilesystemWizard() + { + delete fNewFS; + } + + NEWOS_COPY_DEFAULT(FilesystemWizard); + + /// Grab the disk's NewFS reference. + NewOS::NewFilesystemManager* Leak() + { + return fNewFS; + } + }; + + /// @brief System loader entrypoint. + /// @param void no parameters. + /// @return void no return value. + STATIC NewOS::Void SystemLauncher_Main(NewOS::Void) + { + NewOS::PEFLoader lockScreen("/System/LockScreen"); + + if (!lockScreen.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(lockScreen, + NewOS::ProcessHeader::kAppKind); + + NewOS::PEFLoader stageBoard("/System/StageBoard"); + + if (!stageBoard.IsLoaded()) + { + NewOS::ke_stop(RUNTIME_CHECK_FAILED); + } + + NewOS::Utils::execute_from_image(stageBoard, + NewOS::ProcessHeader::kAppKind); + + NewOS::kcout << "SystemLauncher: done, sleeping..."; + + while (true) {} + } +} // namespace NewOS::Detail + +/// @brief Application entrypoint. +/// @param Void +/// @return Void +EXTERN_C NewOS::Void KeMain(NewOS::Void) +{ + /// Now run kernel loop, until no process are running. + NewOS::Detail::FilesystemWizard wizard; // automatic. + + auto cLoaderName = "SystemLauncher"; + NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName); + + while (true) + { + NewOS::ProcessScheduler::The().Leak().Run(); + } +} diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 1a49af22..08a7971e 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -215,9 +215,6 @@ namespace NewOS if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam) return -kErrorOutOfTeamSlot; - if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) - return -1; - kcout << "ProcessScheduler::Add(Ref& process)\r"; /// Create heap according to type of process. diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index b2c3f488..f0b680ce 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -99,6 +99,21 @@ namespace NewOS fStack->Rsp = stack->Rsp; fStack->Fs = stack->Fs; fStack->Gs = stack->Gs; + + // save global registers. + + fStack->R15 = stack->R15; + fStack->R14 = stack->R14; + + fStack->R13 = stack->R13; + fStack->R12 = stack->R12; + fStack->R11 = stack->R11; + + fStack->R10 = stack->R10; + fStack->R9 = stack->R9; + fStack->R8 = stack->R8; + + fStack->Exception = this->fID; } rt_do_context_switch(fStack); -- cgit v1.2.3