Merge branch 'shell' into acpi
This commit is contained in:
commit
ecb3021d8c
|
@ -45,8 +45,12 @@ struct Command_t
|
||||||
extern int shcol;
|
extern int shcol;
|
||||||
extern int shargc;
|
extern int shargc;
|
||||||
extern char **shargv;
|
extern char **shargv;
|
||||||
|
extern char *shprompt;
|
||||||
|
extern size_t shpromptlen;
|
||||||
extern Command_t shcmdtable[];
|
extern Command_t shcmdtable[];
|
||||||
|
|
||||||
|
#define SHPROMPT_MAXLEN (BStdOut->lineLen / 2)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
void ShStartShell(void);
|
void ShStartShell(void);
|
||||||
|
|
|
@ -33,4 +33,3 @@ volatile bool KeIsPanicking = 0;
|
||||||
volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0];
|
volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0];
|
||||||
volatile CpuInfo_t CpuInfo = { 0 };
|
volatile CpuInfo_t CpuInfo = { 0 };
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,7 @@ const uint RegularScanCodes[2 * 256] =
|
||||||
ENTRY (0x51, '3', NONE),
|
ENTRY (0x51, '3', NONE),
|
||||||
ENTRY (0x52, '0', NONE),
|
ENTRY (0x52, '0', NONE),
|
||||||
ENTRY (0x53, '.', NONE),
|
ENTRY (0x53, '.', NONE),
|
||||||
|
ENTRY (0x56, '<', NONE),
|
||||||
|
|
||||||
ENTRY (0xE0, 0, INVISIBLE),
|
ENTRY (0xE0, 0, INVISIBLE),
|
||||||
};
|
};
|
||||||
|
@ -193,6 +194,8 @@ const uint LeftShiftScanCodes[2 * 256] =
|
||||||
ENTRY (0x52, K_INSERT, INVISIBLE),
|
ENTRY (0x52, K_INSERT, INVISIBLE),
|
||||||
ENTRY (0x53, K_DEL, INVISIBLE),
|
ENTRY (0x53, K_DEL, INVISIBLE),
|
||||||
|
|
||||||
|
ENTRY (0x56, '>', NONE),
|
||||||
|
|
||||||
ENTRY (0xE0, 0, INVISIBLE),
|
ENTRY (0xE0, 0, INVISIBLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,7 @@ error_t IoInitVGABuffer(void)
|
||||||
|
|
||||||
BEnableAutoScroll(BStdOut);
|
BEnableAutoScroll(BStdOut);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
BStdDbg = &bdbgbufstruct;
|
BStdDbg = &bdbgbufstruct;
|
||||||
|
|
||||||
BOpenTermBufEx(&BStdDbg,
|
BOpenTermBufEx(&BStdDbg,
|
||||||
|
@ -198,6 +199,9 @@ error_t IoInitVGABuffer(void)
|
||||||
10, NULL);
|
10, NULL);
|
||||||
|
|
||||||
BEnableAutoScroll(BStdDbg);
|
BEnableAutoScroll(BStdDbg);
|
||||||
|
#else
|
||||||
|
BStdDbg = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,12 +108,16 @@ error_t CmdDmesg(int argc, char **argv, char *cmdline)
|
||||||
size_t N = 0;
|
size_t N = 0;
|
||||||
|
|
||||||
if (argc == 1) N = 999;
|
if (argc == 1) N = 999;
|
||||||
else if (argc == 2) N = atoi(argv[1]);
|
else if (argc == 2) N = 1 + atoi(argv[1]);
|
||||||
else {
|
else {
|
||||||
KernLog("dmesg: no more than one argument\n");
|
KernLog("dmesg: no more than one argument\n");
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DebugLog("dmesg requested from kernel shell (N=%d)\n", N);
|
||||||
|
|
||||||
|
if (N == 0) return EOK;
|
||||||
|
|
||||||
BLockBuf(BStdDbg);
|
BLockBuf(BStdDbg);
|
||||||
|
|
||||||
ptr = (char *)lmax((ulong)BStdDbg->buf,
|
ptr = (char *)lmax((ulong)BStdDbg->buf,
|
||||||
|
@ -151,6 +155,21 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
||||||
return EOK;
|
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)
|
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
PoShutdown();
|
PoShutdown();
|
||||||
|
@ -216,10 +235,12 @@ Command_t shcmdtable[] =
|
||||||
{ "march", CmdStarWars, "Play the Imperial March" },
|
{ "march", CmdStarWars, "Play the Imperial March" },
|
||||||
{ "mmap", CmdMemMap, "Show memory map" },
|
{ "mmap", CmdMemMap, "Show memory map" },
|
||||||
{ "musage", CmdMemUsage, "Show memory statistics" },
|
{ "musage", CmdMemUsage, "Show memory statistics" },
|
||||||
|
{ "prompt", CmdPrompt, "Change shell prompt" },
|
||||||
{ "quit", CmdQuit, "Alias for 'exit'" },
|
{ "quit", CmdQuit, "Alias for 'exit'" },
|
||||||
{ "sleep", CmdSleep, "Sleep N ms" },
|
{ "sleep", CmdSleep, "Sleep N ms" },
|
||||||
{ "time", CmdTime, "Print time" },
|
{ "time", CmdTime, "Print time" },
|
||||||
{ "test", CmdTest, "Launch a test" },
|
{ "test", CmdTest, "Launch a test" },
|
||||||
{ "ver", CmdVersion, "Version and legal infos" },
|
{ "ver", CmdVersion, "Version and legal infos" },
|
||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,9 @@ int shargc = 0;
|
||||||
char **shargv = 0;
|
char **shargv = 0;
|
||||||
int shcol = VGA_COLOR_LIGHT_GREY;
|
int shcol = VGA_COLOR_LIGHT_GREY;
|
||||||
|
|
||||||
|
char *shprompt = "shell> ";
|
||||||
|
size_t shpromptlen = 7;
|
||||||
|
|
||||||
static char *argvbuf = 0;
|
static char *argvbuf = 0;
|
||||||
|
|
||||||
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
|
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)
|
void ShStartShell(void)
|
||||||
{
|
{
|
||||||
|
@ -87,12 +90,17 @@ void ShStartShell(void)
|
||||||
int historyScroll = 0;
|
int historyScroll = 0;
|
||||||
|
|
||||||
bool insertMode = 0;
|
bool insertMode = 0;
|
||||||
|
size_t nLines;
|
||||||
|
|
||||||
argvbuf = malloc(ARG_MAX * 2);
|
argvbuf = malloc(ARG_MAX * 2);
|
||||||
memzero(argvbuf, ARG_MAX * 2);
|
memzero(argvbuf, ARG_MAX * 2);
|
||||||
shargv = (char **)argvbuf;
|
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);
|
BFlushBuf(BStdOut);
|
||||||
|
|
||||||
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
|
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
|
||||||
|
@ -105,7 +113,7 @@ void ShStartShell(void)
|
||||||
|
|
||||||
memzero(cmdbuf, CMDBUFSIZE);
|
memzero(cmdbuf, CMDBUFSIZE);
|
||||||
BFlushBuf(BStdIn);
|
BFlushBuf(BStdIn);
|
||||||
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
|
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
|
||||||
BFlushBuf(BStdOut);
|
BFlushBuf(BStdOut);
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
|
@ -242,7 +250,8 @@ void ShStartShell(void)
|
||||||
BStdOut->wp -= BStdOut->lastLF;
|
BStdOut->wp -= BStdOut->lastLF;
|
||||||
BStdOut->size -= BStdOut->lastLF;
|
BStdOut->size -= BStdOut->lastLF;
|
||||||
BStdOut->lastLF = 0;
|
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);
|
BUnlockBuf(BStdOut);
|
||||||
|
|
||||||
|
@ -286,7 +295,7 @@ void ShStartShell(void)
|
||||||
memzero(cmdbuf, CMDBUFSIZE);
|
memzero(cmdbuf, CMDBUFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
|
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
|
||||||
BFlushBuf(BStdIn);
|
BFlushBuf(BStdIn);
|
||||||
BFlushBuf(BStdOut);
|
BFlushBuf(BStdOut);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue