]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/asm-frv/unaligned.h
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
17 * Unaligned accesses on uClinux can't be performed in a fault handler - the
18 * CPU detects them as imprecise exceptions making this impossible.
20 * With the FR451, however, they are precise, and so we used to fix them up in
21 * the memory access fault handler. However, instruction bundling make this
22 * impractical. So, now we fall back to using memcpy.
27 * The asm statement in the macros below is a way to get GCC to copy a
28 * value from one variable to another without having any clue it's
29 * actually doing so, so that it won't have any idea that the values
30 * in the two variables are related.
33 #define get_unaligned(ptr) ({ \
34 typeof((*(ptr))) __x; \
36 asm("" : "=r" (__ptrcopy) : "0" (ptr)); \
37 memcpy(&__x, __ptrcopy, sizeof(*(ptr))); \
41 #define put_unaligned(val, ptr) ({ \
42 typeof((*(ptr))) __x = (val); \
44 asm("" : "=r" (__ptrcopy) : "0" (ptr)); \
45 memcpy(__ptrcopy, &__x, sizeof(*(ptr))); \
48 extern int handle_misalignment(unsigned long esr0
, unsigned long ear0
, unsigned long epcr0
);
52 #define get_unaligned(ptr) \
55 const char *__p = (const char *) (ptr); \
57 switch (sizeof(x)) { \
64 asm(" ldub%I2 %M2,%0 \n" \
65 " ldub%I3.p %M3,%1 \n" \
68 : "=&r"(x), "=&r"(a) \
69 : "m"(__p[0]), "m"(__p[1]) \
77 asm(" ldub%I2 %M2,%0 \n" \
78 " ldub%I3.p %M3,%1 \n" \
81 " ldub%I4.p %M4,%1 \n" \
84 " ldub%I5.p %M5,%1 \n" \
87 : "=&r"(x), "=&r"(a) \
88 : "m"(__p[0]), "m"(__p[1]), "m"(__p[2]), "m"(__p[3]) \
95 union { uint64_t x; u32 y[2]; } z; \
97 asm(" ldub%I3 %M3,%0 \n" \
98 " ldub%I4.p %M4,%2 \n" \
101 " ldub%I5.p %M5,%2 \n" \
102 " slli %0,#8,%0 \n" \
104 " ldub%I6.p %M6,%2 \n" \
105 " slli %0,#8,%0 \n" \
107 " ldub%I7 %M7,%1 \n" \
108 " ldub%I8.p %M8,%2 \n" \
109 " slli %1,#8,%1 \n" \
111 " ldub%I9.p %M9,%2 \n" \
112 " slli %1,#8,%1 \n" \
114 " ldub%I10.p %M10,%2 \n" \
115 " slli %1,#8,%1 \n" \
117 : "=&r"(z.y[0]), "=&r"(z.y[1]), "=&r"(a) \
118 : "m"(__p[0]), "m"(__p[1]), "m"(__p[2]), "m"(__p[3]), \
119 "m"(__p[4]), "m"(__p[5]), "m"(__p[6]), "m"(__p[7]) \
134 #define put_unaligned(val, ptr) \
136 char *__p = (char *) (ptr); \
139 switch (sizeof(*ptr)) { \
142 asm(" stb%I1.p %0,%M1 \n" \
143 " srli %0,#8,%0 \n" \
144 " stb%I2 %0,%M2 \n" \
145 : "=r"(x), "=m"(__p[1]), "=m"(__p[0]) \
153 asm(" stb%I1.p %0,%M1 \n" \
154 " srli %0,#8,%0 \n" \
155 " stb%I2.p %0,%M2 \n" \
156 " srli %0,#8,%0 \n" \
157 " stb%I3.p %0,%M3 \n" \
158 " srli %0,#8,%0 \n" \
159 " stb%I4 %0,%M4 \n" \
160 : "=r"(x), "=m"(__p[3]), "=m"(__p[2]), "=m"(__p[1]), "=m"(__p[0]) \
168 uint32_t __high, __low; \
169 __high = (uint64_t)val >> 32; \
170 __low = val & 0xffffffff; \
171 asm(" stb%I2.p %0,%M2 \n" \
172 " srli %0,#8,%0 \n" \
173 " stb%I3.p %0,%M3 \n" \
174 " srli %0,#8,%0 \n" \
175 " stb%I4.p %0,%M4 \n" \
176 " srli %0,#8,%0 \n" \
177 " stb%I5.p %0,%M5 \n" \
178 " srli %0,#8,%0 \n" \
179 " stb%I6.p %1,%M6 \n" \
180 " srli %1,#8,%1 \n" \
181 " stb%I7.p %1,%M7 \n" \
182 " srli %1,#8,%1 \n" \
183 " stb%I8.p %1,%M8 \n" \
184 " srli %1,#8,%1 \n" \
185 " stb%I9 %1,%M9 \n" \
186 : "=&r"(__low), "=&r"(__high), "=m"(__p[7]), "=m"(__p[6]), \
187 "=m"(__p[5]), "=m"(__p[4]), "=m"(__p[3]), "=m"(__p[2]), \
188 "=m"(__p[1]), "=m"(__p[0]) \
189 : "0"(__low), "1"(__high) \