Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3022 | Rev 4055 | ||
|---|---|---|---|
| Line 53... | Line 53... | ||
| 53 | void halt() |
53 | void halt() |
| 54 | { |
54 | { |
| 55 | #ifdef CONFIG_DEBUG |
55 | #ifdef CONFIG_DEBUG |
| 56 | bool rundebugger = false; |
56 | bool rundebugger = false; |
| 57 | 57 | ||
| 58 | // TODO test_and_set not defined on all arches |
- | |
| 59 | // if (!test_and_set(&haltstate)) |
- | |
| 60 | if (!atomic_get(&haltstate)) { |
58 | if (!atomic_get(&haltstate)) { |
| 61 | atomic_set(&haltstate, 1); |
59 | atomic_set(&haltstate, 1); |
| 62 | rundebugger = true; |
60 | rundebugger = true; |
| 63 | } |
61 | } |
| 64 | #else |
62 | #else |
| 65 | atomic_set(&haltstate, 1); |
63 | atomic_set(&haltstate, 1); |
| 66 | #endif |
64 | #endif |
| 67 | 65 | ||
| 68 | interrupts_disable(); |
66 | interrupts_disable(); |
| - | 67 | ||
| 69 | #ifdef CONFIG_DEBUG |
68 | #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE)) |
| 70 | if (rundebugger) { |
69 | if (rundebugger) |
| 71 | printf("\n"); |
- | |
| 72 | kconsole("panic"); /* Run kconsole as a last resort to user */ |
70 | kconsole("panic", "\nLast resort kernel console ready\n", false); |
| - | 71 | #endif |
|
| 73 | } |
72 | |
| 74 | #endif |
- | |
| 75 | if (CPU) |
73 | if (CPU) |
| 76 | printf("cpu%d: halted\n", CPU->id); |
74 | printf("cpu%u: halted\n", CPU->id); |
| 77 | else |
75 | else |
| 78 | printf("cpu: halted\n"); |
76 | printf("cpu: halted\n"); |
| 79 | cpu_halt(); |
77 | cpu_halt(); |
| 80 | } |
78 | } |
| 81 | 79 | ||
| 82 | /** Return number of characters in a string. |
- | |
| 83 | * |
- | |
| 84 | * @param str NULL terminated string. |
- | |
| 85 | * |
- | |
| 86 | * @return Number of characters in str. |
- | |
| 87 | */ |
- | |
| 88 | size_t strlen(const char *str) |
- | |
| 89 | { |
- | |
| 90 | int i; |
- | |
| 91 | - | ||
| 92 | for (i = 0; str[i]; i++) |
- | |
| 93 | ; |
- | |
| 94 | - | ||
| 95 | return i; |
- | |
| 96 | } |
- | |
| 97 | - | ||
| 98 | /** Compare two NULL terminated strings |
- | |
| 99 | * |
- | |
| 100 | * Do a char-by-char comparison of two NULL terminated strings. |
- | |
| 101 | * The strings are considered equal iff they consist of the same |
- | |
| 102 | * characters on the minimum of their lengths. |
- | |
| 103 | * |
- | |
| 104 | * @param src First string to compare. |
- | |
| 105 | * @param dst Second string to compare. |
- | |
| 106 | * |
- | |
| 107 | * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
- | |
| 108 | * |
- | |
| 109 | */ |
- | |
| 110 | int strcmp(const char *src, const char *dst) |
- | |
| 111 | { |
- | |
| 112 | for (; *src && *dst; src++, dst++) { |
- | |
| 113 | if (*src < *dst) |
- | |
| 114 | return -1; |
- | |
| 115 | if (*src > *dst) |
- | |
| 116 | return 1; |
- | |
| 117 | } |
- | |
| 118 | if (*src == *dst) |
- | |
| 119 | return 0; |
- | |
| 120 | if (!*src) |
- | |
| 121 | return -1; |
- | |
| 122 | return 1; |
- | |
| 123 | } |
- | |
| 124 | - | ||
| 125 | - | ||
| 126 | /** Compare two NULL terminated strings |
- | |
| 127 | * |
- | |
| 128 | * Do a char-by-char comparison of two NULL terminated strings. |
- | |
| 129 | * The strings are considered equal iff they consist of the same |
- | |
| 130 | * characters on the minimum of their lengths and specified maximal |
- | |
| 131 | * length. |
- | |
| 132 | * |
- | |
| 133 | * @param src First string to compare. |
- | |
| 134 | * @param dst Second string to compare. |
- | |
| 135 | * @param len Maximal length for comparison. |
- | |
| 136 | * |
- | |
| 137 | * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
- | |
| 138 | * |
- | |
| 139 | */ |
- | |
| 140 | int strncmp(const char *src, const char *dst, size_t len) |
- | |
| 141 | { |
- | |
| 142 | unsigned int i; |
- | |
| 143 | - | ||
| 144 | for (i = 0; (*src) && (*dst) && (i < len); src++, dst++, i++) { |
- | |
| 145 | if (*src < *dst) |
- | |
| 146 | return -1; |
- | |
| 147 | if (*src > *dst) |
- | |
| 148 | return 1; |
- | |
| 149 | } |
- | |
| 150 | if (i == len || *src == *dst) |
- | |
| 151 | return 0; |
- | |
| 152 | if (!*src) |
- | |
| 153 | return -1; |
- | |
| 154 | return 1; |
- | |
| 155 | } |
- | |
| 156 | - | ||
| 157 | - | ||
| 158 | - | ||
| 159 | /** Copy NULL terminated string. |
- | |
| 160 | * |
- | |
| 161 | * Copy at most 'len' characters from string 'src' to 'dest'. |
- | |
| 162 | * If 'src' is shorter than 'len', '\0' is inserted behind the |
- | |
| 163 | * last copied character. |
- | |
| 164 | * |
- | |
| 165 | * @param src Source string. |
- | |
| 166 | * @param dest Destination buffer. |
- | |
| 167 | * @param len Size of destination buffer. |
- | |
| 168 | */ |
- | |
| 169 | void strncpy(char *dest, const char *src, size_t len) |
- | |
| 170 | { |
- | |
| 171 | unsigned int i; |
- | |
| 172 | for (i = 0; i < len; i++) { |
- | |
| 173 | if (!(dest[i] = src[i])) |
- | |
| 174 | return; |
- | |
| 175 | } |
- | |
| 176 | dest[i-1] = '\0'; |
- | |
| 177 | } |
- | |
| 178 | - | ||
| 179 | /** Convert ascii representation to unative_t |
80 | /** Convert ascii representation to unative_t |
| 180 | * |
81 | * |
| 181 | * Supports 0x for hexa & 0 for octal notation. |
82 | * Supports 0x for hexa & 0 for octal notation. |
| 182 | * Does not check for overflows, does not support negative numbers |
83 | * Does not check for overflows, does not support negative numbers |
| 183 | * |
84 | * |