Merge remote-tracking branch 'Kernel/master'

This commit is contained in:
EnderIce2
2024-11-20 05:00:33 +02:00
468 changed files with 112800 additions and 1 deletions

View File

@ -0,0 +1,61 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_cat(const char *args)
{
if (args[0] == '\0')
return;
FileNode *node = fs->GetByPath(args, nullptr);
if (node == nullptr)
{
printf("cat: %s: No such file or directory\n", args);
return;
}
if (!node->IsRegularFile() && !node->IsCharacterDevice())
{
printf("cat: %s: Not a regular file or character device\n", args);
return;
}
if (node->IsCharacterDevice())
{
printf("cat: %s: Character devices are not supported yet\n", args);
return;
}
kstat stat = {};
node->Stat(&stat);
uint8_t *buffer = new uint8_t[stat.Size + 1];
ssize_t rBytes = node->Read(buffer, stat.Size, 0);
if (rBytes > 0)
printf("%s\n", buffer);
else
printf("cat: %s: Could not read file\n", args);
delete[] buffer;
}

View File

@ -0,0 +1,46 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_cd(const char *args)
{
if (args[0] == '\0')
return;
FileNode *node = fs->GetByPath(args, nullptr);
if (node == nullptr)
{
printf("cd: %s: No such file or directory\n", args);
return;
}
if (!node->IsDirectory())
{
printf("cd: %s: Not a directory\n", args);
return;
}
thisProcess->CWD = node;
}

View File

@ -0,0 +1,25 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include "../../kernel.h"
void cmd_clear(const char *)
{
printf("\x1b[2J");
}

View File

@ -0,0 +1,77 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <acpi.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_dump(const char *args)
{
if (args[0] == '\0')
return;
// args == "0xdeadbeef 512" aka "address size"
char *strAddr = (char *)args;
char *strLen = (char *)args;
while (*strLen != ' ')
strLen++;
*strLen = '\0';
strLen++;
void *Address = (void *)strtoul(strAddr, nullptr, 16);
unsigned long Length = strtoul(strLen, nullptr, 10);
{
unsigned char *AddressChar = (unsigned char *)Address;
unsigned char Buffer[17];
uint32_t Iterate;
printf("Dumping %lu bytes from %#lx\n", Length, (uintptr_t)AddressChar);
for (Iterate = 0; Iterate < (uint32_t)Length; Iterate++)
{
if ((Iterate % 16) == 0)
{
if (Iterate != 0)
printf(" %s\n", Buffer);
printf(" %04x ", Iterate);
}
printf(" %02x", AddressChar[Iterate]);
if ((AddressChar[Iterate] < 0x20) || (AddressChar[Iterate] > 0x7E))
Buffer[Iterate % 16] = '.';
else
Buffer[Iterate % 16] = AddressChar[Iterate];
Buffer[(Iterate % 16) + 1] = '\0';
}
while ((Iterate % 16) != 0)
{
printf(" ");
Iterate++;
}
putchar('\n');
}
}

View File

@ -0,0 +1,25 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include "../../kernel.h"
void cmd_echo(const char *args)
{
printf("%s\n", args);
}

View File

@ -0,0 +1,33 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_exit(const char *)
{
KernelShutdownThread(false);
// TaskManager->KillThread(thisThread, KILL_SUCCESS);
CPU::Halt(true);
}

View File

@ -0,0 +1,39 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_kill(const char *args)
{
PID pid = atoi(args);
PCB *pcb = TaskManager->GetProcessByID(pid);
if (pcb == nullptr)
{
printf("No process with PID %d\n", pid);
return;
}
TaskManager->KillProcess(pcb, KILL_BY_OTHER_PROCESS);
}

View File

@ -0,0 +1,37 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_killall(const char *args)
{
foreach (auto Proc in TaskManager->GetProcessList())
{
if (strcmp(Proc->Name, args) == 0)
{
TaskManager->KillProcess(Proc, KILL_BY_OTHER_PROCESS);
}
}
}

View File

@ -0,0 +1,135 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
const char *ColorNodeType(FileNode *node)
{
if (node->IsRegularFile())
return "\x1b[32m";
else if (node->IsDirectory())
return "\x1b[34m";
else if (node->IsBlockDevice())
return "\x1b[33m";
else if (node->IsCharacterDevice())
return "\x1b[33m";
else if (node->IsFIFO())
return "\x1b[33m";
else if (node->IsSymbolicLink())
return "\x1b[35m";
else
return "\x1b[0m";
}
__no_sanitize("alignment") size_t MaxNameLength(FileNode *nodes)
{
size_t maxLength = 0;
kdirent *dirBuffer = new kdirent[16];
ssize_t read = 0;
off_t offset = 0;
while ((read = nodes->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
{
if (read / sizeof(kdirent) == 0)
break;
off_t bufOffset = 0;
debug("There are %ld entries in this directory", read / sizeof(kdirent));
for (size_t i = 0; i < read / sizeof(kdirent); i++)
{
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
if (dirent->d_reclen == 0)
break;
bufOffset += dirent->d_reclen;
maxLength = std::max(maxLength, strlen(dirent->d_name));
debug("dirent->d_name: %s (max length: %ld)", dirent->d_name, maxLength);
}
offset += read / sizeof(kdirent);
}
delete[] dirBuffer;
return maxLength;
}
__no_sanitize("alignment") void PrintLS(FileNode *node)
{
size_t maxNameLength = MaxNameLength(node);
int count = 0;
bool first = true;
kdirent *dirBuffer = new kdirent[16];
ssize_t read = 0;
off_t offset = 0;
while ((read = node->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
{
if (read / sizeof(kdirent) == 0)
break;
off_t bufOffset = 0;
for (size_t i = 0; i < read / sizeof(kdirent); i++)
{
if (count % 5 == 0 && !first)
printf("\n");
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
if (dirent->d_reclen == 0)
break;
bufOffset += dirent->d_reclen;
printf(" %s%-*s ", ColorNodeType(node), (int)maxNameLength, dirent->d_name);
count++;
first = false;
}
offset += read / sizeof(kdirent);
}
printf("\x1b[0m\n");
delete[] dirBuffer;
}
void cmd_ls(const char *args)
{
if (args[0] == '\0')
{
FileNode *rootNode = thisProcess->CWD;
if (rootNode == nullptr)
rootNode = fs->GetRoot(0);
PrintLS(rootNode);
return;
}
FileNode *thisNode = fs->GetByPath(args, nullptr);
if (thisNode == nullptr)
{
printf("ls: %s: No such file or directory\n", args);
return;
}
if (!thisNode->IsDirectory())
{
printf("%s%s\n", ColorNodeType(thisNode), thisNode->Path.c_str());
return;
}
PrintLS(thisNode);
}

View File

@ -0,0 +1,39 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <acpi.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_lsacpi(const char *)
{
ACPI::ACPI *acpi = (ACPI::ACPI *)PowerManager->GetACPI();
foreach (auto Table in acpi->Tables)
{
printf("%#lx: %.4s [%.6s:%.8s] %d bytes\n",
(uintptr_t)Table.second,
Table.second->Signature,
Table.second->OEMID,
Table.second->OEMTableID,
Table.second->Length);
}
}

View File

@ -0,0 +1,37 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include "../../kernel.h"
void cmd_lsmod(const char *)
{
std::unordered_map<dev_t, Driver::DriverObject> drivers =
DriverManager->GetDrivers();
printf("DRIVER | ID | INIT | MEMORY\n");
foreach (auto &drv in drivers)
{
printf("%-15s | %5ld | %s | %ld KiB\n",
drv.second.Name,
drv.first,
drv.second.Initialized ? "Y" : "N",
TO_KiB(drv.second.vma->GetAllocatedMemorySize()));
}
}

View File

@ -0,0 +1,80 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_lspci(const char *args)
{
if (args)
{
if (IF_ARG("-i") || IF_ARG("--info"))
{
foreach (auto Device in PCIManager->GetDevices())
{
const char *HdrType;
switch (Device.Header->HeaderType)
{
case 0:
HdrType = "Normal ";
break;
case 1:
HdrType = "PCI-PCI";
break;
case 2:
HdrType = "Cardbus";
break;
default:
HdrType = "Unknown";
break;
}
printf("%04x:%04x | %s:%03d | %02x:%02x.%d | %s: %s %s\n",
Device.Header->VendorID,
Device.Header->DeviceID,
HdrType, Device.Header->HeaderType,
Device.Bus,
Device.Device,
Device.Function,
PCI::Descriptors::GetSubclassName(Device.Header->Class,
Device.Header->Subclass),
PCI::Descriptors::GetVendorName(Device.Header->VendorID),
PCI::Descriptors::GetDeviceName(Device.Header->VendorID,
Device.Header->DeviceID));
}
return;
}
}
foreach (auto Device in PCIManager->GetDevices())
{
printf("%02x:%02x.%d: %s: %s %s\n",
Device.Bus,
Device.Device,
Device.Function,
PCI::Descriptors::GetSubclassName(Device.Header->Class,
Device.Header->Subclass),
PCI::Descriptors::GetVendorName(Device.Header->VendorID),
PCI::Descriptors::GetDeviceName(Device.Header->VendorID,
Device.Header->DeviceID));
}
}

View File

@ -0,0 +1,64 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_mem(const char *)
{
uint64_t total = KernelAllocator.GetTotalMemory();
uint64_t used = KernelAllocator.GetUsedMemory();
uint64_t free = KernelAllocator.GetFreeMemory();
uint64_t reserved = KernelAllocator.GetReservedMemory();
int usedPercent = (int)((used * 100) / total);
int usedBar = (int)(usedPercent / 2);
int reservedPercent = (int)((reserved * 100) / total);
int reservedBar = (int)(reservedPercent / 2);
printf("[");
for (int i = 0; i < usedBar; i++)
printf("=");
for (int i = 0; i < 50 - usedBar; i++)
printf(" ");
printf("] %d%% Used\n", usedPercent);
printf("[");
for (int i = 0; i < reservedBar; i++)
printf("=");
for (int i = 0; i < 50 - reservedBar; i++)
printf(" ");
printf("] %d%% Reserved\n", reservedPercent);
// printf("Total: %d MiB\n", (int)(TO_MiB(total)));
// printf("Used: %d MiB\n", (int)(TO_MiB(used)));
// printf("Free: %d MiB\n", (int)(TO_MiB(free)));
// printf("Reserved: %d MiB\n", (int)(TO_MiB(reserved)));
printf("TOTAL USED FREE RESERVED\n");
printf("%d MiB %d MiB %d MiB %d MiB\n",
(int)(TO_MiB(total)), (int)(TO_MiB(used)),
(int)(TO_MiB(free)), (int)(TO_MiB(reserved)));
}

View File

@ -0,0 +1,78 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include "../../kernel.h"
void cmd_modinfo(const char *args)
{
if (args[0] == '\0')
{
printf("Usage: modinfo <driver id/name>\n");
return;
}
dev_t id = atoi(args);
std::unordered_map<dev_t, Driver::DriverObject> drivers =
DriverManager->GetDrivers();
if (drivers.find(id) == drivers.end())
{
bool found = false;
foreach (auto var in drivers)
{
if (strcmp(var.second.Name, args) == 0)
{
id = var.first;
found = true;
break;
}
}
if (!found)
{
printf("Driver not found\n");
return;
}
}
Driver::DriverObject drv = drivers[id];
char drvVersion[32];
snprintf(drvVersion, sizeof(drvVersion), "%d.%d.%d",
drv.Version.Major, drv.Version.Minor, drv.Version.Patch);
printf("Base Info:\n");
printf(" Name: %s\n", drv.Name);
printf(" Description: %s\n", drv.Description);
printf(" Author: %s\n", drv.Author);
printf(" Version: %s\n", drvVersion);
printf(" License: %s\n", drv.License);
printf("Resource Info:\n");
printf(" Initialized: %s\n", drv.Initialized ? "yes" : "no");
printf(" Error Code: %i (%s)\n", drv.ErrorCode, strerror(drv.ErrorCode));
printf(" Path: %s\n", drv.Path.c_str());
printf(" Used Memory: %ld KiB\n", TO_KiB(drv.vma->GetAllocatedMemorySize()));
printf(" Used IRQs:%s\n", drv.InterruptHandlers->empty() ? " none" : "");
foreach (auto var in *drv.InterruptHandlers)
{
printf(" IRQ%-2d: %#lx\n",
var.first, (uintptr_t)var.second);
}
}

View File

@ -0,0 +1,30 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
nsa void cmd_panic(const char *)
{
asmv("int $0x0");
__unreachable;
}

View File

@ -0,0 +1,33 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_ps(const char *)
{
printf("PID Name\n");
foreach (auto p in TaskManager->GetProcessList())
printf("%d %s\n", p->ID, p->Name);
}

View File

@ -0,0 +1,32 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_reboot(const char *)
{
KernelShutdownThread(true);
CPU::Halt(true);
}

View File

@ -0,0 +1,32 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
void cmd_shutdown(const char *)
{
KernelShutdownThread(false);
CPU::Halt(true);
}

View File

@ -0,0 +1,25 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include "../../kernel.h"
void cmd_theme(const char *args)
{
KernelConsole::SetTheme(args);
}

View File

@ -0,0 +1,75 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include <task.hpp>
#include "../../kernel.h"
using namespace vfs;
using namespace Tasking;
const char *TaskStateStrings[] = {
"Unknown", // Unknown
"Ready", // Ready
"Running", // Running
"Sleeping", // Sleeping
"Blocked", // Blocked
"Stopped", // Stopped
"Waiting", // Waiting
"CoreDump", // Core dump
"Zombie", // Zombie
"Terminated", // Terminated
"Frozen", // Frozen
};
void cmd_top(const char *)
{
printf("PID Name State Priority Memory Usage CPU Usage\n");
foreach (auto Proc in TaskManager->GetProcessList())
{
#if defined(a64)
printf("%-4d %-20s %s %d %ld KiB %ld\n",
Proc->ID, Proc->Name, TaskStateStrings[Proc->State.load()],
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
Proc->Info.UserTime + Proc->Info.KernelTime);
#elif defined(a32)
printf("%-4d %-20s %s %d %lld KiB %lld\n",
Proc->ID, Proc->Name, TaskStateStrings[Proc->State.load()],
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
Proc->Info.UserTime + Proc->Info.KernelTime);
#endif
foreach (auto Thrd in Proc->Threads)
{
#if defined(a64)
printf(" %-4d %-20s %s %d %ld KiB %ld\n",
Thrd->ID, Thrd->Name, TaskStateStrings[Thrd->State.load()],
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
Thrd->Info.UserTime + Thrd->Info.KernelTime);
#elif defined(a32)
printf(" %-4d %-20s %s %d %lld KiB %lld\n",
Thrd->ID, Thrd->Name, TaskStateStrings[Thrd->State.load()],
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
Thrd->Info.UserTime + Thrd->Info.KernelTime);
#endif
}
}
}

View File

@ -0,0 +1,101 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
void tree_loop(FileNode *rootNode, int depth = 0)
{
// foreach (auto Child in rootNode->GetChildren(true))
// {
// Display->UpdateBuffer();
// if (Child->Stat.IsType(DIRECTORY) || Child->Stat.IsType(MOUNTPOINT))
// {
// printf("%*s%*s%*s|- %s\n",
// depth, "",
// depth, "",
// depth, "",
// Child->FileName);
// tree_loop(Child, depth + 1);
// }
// else
// printf("%*s%*s%*s|- %s\n",
// depth, "",
// depth, "",
// depth, "",
// Child->FileName);
// }
kdirent *dirBuffer = new kdirent[16];
ssize_t read = 0;
off_t offset = 0;
while ((read = rootNode->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
{
if (read / sizeof(kdirent) == 0)
break;
off_t bufOffset = 0;
for (size_t i = 0; i < read / sizeof(kdirent); i++)
{
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
if (dirent->d_reclen == 0)
break;
bufOffset += dirent->d_reclen;
if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
continue;
FileNode *node = fs->GetByPath(dirent->d_name, rootNode);
if (node == nullptr)
continue;
for (int i = 0; i < depth; i++)
printf(" ");
printf("|- %s\n", dirent->d_name);
if (node->IsDirectory())
tree_loop(node, depth + 1);
}
offset += read;
}
delete[] dirBuffer;
}
void cmd_tree(const char *args)
{
FileNode *rootNode = thisProcess->CWD;
if (args[0] == '\0')
{
if (rootNode == nullptr)
rootNode = fs->GetRoot(0);
}
else
{
rootNode = fs->GetByPath(args, nullptr);
if (rootNode == nullptr)
{
printf("ls: %s: No such file or directory\n", args);
return;
}
}
printf("%s\n", rootNode->Name.c_str());
tree_loop(rootNode);
}

View File

@ -0,0 +1,65 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_uname(const char *args)
{
if (args)
{
if (IF_ARG("-a") || IF_ARG("--all"))
{
printf("Fennix Kernel %s %s %s %s\n",
KERNEL_VERSION, KERNEL_NAME, __DATE__,
KERNEL_ARCH);
}
else if (IF_ARG("-s") || IF_ARG("--kernel-name"))
{
printf("%s\n", KERNEL_NAME);
}
else if (IF_ARG("-v") || IF_ARG("--kernel-version"))
{
printf("%s\n", KERNEL_VERSION);
}
else if (IF_ARG("-n") || IF_ARG("--nodename"))
{
printf("unknown\n");
}
else if (IF_ARG("-r") || IF_ARG("--kernel-release"))
{
printf("%s\n", KERNEL_NAME);
}
else if (IF_ARG("-m") || IF_ARG("--machine"))
{
printf("%s\n", KERNEL_ARCH);
}
else
{
printf("uname: invalid option: %s\n", args);
}
}
else
{
printf("Fennix Kernel\n");
}
}

View File

@ -0,0 +1,57 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_uptime(const char *)
{
if (TimeManager)
{
uint64_t Nanoseconds =
TimeManager->GetNanosecondsSinceClassCreation();
uint64_t Seconds = Nanoseconds / 10000000;
uint64_t Minutes = Seconds / 60;
uint64_t Hours = Minutes / 60;
uint64_t Days = Hours / 24;
debug("Nanoseconds: %ld", Nanoseconds);
Seconds %= 60;
Minutes %= 60;
Hours %= 24;
#if defined(a64)
printf("%ld days, %ld hours, %ld minutes, %ld %s\n",
Days, Hours, Minutes, Seconds,
Seconds == 1 ? "second" : "seconds");
#elif defined(a32)
printf("%lld days, %lld hours, %lld minutes, %lld %s\n",
Days, Hours, Minutes, Seconds,
Seconds == 1 ? "second" : "seconds");
#endif
}
else
{
printf("Could not get uptime\n");
}
}

View File

@ -0,0 +1,29 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../cmds.hpp"
#include <filesystem.hpp>
#include "../../kernel.h"
using namespace vfs;
void cmd_whoami(const char *)
{
printf("kernel\n");
}