byteorder problem
Antony Pavlov
antonynpavlov at gmail.com
Wed Jun 27 18:24:44 EDT 2012
Hi!
Yesterday I have investigated strange clocksource behaviour of JZ4755
MIPS CPU: the function cyc2ns() works wrong.
The problem was in realisation of the '>>' u64 operation (see __lshrdi3()).
In include/linux/byteorder/generic.h we have
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN 1234
#endif
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN 4321
#endif
so after including this file we will have __BIG_ENDIAN and
__LITTLE_ENDIAN both defined.
On the other hand in arch/mips/lib/libgcc.h we have
#ifdef __BIG_ENDIAN
struct DWstruct {
int high, low;
};
#elif defined(__LITTLE_ENDIAN)
struct DWstruct {
int low, high;
};
#else
#error I feel sick.
#endif
In any case we will got big-endian DWstruct, so on little-endian MIPS
machines we will have wrong result of the '>>' u64 operation (the low
and high parts of 64-bit word will be swapped).
The problem can be solved by this patch:
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -78,13 +78,6 @@
*
*/
-#ifndef __LITTLE_ENDIAN
-#define __LITTLE_ENDIAN 1234
-#endif
-#ifndef __BIG_ENDIAN
-#define __BIG_ENDIAN 4321
-#endif
-
But in several places we have something like this:
#if __BYTE_ORDER == __LITTLE_ENDIAN
...
#elif __BYTE_ORDER == __BIG_ENDIAN
and we will get the warnings from compiler (e.g. warning:
"__BIG_ENDIAN" is not defined). So we need addition changes like this
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#ifdef __LITTLE_ENDIAN
...
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif defined(__BIG_ENDIAN)
There is another solution. We can change arch/mips/lib/libgcc.h:
-#ifdef __LITTLE_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
...
-#elif defined(__BIG_ENDIAN)
+#elif __BYTE_ORDER == __BIG_ENDIAN
But this solution is not linux-compatible because __LITTLE_ENDIAN and
__BIG_ENDIAN can be defined simultaneously.
Please comment this message.
--
Best regards,
Antony Pavlov
More information about the barebox
mailing list