mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox <barebox@lists.infradead.org>
Subject: byteorder problem
Date: Thu, 28 Jun 2012 02:24:44 +0400	[thread overview]
Message-ID: <CAA4bVAE5A5jgk=zwV1PfNcQVyXydDmXLL_VhwAqiYpYOdawLmQ@mail.gmail.com> (raw)

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

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2012-06-27 22:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA4bVAE5A5jgk=zwV1PfNcQVyXydDmXLL_VhwAqiYpYOdawLmQ@mail.gmail.com' \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox