1*530d68baSNigel Croxon /*++ 2*530d68baSNigel Croxon 3*530d68baSNigel Croxon Copyright (c) 1998 Intel Corporation 4*530d68baSNigel Croxon 5*530d68baSNigel Croxon Module Name: 6*530d68baSNigel Croxon 7*530d68baSNigel Croxon str.c 8*530d68baSNigel Croxon 9*530d68baSNigel Croxon Abstract: 10*530d68baSNigel Croxon 11*530d68baSNigel Croxon String runtime functions 12*530d68baSNigel Croxon 13*530d68baSNigel Croxon 14*530d68baSNigel Croxon Revision History 15*530d68baSNigel Croxon 16*530d68baSNigel Croxon --*/ 17*530d68baSNigel Croxon 18*530d68baSNigel Croxon #include "lib.h" 19*530d68baSNigel Croxon 20*530d68baSNigel Croxon #ifndef __GNUC__ 21*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtAcquireLock) 22*530d68baSNigel Croxon #endif 23*530d68baSNigel Croxon INTN 24*530d68baSNigel Croxon RUNTIMEFUNCTION 25*530d68baSNigel Croxon RtStrCmp ( 26*530d68baSNigel Croxon IN CONST CHAR16 *s1, 27*530d68baSNigel Croxon IN CONST CHAR16 *s2 28*530d68baSNigel Croxon ) 29*530d68baSNigel Croxon // compare strings 30*530d68baSNigel Croxon { 31*530d68baSNigel Croxon while (*s1) { 32*530d68baSNigel Croxon if (*s1 != *s2) { 33*530d68baSNigel Croxon break; 34*530d68baSNigel Croxon } 35*530d68baSNigel Croxon 36*530d68baSNigel Croxon s1 += 1; 37*530d68baSNigel Croxon s2 += 1; 38*530d68baSNigel Croxon } 39*530d68baSNigel Croxon 40*530d68baSNigel Croxon return *s1 - *s2; 41*530d68baSNigel Croxon } 42*530d68baSNigel Croxon 43*530d68baSNigel Croxon #ifndef __GNUC__ 44*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrCpy) 45*530d68baSNigel Croxon #endif 46*530d68baSNigel Croxon VOID 47*530d68baSNigel Croxon RUNTIMEFUNCTION 48*530d68baSNigel Croxon RtStrCpy ( 49*530d68baSNigel Croxon IN CHAR16 *Dest, 50*530d68baSNigel Croxon IN CONST CHAR16 *Src 51*530d68baSNigel Croxon ) 52*530d68baSNigel Croxon // copy strings 53*530d68baSNigel Croxon { 54*530d68baSNigel Croxon while (*Src) { 55*530d68baSNigel Croxon *(Dest++) = *(Src++); 56*530d68baSNigel Croxon } 57*530d68baSNigel Croxon *Dest = 0; 58*530d68baSNigel Croxon } 59*530d68baSNigel Croxon 60*530d68baSNigel Croxon #ifndef __GNUC__ 61*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrCat) 62*530d68baSNigel Croxon #endif 63*530d68baSNigel Croxon VOID 64*530d68baSNigel Croxon RUNTIMEFUNCTION 65*530d68baSNigel Croxon RtStrCat ( 66*530d68baSNigel Croxon IN CHAR16 *Dest, 67*530d68baSNigel Croxon IN CONST CHAR16 *Src 68*530d68baSNigel Croxon ) 69*530d68baSNigel Croxon { 70*530d68baSNigel Croxon RtStrCpy(Dest+StrLen(Dest), Src); 71*530d68baSNigel Croxon } 72*530d68baSNigel Croxon 73*530d68baSNigel Croxon #ifndef __GNUC__ 74*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrLen) 75*530d68baSNigel Croxon #endif 76*530d68baSNigel Croxon UINTN 77*530d68baSNigel Croxon RUNTIMEFUNCTION 78*530d68baSNigel Croxon RtStrLen ( 79*530d68baSNigel Croxon IN CONST CHAR16 *s1 80*530d68baSNigel Croxon ) 81*530d68baSNigel Croxon // string length 82*530d68baSNigel Croxon { 83*530d68baSNigel Croxon UINTN len; 84*530d68baSNigel Croxon 85*530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 86*530d68baSNigel Croxon return len; 87*530d68baSNigel Croxon } 88*530d68baSNigel Croxon 89*530d68baSNigel Croxon #ifndef __GNUC__ 90*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrSize) 91*530d68baSNigel Croxon #endif 92*530d68baSNigel Croxon UINTN 93*530d68baSNigel Croxon RUNTIMEFUNCTION 94*530d68baSNigel Croxon RtStrSize ( 95*530d68baSNigel Croxon IN CONST CHAR16 *s1 96*530d68baSNigel Croxon ) 97*530d68baSNigel Croxon // string size 98*530d68baSNigel Croxon { 99*530d68baSNigel Croxon UINTN len; 100*530d68baSNigel Croxon 101*530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 102*530d68baSNigel Croxon return (len + 1) * sizeof(CHAR16); 103*530d68baSNigel Croxon } 104*530d68baSNigel Croxon 105*530d68baSNigel Croxon #ifndef __GNUC__ 106*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtBCDtoDecimal) 107*530d68baSNigel Croxon #endif 108*530d68baSNigel Croxon UINT8 109*530d68baSNigel Croxon RUNTIMEFUNCTION 110*530d68baSNigel Croxon RtBCDtoDecimal( 111*530d68baSNigel Croxon IN UINT8 BcdValue 112*530d68baSNigel Croxon ) 113*530d68baSNigel Croxon { 114*530d68baSNigel Croxon UINTN High, Low; 115*530d68baSNigel Croxon 116*530d68baSNigel Croxon High = BcdValue >> 4; 117*530d68baSNigel Croxon Low = BcdValue - (High << 4); 118*530d68baSNigel Croxon 119*530d68baSNigel Croxon return ((UINT8)(Low + (High * 10))); 120*530d68baSNigel Croxon } 121*530d68baSNigel Croxon 122*530d68baSNigel Croxon 123*530d68baSNigel Croxon #ifndef __GNUC__ 124*530d68baSNigel Croxon #pragma RUNTIME_CODE(RtDecimaltoBCD) 125*530d68baSNigel Croxon #endif 126*530d68baSNigel Croxon UINT8 127*530d68baSNigel Croxon RUNTIMEFUNCTION 128*530d68baSNigel Croxon RtDecimaltoBCD ( 129*530d68baSNigel Croxon IN UINT8 DecValue 130*530d68baSNigel Croxon ) 131*530d68baSNigel Croxon { 132*530d68baSNigel Croxon UINTN High, Low; 133*530d68baSNigel Croxon 134*530d68baSNigel Croxon High = DecValue / 10; 135*530d68baSNigel Croxon Low = DecValue - (High * 10); 136*530d68baSNigel Croxon 137*530d68baSNigel Croxon return ((UINT8)(Low + (High << 4))); 138*530d68baSNigel Croxon } 139*530d68baSNigel Croxon 140*530d68baSNigel Croxon 141