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__ 976058ffcdSGary 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) 1106058ffcdSGary 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__ 129*ba250504SGary Lin #pragma RUNTIME_CODE(RtStrnCat) 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 { 139*ba250504SGary Lin UINTN DestSize, Size; 140*ba250504SGary Lin 141*ba250504SGary Lin DestSize = StrLen(Dest); 142*ba250504SGary Lin Size = RtStrnLen(Src, Len); 143*ba250504SGary Lin RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16)); 144*ba250504SGary Lin Dest[DestSize + Size] = '\0'; 1459485c65fSPeter Jones } 1469485c65fSPeter Jones 1479485c65fSPeter Jones #ifndef __GNUC__ 148530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrLen) 149530d68baSNigel Croxon #endif 150530d68baSNigel Croxon UINTN 151530d68baSNigel Croxon RUNTIMEFUNCTION 152530d68baSNigel Croxon RtStrLen ( 153530d68baSNigel Croxon IN CONST CHAR16 *s1 154530d68baSNigel Croxon ) 155530d68baSNigel Croxon // string length 156530d68baSNigel Croxon { 157530d68baSNigel Croxon UINTN len; 158530d68baSNigel Croxon 159530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 160530d68baSNigel Croxon return len; 161530d68baSNigel Croxon } 162530d68baSNigel Croxon 163530d68baSNigel Croxon #ifndef __GNUC__ 1649485c65fSPeter Jones #pragma RUNTIME_CODE(RtStrnLen) 1659485c65fSPeter Jones #endif 1669485c65fSPeter Jones UINTN 1679485c65fSPeter Jones RUNTIMEFUNCTION 1689485c65fSPeter Jones RtStrnLen ( 1699485c65fSPeter Jones IN CONST CHAR16 *s1, 1709485c65fSPeter Jones IN UINTN Len 1719485c65fSPeter Jones ) 1729485c65fSPeter Jones // copy strings 1739485c65fSPeter Jones { 1749485c65fSPeter Jones UINTN i; 1759485c65fSPeter Jones for (i = 0; *s1 && i < Len; i++) 1769485c65fSPeter Jones s1++; 1779485c65fSPeter Jones return i; 1789485c65fSPeter Jones } 1799485c65fSPeter Jones 1809485c65fSPeter Jones #ifndef __GNUC__ 181530d68baSNigel Croxon #pragma RUNTIME_CODE(RtStrSize) 182530d68baSNigel Croxon #endif 183530d68baSNigel Croxon UINTN 184530d68baSNigel Croxon RUNTIMEFUNCTION 185530d68baSNigel Croxon RtStrSize ( 186530d68baSNigel Croxon IN CONST CHAR16 *s1 187530d68baSNigel Croxon ) 188530d68baSNigel Croxon // string size 189530d68baSNigel Croxon { 190530d68baSNigel Croxon UINTN len; 191530d68baSNigel Croxon 192530d68baSNigel Croxon for (len=0; *s1; s1+=1, len+=1) ; 193530d68baSNigel Croxon return (len + 1) * sizeof(CHAR16); 194530d68baSNigel Croxon } 195530d68baSNigel Croxon 196530d68baSNigel Croxon #ifndef __GNUC__ 197530d68baSNigel Croxon #pragma RUNTIME_CODE(RtBCDtoDecimal) 198530d68baSNigel Croxon #endif 199530d68baSNigel Croxon UINT8 200530d68baSNigel Croxon RUNTIMEFUNCTION 201530d68baSNigel Croxon RtBCDtoDecimal( 202530d68baSNigel Croxon IN UINT8 BcdValue 203530d68baSNigel Croxon ) 204530d68baSNigel Croxon { 205530d68baSNigel Croxon UINTN High, Low; 206530d68baSNigel Croxon 207530d68baSNigel Croxon High = BcdValue >> 4; 208530d68baSNigel Croxon Low = BcdValue - (High << 4); 209530d68baSNigel Croxon 210530d68baSNigel Croxon return ((UINT8)(Low + (High * 10))); 211530d68baSNigel Croxon } 212530d68baSNigel Croxon 213530d68baSNigel Croxon 214530d68baSNigel Croxon #ifndef __GNUC__ 215530d68baSNigel Croxon #pragma RUNTIME_CODE(RtDecimaltoBCD) 216530d68baSNigel Croxon #endif 217530d68baSNigel Croxon UINT8 218530d68baSNigel Croxon RUNTIMEFUNCTION 219530d68baSNigel Croxon RtDecimaltoBCD ( 220530d68baSNigel Croxon IN UINT8 DecValue 221530d68baSNigel Croxon ) 222530d68baSNigel Croxon { 223530d68baSNigel Croxon UINTN High, Low; 224530d68baSNigel Croxon 225530d68baSNigel Croxon High = DecValue / 10; 226530d68baSNigel Croxon Low = DecValue - (High * 10); 227530d68baSNigel Croxon 228530d68baSNigel Croxon return ((UINT8)(Low + (High << 4))); 229530d68baSNigel Croxon } 230530d68baSNigel Croxon 231530d68baSNigel Croxon 232