diff options
author | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-08-18 20:24:08 +0000 |
---|---|---|
committer | andrewfish <andrewfish@6f19259b-4bc3-4df7-8a09-765794883524> | 2010-08-18 20:24:08 +0000 |
commit | bb111c2346bef02c18b30acced3f7b0311bbfe21 (patch) | |
tree | 496916a37849ea45a4083848501de061a2b98732 /UnixPkg/Library/UnixBaseLib/String.c | |
parent | 6989af71680fc69024e68a0ab6d8284f0c4909fc (diff) | |
download | edk2-platforms-bb111c2346bef02c18b30acced3f7b0311bbfe21.tar.xz |
Added support for an EFI X64 ABI compatible UnixPkg. With an internal only compiler I've been able to run checked in X64 EFI shell binary! We are hoping to get the open source LLVM compiler working for this... Since the SEC has to be UNIX ABI to make the POSIX calls it is compiled using a different compiler and the rest of the UnixPkg is compiled with UNIXPKG tool. You just need to point UNIXPKG at your EFI X64 ABI compiler of choice, it should work like MYTOOLS. Some one may want to port this to Linux at some point. To build cd into UnixPkg and ./build64.sh
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10806 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'UnixPkg/Library/UnixBaseLib/String.c')
-rw-r--r-- | UnixPkg/Library/UnixBaseLib/String.c | 51 |
1 files changed, 8 insertions, 43 deletions
diff --git a/UnixPkg/Library/UnixBaseLib/String.c b/UnixPkg/Library/UnixBaseLib/String.c index 2279720951..273291a915 100644 --- a/UnixPkg/Library/UnixBaseLib/String.c +++ b/UnixPkg/Library/UnixBaseLib/String.c @@ -14,17 +14,6 @@ #include "BaseLibInternals.h"
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_10 ((UINTN) -1 / 10)
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_10 ((UINTN) -1 % 10)
-
-#define QUOTIENT_MAX_UINTN_DIVIDED_BY_16 ((UINTN) -1 / 16)
-#define REMAINDER_MAX_UINTN_DIVIDED_BY_16 ((UINTN) -1 % 16)
-
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_10 ((UINT64) -1 / 10)
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_10 ((UINT64) -1 % 10)
-
-#define QUOTIENT_MAX_UINT64_DIVIDED_BY_16 ((UINT64) -1 / 16)
-#define REMAINDER_MAX_UINT64_DIVIDED_BY_16 ((UINT64) -1 % 16)
/**
Copies one Null-terminated Unicode string to another Null-terminated Unicode
@@ -681,10 +670,7 @@ StrDecimalToUintn ( // If the number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||
- ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&
- (*String - L'0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)
- );
+ ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));
Result = Result * 10 + (*String - L'0');
String++;
@@ -763,10 +749,7 @@ StrDecimalToUint64 ( // If the number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) ||
- ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) &&
- (*String - L'0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)
- );
+ ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));
Result = MultU64x32 (Result, 10) + (*String - L'0');
String++;
@@ -855,10 +838,7 @@ StrHexToUintn ( // If the Hex Number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||
- ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) &&
- (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))
- );
+ ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));
Result = (Result << 4) + InternalHexCharToUintn (*String);
String++;
@@ -949,10 +929,7 @@ StrHexToUint64 ( // If the Hex Number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16)||
- ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) &&
- (InternalHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))
- );
+ ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));
Result = LShiftU64 (Result, 4);
Result = Result + InternalHexCharToUintn (*String);
@@ -1716,10 +1693,7 @@ AsciiStrDecimalToUintn ( // If the number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_10) ||
- ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_10) &&
- (*String - '0') <= REMAINDER_MAX_UINTN_DIVIDED_BY_10)
- );
+ ASSERT (Result <= ((((UINTN) ~0) - (*String - L'0')) / 10));
Result = Result * 10 + (*String - '0');
String++;
@@ -1793,10 +1767,7 @@ AsciiStrDecimalToUint64 ( // If the number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_10) ||
- ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_10) &&
- (*String - '0') <= REMAINDER_MAX_UINT64_DIVIDED_BY_10)
- );
+ ASSERT (Result <= DivU64x32 (((UINT64) ~0) - (*String - L'0') , 10));
Result = MultU64x32 (Result, 10) + (*String - '0');
String++;
@@ -1884,10 +1855,7 @@ AsciiStrHexToUintn ( // If the Hex Number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINTN_DIVIDED_BY_16) ||
- ((Result == QUOTIENT_MAX_UINTN_DIVIDED_BY_16) &&
- (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINTN_DIVIDED_BY_16))
- );
+ ASSERT (Result <= ((((UINTN) ~0) - InternalHexCharToUintn (*String)) >> 4));
Result = (Result << 4) + InternalAsciiHexCharToUintn (*String);
String++;
@@ -1979,10 +1947,7 @@ AsciiStrHexToUint64 ( // If the Hex Number represented by String overflows according
// to the range defined by UINTN, then ASSERT().
//
- ASSERT ((Result < QUOTIENT_MAX_UINT64_DIVIDED_BY_16) ||
- ((Result == QUOTIENT_MAX_UINT64_DIVIDED_BY_16) &&
- (InternalAsciiHexCharToUintn (*String) <= REMAINDER_MAX_UINT64_DIVIDED_BY_16))
- );
+ ASSERT (Result <= RShiftU64 (((UINT64) ~0) - InternalHexCharToUintn (*String) , 4));
Result = LShiftU64 (Result, 4);
Result = Result + InternalAsciiHexCharToUintn (*String);
|