Changeset 4ce914d4 in mainline
- Timestamp:
- 2010-04-30T23:10:12Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c42638, bb252ca
- Parents:
- bcb6f27
- Location:
- kernel/generic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/func.h
rbcb6f27 r4ce914d4 42 42 43 43 extern void halt(void) __attribute__((noreturn)); 44 extern unative_t atoi(const char *text);45 44 46 45 #endif -
kernel/generic/src/console/cmd.c
rbcb6f27 r4ce914d4 837 837 bool pointer = false; 838 838 int rc; 839 840 if (((char *) argv->buffer)[0] == '*') {839 840 if (((char *) argv->buffer)[0] == '*') { 841 841 rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); 842 842 pointer = true; 843 } else if (((char *) argv->buffer)[0] >= '0' && 844 ((char *)argv->buffer)[0] <= '9') { 845 rc = EOK; 846 addr = atoi((char *)argv->buffer); 847 } else { 843 } else if (((char *) argv->buffer)[0] >= '0' && 844 ((char *) argv->buffer)[0] <= '9') { 845 uint64_t value; 846 rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value); 847 if (rc == EOK) 848 addr = (uintptr_t) value; 849 } else 848 850 rc = symtab_addr_lookup((char *) argv->buffer, &addr); 849 } 850 851 851 852 if (rc == ENOENT) 852 853 printf("Symbol %s not found.\n", argv->buffer); 854 else if (rc == EINVAL) 855 printf("Invalid address.\n"); 853 856 else if (rc == EOVERFLOW) { 854 857 symtab_print_search((char *) argv->buffer); 855 printf("Duplicate symbol , be more specific.\n");858 printf("Duplicate symbol (be more specific) or address overflow.\n"); 856 859 } else if (rc == EOK) { 857 860 if (pointer) … … 859 862 printf("Writing %#" PRIx64 " -> %p\n", arg1, addr); 860 863 *(uint32_t *) addr = arg1; 861 } else {864 } else 862 865 printf("No symbol information available.\n"); 863 }864 866 865 867 return 1; -
kernel/generic/src/console/kconsole.c
rbcb6f27 r4ce914d4 455 455 printf("No symbol information available.\n"); 456 456 return false; 457 } 458 459 if (isaddr) 460 *result = (unative_t) symaddr; 461 else if (isptr) 462 *result = **((unative_t **) symaddr); 463 else 464 *result = *((unative_t *) symaddr); 457 case EOK: 458 if (isaddr) 459 *result = (unative_t) symaddr; 460 else if (isptr) 461 *result = **((unative_t **) symaddr); 462 else 463 *result = *((unative_t *) symaddr); 464 break; 465 default: 466 printf("Unknown error.\n"); 467 return false; 468 } 465 469 } else { 466 470 /* It's a number - convert it */ 467 *result = atoi(text); 468 if (isptr) 469 *result = *((unative_t *) *result); 471 uint64_t value; 472 int rc = str_uint64(text, NULL, 0, true, &value); 473 switch (rc) { 474 case EINVAL: 475 printf("Invalid number.\n"); 476 return false; 477 case EOVERFLOW: 478 printf("Integer overflow.\n"); 479 return false; 480 case EOK: 481 *result = (unative_t) value; 482 if (isptr) 483 *result = *((unative_t *) *result); 484 break; 485 default: 486 printf("Unknown error.\n"); 487 return false; 488 } 470 489 } 471 490 -
kernel/generic/src/lib/func.c
rbcb6f27 r4ce914d4 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Miscellaneous functions. 36 36 */ 37 37 … … 79 79 } 80 80 81 /** Convert ascii representation to unative_t82 *83 * Supports 0x for hexa & 0 for octal notation.84 * Does not check for overflows, does not support negative numbers85 *86 * @param text Textual representation of number87 * @return Converted number or 0 if no valid number ofund88 */89 unative_t atoi(const char *text)90 {91 int base = 10;92 unative_t result = 0;93 94 if (text[0] == '0' && text[1] == 'x') {95 base = 16;96 text += 2;97 } else if (text[0] == '0')98 base = 8;99 100 while (*text) {101 if (base != 16 && \102 ((*text >= 'A' && *text <= 'F' )103 || (*text >='a' && *text <='f')))104 break;105 if (base == 8 && *text >='8')106 break;107 108 if (*text >= '0' && *text <= '9') {109 result *= base;110 result += *text - '0';111 } else if (*text >= 'A' && *text <= 'F') {112 result *= base;113 result += *text - 'A' + 10;114 } else if (*text >= 'a' && *text <= 'f') {115 result *= base;116 result += *text - 'a' + 10;117 } else118 break;119 text++;120 }121 122 return result;123 }124 125 81 /** @} 126 82 */ -
kernel/generic/src/lib/str.c
rbcb6f27 r4ce914d4 823 823 str++; 824 824 break; 825 default: 826 str--; 825 827 } 826 828 } … … 886 888 * @param base Zero or number between 2 and 36 inclusive. 887 889 * @param strict Do not allow any trailing characters. 888 * @ apram result Result of the conversion.890 * @param result Result of the conversion. 889 891 * 890 892 * @return EOK if conversion was successful.
Note:
See TracChangeset
for help on using the changeset viewer.