1530d68baSNigel Croxon /*++ 2530d68baSNigel Croxon 3530d68baSNigel Croxon Copyright (c) 1998 Intel Corporation 4530d68baSNigel Croxon 5530d68baSNigel Croxon Module Name: 6530d68baSNigel Croxon 7530d68baSNigel Croxon str.c 8530d68baSNigel Croxon 9530d68baSNigel Croxon Abstract: 10530d68baSNigel Croxon 11530d68baSNigel Croxon String runtime functions 12530d68baSNigel Croxon 13530d68baSNigel Croxon 14530d68baSNigel Croxon Revision History 15530d68baSNigel Croxon 16530d68baSNigel Croxon --*/ 17530d68baSNigel Croxon 18530d68baSNigel Croxon #include "lib.h" 19530d68baSNigel Croxon 20530d68baSNigel Croxon #ifndef __GNUC__ 21530d68baSNigel Croxon #pragma RUNTIME_CODE(RtAcquireLock) 22530d68baSNigel Croxon #endif 23530d68baSNigel Croxon INTN 24530d68baSNigel Croxon RUNTIMEFUNCTION 25530d68baSNigel Croxon RtStrCmp ( 26530d68baSNigel Croxon IN CONST CHAR16 *s1, 27530d68baSNigel Croxon IN CONST CHAR16 *s2 28530d68baSNigel Croxon ) 29530d68baSNigel Croxon // compare strings 30530d68baSNigel Croxon { 31530d68baSNigel Croxon while (*s1) { 32530d68baSNigel Croxon if (*s1 != *s2) { 33530d68baSNigel Croxon break; 34530d68baSNigel Croxon } 35530d68baSNigel Croxon 36530d68baSNigel Croxon s1 += 1; 37530d68baSNigel Croxon s2 += 1; 38530d68baSNigel Croxon } 39530d68baSNigel Croxon 40530d68baSNigel Croxon return *s1 - *s2; 41530d68baSNigel Croxon } 42530d68baSNigel Croxon 43530d68baSNigel Croxon #ifndef __GNUC__ 44530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrCpy) 45530d68baSNigel Croxon #endif 46530d68baSNigel Croxon VOID 47530d68baSNigel Croxon RUNTIMEFUNCTION 48530d68baSNigel Croxon RtStrCpy ( 49530d68baSNigel Croxon IN CHAR16 *Dest, 50530d68baSNigel Croxon IN CONST CHAR16 *Src 51530d68baSNigel Croxon ) 52530d68baSNigel Croxon // copy strings 53530d68baSNigel Croxon { 54530d68baSNigel Croxon while (*Src) { 55530d68baSNigel Croxon *(Dest++) = *(Src++); 56530d68baSNigel Croxon } 57530d68baSNigel Croxon *Dest = 0; 58530d68baSNigel Croxon } 59530d68baSNigel Croxon 60530d68baSNigel Croxon #ifndef __GNUC__ 619485c65fSPeter Jones #pragma RUNTIME_CODE(RtStrnCpy) 629485c65fSPeter Jones #endif 639485c65fSPeter Jones VOID 649485c65fSPeter Jones RUNTIMEFUNCTION 659485c65fSPeter Jones RtStrnCpy ( 669485c65fSPeter Jones IN CHAR16 *Dest, 679485c65fSPeter Jones IN CONST CHAR16 *Src, 689485c65fSPeter Jones IN UINTN Len 699485c65fSPeter Jones ) 709485c65fSPeter Jones // copy strings 719485c65fSPeter Jones { 729485c65fSPeter Jones UINTN Size = RtStrnLen(Src, Len); 739485c65fSPeter Jones if (Size != Len) 7485f1c797SPete Batard RtSetMem(Dest + Len, '\0', (UINT8)((Len - Size) * sizeof(CHAR16))); 759485c65fSPeter Jones RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); 769485c65fSPeter Jones } 779485c65fSPeter Jones 789485c65fSPeter Jones #ifndef __GNUC__ 799485c65fSPeter Jones #pragma RUNTIME_CODE(RtStrCpy) 809485c65fSPeter Jones #endif 819485c65fSPeter Jones CHAR16 * 829485c65fSPeter Jones RUNTIMEFUNCTION 839485c65fSPeter Jones RtStpCpy ( 849485c65fSPeter Jones IN CHAR16 *Dest, 859485c65fSPeter Jones IN CONST CHAR16 *Src 869485c65fSPeter Jones ) 879485c65fSPeter Jones // copy strings 889485c65fSPeter Jones { 899485c65fSPeter Jones while (*Src) { 909485c65fSPeter Jones *(Dest++) = *(Src++); 919485c65fSPeter Jones } 929485c65fSPeter Jones *Dest = 0; 939485c65fSPeter Jones return Dest; 949485c65fSPeter Jones } 959485c65fSPeter Jones 969485c65fSPeter Jones #ifndef __GNUC__ 97*6058ffcdSGary Lin #pragma RUNTIME_CODE(RtStpnCpy) 989485c65fSPeter Jones #endif 999485c65fSPeter Jones CHAR16 * 1009485c65fSPeter Jones RUNTIMEFUNCTION 1019485c65fSPeter Jones RtStpnCpy ( 1029485c65fSPeter Jones IN CHAR16 *Dest, 1039485c65fSPeter Jones IN CONST CHAR16 *Src, 1049485c65fSPeter Jones IN UINTN Len 1059485c65fSPeter Jones ) 1069485c65fSPeter Jones // copy strings 1079485c65fSPeter Jones { 1089485c65fSPeter Jones UINTN Size = RtStrnLen(Src, Len); 1099485c65fSPeter Jones if (Size != Len) 110*6058ffcdSGary Lin RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0'); 1119485c65fSPeter Jones RtCopyMem(Dest, Src, Size * sizeof(CHAR16)); 1129485c65fSPeter Jones return Dest + Size; 1139485c65fSPeter Jones } 1149485c65fSPeter Jones 1159485c65fSPeter Jones #ifndef __GNUC__ 116530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrCat) 117530d68baSNigel Croxon #endif 118530d68baSNigel Croxon VOID 119530d68baSNigel Croxon RUNTIMEFUNCTION 120530d68baSNigel Croxon RtStrCat ( 121530d68baSNigel Croxon IN CHAR16 *Dest, 122530d68baSNigel Croxon IN CONST CHAR16 *Src 123530d68baSNigel Croxon ) 124530d68baSNigel Croxon { 125530d68baSNigel Croxon RtStrCpy(Dest+StrLen(Dest), Src); 126530d68baSNigel Croxon } 127530d68baSNigel Croxon 128530d68baSNigel Croxon #ifndef __GNUC__ 1299485c65fSPeter Jones #pragma RUNTIME_CODE(RtStrCat) 1309485c65fSPeter Jones #endif 1319485c65fSPeter Jones VOID 1329485c65fSPeter Jones RUNTIMEFUNCTION 1339485c65fSPeter Jones RtStrnCat ( 1349485c65fSPeter Jones IN CHAR16 *Dest, 1359485c65fSPeter Jones IN CONST CHAR16 *Src, 1369485c65fSPeter Jones IN UINTN Len 1379485c65fSPeter Jones ) 1389485c65fSPeter Jones { 1399485c65fSPeter Jones RtStrnCpy(Dest+StrLen(Dest), Src, Len); 1409485c65fSPeter Jones } 1419485c65fSPeter Jones 1429485c65fSPeter Jones #ifndef __GNUC__ 143530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrLen) 144530d68baSNigel Croxon #endif 145530d68baSNigel Croxon UINTN 146530d68baSNigel Croxon RUNTIMEFUNCTION 147530d68baSNigel Croxon RtStrLen ( 148530d68baSNigel Croxon IN CONST CHAR16 *s1 149530d68baSNigel Croxon ) 150530d68baSNigel Croxon // string length 151530d68baSNigel Croxon { 152530d68baSNigel Croxon UINTN len; 153530d68baSNigel Croxon 154530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 155530d68baSNigel Croxon return len; 156530d68baSNigel Croxon } 157530d68baSNigel Croxon 158530d68baSNigel Croxon #ifndef __GNUC__ 1599485c65fSPeter Jones #pragma RUNTIME_CODE(RtStrnLen) 1609485c65fSPeter Jones #endif 1619485c65fSPeter Jones UINTN 1629485c65fSPeter Jones RUNTIMEFUNCTION 1639485c65fSPeter Jones RtStrnLen ( 1649485c65fSPeter Jones IN CONST CHAR16 *s1, 1659485c65fSPeter Jones IN UINTN Len 1669485c65fSPeter Jones ) 1679485c65fSPeter Jones // copy strings 1689485c65fSPeter Jones { 1699485c65fSPeter Jones UINTN i; 1709485c65fSPeter Jones for (i = 0; *s1 && i < Len; i++) 1719485c65fSPeter Jones s1++; 1729485c65fSPeter Jones return i; 1739485c65fSPeter Jones } 1749485c65fSPeter Jones 1759485c65fSPeter Jones #ifndef __GNUC__ 176530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrSize) 177530d68baSNigel Croxon #endif 178530d68baSNigel Croxon UINTN 179530d68baSNigel Croxon RUNTIMEFUNCTION 180530d68baSNigel Croxon RtStrSize ( 181530d68baSNigel Croxon IN CONST CHAR16 *s1 182530d68baSNigel Croxon ) 183530d68baSNigel Croxon // string size 184530d68baSNigel Croxon { 185530d68baSNigel Croxon UINTN len; 186530d68baSNigel Croxon 187530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 188530d68baSNigel Croxon return (len + 1) * sizeof(CHAR16); 189530d68baSNigel Croxon } 190530d68baSNigel Croxon 191530d68baSNigel Croxon #ifndef __GNUC__ 192530d68baSNigel Croxon #pragma RUNTIME_CODE(RtBCDtoDecimal) 193530d68baSNigel Croxon #endif 194530d68baSNigel Croxon UINT8 195530d68baSNigel Croxon RUNTIMEFUNCTION 196530d68baSNigel Croxon RtBCDtoDecimal( 197530d68baSNigel Croxon IN UINT8 BcdValue 198530d68baSNigel Croxon ) 199530d68baSNigel Croxon { 200530d68baSNigel Croxon UINTN High, Low; 201530d68baSNigel Croxon 202530d68baSNigel Croxon High = BcdValue >> 4; 203530d68baSNigel Croxon Low = BcdValue - (High << 4); 204530d68baSNigel Croxon 205530d68baSNigel Croxon return ((UINT8)(Low + (High * 10))); 206530d68baSNigel Croxon } 207530d68baSNigel Croxon 208530d68baSNigel Croxon 209530d68baSNigel Croxon #ifndef __GNUC__ 210530d68baSNigel Croxon #pragma RUNTIME_CODE(RtDecimaltoBCD) 211530d68baSNigel Croxon #endif 212530d68baSNigel Croxon UINT8 213530d68baSNigel Croxon RUNTIMEFUNCTION 214530d68baSNigel Croxon RtDecimaltoBCD ( 215530d68baSNigel Croxon IN UINT8 DecValue 216530d68baSNigel Croxon ) 217530d68baSNigel Croxon { 218530d68baSNigel Croxon UINTN High, Low; 219530d68baSNigel Croxon 220530d68baSNigel Croxon High = DecValue / 10; 221530d68baSNigel Croxon Low = DecValue - (High * 10); 222530d68baSNigel Croxon 223530d68baSNigel Croxon return ((UINT8)(Low + (High << 4))); 224530d68baSNigel Croxon } 225530d68baSNigel Croxon 226530d68baSNigel Croxon 227