Subversion Repositories HelenOS

Rev

Rev 4333 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4333 Rev 4556
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup generic
29
/** @addtogroup generic
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#ifndef KERN_BYTEORDER_H_
35
#ifndef KERN_BYTEORDER_H_
36
#define KERN_BYTEORDER_H_
36
#define KERN_BYTEORDER_H_
37
 
37
 
38
#include <arch/byteorder.h>
-
 
39
#include <arch/types.h>
38
#include <arch/types.h>
40
 
39
 
41
#if !(defined(ARCH_IS_BIG_ENDIAN) ^ defined(ARCH_IS_LITTLE_ENDIAN))
40
#if !(defined(__BE__) ^ defined(__LE__))
42
#error The architecture must be either big-endian or little-endian.
41
    #error The architecture must be either big-endian or little-endian.
43
#endif
42
#endif
44
 
43
 
45
#ifdef ARCH_IS_BIG_ENDIAN
44
#ifdef __BE__
46
 
45
 
47
#define uint16_t_le2host(n)     uint16_t_byteorder_swap(n)
46
#define uint16_t_le2host(n)  (uint16_t_byteorder_swap(n))
48
#define uint32_t_le2host(n)     uint32_t_byteorder_swap(n)
47
#define uint32_t_le2host(n)  (uint32_t_byteorder_swap(n))
49
#define uint64_t_le2host(n)     uint64_t_byteorder_swap(n)
48
#define uint64_t_le2host(n)  (uint64_t_byteorder_swap(n))
50
 
49
 
51
#define uint16_t_be2host(n)     (n)
50
#define uint16_t_be2host(n)  (n)
52
#define uint32_t_be2host(n)     (n)
51
#define uint32_t_be2host(n)  (n)
53
#define uint64_t_be2host(n)     (n)
52
#define uint64_t_be2host(n)  (n)
54
 
53
 
55
#define host2uint16_t_le(n)     uint16_t_byteorder_swap(n)
54
#define host2uint16_t_le(n)  (uint16_t_byteorder_swap(n))
56
#define host2uint32_t_le(n)     uint32_t_byteorder_swap(n)
55
#define host2uint32_t_le(n)  (uint32_t_byteorder_swap(n))
57
#define host2uint64_t_le(n)     uint64_t_byteorder_swap(n)
56
#define host2uint64_t_le(n)  (uint64_t_byteorder_swap(n))
58
 
57
 
59
#define host2uint16_t_be(n)     (n)
58
#define host2uint16_t_be(n)  (n)
60
#define host2uint32_t_be(n)     (n)
59
#define host2uint32_t_be(n)  (n)
61
#define host2uint64_t_be(n)     (n)
60
#define host2uint64_t_be(n)  (n)
62
 
61
 
63
#else
62
#else
64
 
63
 
65
#define uint16_t_le2host(n)     (n)
64
#define uint16_t_le2host(n)  (n)
66
#define uint32_t_le2host(n)     (n)
65
#define uint32_t_le2host(n)  (n)
67
#define uint64_t_le2host(n)     (n)
66
#define uint64_t_le2host(n)  (n)
68
 
67
 
69
#define uint16_t_be2host(n)     uint16_t_byteorder_swap(n)
68
#define uint16_t_be2host(n)  (uint16_t_byteorder_swap(n))
70
#define uint32_t_be2host(n)     uint32_t_byteorder_swap(n)
69
#define uint32_t_be2host(n)  (uint32_t_byteorder_swap(n))
71
#define uint64_t_be2host(n)     uint64_t_byteorder_swap(n)
70
#define uint64_t_be2host(n)  (uint64_t_byteorder_swap(n))
72
 
71
 
73
#define host2uint16_t_le(n)     (n)
72
#define host2uint16_t_le(n)  (n)
74
#define host2uint32_t_le(n)     (n)
73
#define host2uint32_t_le(n)  (n)
75
#define host2uint64_t_le(n)     (n)
74
#define host2uint64_t_le(n)  (n)
76
 
75
 
77
#define host2uint16_t_be(n)     uint16_t_byteorder_swap(n)
76
#define host2uint16_t_be(n)  (uint16_t_byteorder_swap(n))
78
#define host2uint32_t_be(n)     uint32_t_byteorder_swap(n)
77
#define host2uint32_t_be(n)  (uint32_t_byteorder_swap(n))
79
#define host2uint64_t_be(n)     uint64_t_byteorder_swap(n)
78
#define host2uint64_t_be(n)  (uint64_t_byteorder_swap(n))
80
 
79
 
81
#endif
80
#endif
82
 
81
 
83
static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
82
static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
84
{
83
{