[U-Boot] [PATCH 7/7] Make BITS_PER_LONG compiler-dependent (MAD)

Masahiro Yamada yamada.m at jp.panasonic.com
Mon Dec 22 11:16:03 CET 2014


Linux expects "unsigned long" has the same bit-width as the pointer,
i.e. the size of "unsigned long" is 4 on 32-bit compilers (ILP32)
and it is 8 on 64-bit compilers (LLP64).
It provides us the convenience in return of the limitation that
LP64 data model is not supported.

U-Boot used to follow Linux's way, but it does not now.

Including <stdint.h> means the width of "long" type is provided by
the compiler.

Use __SIZEOF_LONG__ instead of hard-coding BITS_PER_LONG.

Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
Cc: Gabe Black <gabeblack at chromium.org>
Cc: Simon Glass <sjg at chromium.org>
Cc: Bill Richardson <wfrichar at google.com>
Cc: Tom Rini <trini at ti.com>
---

 arch/arc/include/asm/types.h        | 4 ++++
 arch/arm/include/asm/types.h        | 4 ++++
 arch/avr32/include/asm/types.h      | 4 ++++
 arch/blackfin/include/asm/types.h   | 4 ++++
 arch/m68k/include/asm/types.h       | 4 ++++
 arch/microblaze/include/asm/types.h | 4 ++++
 arch/mips/include/asm/types.h       | 4 ++++
 arch/nds32/include/asm/types.h      | 4 ++++
 arch/nios2/include/asm/types.h      | 4 ++++
 arch/openrisc/include/asm/types.h   | 4 ++++
 arch/powerpc/include/asm/types.h    | 4 ++++
 arch/sandbox/include/asm/types.h    | 4 ++++
 arch/sh/include/asm/types.h         | 4 ++++
 arch/sparc/include/asm/types.h      | 4 ++++
 arch/x86/include/asm/types.h        | 4 ++++
 15 files changed, 60 insertions(+)

diff --git a/arch/arc/include/asm/types.h b/arch/arc/include/asm/types.h
index 5693e5f..71779e9 100644
--- a/arch/arc/include/asm/types.h
+++ b/arch/arc/include/asm/types.h
@@ -73,7 +73,11 @@ typedef signed long long s64;
 typedef unsigned long long u64;
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide. */
 
diff --git a/arch/arm/include/asm/types.h b/arch/arm/include/asm/types.h
index e24acc59..510b694 100644
--- a/arch/arm/include/asm/types.h
+++ b/arch/arm/include/asm/types.h
@@ -72,11 +72,15 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #ifdef	CONFIG_ARM64
 #define BITS_PER_LONG 64
 #else	/* CONFIG_ARM64 */
 #define BITS_PER_LONG 32
 #endif	/* CONFIG_ARM64 */
+#endif
 
 /* Dma addresses are 32-bits wide.  */
 
diff --git a/arch/avr32/include/asm/types.h b/arch/avr32/include/asm/types.h
index 032a765..5311daa 100644
--- a/arch/avr32/include/asm/types.h
+++ b/arch/avr32/include/asm/types.h
@@ -51,7 +51,11 @@ __extension__ typedef unsigned long long __u64;
  */
 #ifdef __KERNEL__
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/blackfin/include/asm/types.h b/arch/blackfin/include/asm/types.h
index 8cae642..2cdb0e8 100644
--- a/arch/blackfin/include/asm/types.h
+++ b/arch/blackfin/include/asm/types.h
@@ -88,7 +88,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide. */
 
diff --git a/arch/m68k/include/asm/types.h b/arch/m68k/include/asm/types.h
index 83de4d5..53414db 100644
--- a/arch/m68k/include/asm/types.h
+++ b/arch/m68k/include/asm/types.h
@@ -72,7 +72,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* DMA addresses are 32-bits wide */
 typedef u32 dma_addr_t;
diff --git a/arch/microblaze/include/asm/types.h b/arch/microblaze/include/asm/types.h
index afcd811..7418499 100644
--- a/arch/microblaze/include/asm/types.h
+++ b/arch/microblaze/include/asm/types.h
@@ -79,7 +79,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide.  */
 
diff --git a/arch/mips/include/asm/types.h b/arch/mips/include/asm/types.h
index f372c70..546a9c1 100644
--- a/arch/mips/include/asm/types.h
+++ b/arch/mips/include/asm/types.h
@@ -58,7 +58,11 @@ typedef unsigned long long __u64;
  */
 #ifdef __KERNEL__
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG _MIPS_SZLONG
+#endif
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/nds32/include/asm/types.h b/arch/nds32/include/asm/types.h
index 8416cef..6d0a2db 100644
--- a/arch/nds32/include/asm/types.h
+++ b/arch/nds32/include/asm/types.h
@@ -79,7 +79,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 #include <stddef.h>
 
diff --git a/arch/nios2/include/asm/types.h b/arch/nios2/include/asm/types.h
index 43c76cc..d5751e2 100644
--- a/arch/nios2/include/asm/types.h
+++ b/arch/nios2/include/asm/types.h
@@ -78,7 +78,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide.  */
 
diff --git a/arch/openrisc/include/asm/types.h b/arch/openrisc/include/asm/types.h
index 069c8d6..16a0ad9 100644
--- a/arch/openrisc/include/asm/types.h
+++ b/arch/openrisc/include/asm/types.h
@@ -84,7 +84,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide.  */
 
diff --git a/arch/powerpc/include/asm/types.h b/arch/powerpc/include/asm/types.h
index 71868ef..cba487c 100644
--- a/arch/powerpc/include/asm/types.h
+++ b/arch/powerpc/include/asm/types.h
@@ -71,7 +71,11 @@ typedef unsigned long long u64;
 
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 #ifdef CONFIG_PHYS_64BIT
 typedef unsigned long long dma_addr_t;
diff --git a/arch/sandbox/include/asm/types.h b/arch/sandbox/include/asm/types.h
index 1bb168c..6d69422 100644
--- a/arch/sandbox/include/asm/types.h
+++ b/arch/sandbox/include/asm/types.h
@@ -80,7 +80,11 @@ typedef __INT64_TYPE__ s64;
 typedef __UINT64_TYPE__ u64;
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG	CONFIG_SANDBOX_BITS_PER_LONG
+#endif
 
 typedef unsigned long dma_addr_t;
 typedef u32 phys_addr_t;
diff --git a/arch/sh/include/asm/types.h b/arch/sh/include/asm/types.h
index eb47b0f..82884f4 100644
--- a/arch/sh/include/asm/types.h
+++ b/arch/sh/include/asm/types.h
@@ -46,7 +46,11 @@ __extension__ typedef unsigned long long __u64;
  */
 #ifdef __KERNEL__
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/sparc/include/asm/types.h b/arch/sparc/include/asm/types.h
index 79484c5..5794152 100644
--- a/arch/sparc/include/asm/types.h
+++ b/arch/sparc/include/asm/types.h
@@ -77,7 +77,11 @@ typedef unsigned int u32;
 typedef signed long long s64;
 typedef unsigned long long u64;
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* DMA addresses are 32-bits wide */
 typedef u32 dma_addr_t;
diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index 88c6645..7ff1520 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -75,7 +75,11 @@ typedef __INT64_TYPE__ s64;
 typedef __UINT64_TYPE__ u64;
 #endif
 
+#ifdef CONFIG_USE_STDINT
+#define BITS_PER_LONG ((__SIZEOF_LONG__) * 8)
+#else
 #define BITS_PER_LONG 32
+#endif
 
 /* Dma addresses are 32-bits wide.  */
 
-- 
1.9.1



More information about the U-Boot mailing list