00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00038 #include <func.h>
00039 #include <print.h>
00040 #include <cpu.h>
00041 #include <arch/asm.h>
00042 #include <arch.h>
00043 #include <typedefs.h>
00044 #include <console/kconsole.h>
00045
00046 atomic_t haltstate = {0};
00054 void halt()
00055 {
00056 #ifdef CONFIG_DEBUG
00057 bool rundebugger = false;
00058
00059
00060
00061 if (!atomic_get(&haltstate)) {
00062 atomic_set(&haltstate, 1);
00063 rundebugger = true;
00064 }
00065 #else
00066 atomic_set(&haltstate, 1);
00067 #endif
00068
00069 interrupts_disable();
00070 #ifdef CONFIG_DEBUG
00071 if (rundebugger) {
00072 printf("\n");
00073 kconsole("panic");
00074 }
00075 #endif
00076 if (CPU)
00077 printf("cpu%d: halted\n", CPU->id);
00078 else
00079 printf("cpu: halted\n");
00080 cpu_halt();
00081 }
00082
00089 size_t strlen(const char *str)
00090 {
00091 int i;
00092
00093 for (i = 0; str[i]; i++)
00094 ;
00095
00096 return i;
00097 }
00098
00113 int strncmp(const char *src, const char *dst, size_t len)
00114 {
00115 int i;
00116
00117 i = 0;
00118 for (;*src && *dst && i < len;src++,dst++,i++) {
00119 if (*src < *dst)
00120 return -1;
00121 if (*src > *dst)
00122 return 1;
00123 }
00124 if (i == len || *src == *dst)
00125 return 0;
00126 if (!*src)
00127 return -1;
00128 return 1;
00129 }
00130
00141 void strncpy(char *dest, const char *src, size_t len)
00142 {
00143 int i;
00144 for (i = 0; i < len; i++) {
00145 if (!(dest[i] = src[i]))
00146 return;
00147 }
00148 dest[i-1] = '\0';
00149 }
00150
00159 __native atoi(const char *text)
00160 {
00161 int base = 10;
00162 __native result = 0;
00163
00164 if (text[0] == '0' && text[1] == 'x') {
00165 base = 16;
00166 text += 2;
00167 } else if (text[0] == '0')
00168 base = 8;
00169
00170 while (*text) {
00171 if (base != 16 && \
00172 ((*text >= 'A' && *text <= 'F' )
00173 || (*text >='a' && *text <='f')))
00174 break;
00175 if (base == 8 && *text >='8')
00176 break;
00177
00178 if (*text >= '0' && *text <= '9') {
00179 result *= base;
00180 result += *text - '0';
00181 } else if (*text >= 'A' && *text <= 'F') {
00182 result *= base;
00183 result += *text - 'A' + 10;
00184 } else if (*text >= 'a' && *text <= 'f') {
00185 result *= base;
00186 result += *text - 'a' + 10;
00187 } else
00188 break;
00189 text++;
00190 }
00191
00192 return result;
00193 }
00194