mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
142 lines
4.5 KiB
C
142 lines
4.5 KiB
C
//----------------------------------------------------------------------------//
|
|
// GNU GPL OS/K //
|
|
// //
|
|
// Desc: Kernel shell //
|
|
// //
|
|
// //
|
|
// Copyright © 2018-2019 The OS/K Team //
|
|
// //
|
|
// This file is part of OS/K. //
|
|
// //
|
|
// OS/K 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 //
|
|
// any later version. //
|
|
// //
|
|
// OS/K 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 OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#include "shell.h"
|
|
|
|
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
|
{
|
|
if (rand() % 64 == 0 || (argc > 1 && !strcmp(argv[1], "starwars"))) {
|
|
IoDoStarWars();
|
|
}
|
|
|
|
else IoDoBeep();
|
|
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
|
{
|
|
PoShutdownQemu();
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
|
{
|
|
uint count = 0;
|
|
Command_t *cmd;
|
|
|
|
if (argc == 1) {
|
|
KernLog("List of all shell built-ins:\n");
|
|
for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) {
|
|
KernLog("\t%s\t\t%s\n", cmd->name, cmd->help);
|
|
}
|
|
KernLog("End of list; %u commands total\n", count);
|
|
}
|
|
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdDate(int argc, char **argv, char *cmdline)
|
|
{
|
|
IoPrintRtcTime();
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
|
{
|
|
MmPrintMemoryMap();
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
|
|
{
|
|
size_t start, end;
|
|
size_t diff, max;
|
|
|
|
ulong flags = KePauseIRQs();
|
|
|
|
start = (size_t)_heap_start;
|
|
end = (size_t)_heap_end;
|
|
max = _heap_max;
|
|
|
|
KeRestoreIRQs(flags);
|
|
|
|
diff = (size_t)end - (size_t)start;
|
|
|
|
KernLog("Heap start:\t\t%p (%luMB + %luKB + %luB)\n",
|
|
start, _ADDR_TO_MB(start),
|
|
_ADDR_TO_KB(start),
|
|
_ADDR_TO_B(start));
|
|
|
|
KernLog("Heap end:\t\t%p (%luMB + %luKB + %luB)\n",
|
|
end, _ADDR_TO_MB(end),
|
|
_ADDR_TO_KB(end),
|
|
_ADDR_TO_B(end));
|
|
|
|
KernLog("Heap size:\t\t%luMB + %luKB + %luB (%#lx)\n",
|
|
_ADDR_TO_MB(diff),
|
|
_ADDR_TO_KB(diff),
|
|
_ADDR_TO_B(diff),
|
|
diff);
|
|
|
|
KernLog("Max heap size:\t%luMB + %luKB + %luB (%#lx)\n",
|
|
_ADDR_TO_MB(max),
|
|
_ADDR_TO_KB(max),
|
|
_ADDR_TO_B(max),
|
|
max);
|
|
|
|
return EOK;
|
|
}
|
|
|
|
extern void pstest(void);
|
|
|
|
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
|
{
|
|
pstest();
|
|
return EOK;
|
|
}
|
|
|
|
error_t CmdDie(int argc, char **argv, char *cmdline)
|
|
{
|
|
*(char *)NULL += 1;
|
|
return EOK;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
Command_t cmdtable[] =
|
|
{
|
|
{ "beep", CmdBeep, "Make a beep" },
|
|
{ "date", CmdDate, "Print date" },
|
|
{ "die", CmdDie, "Die painfully" },
|
|
{ "exit", CmdQuit, "Initiate shutdown" },
|
|
{ "help", CmdHelp, "Show this message" },
|
|
{ "mmap", CmdMemMap, "Show memory map" },
|
|
{ "musage", CmdMemUsage, "Show memory statistics" },
|
|
{ "pstest", CmdPsTest, "Scheduler test routine" },
|
|
{ "quit", CmdQuit, "Alias for 'exit'" },
|
|
{ NULL, NULL, NULL }
|
|
};
|
|
|