mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Update kernel
This commit is contained in:
@ -47,8 +47,11 @@ void cmd_cat(const char *args)
|
||||
fstat(fd, &st);
|
||||
|
||||
char *buffer = new char[st.st_size + 1];
|
||||
fread(fd, buffer, st.st_size);
|
||||
printf("%s\n", buffer);
|
||||
ssize_t rBytes = fread(fd, buffer, st.st_size);
|
||||
if (rBytes > 0)
|
||||
printf("%s\n", buffer);
|
||||
else
|
||||
printf("cat: %s: Could not read file\n", args);
|
||||
delete[] buffer;
|
||||
fclose(fd);
|
||||
}
|
||||
|
26
kshell/commands/clear.cpp
Normal file
26
kshell/commands/clear.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
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 *)
|
||||
{
|
||||
Display->SetBufferCursor(0, 0, 0);
|
||||
Display->ClearBuffer(0);
|
||||
}
|
35
kshell/commands/lsacpi.cpp
Normal file
35
kshell/commands/lsacpi.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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("%s ", Table.first);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
37
kshell/commands/lsmod.cpp
Normal file
37
kshell/commands/lsmod.cpp
Normal 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()));
|
||||
}
|
||||
}
|
@ -23,8 +23,48 @@
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_lspci(const char *)
|
||||
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",
|
||||
|
73
kshell/commands/modinfo.cpp
Normal file
73
kshell/commands/modinfo.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
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];
|
||||
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", drv.Version);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
@ -25,6 +25,20 @@
|
||||
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
|
||||
};
|
||||
|
||||
void cmd_top(const char *)
|
||||
{
|
||||
printf("\e9400A1PID \e9CA100Name \e00A15BState \eCCCCCCPriority Memory Usage CPU Usage\n");
|
||||
@ -32,12 +46,12 @@ void cmd_top(const char *)
|
||||
{
|
||||
#if defined(a64)
|
||||
printf("\e9400A1%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %ld KiB %ld\n",
|
||||
Proc->ID, Proc->Name, Proc->State == Running ? "Running" : "Stopped",
|
||||
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("\e9400A1%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %lld KiB %lld\n",
|
||||
Proc->ID, Proc->Name, Proc->State == Running ? "Running" : "Stopped",
|
||||
Proc->ID, Proc->Name, TaskStateStrings[Proc->State.load()],
|
||||
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
|
||||
Proc->Info.UserTime + Proc->Info.KernelTime);
|
||||
#endif
|
||||
@ -46,12 +60,12 @@ void cmd_top(const char *)
|
||||
{
|
||||
#if defined(a64)
|
||||
printf(" \eA80011%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %ld KiB %ld\n",
|
||||
Thrd->ID, Thrd->Name, Thrd->State == Running ? "Running" : "Stopped",
|
||||
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(" \eA80011%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %lld KiB %lld\n",
|
||||
Thrd->ID, Thrd->Name, Thrd->State == Running ? "Running" : "Stopped",
|
||||
Thrd->ID, Thrd->Name, TaskStateStrings[Thrd->State.load()],
|
||||
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
|
||||
Thrd->Info.UserTime + Thrd->Info.KernelTime);
|
||||
#endif
|
||||
|
75
kshell/commands/tree.cpp
Normal file
75
kshell/commands/tree.cpp
Normal 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 "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void tree_loop(Node *rootNode, int depth = 0)
|
||||
{
|
||||
foreach (auto Child in rootNode->Children)
|
||||
{
|
||||
Display->SetBuffer(0);
|
||||
if (Child->Type == NodeType::DIRECTORY ||
|
||||
Child->Type == NodeType::MOUNTPOINT)
|
||||
{
|
||||
printf("%*s%*s%*s|- %s\n",
|
||||
depth, "",
|
||||
depth, "",
|
||||
depth, "",
|
||||
Child->Name);
|
||||
tree_loop(Child, depth + 1);
|
||||
}
|
||||
else
|
||||
printf("%*s%*s%*s|- %s\n",
|
||||
depth, "",
|
||||
depth, "",
|
||||
depth, "",
|
||||
Child->Name);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_tree(const char *args)
|
||||
{
|
||||
Node *rootNode = thisProcess->CurrentWorkingDirectory;
|
||||
if (args[0] == '\0')
|
||||
{
|
||||
if (rootNode == nullptr)
|
||||
rootNode = fs->GetRootNode()->Children[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
rootNode = fs->GetNodeFromPath(args, thisProcess->CurrentWorkingDirectory);
|
||||
if (rootNode == nullptr)
|
||||
{
|
||||
printf("ls: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
if (rootNode->Type != NodeType::DIRECTORY)
|
||||
{
|
||||
printf("%s\n", rootNode->Name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s\n", rootNode->Name);
|
||||
tree_loop(rootNode);
|
||||
}
|
@ -27,29 +27,29 @@ void cmd_uname(const char *args)
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
if (strcmp(args, "-a") == 0)
|
||||
if (IF_ARG("-a") || IF_ARG("--all"))
|
||||
{
|
||||
printf("Fennix Kernel %s %s %s %s\n",
|
||||
KERNEL_VERSION, KERNEL_NAME, __DATE__,
|
||||
KERNEL_ARCH);
|
||||
}
|
||||
else if (strcmp(args, "-s") == 0)
|
||||
else if (IF_ARG("-s") || IF_ARG("--kernel-name"))
|
||||
{
|
||||
printf("%s\n", KERNEL_NAME);
|
||||
}
|
||||
else if (strcmp(args, "-v") == 0)
|
||||
else if (IF_ARG("-v") || IF_ARG("--kernel-version"))
|
||||
{
|
||||
printf("%s\n", KERNEL_VERSION);
|
||||
}
|
||||
else if (strcmp(args, "-n") == 0)
|
||||
else if (IF_ARG("-n") || IF_ARG("--nodename"))
|
||||
{
|
||||
printf("unknown\n");
|
||||
}
|
||||
else if (strcmp(args, "-r") == 0)
|
||||
else if (IF_ARG("-r") || IF_ARG("--kernel-release"))
|
||||
{
|
||||
printf("%s\n", KERNEL_NAME);
|
||||
}
|
||||
else if (strcmp(args, "-m") == 0)
|
||||
else if (IF_ARG("-m") || IF_ARG("--machine"))
|
||||
{
|
||||
printf("%s\n", KERNEL_ARCH);
|
||||
}
|
||||
|
Reference in New Issue
Block a user