os-k/kaleid/kernel/sh/shcmds.c

135 lines
4.1 KiB
C
Raw Normal View History

2019-05-08 17:20:27 +02:00
//----------------------------------------------------------------------------//
// 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"
Command_t cmdtable[] =
{
{ "beep", CmdBeep, "Make a beep" },
2019-05-08 20:23:52 +02:00
{ "date", CmdDate, "Print date" },
2019-05-08 17:20:27 +02:00
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" },
2019-05-08 20:23:52 +02:00
{ "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" },
2019-05-08 17:20:27 +02:00
{ "quit", CmdQuit, "Alias for 'exit'" },
{ NULL, NULL, NULL }
};
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++) {
2019-05-08 20:23:52 +02:00
KernLog("\t%s\t\t%s\n", cmd->name, cmd->help);
2019-05-08 17:20:27 +02:00
}
2019-05-08 20:23:52 +02:00
KernLog("End of list; %u commands total\n", count);
2019-05-08 17:20:27 +02:00
}
return EOK;
}
2019-05-08 20:23:52 +02:00
error_t CmdDate(int argc, char **argv, char *cmdline)
{
IoPrintRtcTime();
return EOK;
}
error_t CmdMemMap(int argc, char **argv, char *cmdline)
{
MmPrintMemoryMap();
return EOK;
}
#define ADDR_TO_MB(x) ((x)>>20)
#define ADDR_TO_KB(x) (((x)>>10)&(KB-1))
#define ADDR_TO_B(x) ((x)&(KB-1))
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%p (%luMB + %luKB + %luB)\n",
diff, ADDR_TO_MB(diff),
ADDR_TO_KB(diff),
ADDR_TO_B(diff));
KernLog("Max heap size:\t%luMB + %luKB + %luB\n",
ADDR_TO_MB(max),
ADDR_TO_KB(max),
ADDR_TO_B(max));
return EOK;
}