patch-2.3.23 linux/include/asm-arm/unaligned.h
Next file: linux/include/asm-arm/unistd.h
Previous file: linux/include/asm-arm/uaccess.h
Back to the patch index
Back to the overall index
- Lines: 94
- Date:
Wed Oct 20 16:29:08 1999
- Orig file:
v2.3.22/linux/include/asm-arm/unaligned.h
- Orig date:
Tue Jan 20 16:39:43 1998
diff -u --recursive --new-file v2.3.22/linux/include/asm-arm/unaligned.h linux/include/asm-arm/unaligned.h
@@ -1,59 +1,46 @@
-#ifndef __ARM_UNALIGNED_H
-#define __ARM_UNALIGNED_H
+#ifndef __ASM_ARM_UNALIGNED_H
+#define __ASM_ARM_UNALIGNED_H
#define get_unaligned(ptr) \
- ((__typeof__(*(ptr)))__get_unaligned((ptr), sizeof(*(ptr))))
+ ((__typeof__(*(ptr)))__get_unaligned_size((ptr), sizeof(*(ptr))))
#define put_unaligned(val, ptr) \
- __put_unaligned((unsigned long)(val), (ptr), sizeof(*(ptr)))
+ __put_unaligned_size((unsigned long)(val), (ptr), sizeof(*(ptr)))
-extern void bad_unaligned_access_length (void);
-
-extern inline unsigned long __get_unaligned(const void *ptr, size_t size)
+/*
+ * We use a similar method to the uaccess.h badness detection.
+ *
+ * These are actually never defined anywhere, and therefore
+ * catch errors at compile/link time. Don't be tempted to
+ * provide a declaration for them; doing so will mask the
+ * errors.
+ */
+extern unsigned long __get_unaligned_bad(void);
+extern void __put_unaligned_bad(void);
+
+extern __inline__ unsigned long __get_unaligned_size(const void *ptr, size_t size)
{
- unsigned long val;
- switch (size) {
- case 1:
- val = *(const unsigned char *)ptr;
- break;
-
- case 2:
- val = ((const unsigned char *)ptr)[0] | (((const unsigned char *)ptr)[1] << 8);
- break;
-
- case 4:
- val = ((const unsigned char *)ptr)[0] | (((const unsigned char *)ptr)[1] << 8) |
- (((const unsigned char *)ptr)[2]) << 16 | (((const unsigned char *)ptr)[3] << 24);
- break;
-
- default:
- bad_unaligned_access_length ();
- }
- return val;
+ const unsigned char *p = (const unsigned char *)ptr;
+ unsigned long val = 0;
+
+ switch (size) {
+ case 4: val = p[2] << 16 | p[3] << 24;
+ case 2: val |= p[1] << 8;
+ case 1: val |= p[0]; break;
+ default: val = __get_unaligned_bad(); break;
+ }
+ return val;
}
-extern inline void __put_unaligned(unsigned long val, void *ptr, size_t size)
+extern __inline__ void __put_unaligned_size(unsigned long val, void *ptr, size_t size)
{
- switch (size) {
- case 1:
- *(unsigned char *)ptr = val;
- break;
-
- case 2:
- ((unsigned char *)ptr)[0] = val;
- ((unsigned char *)ptr)[1] = val >> 8;
- break;
-
- case 4:
- ((unsigned char *)ptr)[0] = val;
- ((unsigned char *)ptr)[1] = val >> 8;
- ((unsigned char *)ptr)[2] = val >> 16;
- ((unsigned char *)ptr)[3] = val >> 24;
- break;
-
- default:
- bad_unaligned_access_length ();
- }
+ switch (size) {
+ case 4: ((unsigned char *)ptr)[3] = val >> 24;
+ ((unsigned char *)ptr)[2] = val >> 16;
+ case 2: ((unsigned char *)ptr)[1] = val >> 8;
+ case 1: ((unsigned char *)ptr)[0] = val; break;
+ default: __put_unaligned_bad(); break;
+ }
}
#endif
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)