blob: 9b86bd415aa2210d54df83b085415505a040b837 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#ifndef __ARM_UNALIGNED_H
#define __ARM_UNALIGNED_H
#define get_unaligned(ptr) \
((__typeof__(*(ptr)))__get_unaligned((ptr), sizeof(*(ptr))))
#define put_unaligned(val, ptr) \
__put_unaligned((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)
{
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;
}
extern inline void __put_unaligned(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 ();
}
}
#endif
|