#include "vxBoot/terminal.h" #include "vxBoot/cli.h" #include "vxBoot/builtin.h" #include "vxBoot/fs/smemfs.h" #include #include #include //TODO: better API for the command-line parser /* internal builtin list */ struct { const char *name; int (*f)(int argc, char **argv); } cmd_list[] = { {.name = "ls", &ls_main}, {.name = "os", NULL}, {.name = "help", &help_main}, {.name = NULL, NULL} }; /* try to find the appropriate command */ static int (*check_cmd(char *cmd))(int, char**) { for (int i = 0; cmd_list[i].name != NULL; ++i) { if (strcmp(cmd, cmd_list[i].name) != 0) continue; if (cmd_list[i].f == NULL) terminal_write("command exist but not implemented\n"); return (cmd_list[i].f); } return (NULL); } /* entry of the bootloader */ int main(void) { int (*builtin)(int, char**); const char *usrline; char buff[128]; char **argv; int argc; int ret; /* change default font on fx9860 */ #ifdef FX9860G extern font_t font_hexa; dfont(&font_hexa); #endif /* automated hook */ /* TODO: better way to execute early command */ smemfs_mount(); ret = 0; terminal_open(); terminal_write("Welcome to vxBoot, the bootstrapper for the Vhex kernel!\n"); terminal_write("Type `help` for instruction on how to use vxBoot\n"); while (1) { /* get user command */ usrline = (ret != 0) ? "/[%d]>" : "/>"; terminal_write(usrline, ret); ret = 0; if (terminal_read(buff, 128) <= 1) continue; /* parse and try to find the command */ if (cli_parser_strtotab(&argc, &argv, buff) != 0) { terminal_write("error when processing \"%s\"", buff); ret = 255; continue; } builtin = check_cmd(argv[0]); if (builtin == NULL) { terminal_write("command \"%s\" not found\n", argv[0]); ret = 127; continue; } /* execute the command and free'd allocated memories */ ret = builtin(argc, argv); cli_parser_strtotab_quit(&argc, &argv); } return (1); }