More shell stuff
This commit is contained in:
parent
5bf39b04c7
commit
fcffbcabe9
6
Makefile
6
Makefile
|
@ -37,7 +37,7 @@ CCNAME=x86_64-elf-gcc
|
|||
ASMFLAGS=-f elf64
|
||||
LDFLAGS=-melf_x86_64
|
||||
COPTIM=-O2
|
||||
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration
|
||||
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type
|
||||
CINCLUDES=-Iinclude
|
||||
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11
|
||||
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
||||
|
@ -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/shell.c kernel/ke/shcmds.c
|
||||
|
||||
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
|
||||
|
||||
|
@ -155,7 +155,7 @@ $(KOBJDIR)/kernel/cpu/idt.o: $(KALEIDDIR)/kernel/cpu/idt.c \
|
|||
|
||||
## MAIN MAKEFILE ------------------------------------------------------------- #
|
||||
|
||||
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
|
||||
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h $(KALEIDDIR)/*/*/*.h | $(KOBJDIR)
|
||||
@mkdir -p $(shell dirname $@)
|
||||
@$(KCC) $< -o $@
|
||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
// 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"
|
||||
|
||||
Command_t cmdtable[] =
|
||||
{
|
||||
{ "beep", CmdBeep, "Make a beep" },
|
||||
{ "exit", CmdQuit, "Initiate shutdown" },
|
||||
{ "help", CmdHelp, "Show this message" },
|
||||
{ "quit", CmdQuit, "Alias for 'exit'" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
error_t CmdBeep(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
if (rand() % 64 == 0 || (argc > 1 && !strcmp(argv[1], "starwars"))) {
|
||||
IoDoStarWars();
|
||||
}
|
||||
|
||||
else IoDoBeep();
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
PoShutdownQemu();
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdHelp(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
uint count = 0;
|
||||
Command_t *cmd;
|
||||
|
||||
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("End of list; %u commands total\n\n", count);
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
#include "shell.h"
|
||||
|
||||
int shargc = 0;
|
||||
char *argv0 = 0;
|
||||
char **shargv = 0;
|
||||
|
||||
void ExecuteCommand(char *cmdbuf)
|
||||
{
|
||||
error_t rc;
|
||||
|
@ -36,14 +40,15 @@ void ExecuteCommand(char *cmdbuf)
|
|||
|
||||
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
|
||||
if (!strcmp(cmd->name, shargv[0])) {
|
||||
cmd->func(shargc, shargv);
|
||||
cmd->func(shargc, shargv, cmdbuf);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
KernLog("err: command not found: '%s'\n", shargv[0]);
|
||||
KernLog("err: command not found: '%s' (%ld)\n",
|
||||
shargv[0], strlen(shargv[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,12 +61,13 @@ void KeStartShell(void)
|
|||
char *bufptr = cmdbuf;
|
||||
|
||||
argv0 = malloc(ARG_MAX);
|
||||
memzero(argv0, ARG_MAX);
|
||||
shargv = &argv0;
|
||||
|
||||
KernLog("\nshell> ");
|
||||
BFlushBuf(BStdOut);
|
||||
|
||||
while ((rc = bgetc(BStdIn, &ch)) == EOK || rc == EENDF) {
|
||||
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
|
||||
// Reset BStdIn's content
|
||||
if (rc == EENDF) {
|
||||
if (!(BStdIn->flags & BF_ERR)) {
|
||||
|
|
|
@ -33,40 +33,26 @@
|
|||
extern void IoScrollDown(void);
|
||||
extern void IoScrollUp(void);
|
||||
|
||||
static int shargc = 0;
|
||||
static char *argv0 = 0;
|
||||
static char **shargv = 0;
|
||||
extern int shargc;
|
||||
extern char *argv0;
|
||||
extern char **shargv;
|
||||
|
||||
#define CMDBUFSIZE 256
|
||||
|
||||
error_t CmdBeep(int argc, char **argv)
|
||||
{
|
||||
if (rand() % 16 == 0) {
|
||||
IoDoStarWars();
|
||||
}
|
||||
else IoDoBeep();
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdQuit(int argc, char **argv)
|
||||
{
|
||||
PoShutdownQemu();
|
||||
return EOK;
|
||||
}
|
||||
|
||||
typedef struct Command_t Command_t;
|
||||
|
||||
struct Command_t
|
||||
{
|
||||
const char *name;
|
||||
error_t (*func)(int argc, char **argv);
|
||||
error_t (*func)(int argc, char **argv, char *cmdline);
|
||||
const char *help;
|
||||
};
|
||||
|
||||
Command_t cmdtable[] =
|
||||
{
|
||||
{ "beep", CmdBeep },
|
||||
{ "exit", CmdQuit },
|
||||
{ "quit", CmdQuit },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
#define DEC_CMD(name) error_t Cmd##name(int, char **, char *)
|
||||
|
||||
DEC_CMD(Beep);
|
||||
DEC_CMD(Quit);
|
||||
DEC_CMD(Help);
|
||||
|
||||
extern Command_t cmdtable[];
|
||||
|
||||
|
|
Loading…
Reference in New Issue