diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-02-02 15:09:36 +0900 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-04-27 18:35:02 +0900 |
commit | 0a2d5b43c81ed6132761023bf43755f13122ddf0 (patch) | |
tree | 4e44fd99d23f9ca0ce09d62cc51f3c3b392229de /include | |
parent | 8f4dbaab648e587b28c658e12ab0b4e943f1d544 (diff) | |
download | platform_external_arm-trusted-firmware-0a2d5b43c81ed6132761023bf43755f13122ddf0.tar.gz platform_external_arm-trusted-firmware-0a2d5b43c81ed6132761023bf43755f13122ddf0.tar.bz2 platform_external_arm-trusted-firmware-0a2d5b43c81ed6132761023bf43755f13122ddf0.zip |
types: use int-ll64 for both aarch32 and aarch64
Since commit 031dbb122472 ("AArch32: Add essential Arch helpers"),
it is difficult to use consistent format strings for printf() family
between aarch32 and aarch64.
For example, uint64_t is defined as 'unsigned long long' for aarch32
and as 'unsigned long' for aarch64. Likewise, uintptr_t is defined
as 'unsigned int' for aarch32, and as 'unsigned long' for aarch64.
A problem typically arises when you use printf() in common code.
One solution could be, to cast the arguments to a type long enough
for both architectures. For example, if 'val' is uint64_t type,
like this:
printf("val = %llx\n", (unsigned long long)val);
Or, somebody may suggest to use a macro provided by <inttypes.h>,
like this:
printf("val = %" PRIx64 "\n", val);
But, both would make the code ugly.
The solution adopted in Linux kernel is to use the same typedefs for
all architectures. The fixed integer types in the kernel-space have
been unified into int-ll64, like follows:
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
[ Linux commit: 0c79a8e29b5fcbcbfd611daf9d500cfad8370fcf ]
This gets along with the codebase shared between 32 bit and 64 bit,
with the data model called ILP32, LP64, respectively.
The width for primitive types is defined as follows:
ILP32 LP64
int 32 32
long 32 64
long long 64 64
pointer 32 64
'long long' is 64 bit for both, so it is used for defining uint64_t.
'long' has the same width as pointer, so for uintptr_t.
We still need an ifdef conditional for (s)size_t.
All 64 bit architectures use "unsigned long" size_t, and most 32 bit
architectures use "unsigned int" size_t. H8/300, S/390 are known as
exceptions; they use "unsigned long" size_t despite their architecture
is 32 bit.
One idea for simplification might be to define size_t as 'unsigned long'
across architectures, then forbid the use of "%z" string format.
However, this would cause a distortion between size_t and sizeof()
operator. We have unknowledge about the native type of sizeof(), so
we need a guess of it anyway. I want the following formula to always
return 1:
__builtin_types_compatible_p(size_t, typeof(sizeof(int)))
Fortunately, ARM is probably a majority case. As far as I know, all
32 bit ARM compilers use "unsigned int" size_t.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/lib/stdlib/machine/_types.h | 61 |
1 files changed, 21 insertions, 40 deletions
diff --git a/include/lib/stdlib/machine/_types.h b/include/lib/stdlib/machine/_types.h index fb1083b74..037fdf2f3 100644 --- a/include/lib/stdlib/machine/_types.h +++ b/include/lib/stdlib/machine/_types.h @@ -52,56 +52,19 @@ typedef short __int16_t; typedef unsigned short __uint16_t; typedef int __int32_t; typedef unsigned int __uint32_t; - - -/* - * Standard type definitions which are different in AArch64 and AArch32 - */ -#ifdef AARCH32 typedef long long __int64_t; typedef unsigned long long __uint64_t; -typedef __int32_t __critical_t; -typedef __int32_t __intfptr_t; -typedef __int32_t __intptr_t; -typedef __int32_t __ptrdiff_t; /* ptr1 - ptr2 */ -typedef __int32_t __register_t; -typedef __int32_t __segsz_t; /* segment size (in pages) */ -typedef __uint32_t __size_t; /* sizeof() */ -typedef __int32_t __ssize_t; /* byte count or error */ -typedef __uint32_t __uintfptr_t; -typedef __uint32_t __uintptr_t; -typedef __uint32_t __u_register_t; -typedef __uint32_t __vm_offset_t; -typedef __uint32_t __vm_paddr_t; -typedef __uint32_t __vm_size_t; -#elif defined AARCH64 -typedef long __int64_t; -typedef unsigned long __uint64_t; -typedef __int64_t __critical_t; -typedef __int64_t __intfptr_t; -typedef __int64_t __intptr_t; -typedef __int64_t __ptrdiff_t; /* ptr1 - ptr2 */ -typedef __int64_t __register_t; -typedef __int64_t __segsz_t; /* segment size (in pages) */ -typedef __uint64_t __size_t; /* sizeof() */ -typedef __int64_t __ssize_t; /* byte count or error */ -typedef __uint64_t __uintfptr_t; -typedef __uint64_t __uintptr_t; -typedef __uint64_t __u_register_t; -typedef __uint64_t __vm_offset_t; -typedef __uint64_t __vm_paddr_t; -typedef __uint64_t __vm_size_t; -#else -#error "Only AArch32 or AArch64 supported" -#endif /* AARCH32 */ /* * Standard type definitions. */ typedef __int32_t __clock_t; /* clock()... */ +typedef long __critical_t; typedef double __double_t; typedef float __float_t; +typedef long __intfptr_t; typedef __int64_t __intmax_t; +typedef long __intptr_t; typedef __int32_t __int_fast8_t; typedef __int32_t __int_fast16_t; typedef __int32_t __int_fast32_t; @@ -110,8 +73,22 @@ typedef __int8_t __int_least8_t; typedef __int16_t __int_least16_t; typedef __int32_t __int_least32_t; typedef __int64_t __int_least64_t; +typedef long __ptrdiff_t; /* ptr1 - ptr2 */ +typedef long __register_t; +typedef long __segsz_t; /* segment size (in pages) */ +#ifdef AARCH32 +typedef unsigned int __size_t; /* sizeof() */ +typedef int __ssize_t; /* byte count or error */ +#elif defined AARCH64 +typedef unsigned long __size_t; /* sizeof() */ +typedef long __ssize_t; /* byte count or error */ +#else +#error "Only AArch32 or AArch64 supported" +#endif /* AARCH32 */ typedef __int64_t __time_t; /* time()... */ +typedef unsigned long __uintfptr_t; typedef __uint64_t __uintmax_t; +typedef unsigned long __uintptr_t; typedef __uint32_t __uint_fast8_t; typedef __uint32_t __uint_fast16_t; typedef __uint32_t __uint_fast32_t; @@ -120,8 +97,12 @@ typedef __uint8_t __uint_least8_t; typedef __uint16_t __uint_least16_t; typedef __uint32_t __uint_least32_t; typedef __uint64_t __uint_least64_t; +typedef unsigned long __u_register_t; +typedef unsigned long __vm_offset_t; typedef __int64_t __vm_ooffset_t; +typedef unsigned long __vm_paddr_t; typedef __uint64_t __vm_pindex_t; +typedef unsigned long __vm_size_t; /* * Unusual type definitions. |