1 /* unaligned.h: unaligned access handler
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #ifndef _ASM_UNALIGNED_H
13 #define _ASM_UNALIGNED_H
15 #include <linux/config.h>
18 * Unaligned accesses on uClinux can't be performed in a fault handler - the
19 * CPU detects them as imprecise exceptions making this impossible.
21 * With the FR451, however, they are precise, and so we used to fix them up in
22 * the memory access fault handler. However, instruction bundling make this
23 * impractical. So, now we fall back to using memcpy.
28 * The asm statement in the macros below is a way to get GCC to copy a
29 * value from one variable to another without having any clue it's
30 * actually doing so, so that it won't have any idea that the values
31 * in the two variables are related.
34 #define get_unaligned(ptr) ({ \
35 typeof((*(ptr))) __x; \
37 asm("" : "=r" (__ptrcopy) : "0" (ptr)); \
38 memcpy(&__x, __ptrcopy, sizeof(*(ptr))); \
42 #define put_unaligned(val, ptr) ({ \
43 typeof((*(ptr))) __x = (val); \
45 asm("" : "=r" (__ptrcopy) : "0" (ptr)); \
46 memcpy(__ptrcopy, &__x, sizeof(*(ptr))); \
49 extern int handle_misalignment(unsigned long esr0
, unsigned long ear0
, unsigned long epcr0
);
53 #define get_unaligned(ptr) \
56 const char *__p = (const char *) (ptr); \
58 switch (sizeof(x)) { \
65 asm(" ldub%I2 %M2,%0 \n" \
66 " ldub%I3.p %M3,%1 \n" \
69 : "=&r"(x), "=&r"(a) \
70 : "m"(__p[0]), "m"(__p[1]) \
78 asm(" ldub%I2 %M2,%0 \n" \
79 " ldub%I3.p %M3,%1 \n" \
82 " ldub%I4.p %M4,%1 \n" \
85 " ldub%I5.p %M5,%1 \n" \
88 : "=&r"(x), "=&r"(a) \
89 : "m"(__p[0]), "m"(__p[1]), "m"(__p[2]), "m"(__p[3]) \
96 union { uint64_t x; u32 y[2]; } z; \
98 asm(" ldub%I3 %M3,%0 \n" \
99 " ldub%I4.p %M4,%2 \n" \
100 " slli %0,#8,%0 \n" \
102 " ldub%I5.p %M5,%2 \n" \
103 " slli %0,#8,%0 \n" \
105 " ldub%I6.p %M6,%2 \n" \
106 " slli %0,#8,%0 \n" \
108 " ldub%I7 %M7,%1 \n" \
109 " ldub%I8.p %M8,%2 \n" \
110 " slli %1,#8,%1 \n" \
112 " ldub%I9.p %M9,%2 \n" \
113 " slli %1,#8,%1 \n" \
115 " ldub%I10.p %M10,%2 \n" \
116 " slli %1,#8,%1 \n" \
118 : "=&r"(z.y[0]), "=&r"(z.y[1]), "=&r"(a) \
119 : "m"(__p[0]), "m"(__p[1]), "m"(__p[2]), "m"(__p[3]), \
120 "m"(__p[4]), "m"(__p[5]), "m"(__p[6]), "m"(__p[7]) \
135 #define put_unaligned(val, ptr) \
137 char *__p = (char *) (ptr); \
140 switch (sizeof(*ptr)) { \
143 asm(" stb%I1.p %0,%M1 \n" \
144 " srli %0,#8,%0 \n" \
145 " stb%I2 %0,%M2 \n" \
146 : "=r"(x), "=m"(__p[1]), "=m"(__p[0]) \
154 asm(" stb%I1.p %0,%M1 \n" \
155 " srli %0,#8,%0 \n" \
156 " stb%I2.p %0,%M2 \n" \
157 " srli %0,#8,%0 \n" \
158 " stb%I3.p %0,%M3 \n" \
159 " srli %0,#8,%0 \n" \
160 " stb%I4 %0,%M4 \n" \
161 : "=r"(x), "=m"(__p[3]), "=m"(__p[2]), "=m"(__p[1]), "=m"(__p[0]) \
169 uint32_t __high, __low; \
170 __high = (uint64_t)val >> 32; \
171 __low = val & 0xffffffff; \
172 asm(" stb%I2.p %0,%M2 \n" \
173 " srli %0,#8,%0 \n" \
174 " stb%I3.p %0,%M3 \n" \
175 " srli %0,#8,%0 \n" \
176 " stb%I4.p %0,%M4 \n" \
177 " srli %0,#8,%0 \n" \
178 " stb%I5.p %0,%M5 \n" \
179 " srli %0,#8,%0 \n" \
180 " stb%I6.p %1,%M6 \n" \
181 " srli %1,#8,%1 \n" \
182 " stb%I7.p %1,%M7 \n" \
183 " srli %1,#8,%1 \n" \
184 " stb%I8.p %1,%M8 \n" \
185 " srli %1,#8,%1 \n" \
186 " stb%I9 %1,%M9 \n" \
187 : "=&r"(__low), "=&r"(__high), "=m"(__p[7]), "=m"(__p[6]), \
188 "=m"(__p[5]), "=m"(__p[4]), "=m"(__p[3]), "=m"(__p[2]), \
189 "=m"(__p[1]), "=m"(__p[0]) \
190 : "0"(__low), "1"(__high) \