func.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 //      TODO test_and_set not defined on all arches
00060 //      if (!test_and_set(&haltstate))
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"); /* Run kconsole as a last resort to user */
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 

Generated on Sun Jun 18 17:17:05 2006 for HelenOS Kernel (ppc32) by  doxygen 1.4.6