return -EFAULT;
}
+static inline void sign_extend(unsigned int count, unsigned char *dst)
+{
+#ifdef __LITTLE_ENDIAN__
+ if ((count == 2) && dst[1] & 0x80) {
+ dst[2] = 0xff;
+ dst[3] = 0xff;
+ }
+#else
+ if ((count == 2) && dst[2] & 0x80) {
+ dst[0] = 0xff;
+ dst[1] = 0xff;
+ }
+#endif
+}
+
/*
* handle an instruction that does an unaligned memory access by emulating the
* desired behaviour
dst = (unsigned char*) rn;
*(unsigned long*)dst = 0;
-#ifdef __LITTLE_ENDIAN__
- if (copy_from_user(dst, src, count))
- goto fetch_fault;
-
- if ((count == 2) && dst[1] & 0x80) {
- dst[2] = 0xff;
- dst[3] = 0xff;
- }
-#else
+#if !defined(__LITTLE_ENDIAN__)
dst += 4-count;
-
- if (__copy_user(dst, src, count))
+#endif
+ if (copy_from_user(dst, src, count))
goto fetch_fault;
- if ((count == 2) && dst[2] & 0x80) {
- dst[0] = 0xff;
- dst[1] = 0xff;
- }
-#endif
+ sign_extend(count, dst);
} else {
/* to memory */
src = (unsigned char*) rm;
dst = (unsigned char*) rn;
*(unsigned long*)dst = 0;
-#ifdef __LITTLE_ENDIAN__
- if (copy_from_user(dst, src, count))
- goto fetch_fault;
-
- if ((count == 2) && dst[1] & 0x80) {
- dst[2] = 0xff;
- dst[3] = 0xff;
- }
-#else
+#if !defined(__LITTLE_ENDIAN__)
dst += 4-count;
-
+#endif
if (copy_from_user(dst, src, count))
goto fetch_fault;
-
- if ((count == 2) && dst[2] & 0x80) {
- dst[0] = 0xff;
- dst[1] = 0xff;
- }
-#endif
+ sign_extend(count, dst);
ret = 0;
break;
#if !defined(__LITTLE_ENDIAN__)
dst += 2;
#endif
-
if (copy_from_user(dst, src, 2))
goto fetch_fault;
-
-#ifdef __LITTLE_ENDIAN__
- if (dst[1] & 0x80) {
- dst[2] = 0xff;
- dst[3] = 0xff;
- }
-#else
- if (dst[2] & 0x80) {
- dst[0] = 0xff;
- dst[1] = 0xff;
- }
-#endif
+ sign_extend(2, dst);
ret = 0;
break;
}