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/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-05-29 14:34:37 +02:00
|
|
|
#include <vers.h>
|
|
|
|
#include <mm/mm.h>
|
|
|
|
#include <io/ata.h>
|
|
|
|
#include <io/vga.h>
|
|
|
|
#include <io/spkr.h>
|
|
|
|
#include <ke/time.h>
|
|
|
|
#include <lib/buf.h>
|
|
|
|
#include <sh/shell.h>
|
|
|
|
#include <po/shtdwn.h>
|
2019-05-23 14:50:05 +02:00
|
|
|
|
2019-11-25 17:22:54 +01:00
|
|
|
static Command_t testcmdtable[];
|
|
|
|
|
2019-11-25 16:59:04 +01:00
|
|
|
static inline int ShAtoi(char* str)
|
2019-05-23 14:50:05 +02:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
for (int i = 0; str[i] != 0; ++i)
|
|
|
|
res = res * 10 + str[i] - '0';
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
error_t CmdArgs(int argc, char **argv, char *cmdline)
|
2019-05-08 17:20:27 +02:00
|
|
|
{
|
2019-05-22 18:15:23 +02:00
|
|
|
int i;
|
2019-05-08 17:20:27 +02:00
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
|
2019-05-08 23:06:57 +02:00
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
KernLog("argv[%d]: '%s'\n", i, argv[i]);
|
|
|
|
}
|
2019-05-08 23:06:57 +02:00
|
|
|
|
2019-05-08 17:20:27 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
2019-05-08 17:20:27 +02:00
|
|
|
{
|
2019-05-22 18:15:23 +02:00
|
|
|
IoDoBeep();
|
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);
|
2019-05-22 18:15:23 +02:00
|
|
|
|
2019-05-18 19:56:10 +02:00
|
|
|
BStdOut->wp = BStdOut->rp = BStdOut->buf;
|
|
|
|
BStdOut->lastLF = 0;
|
2019-05-14 11:56:42 +02:00
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
BUnlockBuf(BStdOut);
|
2019-05-18 19:09:46 +02:00
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-18 22:02:16 +02:00
|
|
|
error_t CmdColor(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
int col = 0;
|
|
|
|
char *p;
|
2019-05-22 18:15:23 +02:00
|
|
|
|
2019-05-18 22:02:16 +02:00
|
|
|
if (argc > 2) {
|
|
|
|
KernLog("Usage: 'color [#|list]'\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2019-05-22 18:15:23 +02:00
|
|
|
|
2019-05-18 22:02:16 +02:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
2019-05-22 18:15:23 +02:00
|
|
|
|
2019-05-18 22:02:16 +02:00
|
|
|
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;
|
|
|
|
}
|
2019-05-22 18:15:23 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdDate(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
KernLog("%.10s\n", KeFormatCurTime());
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-23 14:50:05 +02:00
|
|
|
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-24 11:28:18 +02:00
|
|
|
char sector[512] = {0};
|
2019-05-23 14:50:05 +02:00
|
|
|
int sectNumber = ShAtoi(argv[1]);
|
2019-05-24 11:28:18 +02:00
|
|
|
int nb = 1; //ShAtoi(argv[2]);
|
2019-05-23 23:21:58 +02:00
|
|
|
int x = 0;
|
2019-05-24 11:16:59 +02:00
|
|
|
int step = 16;
|
2019-05-23 14:50:05 +02:00
|
|
|
|
2019-05-24 11:28:18 +02:00
|
|
|
if (sectNumber <= 0 || sectNumber > 255) {
|
2019-05-23 14:50:05 +02:00
|
|
|
KernLog("Bad argument\n\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-05-24 11:16:59 +02:00
|
|
|
if (!nb) nb = 1;
|
|
|
|
|
2019-05-24 11:28:18 +02:00
|
|
|
KernLog("Sector begin: %d\n", (sectNumber - 1)*512);
|
2019-05-23 14:50:05 +02:00
|
|
|
|
2019-05-24 11:16:59 +02:00
|
|
|
IoReadATA(sector, nb, sectNumber);
|
2019-05-23 14:50:05 +02:00
|
|
|
|
2019-05-24 11:16:59 +02:00
|
|
|
while(x < 512*nb) {
|
2019-05-24 10:50:55 +02:00
|
|
|
KernLog("%C", shcol);
|
|
|
|
for (int i = 0; i < step; i++) {
|
2019-05-23 23:21:58 +02:00
|
|
|
KernLog("%02x ", (uchar)sector[i+x]);
|
|
|
|
}
|
2019-05-24 10:50:55 +02:00
|
|
|
KernLog(" %C ", VGA_COLOR_LIGHT_BLUE);
|
|
|
|
for (int i = 0; i < step; i++) {
|
2019-05-23 23:21:58 +02:00
|
|
|
if (isprint(sector[i+x]))
|
2019-05-24 10:50:55 +02:00
|
|
|
KernLog("%c",
|
|
|
|
sector[i+x]
|
|
|
|
);
|
2019-05-23 23:21:58 +02:00
|
|
|
else
|
|
|
|
KernLog("%c", 0);
|
|
|
|
}
|
|
|
|
KernLog("\n");
|
2019-05-24 10:50:55 +02:00
|
|
|
x += step;
|
2019-05-23 14:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("\n\n");
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
uint i, count = 0;
|
|
|
|
Command_t *cmd;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
KernLog("List of all shell built-ins:\n");
|
2019-05-29 14:34:37 +02:00
|
|
|
for (cmd = shcmdtable; cmd->name != NULL; cmd++, count++) {
|
2019-05-22 18:15:23 +02:00
|
|
|
KernLog("\t%s", cmd->name);
|
|
|
|
for (i = strlen(cmd->name)/4; i<3; i++) {
|
|
|
|
KernLog("\t");
|
|
|
|
}
|
|
|
|
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
|
|
|
}
|
|
|
|
KernLog("End of list; %u commands total\n", count);
|
2019-05-18 22:02:16 +02:00
|
|
|
}
|
2019-05-22 18:15:23 +02:00
|
|
|
|
2019-05-18 22:02:16 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-11-25 17:22:54 +01:00
|
|
|
error_t CmdHelpTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
uint i, count = 0;
|
|
|
|
Command_t *cmd;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
KernLog("List of all test built-ins:\n");
|
|
|
|
for (cmd = testcmdtable; cmd->name != NULL; cmd++, count++) {
|
|
|
|
KernLog("\t%s", cmd->name);
|
|
|
|
for (i = strlen(cmd->name)/4; i<3; i++) {
|
|
|
|
KernLog("\t");
|
|
|
|
}
|
|
|
|
KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol);
|
|
|
|
}
|
|
|
|
KernLog("End of list; %u commands total\n", count);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
MmPrintMemoryMap();
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdMemUsage(int argc, char **argv, char *cmdline);
|
|
|
|
|
|
|
|
error_t CmdPF(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-11-15 21:31:10 +01:00
|
|
|
char *address = (void*)(ulong)ShAtoi(argv[1]);
|
|
|
|
|
|
|
|
KernLog("Provoking Page Fault at %#x\n", address);
|
|
|
|
|
|
|
|
*address = 1;
|
|
|
|
|
|
|
|
KernLog("No page fault : address was valid/present\n");
|
2019-05-22 18:15:23 +02:00
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-11-18 00:15:39 +01:00
|
|
|
// pstest();
|
2019-05-22 18:15:23 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
PoShutdown();
|
|
|
|
return EOK;
|
|
|
|
}
|
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-18 19:09:46 +02:00
|
|
|
error_t CmdShell(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-29 14:34:37 +02:00
|
|
|
ShStartShell();
|
2019-05-18 19:09:46 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-11-18 00:15:39 +01:00
|
|
|
error_t CmdSleep(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
int delay = ShAtoi(argv[1]);
|
|
|
|
|
|
|
|
KeSleep(delay);
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-15 15:55:57 +02:00
|
|
|
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
2019-05-22 18:15:23 +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-22 08:35:58 +02:00
|
|
|
error_t CmdStackUnderflow(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-22 14:18:03 +02:00
|
|
|
for (int i = 0 ;; i++) {
|
|
|
|
asm volatile ("pop %rax\n");
|
|
|
|
}
|
|
|
|
|
2019-05-22 08:35:58 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
error_t CmdStarWars(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
IoDoStarWars();
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-11-25 16:59:04 +01:00
|
|
|
error_t CmdTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-11-25 17:22:54 +01:00
|
|
|
ExecuteCommand(cmdline+5, testcmdtable);
|
|
|
|
KernLog ("\n");
|
2019-11-25 16:59:04 +01:00
|
|
|
|
2019-05-22 18:15:23 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdTime(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
KernLog("%s\n", &KeFormatCurTime()[13]);
|
|
|
|
return EOK;
|
|
|
|
}
|
2019-05-18 23:03:41 +02:00
|
|
|
|
2019-11-18 00:15:39 +01:00
|
|
|
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
int delay = ShAtoi(argv[1]);
|
|
|
|
|
|
|
|
Timer_t *timer = KeSetTimer(delay);
|
|
|
|
|
|
|
|
while(!(KeGetTimer(timer))) {
|
|
|
|
bprintf(BStdOut,".");
|
|
|
|
BStdOut->flusher(BStdOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("Finished !\n");
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-18 23:19:49 +02:00
|
|
|
error_t CmdVersion(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-05-22 18:15:23 +02:00
|
|
|
int CH = VGA_COLOR_LIGHT_BLUE;
|
|
|
|
int CN = shcol;
|
|
|
|
|
|
|
|
KernLog("OS/K version %C%s (x86-64)%C\n",
|
|
|
|
CH,
|
|
|
|
_KALEID_VERSION,
|
|
|
|
CN
|
|
|
|
);
|
|
|
|
|
|
|
|
KernLog("Copyright (C) 2018-2019 The OS/K Team\n\n");
|
|
|
|
KernLog("This program is free software, released under the\n");
|
|
|
|
KernLog("terms of the GNU GPL version 3 or later as published\n");
|
|
|
|
KernLog("by the Free Software Foundation.\n");
|
|
|
|
KernLog("You are free to change and redistribute it.\n");
|
|
|
|
KernLog("There is NO WARRANTY, to the extent permitted by law.\n");
|
|
|
|
KernLog("See <http://gnu.org/licenses/gpl.html>\n\n");
|
|
|
|
|
2019-05-18 23:19:49 +02:00
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-05-08 20:45:28 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2019-05-29 14:34:37 +02:00
|
|
|
|
2019-11-25 17:22:54 +01:00
|
|
|
static Command_t testcmdtable[] =
|
2019-05-08 20:45:28 +02:00
|
|
|
{
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "args", CmdArgs, "Print command line" },
|
2019-11-25 17:22:54 +01:00
|
|
|
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
|
|
|
|
{ "help", CmdHelpTest, "Show this message" },
|
|
|
|
{ "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
|
|
|
{ "pstest", CmdPsTest, "Scheduler test routine" },
|
|
|
|
{ "rpag", CmdReloadPage, "Reload the pages directory" },
|
|
|
|
{ "shell", CmdShell, "Start a new shell (nested)", },
|
|
|
|
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
|
|
|
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
|
2019-11-25 17:28:53 +01:00
|
|
|
{ "timer", CmdTimerTest, "test timer of x ms" },
|
2019-11-25 17:22:54 +01:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
Command_t shcmdtable[] =
|
|
|
|
{
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "beep", CmdBeep, "Make a beep" },
|
|
|
|
{ "cls", CmdClear, "Clears standard output" },
|
|
|
|
{ "color", CmdColor, "Change shell text color" },
|
|
|
|
{ "date", CmdDate, "Print date" },
|
2019-11-18 00:15:39 +01:00
|
|
|
{ "exit", CmdQuit, "Initiate shutdown" },
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "help", CmdHelp, "Show this message" },
|
2019-11-18 00:15:39 +01:00
|
|
|
{ "march", CmdStarWars, "Play the Imperial March" },
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "mmap", CmdMemMap, "Show memory map" },
|
|
|
|
{ "musage", CmdMemUsage, "Show memory statistics" },
|
|
|
|
{ "quit", CmdQuit, "Alias for 'exit'" },
|
|
|
|
{ "shell", CmdShell, "Start a new shell (nested)", },
|
2019-11-18 00:15:39 +01:00
|
|
|
{ "sleep", CmdSleep, "Sleep x ms" },
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "time", CmdTime, "Print time" },
|
2019-11-25 17:22:54 +01:00
|
|
|
{ "test", CmdTest, "Launch the x test" },
|
2019-05-23 14:50:05 +02:00
|
|
|
{ "ver", CmdVersion, "Version and legal infos" },
|
2019-05-08 20:45:28 +02:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|