Merge branch 'shell' into acpi

This commit is contained in:
Adrien Bourmault 2020-02-06 17:46:12 +01:00
commit ecb3021d8c
6 changed files with 49 additions and 9 deletions

View File

@ -45,8 +45,12 @@ struct Command_t
extern int shcol;
extern int shargc;
extern char **shargv;
extern char *shprompt;
extern size_t shpromptlen;
extern Command_t shcmdtable[];
#define SHPROMPT_MAXLEN (BStdOut->lineLen / 2)
//----------------------------------------------------------------------------//
void ShStartShell(void);

View File

@ -33,4 +33,3 @@ volatile bool KeIsPanicking = 0;
volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0];
volatile CpuInfo_t CpuInfo = { 0 };

View File

@ -112,6 +112,7 @@ const uint RegularScanCodes[2 * 256] =
ENTRY (0x51, '3', NONE),
ENTRY (0x52, '0', NONE),
ENTRY (0x53, '.', NONE),
ENTRY (0x56, '<', NONE),
ENTRY (0xE0, 0, INVISIBLE),
};
@ -193,6 +194,8 @@ const uint LeftShiftScanCodes[2 * 256] =
ENTRY (0x52, K_INSERT, INVISIBLE),
ENTRY (0x53, K_DEL, INVISIBLE),
ENTRY (0x56, '>', NONE),
ENTRY (0xE0, 0, INVISIBLE),
};

View File

@ -189,6 +189,7 @@ error_t IoInitVGABuffer(void)
BEnableAutoScroll(BStdOut);
#ifndef NDEBUG
BStdDbg = &bdbgbufstruct;
BOpenTermBufEx(&BStdDbg,
@ -198,6 +199,9 @@ error_t IoInitVGABuffer(void)
10, NULL);
BEnableAutoScroll(BStdDbg);
#else
BStdDbg = NULL;
#endif
return EOK;
}

View File

@ -108,12 +108,16 @@ error_t CmdDmesg(int argc, char **argv, char *cmdline)
size_t N = 0;
if (argc == 1) N = 999;
else if (argc == 2) N = atoi(argv[1]);
else if (argc == 2) N = 1 + atoi(argv[1]);
else {
KernLog("dmesg: no more than one argument\n");
return EINVAL;
}
DebugLog("dmesg requested from kernel shell (N=%d)\n", N);
if (N == 0) return EOK;
BLockBuf(BStdDbg);
ptr = (char *)lmax((ulong)BStdDbg->buf,
@ -151,6 +155,21 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
return EOK;
}
error_t CmdPrompt(int argc, char **argv, char *cmdline)
{
if (cmdline[6] == 0) {
shprompt[0] = 0;
shpromptlen = 0;
}
else {
strnzcpy(shprompt, &cmdline[7], SHPROMPT_MAXLEN);
shpromptlen = strlen(shprompt);
}
return EOK;
}
error_t CmdQuit(int argc, char **argv, char *cmdline)
{
PoShutdown();
@ -216,10 +235,12 @@ Command_t shcmdtable[] =
{ "march", CmdStarWars, "Play the Imperial March" },
{ "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" },
{ "prompt", CmdPrompt, "Change shell prompt" },
{ "quit", CmdQuit, "Alias for 'exit'" },
{ "sleep", CmdSleep, "Sleep N ms" },
{ "time", CmdTime, "Print time" },
{ "test", CmdTest, "Launch a test" },
{ "ver", CmdVersion, "Version and legal infos" },
{ NULL, NULL, NULL }
{ NULL, NULL, NULL },
};

View File

@ -35,6 +35,9 @@ int shargc = 0;
char **shargv = 0;
int shcol = VGA_COLOR_LIGHT_GREY;
char *shprompt = "shell> ";
size_t shpromptlen = 7;
static char *argvbuf = 0;
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
@ -66,7 +69,7 @@ void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
}
}
#define CMDBUFSIZE (BStdOut->lineLen - 9) // strlen("%Cshell> %C" = 9
#define CMDBUFSIZE (BStdOut->lineLen - shpromptlen - 2)
void ShStartShell(void)
{
@ -87,12 +90,17 @@ void ShStartShell(void)
int historyScroll = 0;
bool insertMode = 0;
size_t nLines;
argvbuf = malloc(ARG_MAX * 2);
memzero(argvbuf, ARG_MAX * 2);
shargv = (char **)argvbuf;
KernLog("\n%Cshell> %C", VGA_COLOR_WHITE, shcol);
shprompt = malloc(SHPROMPT_MAXLEN);
strcpy(shprompt, "shell> ");
shpromptlen = 7;
KernLog("\n%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdOut);
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
@ -105,7 +113,7 @@ void ShStartShell(void)
memzero(cmdbuf, CMDBUFSIZE);
BFlushBuf(BStdIn);
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdOut);
}
else break;
@ -242,7 +250,8 @@ void ShStartShell(void)
BStdOut->wp -= BStdOut->lastLF;
BStdOut->size -= BStdOut->lastLF;
BStdOut->lastLF = 0;
bprintf(BStdOut, "%Cshell> %C%s", VGA_COLOR_WHITE, shcol, cmdbuf);
bprintf(BStdOut, "%C%s%C%s",
VGA_COLOR_WHITE, shprompt, shcol, cmdbuf);
BUnlockBuf(BStdOut);
@ -286,7 +295,7 @@ void ShStartShell(void)
memzero(cmdbuf, CMDBUFSIZE);
}
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdIn);
BFlushBuf(BStdOut);
break;