From: Remy Bohmer <linux@bohmer.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Make the generic unaligned access code safe for unaligned access
Date: Wed, 28 Oct 2009 22:13:38 +0100 [thread overview]
Message-ID: <1256764421-27799-4-git-send-email-linux@bohmer.net> (raw)
In-Reply-To: <1256764421-27799-3-git-send-email-linux@bohmer.net>
The current generic code for handling unaligned access assumes that
the processor can properly handle unaligned accesses itself.
This is at least not the case for ARM, which results in runtime
errors.
Rewrite it such that it works for ARM as well.
Signed-off-by: Remy Bohmer <linux@bohmer.net>
---
include/linux/unaligned/access_ok.h | 48 ++++++++++++++++++++++++----------
1 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
index 5f46eee..172124f 100644
--- a/include/linux/unaligned/access_ok.h
+++ b/include/linux/unaligned/access_ok.h
@@ -1,66 +1,86 @@
#ifndef _LINUX_UNALIGNED_ACCESS_OK_H
#define _LINUX_UNALIGNED_ACCESS_OK_H
-#include <asm/byteorder.h>
-
static inline u16 get_unaligned_le16(const void *p)
{
- return le16_to_cpup((__le16 *)p);
+ const u8 *__p = p;
+ return __p[0] | __p[1] << 8;
}
static inline u32 get_unaligned_le32(const void *p)
{
- return le32_to_cpup((__le32 *)p);
+ const u8 *__p = p;
+ return __p[0] | __p[1] << 8 | __p[2] << 16 | __p[3] << 24;
}
static inline u64 get_unaligned_le64(const void *p)
{
- return le64_to_cpup((__le64 *)p);
+ const u8 *__p = p;
+ return (unsigned long long)
+ get_unaligned_le32((__p + 4)) << 32 |
+ get_unaligned_le32(__p);
}
static inline u16 get_unaligned_be16(const void *p)
{
- return be16_to_cpup((__be16 *)p);
+ const u8 *__p = p;
+ return __p[0] << 8 | __p[1];
}
static inline u32 get_unaligned_be32(const void *p)
{
- return be32_to_cpup((__be32 *)p);
+ const u8 *__p = p;
+ return __p[0] << 24 | __p[1] << 16 | __p[2] << 8 | __p[3];
}
static inline u64 get_unaligned_be64(const void *p)
{
- return be64_to_cpup((__be64 *)p);
+ const u8 *__p = p;
+ return (unsigned long long)
+ get_unaligned_be32(__p) << 32 |
+ get_unaligned_be32((__p + 4));
}
static inline void put_unaligned_le16(u16 val, void *p)
{
- *((__le16 *)p) = cpu_to_le16(val);
+ u8 *__p = p;
+ *__p++ = val;
+ *__p++ = val >> 8;
}
static inline void put_unaligned_le32(u32 val, void *p)
{
- *((__le32 *)p) = cpu_to_le32(val);
+ u8 *__p = p;
+ put_unaligned_le16(val >> 16, __p + 2);
+ put_unaligned_le16(val, __p);
}
static inline void put_unaligned_le64(u64 val, void *p)
{
- *((__le64 *)p) = cpu_to_le64(val);
+ u8 *__p = p;
+ put_unaligned_le32(val >> 32, __p + 4);
+ put_unaligned_le32(val, __p);
}
static inline void put_unaligned_be16(u16 val, void *p)
{
- *((__be16 *)p) = cpu_to_be16(val);
+ u8 *__p = p;
+ *__p++ = val >> 8;
+ *__p++ = val;
}
static inline void put_unaligned_be32(u32 val, void *p)
{
- *((__be32 *)p) = cpu_to_be32(val);
+ u8 *__p = p;
+ put_unaligned_be16(val >> 16, __p);
+ put_unaligned_be16(val, __p + 2);
}
static inline void put_unaligned_be64(u64 val, void *p)
{
- *((__be64 *)p) = cpu_to_be64(val);
+ u8 *__p = p;
+ put_unaligned_be32(val >> 32, __p);
+ put_unaligned_be32(val, __p + 4);
}
#endif /* _LINUX_UNALIGNED_ACCESS_OK_H */
--
1.6.0.4
next prev parent reply other threads:[~2009-10-28 21:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 21:13 [U-Boot] [PATCH] Building of FIT images does not work Remy Bohmer
2009-10-28 21:13 ` [U-Boot] [PATCH] Fix mingw tools build Remy Bohmer
2009-10-28 21:13 ` [U-Boot] [PATCH] Add support for CS2 dataflash for Atmel-SPI Remy Bohmer
2009-10-28 21:13 ` Remy Bohmer [this message]
2009-10-28 21:13 ` [U-Boot] [PATCH] Repair the 'netry=once' option Remy Bohmer
2009-10-28 21:13 ` [U-Boot] [PATCH] Add error codes/handling for TFTP-server Remy Bohmer
2009-10-28 21:13 ` [U-Boot] [PATCH] Repair build failure in case PPC is not defined and FIT is beng used Remy Bohmer
2009-10-29 10:53 ` Wolfgang Denk
2009-10-29 11:35 ` Remy Bohmer
2009-10-29 12:36 ` Wolfgang Denk
2009-11-10 6:30 ` [U-Boot] [PATCH] Add error codes/handling for TFTP-server Ben Warren
2009-11-10 6:28 ` [U-Boot] [PATCH] Repair the 'netry=once' option Ben Warren
2009-11-23 22:48 ` Wolfgang Denk
2009-10-29 5:01 ` [U-Boot] [PATCH] Make the generic unaligned access code safe for unaligned access Stefan Roese
2009-10-29 11:24 ` Remy Bohmer
2009-10-29 14:30 ` Tom
2009-10-29 14:34 ` Remy Bohmer
2009-10-29 15:17 ` Tom
2009-10-29 15:34 ` Remy Bohmer
2009-10-29 15:40 ` Stefan Roese
2009-10-29 17:51 ` Tom
2009-11-23 22:46 ` Wolfgang Denk
2009-11-24 4:05 ` Stefan Roese
2009-11-24 10:07 ` Remy Bohmer
2009-11-24 21:41 ` Wolfgang Denk
2009-11-23 22:44 ` [U-Boot] [PATCH] Add support for CS2 dataflash for Atmel-SPI Wolfgang Denk
2009-11-23 22:43 ` [U-Boot] [PATCH] Fix mingw tools build Wolfgang Denk
2009-11-23 22:43 ` [U-Boot] [PATCH] Building of FIT images does not work Wolfgang Denk
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=1256764421-27799-4-git-send-email-linux@bohmer.net \
--to=linux@bohmer.net \
--cc=u-boot@lists.denx.de \
/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