Subversion Repositories HelenOS

Rev

Rev 4153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4581
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>
38
#include <arch/types.h>
39
 
39
 
40
#if !(defined(ARCH_IS_BIG_ENDIAN) ^ defined(ARCH_IS_LITTLE_ENDIAN))
40
#if !(defined(__BE__) ^ defined(__LE__))
41
#error The architecture must be either big-endian or little-endian.
41
    #error The architecture must be either big-endian or little-endian.
42
#endif
42
#endif
43
 
43
 
44
#ifdef ARCH_IS_BIG_ENDIAN
44
#ifdef __BE__
45
 
45
 
46
#define uint16_t_le2host(n)     uint16_t_byteorder_swap(n)
46
#define uint16_t_le2host(n)  (uint16_t_byteorder_swap(n))
47
#define uint32_t_le2host(n)     uint32_t_byteorder_swap(n)
47
#define uint32_t_le2host(n)  (uint32_t_byteorder_swap(n))
48
#define uint64_t_le2host(n)     uint64_t_byteorder_swap(n)
48
#define uint64_t_le2host(n)  (uint64_t_byteorder_swap(n))
49
 
49
 
50
#define uint16_t_be2host(n)     (n)
50
#define uint16_t_be2host(n)  (n)
51
#define uint32_t_be2host(n)     (n)
51
#define uint32_t_be2host(n)  (n)
52
#define uint64_t_be2host(n)     (n)
52
#define uint64_t_be2host(n)  (n)
53
 
53
 
54
#define host2uint16_t_le(n)     uint16_t_byteorder_swap(n)
54
#define host2uint16_t_le(n)  (uint16_t_byteorder_swap(n))
55
#define host2uint32_t_le(n)     uint32_t_byteorder_swap(n)
55
#define host2uint32_t_le(n)  (uint32_t_byteorder_swap(n))
56
#define host2uint64_t_le(n)     uint64_t_byteorder_swap(n)
56
#define host2uint64_t_le(n)  (uint64_t_byteorder_swap(n))
57
 
57
 
58
#define host2uint16_t_be(n)     (n)
58
#define host2uint16_t_be(n)  (n)
59
#define host2uint32_t_be(n)     (n)
59
#define host2uint32_t_be(n)  (n)
60
#define host2uint64_t_be(n)     (n)
60
#define host2uint64_t_be(n)  (n)
61
 
61
 
62
#else
62
#else
63
 
63
 
64
#define uint16_t_le2host(n)     (n)
64
#define uint16_t_le2host(n)  (n)
65
#define uint32_t_le2host(n)     (n)
65
#define uint32_t_le2host(n)  (n)
66
#define uint64_t_le2host(n)     (n)
66
#define uint64_t_le2host(n)  (n)
67
 
67
 
68
#define uint16_t_be2host(n)     uint16_t_byteorder_swap(n)
68
#define uint16_t_be2host(n)  (uint16_t_byteorder_swap(n))
69
#define uint32_t_be2host(n)     uint32_t_byteorder_swap(n)
69
#define uint32_t_be2host(n)  (uint32_t_byteorder_swap(n))
70
#define uint64_t_be2host(n)     uint64_t_byteorder_swap(n)
70
#define uint64_t_be2host(n)  (uint64_t_byteorder_swap(n))
71
 
71
 
72
#define host2uint16_t_le(n)     (n)
72
#define host2uint16_t_le(n)  (n)
73
#define host2uint32_t_le(n)     (n)
73
#define host2uint32_t_le(n)  (n)
74
#define host2uint64_t_le(n)     (n)
74
#define host2uint64_t_le(n)  (n)
75
 
75
 
76
#define host2uint16_t_be(n)     uint16_t_byteorder_swap(n)
76
#define host2uint16_t_be(n)  (uint16_t_byteorder_swap(n))
77
#define host2uint32_t_be(n)     uint32_t_byteorder_swap(n)
77
#define host2uint32_t_be(n)  (uint32_t_byteorder_swap(n))
78
#define host2uint64_t_be(n)     uint64_t_byteorder_swap(n)
78
#define host2uint64_t_be(n)  (uint64_t_byteorder_swap(n))
79
 
79
 
80
#endif
80
#endif
81
 
81
 
82
static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
82
static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
83
{
83
{