Changeset 6e716a59 in mainline
- Timestamp:
- 2005-12-10T15:05:46Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 72f5866d
- Parents:
- a3ac9a7
- Location:
- generic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/console/kconsole.h
ra3ac9a7 r6e716a59 45 45 void *buffer; /**< Buffer where to store data. */ 46 46 size_t len; /**< Size of the buffer. */ 47 __native intval; /**< Integer value */ 47 48 }; 48 49 -
generic/include/func.h
ra3ac9a7 r6e716a59 40 40 extern int strncmp(const char *src, const char *dst, size_t len); 41 41 extern void strncpy(char *dest, const char *src, size_t len); 42 extern __native atoi(const char *text); 42 43 43 44 #endif -
generic/include/symtab.h
ra3ac9a7 r6e716a59 40 40 41 41 extern char * get_symtab_entry(__native addr); 42 extern __address get_symbol_addr(const char *name); 43 extern void symtab_print_search(const char *name); 42 44 43 45 /* Symtable linked together by build process */ -
generic/src/console/kconsole.c
ra3ac9a7 r6e716a59 39 39 #include <macros.h> 40 40 #include <debug.h> 41 #include <symtab.h> 41 42 42 43 #define MAX_CMDLINE 256 … … 73 74 /** Data and methods for 'help' command. */ 74 75 static int cmd_help(cmd_arg_t *argv); 75 static cmd_info_t help_info; 76 static cmd_info_t help_info = { 77 .name = "help", 78 .description = "List of supported commands.", 79 .func = cmd_help, 80 .argc = 0 81 }; 76 82 77 83 /** Data and methods for 'description' command. */ 78 84 static int cmd_desc(cmd_arg_t *argv); 79 85 static void desc_help(void); 80 static cmd_info_t desc_info;81 86 static char desc_buf[MAX_CMDLINE+1]; 82 87 static cmd_arg_t desc_argv = { … … 85 90 .len = sizeof(desc_buf) 86 91 }; 92 static cmd_info_t desc_info = { 93 .name = "describe", 94 .description = "Describe specified command.", 95 .help = desc_help, 96 .func = cmd_desc, 97 .argc = 1, 98 .argv = &desc_argv 99 }; 100 101 /** Data and methods for 'symaddr' command. */ 102 static int cmd_symaddr(cmd_arg_t *argv); 103 static char symaddr_buf[MAX_CMDLINE+1]; 104 static cmd_arg_t symaddr_argv = { 105 .type = ARG_TYPE_STRING, 106 .buffer = symaddr_buf, 107 .len = sizeof(symaddr_buf) 108 }; 109 static cmd_info_t symaddr_info = { 110 .name = "symaddr", 111 .description = "Return symbol address.", 112 .func = cmd_symaddr, 113 .argc = 1, 114 .argv = &symaddr_argv 115 }; 116 117 /** Call0 - call function with no parameters */ 118 static char call0_buf[MAX_CMDLINE+1]; 119 120 static int cmd_call0(cmd_arg_t *argv); 121 static cmd_arg_t call0_argv = { 122 .type = ARG_TYPE_STRING, 123 .buffer = call0_buf, 124 .len = sizeof(call0_buf) 125 }; 126 static cmd_info_t call0_info = { 127 .name = "call0", 128 .description = "call0 <function> -> call function().", 129 .func = cmd_call0, 130 .argc = 1, 131 .argv = &call0_argv 132 }; 133 134 static int cmd_call1(cmd_arg_t *argv); 135 static cmd_arg_t call1_argv[] = { 136 { 137 .type = ARG_TYPE_STRING, 138 .buffer = call0_buf, 139 .len = sizeof(call0_buf) 140 }, 141 { .type = ARG_TYPE_INT } 142 }; 143 static cmd_info_t call1_info = { 144 .name = "call1", 145 .description = "call1 <function> <arg1> -> call function(arg1).", 146 .func = cmd_call1, 147 .argc = 2, 148 .argv = call1_argv 149 }; 150 151 static int cmd_call2(cmd_arg_t *argv); 152 static cmd_arg_t call2_argv[] = { 153 { 154 .type = ARG_TYPE_STRING, 155 .buffer = call0_buf, 156 .len = sizeof(call0_buf) 157 }, 158 { .type = ARG_TYPE_INT }, 159 { .type = ARG_TYPE_INT } 160 }; 161 static cmd_info_t call2_info = { 162 .name = "call2", 163 .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", 164 .func = cmd_call2, 165 .argc = 3, 166 .argv = call2_argv 167 }; 168 87 169 88 170 /** Data and methods for 'halt' command. */ 89 171 static int cmd_halt(cmd_arg_t *argv); 90 static cmd_info_t halt_info; 172 static cmd_info_t halt_info = { 173 .name = "halt", 174 .description = "Halt the kernel.", 175 .func = cmd_halt, 176 .argc = 0 177 }; 91 178 92 179 /** Initialize kconsole data structures. */ … … 96 183 list_initialize(&cmd_head); 97 184 98 help_info.name = "help";99 help_info.description = "List supported commands.";100 help_info.func = cmd_help;101 help_info.help = NULL;102 help_info.argc = 0;103 help_info.argv = NULL;104 105 185 spinlock_initialize(&help_info.lock, "kconsole_help"); 106 186 link_initialize(&help_info.link); 107 108 187 if (!cmd_register(&help_info)) 109 188 panic("could not register command %s\n", help_info.name); 110 189 111 190 112 desc_info.name = "describe";113 desc_info.description = "Describe specified command.";114 desc_info.help = desc_help;115 desc_info.func = cmd_desc;116 desc_info.argc = 1;117 desc_info.argv = &desc_argv;118 119 191 spinlock_initialize(&desc_info.lock, "kconsole_desc"); 120 192 link_initialize(&desc_info.link); 121 122 193 if (!cmd_register(&desc_info)) 123 194 panic("could not register command %s\n", desc_info.name); 124 195 125 126 halt_info.name = "halt"; 127 halt_info.description = "Halt the kernel."; 128 halt_info.func = cmd_halt; 129 halt_info.help = NULL; 130 halt_info.argc = 0; 131 halt_info.argv = NULL; 132 196 spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr"); 197 link_initialize(&symaddr_info.link); 198 if (!cmd_register(&symaddr_info)) 199 panic("could not register command %s\n", symaddr_info.name); 200 201 spinlock_initialize(&call0_info.lock, "kconsole_call0"); 202 link_initialize(&call0_info.link); 203 if (!cmd_register(&call0_info)) 204 panic("could not register command %s\n", call0_info.name); 205 206 spinlock_initialize(&call1_info.lock, "kconsole_call1"); 207 link_initialize(&call1_info.link); 208 if (!cmd_register(&call1_info)) 209 panic("could not register command %s\n", call1_info.name); 210 211 212 spinlock_initialize(&call2_info.lock, "kconsole_call2"); 213 link_initialize(&call2_info.link); 214 if (!cmd_register(&call2_info)) 215 panic("could not register command %s\n", call2_info.name); 216 133 217 spinlock_initialize(&halt_info.lock, "kconsole_halt"); 134 218 link_initialize(&halt_info.link); 135 136 219 if (!cmd_register(&halt_info)) 137 220 panic("could not register command %s\n", halt_info.name); … … 286 369 287 370 switch (cmd->argv[i].type) { 288 371 case ARG_TYPE_STRING: 289 372 buf = cmd->argv[i].buffer; 290 373 strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1)); 291 374 buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; 292 375 break; 293 case ARG_TYPE_INT: 294 case ARG_TYPE_INVALID: 295 default: 296 panic("invalid argument type\n"); 376 case ARG_TYPE_INT: { 377 char symname[MAX_SYMBOL_NAME]; 378 __address symaddr; 379 380 /* If we get a name, try to find it in symbol table */ 381 if (cmdline[start] < '0' | cmdline[start] > '9') { 382 strncpy(symname, cmdline+start, min((end-start) + 1, MAX_SYMBOL_NAME -1 )); 383 symaddr = get_symbol_addr(symname); 384 if (!symaddr) { 385 printf("Symbol %s not found.\n",symname); 386 return NULL; 387 } 388 if (symaddr == (__address) -1) { 389 printf("Duplicate symbol %s.\n",symname); 390 symtab_print_search(symname); 391 return NULL; 392 } 393 cmd->argv[i].intval = *((__native *)symaddr); 394 } else /* It's a number - convert it */ 395 cmd->argv[i].intval = atoi(cmdline+start); 396 break; 397 } 398 case ARG_TYPE_INVALID: 399 default: 400 printf("invalid argument type\n"); 401 return NULL; 297 402 break; 298 403 } … … 413 518 } 414 519 520 /** Search symbol table */ 521 int cmd_symaddr(cmd_arg_t *argv) 522 { 523 __address symaddr; 524 char *symbol; 525 526 symtab_print_search(argv->buffer); 527 528 return 1; 529 } 530 531 /** Call function with zero parameters */ 532 int cmd_call0(cmd_arg_t *argv) 533 { 534 __address symaddr; 535 char *symbol; 536 __native (*f)(void); 537 538 symaddr = get_symbol_addr(argv->buffer); 539 if (!symaddr) 540 printf("Symbol not found.\n"); 541 else if (symaddr == (__address) -1) { 542 symtab_print_search(argv->buffer); 543 printf("Duplicate symbol, be more specific.\n"); 544 } else { 545 symbol = get_symtab_entry(symaddr); 546 printf("Calling f(): 0x%p: %s\n", symaddr, symbol); 547 f = (__native (*)(void)) symaddr; 548 printf("Result: 0x%X\n", f()); 549 } 550 551 return 1; 552 } 553 554 /** Call function with one parameter */ 555 int cmd_call1(cmd_arg_t *argv) 556 { 557 __address symaddr; 558 char *symbol; 559 __native (*f)(__native); 560 __native arg1 = argv[1].intval; 561 562 symaddr = get_symbol_addr(argv->buffer); 563 if (!symaddr) 564 printf("Symbol not found.\n"); 565 else if (symaddr == (__address) -1) { 566 symtab_print_search(argv->buffer); 567 printf("Duplicate symbol, be more specific.\n"); 568 } else { 569 symbol = get_symtab_entry(symaddr); 570 printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol); 571 f = (__native (*)(__native)) symaddr; 572 printf("Result: 0x%x\n", f(arg1)); 573 } 574 575 return 1; 576 } 577 578 /** Call function with two parameters */ 579 int cmd_call2(cmd_arg_t *argv) 580 { 581 __address symaddr; 582 char *symbol; 583 __native (*f)(__native); 584 __native arg1 = argv[1].intval; 585 __native arg2 = argv[2].intval; 586 587 symaddr = get_symbol_addr(argv->buffer); 588 if (!symaddr) 589 printf("Symbol not found.\n"); 590 else if (symaddr == (__address) -1) { 591 symtab_print_search(argv->buffer); 592 printf("Duplicate symbol, be more specific.\n"); 593 } else { 594 symbol = get_symtab_entry(symaddr); 595 printf("Calling f(0x%x,0x%x): 0x%p: %s\n", 596 arg1, arg2, symaddr, symbol); 597 f = (__native (*)(__native)) symaddr; 598 printf("Result: 0x%x\n", f(arg1)); 599 } 600 601 return 1; 602 } 603 604 415 605 /** Print detailed description of 'describe' command. */ 416 606 void desc_help(void) -
generic/src/debug/symtab.c
ra3ac9a7 r6e716a59 31 31 #include <typedefs.h> 32 32 #include <arch/byteorder.h> 33 #include <func.h> 34 #include <print.h> 33 35 34 36 /** Return entry that seems most likely to correspond to address … … 53 55 return NULL; 54 56 } 57 58 /** Return address that corresponds to the entry 59 * 60 * Search symbol table, and if the address ENDS with 61 * the parameter, return value 62 * 63 * @param name Name of the symbol 64 * @return 0 - Not found, -1 - Duplicate symbol, other - address of symbol 65 */ 66 __address get_symbol_addr(const char *name) 67 { 68 count_t i; 69 count_t found = 0; 70 count_t found_pos; 71 72 count_t nmlen = strlen(name); 73 count_t slen; 74 75 for (i=0;symbol_table[i].address_le;++i) { 76 slen = strlen(symbol_table[i].symbol_name); 77 if (slen < nmlen) 78 continue; 79 if (strncmp(name, symbol_table[i].symbol_name + (slen-nmlen), 80 nmlen) == 0) { 81 found++; 82 found_pos = i; 83 } 84 } 85 if (found == 0) 86 return NULL; 87 if (found == 1) 88 return __u64_le2host(symbol_table[found_pos].address_le); 89 return ((__address) -1); 90 } 91 92 void symtab_print_search(const char *name) 93 { 94 int i; 95 count_t nmlen = strlen(name); 96 count_t slen; 97 __address addr; 98 char *realname; 99 100 for (i=0;symbol_table[i].address_le;++i) { 101 slen = strlen(symbol_table[i].symbol_name); 102 if (slen < nmlen) 103 continue; 104 if (strncmp(name, symbol_table[i].symbol_name + (slen-nmlen), 105 nmlen) == 0) { 106 addr = __u64_le2host(symbol_table[i].address_le); 107 realname = symbol_table[i].symbol_name; 108 printf("0x%p: %s\n", addr, realname); 109 } 110 } 111 } -
generic/src/interrupt/interrupt.c
ra3ac9a7 r6e716a59 91 91 92 92 spinlock_lock(&exctbl_lock); 93 printf("Exc Handler Description\n");93 printf("Exc Description Handler\n"); 94 94 for (i=0; i < IVT_ITEMS; i++) { 95 95 symbol = get_symtab_entry((__native)exc_table[i].f); -
generic/src/lib/func.c
ra3ac9a7 r6e716a59 114 114 } 115 115 } 116 117 /** Convert ascii representation to __native 118 * 119 * Supports 0x for hexa & 0 for octal notation. 120 * Does not check for overflows, does not support negative numbers 121 * 122 * @param text Textual representation of number 123 * @return Converted number or 0 if no valid number ofund 124 */ 125 __native atoi(const char *text) 126 { 127 int base = 10; 128 __native result = 0; 129 130 if (text[0] == '0' && text[1] == 'x') { 131 base = 16; 132 text += 2; 133 } else if (text[0] == '0') 134 base = 8; 135 136 while (*text) { 137 result *= base; 138 if (base != 16 && *text >= 'A' && *text <= 'F') 139 break; 140 if (base == 8 && *text >='8') 141 break; 142 143 if (*text >= '0' && *text <= '9') 144 result += *text - '0'; 145 else if (*text >= 'A' && *text <= 'F') 146 result += *text - 'A' + 10; 147 else 148 break; 149 text++; 150 } 151 152 return result; 153 }
Note:
See TracChangeset
for help on using the changeset viewer.