Shell commands musage, mmap, date

This commit is contained in:
Julian Barathieu 2019-05-08 20:23:52 +02:00
parent fcffbcabe9
commit 3ddfce4ba8
5 changed files with 85 additions and 4 deletions

View File

@ -99,7 +99,7 @@ KernSources = kernel/cpu/cpuid.c \
kernel/init/info.c kernel/init/ssp.c \
kernel/io/rtc.c kernel/io/keyb.c \
kernel/io/spkr.c kernel/po/shtdwn.c \
kernel/ke/shell.c kernel/ke/shcmds.c
kernel/sh/shell.c kernel/sh/shcmds.c
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))

View File

@ -38,6 +38,7 @@ void IoChangeCodePage(char *CodePage);
//----------------------------------------------------------------------------//
#define KEY_ESC 27
#define KEY_BS 8
#define KEY_BEL 7
#define KEY_DC1 17
#define KEY_DC2 18

View File

@ -27,8 +27,11 @@
Command_t cmdtable[] =
{
{ "beep", CmdBeep, "Make a beep" },
{ "date", CmdDate, "Print date" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" },
{ "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" },
{ "quit", CmdQuit, "Alias for 'exit'" },
{ NULL, NULL, NULL }
};
@ -58,10 +61,74 @@ error_t CmdHelp(int argc, char **argv, char *cmdline)
if (argc == 1) {
KernLog("List of all shell built-ins:\n");
for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) {
KernLog("\t%s\t%s\n", cmd->name, cmd->help);
KernLog("\t%s\t\t%s\n", cmd->name, cmd->help);
}
KernLog("End of list; %u commands total\n\n", count);
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;
}
#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;
}

View File

@ -64,7 +64,7 @@ void KeStartShell(void)
memzero(argv0, ARG_MAX);
shargv = &argv0;
KernLog("\nshell> ");
KernLog("shell> ");
BFlushBuf(BStdOut);
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
@ -85,6 +85,13 @@ void KeStartShell(void)
switch (ch) {
case KEY_BS:
*bufptr = 0;
if (bufptr > cmdbuf) {
bufptr--;
}
break;
case KEY_BEL:
if (rand() % 64 == 0) {
IoDoStarWars();

View File

@ -24,6 +24,9 @@
#include <extras/buf.h>
#include <extras/argv.h>
#include <kernel/mm.h>
#include <kernel/heap.h>
#include <kernel/time.h>
#include <kernel/speaker.h>
#include <kernel/iomisc.h>
@ -53,6 +56,9 @@ struct Command_t
DEC_CMD(Beep);
DEC_CMD(Quit);
DEC_CMD(Help);
DEC_CMD(Date);
DEC_CMD(MemMap);
DEC_CMD(MemUsage);
extern Command_t cmdtable[];