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"
|
|
|
|
|
|
|
|
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
if (rand() % 64 == 0 || (argc > 1 && !strcmp(argv[1], "starwars"))) {
|
|
|
|
IoDoStarWars();
|
|
|
|
}
|
|
|
|
|
|
|
|
else IoDoBeep();
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 23:06:57 +02:00
|
|
|
error_t CmdStarWars(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
IoDoStarWars();
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 17:20:27 +02:00
|
|
|
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-09 10:27:44 +02:00
|
|
|
PoShutdown();
|
2019-05-08 17:20:27 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-09 10:25:52 +02:00
|
|
|
uint i, count = 0;
|
2019-05-08 17:20:27 +02:00
|
|
|
Command_t *cmd;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
KernLog("List of all shell built-ins:\n");
|
|
|
|
for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) {
|
2019-05-09 10:25:52 +02:00
|
|
|
KernLog("\t%s", cmd->name);
|
|
|
|
for (i = strlen(cmd->name)/4; i<3; i++) {
|
|
|
|
KernLog("\t");
|
|
|
|
}
|
|
|
|
KernLog("%s\n", 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
|
|
|
|
2019-05-14 11:56:42 +02:00
|
|
|
error_t CmdClear(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < BtVideoInfo.framebufferHeight; i++)
|
|
|
|
KernLog("\n");
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:23:52 +02:00
|
|
|
error_t CmdDate(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-14 11:56:42 +02:00
|
|
|
KernLog("%.10s\n", KeFormatCurTime());
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdTime(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
KernLog("%s\n", &KeFormatCurTime()[13]);
|
2019-05-08 20:23:52 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
MmPrintMemoryMap();
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-13 20:34:41 +02:00
|
|
|
char var;
|
|
|
|
(void)var;
|
|
|
|
|
2019-05-09 11:19:44 +02:00
|
|
|
size_t stack_cur;
|
|
|
|
size_t img_diff, stack_diff;
|
|
|
|
size_t heap_start, heap_end;
|
|
|
|
size_t heap_diff, heap_max;
|
2019-05-08 20:23:52 +02:00
|
|
|
|
|
|
|
ulong flags = KePauseIRQs();
|
|
|
|
|
2019-05-09 11:19:44 +02:00
|
|
|
heap_start = (size_t)_heap_start;
|
|
|
|
heap_end = (size_t)_heap_end;
|
|
|
|
heap_max = _heap_max;
|
2019-05-08 20:23:52 +02:00
|
|
|
|
|
|
|
KeRestoreIRQs(flags);
|
|
|
|
|
2019-05-13 20:34:41 +02:00
|
|
|
img_diff = (size_t)BtLoaderInfo.kernelEndAddr
|
|
|
|
- (size_t)BtLoaderInfo.kernelAddr;
|
|
|
|
|
|
|
|
stack_diff = (size_t)BtLoaderInfo.stackEndAddr
|
|
|
|
- ((size_t)BtLoaderInfo.kernelEndAddr + 16);
|
|
|
|
|
2019-05-09 11:19:44 +02:00
|
|
|
heap_diff = (size_t)heap_end - (size_t)heap_start;
|
2019-05-13 20:34:41 +02:00
|
|
|
|
|
|
|
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
|
2019-05-13 15:18:00 +02:00
|
|
|
|
2019-05-09 11:33:07 +02:00
|
|
|
KernLog("Kernel image\n");
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
BtLoaderInfo.kernelAddr,
|
|
|
|
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr),
|
|
|
|
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr),
|
|
|
|
_ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr));
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-13 15:18:00 +02:00
|
|
|
(size_t)BtLoaderInfo.kernelEndAddr,
|
|
|
|
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr),
|
|
|
|
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr),
|
|
|
|
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr));
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tsize:\t\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
_ADDR_TO_MB(img_diff),
|
|
|
|
_ADDR_TO_KB(img_diff),
|
|
|
|
_ADDR_TO_B(img_diff),
|
|
|
|
img_diff);
|
|
|
|
|
2019-05-09 11:33:07 +02:00
|
|
|
KernLog("Kernel stack\n");
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
BtLoaderInfo.kernelEndAddr,
|
2019-05-13 15:18:00 +02:00
|
|
|
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
|
|
|
|
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
|
|
|
|
_ADDR_TO_B((size_t)BtLoaderInfo.stackEndAddr));
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 20:34:41 +02:00
|
|
|
KernLog("\tcurrently at:\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-13 15:18:00 +02:00
|
|
|
(size_t)&var,
|
|
|
|
_ADDR_TO_MB((size_t)&var),
|
|
|
|
_ADDR_TO_KB((size_t)&var),
|
|
|
|
_ADDR_TO_B((size_t)&var));
|
|
|
|
|
2019-05-13 20:34:41 +02:00
|
|
|
KernLog("\tmin address:\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-13 15:18:00 +02:00
|
|
|
(size_t)BtLoaderInfo.kernelEndAddr+16,
|
|
|
|
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
|
|
|
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
|
|
|
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr+16));
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
_ADDR_TO_MB(stack_cur),
|
|
|
|
_ADDR_TO_KB(stack_cur),
|
|
|
|
_ADDR_TO_B(stack_cur),
|
|
|
|
stack_cur);
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
_ADDR_TO_MB(stack_diff),
|
|
|
|
_ADDR_TO_KB(stack_diff),
|
|
|
|
_ADDR_TO_B(stack_diff),
|
|
|
|
stack_diff);
|
|
|
|
|
2019-05-09 11:33:07 +02:00
|
|
|
KernLog("Kernel heap\n");
|
2019-05-09 11:19:44 +02:00
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tstarts at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
heap_start, _ADDR_TO_MB(heap_start),
|
|
|
|
_ADDR_TO_KB(heap_start),
|
|
|
|
_ADDR_TO_B(heap_start));
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
heap_end, _ADDR_TO_MB(heap_end),
|
|
|
|
_ADDR_TO_KB(heap_end),
|
|
|
|
_ADDR_TO_B(heap_end));
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tmax addr:\t\t%p (%4luMB + %4luKB + %4luB)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
heap_start + heap_max,
|
|
|
|
_ADDR_TO_MB(heap_start + heap_max),
|
|
|
|
_ADDR_TO_KB(heap_start + heap_max),
|
|
|
|
_ADDR_TO_B(heap_start + heap_max));
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tsize (cur):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
_ADDR_TO_MB(heap_diff),
|
|
|
|
_ADDR_TO_KB(heap_diff),
|
|
|
|
_ADDR_TO_B(heap_diff),
|
|
|
|
heap_diff);
|
|
|
|
|
2019-05-13 02:00:02 +02:00
|
|
|
KernLog("\tsize (max):\t\t%4luMB + %4luKB + %4luB (%p)\n",
|
2019-05-09 11:19:44 +02:00
|
|
|
_ADDR_TO_MB(heap_max),
|
|
|
|
_ADDR_TO_KB(heap_max),
|
|
|
|
_ADDR_TO_B(heap_max),
|
|
|
|
heap_max);
|
2019-05-08 20:23:52 +02:00
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:45:28 +02:00
|
|
|
extern void pstest(void);
|
2019-05-08 20:23:52 +02:00
|
|
|
|
2019-05-08 20:45:28 +02:00
|
|
|
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-13 23:22:27 +02:00
|
|
|
// pstest();
|
2019-05-08 20:45:28 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
2019-05-08 20:23:52 +02:00
|
|
|
|
2019-05-08 20:54:40 +02:00
|
|
|
error_t CmdDie(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
*(char *)NULL += 1;
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-13 15:18:00 +02:00
|
|
|
error_t CmdPF(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
*((char*)0xDEADBEEF0) = 1;
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-14 11:48:07 +02:00
|
|
|
extern void KeStartShell(void);
|
2019-05-13 15:18:00 +02:00
|
|
|
error_t CmdShell(int argc, char **argv, char *cmdline)
|
2019-05-14 11:48:07 +02:00
|
|
|
{
|
2019-05-13 15:18:00 +02:00
|
|
|
KeStartShell();
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:45:28 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-05-08 20:23:52 +02:00
|
|
|
|
2019-05-08 20:45:28 +02:00
|
|
|
Command_t cmdtable[] =
|
|
|
|
{
|
2019-05-14 11:48:07 +02:00
|
|
|
{ "beep", CmdBeep, "Make a beep" },
|
|
|
|
{ "cls", CmdClear, "Clears standard output" },
|
|
|
|
{ "date", CmdDate, "Print date" },
|
|
|
|
{ "die", CmdDie, "Die painfully" },
|
|
|
|
{ "exit", CmdQuit, "Initiate shutdown" },
|
|
|
|
{ "help", CmdHelp, "Show this message" },
|
|
|
|
{ "march", CmdStarWars, "Play the Imperial March"},
|
|
|
|
{ "mmap", CmdMemMap, "Show memory map" },
|
|
|
|
{ "musage", CmdMemUsage, "Show memory statistics" },
|
|
|
|
{ "pfault", CmdPF, "Provokes a PF" },
|
|
|
|
{ "pstest", CmdPsTest, "Scheduler test routine" },
|
|
|
|
{ "quit", CmdQuit, "Alias for 'exit'" },
|
|
|
|
{ "shell", CmdShell, "New shell instance" },
|
|
|
|
{ "time", CmdTime, "Print time" },
|
2019-05-08 20:45:28 +02:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
2019-05-08 20:23:52 +02:00
|
|
|
|