Changeset 91c78c9 in mainline
- Timestamp:
- 2005-12-10T16:02:39Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- adb2ebf8
- Parents:
- 5bb20ec
- Location:
- generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/console/kconsole.h
r5bb20ec r91c78c9 37 37 ARG_TYPE_INVALID = 0, 38 38 ARG_TYPE_INT, 39 ARG_TYPE_STRING 39 ARG_TYPE_STRING, 40 ARG_TYPE_VAR /**< Variable type - either symbol or string */ 40 41 }; 41 42 … … 46 47 size_t len; /**< Size of the buffer. */ 47 48 __native intval; /**< Integer value */ 49 cmd_arg_type_t vartype; /**< Resulting type of variable arg */ 48 50 }; 49 51 -
generic/src/console/kconsole.c
r5bb20ec r91c78c9 117 117 /** Call0 - call function with no parameters */ 118 118 static char call0_buf[MAX_CMDLINE+1]; 119 static char carg1_buf[MAX_CMDLINE+1]; 120 static char carg2_buf[MAX_CMDLINE+1]; 119 121 120 122 static int cmd_call0(cmd_arg_t *argv); … … 139 141 .len = sizeof(call0_buf) 140 142 }, 141 { .type = ARG_TYPE_INT } 143 { 144 .type = ARG_TYPE_VAR, 145 .buffer = carg1_buf, 146 .len = sizeof(carg1_buf) 147 } 142 148 }; 143 149 static cmd_info_t call1_info = { … … 156 162 .len = sizeof(call0_buf) 157 163 }, 158 { .type = ARG_TYPE_INT }, 159 { .type = ARG_TYPE_INT } 164 { 165 .type = ARG_TYPE_VAR, 166 .buffer = carg1_buf, 167 .len = sizeof(carg1_buf) 168 }, 169 { 170 .type = ARG_TYPE_VAR, 171 .buffer = carg2_buf, 172 .len = sizeof(carg2_buf) 173 } 160 174 }; 161 175 static cmd_info_t call2_info = { … … 306 320 } 307 321 322 static int parse_int_arg(char *text, size_t len, __native *result) 323 { 324 char symname[MAX_SYMBOL_NAME]; 325 __address symaddr; 326 bool isaddr = false; 327 328 /* If we get a name, try to find it in symbol table */ 329 if (text[0] < '0' | text[0] > '9') { 330 if (text[0] == '&') { 331 isaddr = true; 332 text++;len--; 333 } 334 strncpy(symname, text, min(len+1, MAX_SYMBOL_NAME)); 335 symaddr = get_symbol_addr(symname); 336 if (!symaddr) { 337 printf("Symbol %s not found.\n",symname); 338 return -1; 339 } 340 if (symaddr == (__address) -1) { 341 printf("Duplicate symbol %s.\n",symname); 342 symtab_print_search(symname); 343 return -1; 344 } 345 if (isaddr) 346 *result = (__native)symaddr; 347 else 348 *result = *((__native *)symaddr); 349 } else /* It's a number - convert it */ 350 *result = atoi(text); 351 return 0; 352 } 353 308 354 /** Parse command line. 309 355 * … … 371 417 case ARG_TYPE_STRING: 372 418 buf = cmd->argv[i].buffer; 373 strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1));419 strncpy(buf, (const char *) &cmdline[start], min((end - start) + 2, cmd->argv[i].len)); 374 420 buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; 375 421 break; 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); 422 case ARG_TYPE_INT: 423 if (parse_int_arg(cmdline+start, end-start+1, 424 &cmd->argv[i].intval)) 425 return NULL; 396 426 break; 427 case ARG_TYPE_VAR: 428 if (start != end && cmdline[start] == '"' && cmdline[end] == '"') { 429 buf = cmd->argv[i].buffer; 430 strncpy(buf, (const char *) &cmdline[start+1], 431 min((end-start), cmd->argv[i].len)); 432 buf[min((end - start), cmd->argv[i].len - 1)] = '\0'; 433 cmd->argv[i].intval = (__native) buf; 434 cmd->argv[i].vartype = ARG_TYPE_STRING; 435 } else if (!parse_int_arg(cmdline+start, end-start+1, 436 &cmd->argv[i].intval)) 437 cmd->argv[i].vartype = ARG_TYPE_INT; 438 else { 439 printf("Unrecognized variable argument.\n"); 440 return NULL; 397 441 } 442 break; 398 443 case ARG_TYPE_INVALID: 399 444 default: … … 538 583 symaddr = get_symbol_addr(argv->buffer); 539 584 if (!symaddr) 540 printf("Symbol not found.\n");585 printf("Symbol %s not found.\n", argv->buffer); 541 586 else if (symaddr == (__address) -1) { 542 587 symtab_print_search(argv->buffer); … … 562 607 symaddr = get_symbol_addr(argv->buffer); 563 608 if (!symaddr) 564 printf("Symbol not found.\n");609 printf("Symbol %s not found.\n", argv->buffer); 565 610 else if (symaddr == (__address) -1) { 566 611 symtab_print_search(argv->buffer); … … 581 626 __address symaddr; 582 627 char *symbol; 583 __native (*f)(__native );628 __native (*f)(__native,__native); 584 629 __native arg1 = argv[1].intval; 585 630 __native arg2 = argv[2].intval; … … 587 632 symaddr = get_symbol_addr(argv->buffer); 588 633 if (!symaddr) 589 printf("Symbol not found.\n");634 printf("Symbol %s not found.\n", argv->buffer); 590 635 else if (symaddr == (__address) -1) { 591 636 symtab_print_search(argv->buffer); … … 595 640 printf("Calling f(0x%x,0x%x): 0x%p: %s\n", 596 641 arg1, arg2, symaddr, symbol); 597 f = (__native (*)(__native )) symaddr;598 printf("Result: 0x%x\n", f(arg1 ));642 f = (__native (*)(__native,__native)) symaddr; 643 printf("Result: 0x%x\n", f(arg1, arg2)); 599 644 } 600 645 -
generic/src/lib/func.c
r5bb20ec r91c78c9 113 113 return; 114 114 } 115 dest[i-1] = '\0'; 115 116 } 116 117
Note:
See TracChangeset
for help on using the changeset viewer.