5 #include <sys/robsys.h>
9 #include <lib/string.h>
10 #include <lib/regfunc.h>
12 #include <drivers/led.h>
17 #define WHITESPACE "\t\r\n "
20 int help(int, char**);
24 * info -- shows basic info of system
25 * reset -- software reset
26 * show [ADDRESS-ADDRESS] -- shows SRAM range
27 * switchmode -- switch to unprivileged mode
30 static char buf[BUFSIZE];
35 int (*function)(int argc, char ** argsv);
38 struct cmd builtincmds[4];
40 int help(int argc, char ** argsv) {
45 int led(int argc, char ** argsv) {
48 if (argsv[1] != NULL) {
49 if (strcmp(argsv[1], "on")) {
53 else if (strcmp(argsv[1], "off")) {
61 int show(int argc, char ** argsv) {
63 if ((argsv[1] != NULL) && (strlen(argsv[1]) == 8)) {
65 uint32_t * check = (uint32_t *) hextoreg(argsv[1]);
69 cputs(regtohex(*check));
78 int exec_cmd(char * buf) {
84 // Parse the command buffer into whitespace-separated arguments
89 while (*buf && strchr(WHITESPACE, *buf))
94 // save and scan past next arg
95 if (argc == MAXARGS-1) {
96 cputs("Too many arguments");
100 while (*buf && !strchr(WHITESPACE, *buf))
105 // Lookup and invoke the command
108 for (i = 0; i < BUILTINCMDS; i++) {
109 if (strcmp(argv[0], builtincmds[i].name))
110 return builtincmds[i].function(argc, argv);
112 cputs("Unknown command");
119 builtincmds[0].name = "help";
120 builtincmds[0].function = help;
122 builtincmds[1].name = "led";
123 builtincmds[1].function = led;
125 builtincmds[2].name = "show";
126 builtincmds[2].function = show;
129 cputs("WELCOME TO ROBSYS!\n");
132 buf = readline("root# ");
134 if (exec_cmd(buf) < 0)