mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Updated kernel (tl;dr: improved filesystem, tasking, loading files, etc..)
This commit is contained in:
126
KThread.cpp
126
KThread.cpp
@ -11,23 +11,61 @@
|
||||
#include "DAPI.hpp"
|
||||
#include "Fex.hpp"
|
||||
|
||||
using VirtualFileSystem::File;
|
||||
using VirtualFileSystem::FileStatus;
|
||||
using VirtualFileSystem::Node;
|
||||
using VirtualFileSystem::NodeFlags;
|
||||
|
||||
Driver::Driver *DriverManager = nullptr;
|
||||
Disk::Manager *DiskManager = nullptr;
|
||||
NetworkInterfaceManager::NetworkInterface *NIManager = nullptr;
|
||||
Recovery::KernelRecovery *RecoveryScreen = nullptr;
|
||||
VirtualFileSystem::Node *DevFS = nullptr;
|
||||
VirtualFileSystem::Node *MntFS = nullptr;
|
||||
VirtualFileSystem::Node *ProcFS = nullptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
void TreeFS(Node *node, int Depth)
|
||||
{
|
||||
return;
|
||||
foreach (auto Chld in node->Children)
|
||||
{
|
||||
printf("%*c %s\eFFFFFF\n", Depth, ' ', Chld->Name);
|
||||
Display->SetBuffer(0);
|
||||
TreeFS(Chld, Depth + 1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Execute::SpawnData SpawnInit()
|
||||
{
|
||||
const char *envp[9] = {
|
||||
"PATH=/system:/system/bin",
|
||||
"TERM=tty",
|
||||
"HOME=/",
|
||||
"USER=root",
|
||||
"SHELL=/system/sh",
|
||||
"PWD=/",
|
||||
"LANG=en_US.UTF-8",
|
||||
"TZ=UTC",
|
||||
nullptr};
|
||||
|
||||
const char *argv[4] = {
|
||||
Config.InitPath,
|
||||
"--init",
|
||||
"--critical",
|
||||
nullptr};
|
||||
|
||||
return Execute::Spawn(Config.InitPath, argv, envp);
|
||||
}
|
||||
|
||||
void KernelMainThread()
|
||||
{
|
||||
TaskManager->InitIPC();
|
||||
TaskManager->GetCurrentThread()->SetPriority(100);
|
||||
CPU::Interrupts(CPU::Disable);
|
||||
TaskManager->GetCurrentThread()->SetPriority(Tasking::Critical);
|
||||
|
||||
KPrint("Kernel Compiled at: %s %s with C++ Standard: %d", __DATE__, __TIME__, CPP_LANGUAGE_STANDARD);
|
||||
KPrint("C++ Language Version (__cplusplus): %ld", __cplusplus);
|
||||
|
||||
KPrint("Initializing Filesystem...");
|
||||
vfs = new FileSystem::Virtual;
|
||||
new FileSystem::USTAR((uintptr_t)bInfo->Modules[0].Address, vfs); // TODO: Detect initrd
|
||||
KPrint("Initializing Disk Manager...");
|
||||
DiskManager = new Disk::Manager;
|
||||
|
||||
@ -49,43 +87,69 @@ void KernelMainThread()
|
||||
KPrint("Starting Network Interface Manager...");
|
||||
NIManager->StartService();
|
||||
|
||||
KPrint("Setting up userspace...");
|
||||
KPrint("Setting up userspace");
|
||||
|
||||
const char *envp[9] = {
|
||||
"PATH=/system:/system/bin",
|
||||
"TERM=tty",
|
||||
"HOME=/",
|
||||
"USER=root",
|
||||
"SHELL=/system/sh",
|
||||
"PWD=/",
|
||||
"LANG=en_US.UTF-8",
|
||||
"TZ=UTC",
|
||||
nullptr};
|
||||
#ifdef DEBUG
|
||||
TreeFS(vfs->GetRootNode(), 0);
|
||||
#endif
|
||||
|
||||
const char *argv[4] = {
|
||||
Config.InitPath,
|
||||
"--init",
|
||||
"--critical",
|
||||
nullptr};
|
||||
const char *USpace_msg = "Setting up userspace";
|
||||
for (size_t i = 0; i < strlen(USpace_msg); i++)
|
||||
Display->Print(USpace_msg[i], 0);
|
||||
|
||||
Display->SetBuffer(0);
|
||||
|
||||
Execute::SpawnData ret = {Execute::ExStatus::Unknown, nullptr, nullptr};
|
||||
Tasking::TCB *ExecuteThread = nullptr;
|
||||
int ExitCode = -1;
|
||||
|
||||
Display->Print('.', 0);
|
||||
Display->SetBuffer(0);
|
||||
|
||||
ExecuteThread = TaskManager->CreateThread(TaskManager->GetCurrentProcess(), (Tasking::IP)Execute::StartExecuteService);
|
||||
ExecuteThread->Rename("Library Manager");
|
||||
ExecuteThread->SetCritical(true);
|
||||
ExecuteThread->SetPriority(Tasking::Idle);
|
||||
|
||||
Display->Print('.', 0);
|
||||
Display->SetBuffer(0);
|
||||
|
||||
CPU::Interrupts(CPU::Disable);
|
||||
ret = SpawnInit();
|
||||
|
||||
Display->Print('.', 0);
|
||||
Display->Print('\n', 0);
|
||||
Display->SetBuffer(0);
|
||||
|
||||
Execute::SpawnData ret = Execute::Spawn(Config.InitPath, argv, envp);
|
||||
if (ret.Status != Execute::ExStatus::OK)
|
||||
{
|
||||
KPrint("\eE85230Failed to start %s! Code: %d", Config.InitPath, ret.Status);
|
||||
CPU::Interrupts(CPU::Enable);
|
||||
goto Exit;
|
||||
}
|
||||
TaskManager->GetSecurityManager()->TrustToken(ret.Process->Security.UniqueToken, Tasking::TTL::FullTrust);
|
||||
TaskManager->GetSecurityManager()->TrustToken(ret.Thread->Security.UniqueToken, Tasking::TTL::FullTrust);
|
||||
ret.Thread->SetCritical(true);
|
||||
KPrint("Waiting for \e22AAFF%s\eCCCCCC to start...", Config.InitPath);
|
||||
CPU::Interrupts(CPU::Enable);
|
||||
TaskManager->GetCurrentThread()->SetPriority(1);
|
||||
TaskManager->GetCurrentThread()->SetPriority(Tasking::Idle);
|
||||
TaskManager->WaitForThread(ret.Thread);
|
||||
KPrint("\eE85230Userspace process exited with code %d", ret.Thread->GetExitCode());
|
||||
error("Userspace process exited with code %d (%#x)", ret.Thread->GetExitCode(), ret.Thread->GetExitCode());
|
||||
ExitCode = ret.Thread->GetExitCode();
|
||||
if (ExitCode != 0)
|
||||
KPrint("\eE85230Userspace process exited with code %d", ExitCode);
|
||||
error("Userspace process exited with code %d (%#x)", ExitCode, ExitCode);
|
||||
Exit:
|
||||
KPrint("%s exited with code %d! Dropping to recovery screen...", Config.InitPath, ret.Thread->GetExitCode());
|
||||
TaskManager->Sleep(1000);
|
||||
RecoveryScreen = new Recovery::KernelRecovery;
|
||||
if (ExitCode != 0)
|
||||
{
|
||||
KPrint("Dropping to recovery screen...", ExitCode);
|
||||
TaskManager->Sleep(5000);
|
||||
RecoveryScreen = new Recovery::KernelRecovery;
|
||||
}
|
||||
else
|
||||
{
|
||||
KPrint("\eFF7900%s process exited with code %d and it didn't invoked the shutdown function.",
|
||||
Config.InitPath, ExitCode);
|
||||
KPrint("System Halted");
|
||||
}
|
||||
CPU::Halt(true);
|
||||
}
|
||||
|
||||
@ -93,7 +157,7 @@ void KernelShutdownThread(bool Reboot)
|
||||
{
|
||||
BeforeShutdown();
|
||||
|
||||
trace("Shutting Down/Rebooting...");
|
||||
trace("%s...", Reboot ? "Rebooting" : "Shutting down");
|
||||
if (Reboot)
|
||||
PowerManager->Reboot();
|
||||
else
|
||||
|
Reference in New Issue
Block a user