From: Erik M. <er...@us...> - 2001-09-15 20:14:26
|
Update of /cvsroot/blob/blob/src In directory usw-pr-cvs1:/tmp/cvs-serv23633/src Modified Files: command.c main.c rest-ld-script Log Message: Initial new command line stuff. It has some strange bugs right now, but it allows Russ to see what's going on :) Index: command.c =================================================================== RCS file: /cvsroot/blob/blob/src/command.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- command.c 2001/08/06 22:44:52 1.2 +++ command.c 2001/09/15 20:14:23 1.3 @@ -39,7 +39,104 @@ #include "serial.h" #include "time.h" #include "types.h" +#include "util.h" +/* command list start and end. filled in by the linker */ +extern commandlist_t *__commandlist_start; +extern commandlist_t *__commandlist_end; + + +#if 0 +/* the last command in the list */ +static commandlist_t __command last_command = { + callback: NULL, +}; + +#endif + +/* the first command */ +static commandlist_t *commands; + + +void init_commands(void) +{ + SerialOutputString("Command list start: 0x"); + SerialOutputHex((unsigned int)__commandlist_start); + SerialOutputString("\nCommand list end: 0x"); + SerialOutputHex((unsigned int)__commandlist_end); + SerialOutputByte('\n'); + + commands = __commandlist_start; +} + + +int parse_command(char *cmdline) +{ + commandlist_t *cmd; + int len; + + SerialOutputString("*** " __FUNCTION__ " called\n"); + + for(cmd = commands; cmd->callback != NULL; cmd++) { + SerialOutputString("\n*** cmd = 0x"); + SerialOutputHex((u32)cmd); + + SerialOutputString("\n*** cmd->magic = 0x"); + SerialOutputHex((u32)cmd->magic); + + SerialOutputString("\n*** cmd->name = 0x"); + SerialOutputHex((u32)cmd->name); + + SerialOutputString("\n*** cmd->help = 0x"); + SerialOutputHex((u32)cmd->help); + + SerialOutputString("\n*** cmd->callback = 0x"); + SerialOutputHex((u32)cmd->callback); + + SerialOutputString("\n*** cmd->next = 0x"); + SerialOutputHex((u32)cmd->next); + + if(cmd->magic != COMMAND_MAGIC) { + SerialOutputString("*** Oops, not a command, continuing...\n"); + continue; + } + + SerialOutputString("\n*** Trying to match command '"); + SerialOutputString(cmd->name); + SerialOutputString("'... "); + + len = strlen(cmd->name); + + if(MyStrNCmp(cmd->name, cmdline, len) == 0) { + SerialOutputString("yes\n"); + + /* call function */ + return cmd->callback(1, cmdline); + } else { + SerialOutputString("no\n"); + } + } + + return -1; +} + + + + +static int foo(int argc, char *argv[]) +{ + SerialOutputString("*** foo() got called!\n"); + return 0; +} + + +static char fooname[] = "foo"; +static char foohelp[] = "foo help"; + +__commandlist(foo, fooname, foohelp); + +/* the last command in the list */ +__commandlist(NULL, NULL, NULL); Index: main.c =================================================================== RCS file: /cvsroot/blob/blob/src/main.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- main.c 2001/09/02 23:35:28 1.8 +++ main.c 2001/09/15 20:14:23 1.9 @@ -101,6 +101,7 @@ blob_status.load_ramdisk = 1; blob_status.cmdline[0] = '\0'; blob_status.boot_delay = 10; + SerialInit(blob_status.terminalSpeed); /* parse the core tag, for critical things like terminal speed */ @@ -124,6 +125,8 @@ SerialOutputString("under certain conditions; " "read the GNU GPL for details.\n"); + init_commands(); + /* get the amount of memory */ get_memory_map(); @@ -200,7 +203,7 @@ } else if(MyStrNCmp(commandline, "status", 6) == 0) { PrintStatus(); - } else { + } else if(parse_command(commandline) != 0 ) { SerialOutputString("*** Unknown command: "); SerialOutputString(commandline); SerialOutputByte('\n'); Index: rest-ld-script =================================================================== RCS file: /cvsroot/blob/blob/src/rest-ld-script,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- rest-ld-script 2001/08/31 06:26:59 1.3 +++ rest-ld-script 2001/09/15 20:14:23 1.4 @@ -30,7 +30,11 @@ .got : { *(.got) } . = ALIGN(4); - .bss : { *(.bss) } + .commandlist : { + __commandlist_start = .; + *(.commandlist) + __commandlist_end = .; + } . = ALIGN(4); .ptaglist : { @@ -39,5 +43,8 @@ __ptagtable_end = .; } + /* the BSS section should be the last section */ + . = ALIGN(4); + .bss : { *(.bss) } } |