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

233 lines
6.6 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"
error_t CmdBeep(int argc, char **argv, char *cmdline)
{
2019-05-18 19:09:46 +02:00
IoDoBeep();
2019-05-08 17:20:27 +02:00
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)
{
2019-05-18 19:56:10 +02:00
BLockBuf(BStdOut);
BStdOut->wp = BStdOut->rp = BStdOut->buf;
BStdOut->lastLF = 0;
BUnlockBuf(BStdOut);
2019-05-14 11:56:42 +02:00
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;
}
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)
{
2019-05-16 23:56:23 +02:00
/* if (argc != 2) */
/* return EINVAL; */
2019-05-15 21:02:16 +02:00
2019-05-16 23:56:23 +02:00
/* ulong address = atoul(argv[1]); */
/* KernLog("print: %s, %d\n", argv[1], address); */
2019-05-15 21:02:16 +02:00
2019-05-16 23:56:23 +02:00
/* *((char*)address) += 1; */
2019-05-17 10:53:10 +02:00
for (int i = 0; i < 32; i++) {
KernLog("%dGB ", i);
*((char*)(i*GB)) = 1;
}
2019-05-16 23:56:23 +02:00
return EOK;
}
2019-05-18 19:09:46 +02:00
error_t CmdArgs(int argc, char **argv, char *cmdline)
{
int i;
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
for (i = 0; i < argc; i++) {
KernLog("argv[%d]: '%s'\n", i, argv[i]);
}
return EOK;
}
2019-05-18 22:02:16 +02:00
error_t CmdColor(int argc, char **argv, char *cmdline)
{
int col = 0;
char *p;
if (argc > 2) {
KernLog("Usage: 'color [#|list]'\n");
return EINVAL;
}
if (argc == 1) {
KernLog("Current color: %s (%d)\n", RtlColorNames[shcol], shcol);
}
else if (!strcmp(argv[1], "list")) {
KernLog("Available colors:\n");
for (col = 0; col <= VGA_COLOR_WHITE; col++) {
KernLog("%d - %s\n", col, RtlColorNames[col]);
}
}
else {
p = argv[1];
while (isdigit(*p) && col < VGA_COLOR_WHITE) {
col = 10 * col + *p++ - '0';
}
if (*p || col < VGA_COLOR_BLACK || col > VGA_COLOR_WHITE) {
KernLog("Invalid color: %d\n", col);
KernLog("Usage: 'color [#|list]'\n");
return EINVAL;
}
else {
shcol = col;
}
}
return EOK;
}
2019-05-16 23:56:23 +02:00
void MmInitPaging(void);
2019-05-18 13:39:58 +02:00
void MmReloadPaging(void);
2019-05-16 23:56:23 +02:00
error_t CmdReloadPage(int argc, char **argv, char *cmdline)
{
2019-05-18 13:39:58 +02:00
MmReloadPaging();
2019-05-13 15:18:00 +02:00
return EOK;
}
2019-05-14 11:48:07 +02:00
extern void KeStartShell(void);
2019-05-18 19:09:46 +02:00
error_t CmdShell(int argc, char **argv, char *cmdline)
{
KeStartShell();
return EOK;
}
2019-05-15 15:55:57 +02:00
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
2019-05-14 11:48:07 +02:00
{
2019-05-15 15:55:57 +02:00
CmdStackOverflow(0, 0, 0);
2019-05-13 15:18:00 +02:00
return EOK;
}
2019-05-18 23:03:41 +02:00
error_t CmdMemUsage(int argc, char **argv, char *cmdline);
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-18 19:09:46 +02:00
{ "args", CmdArgs, "Print command line" },
2019-05-15 15:55:57 +02:00
{ "beep", CmdBeep, "Make a beep" },
{ "cls", CmdClear, "Clears standard output" },
2019-05-18 22:02:16 +02:00
{ "color", CmdColor, "Change shell text color" },
2019-05-15 15:55:57 +02:00
{ "date", CmdDate, "Print date" },
{ "die", CmdDie, "Die painfully" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" },
2019-05-18 19:09:46 +02:00
{ "rpag", CmdReloadPage, "Reload the pages directory" },
2019-05-15 15:55:57 +02:00
{ "march", CmdStarWars, "Play the Imperial March"},
{ "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" },
2019-05-15 21:02:16 +02:00
{ "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" },
2019-05-15 15:55:57 +02:00
{ "pstest", CmdPsTest, "Scheduler test routine" },
{ "quit", CmdQuit, "Alias for 'exit'" },
2019-05-18 19:09:46 +02:00
{ "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
2019-05-15 15:55:57 +02:00
{ "time", CmdTime, "Print time" },
2019-05-08 20:45:28 +02:00
{ NULL, NULL, NULL }
};
2019-05-08 20:23:52 +02:00