KallistiOS
git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
byteorder.h
Go to the documentation of this file.
1
/* KallistiOS ##version##
2
3
arch/dreamcast/include/arch/byteorder.h
4
Copyright (C) 2015 Lawrence Sebald
5
6
*/
7
8
/** \file arch/byteorder.h
9
\brief Byte-order related macros.
10
\ingroup system_arch
11
12
This file contains architecture-specific byte-order related macros and/or
13
functions. Each platform should define six macros/functions in this file:
14
arch_swap16, arch_swap32, arch_ntohs, arch_ntohl, arch_htons, and
15
arch_htonl. The first two of these swap the byte order of 16-bit and 32-bit
16
integers, respectively. The other four macros will be used by the kernel to
17
implement the network-related byte order functions.
18
19
\author Lawrence Sebald
20
*/
21
22
#ifndef __ARCH_BYTEORDER_H
23
#define __ARCH_BYTEORDER_H
24
25
#include <sys/cdefs.h>
26
__BEGIN_DECLS
27
28
#include <
sys/_types.h
>
29
30
#ifdef BYTE_ORDER
31
/* If we've included <arch/types.h>, this might already be defined... */
32
#undef BYTE_ORDER
33
#endif
34
35
/** \defgroup system_arch Byte Order
36
\brief Byte-order management for the SH4 architecture
37
\ingroup arch
38
39
@{
40
*/
41
42
/** \brief Define the byte-order of the platform in use. */
43
#define BYTE_ORDER LITTLE_ENDIAN
44
45
/** \brief Swap the byte order of a 16-bit integer.
46
47
This macro swaps the byte order of a 16-bit integer in an architecture-
48
defined manner.
49
50
\param x The value to be byte-swapped. This should be a uint16,
51
or equivalent.
52
\return The swapped value.
53
*/
54
#define arch_swap16(x) ({ \
55
uint16 __x = (x); \
56
__asm__ __volatile__("swap.b %0, %0" : "=r" (__x) : "0" (__x)); \
57
__x; \
58
})
59
60
/** \brief Swap the byte order of a 32-bit integer.
61
62
This macro swaps the byte order of a 32-bit integer in an architecture-
63
defined manner.
64
65
\param x The value to be byte-swapped. This should be a uint32,
66
or equivalent.
67
\return The swapped value.
68
*/
69
#define arch_swap32(x) ({ \
70
uint32 __x = (x); \
71
__asm__ __volatile__("swap.b %0, %0\n\t" \
72
"swap.w %0, %0\n\t" \
73
"swap.b %0, %0\n\t" : "=r"(__x) : "0" (__x)); \
74
__x; \
75
})
76
77
/** \brief Convert network-to-host short.
78
79
This macro converts a network byte order (big endian) value to the host's
80
native byte order. On a little endian system (like the Dreamcast), this
81
should just call arch_swap16(). On a big endian system, this should be a
82
no-op.
83
84
\param x The value to be converted. This should be a uint16,
85
or equivalent.
86
\return The converted value.
87
*/
88
#define arch_ntohs(x) arch_swap16(x)
89
90
/** \brief Convert network-to-host long.
91
92
This macro converts a network byte order (big endian) value to the host's
93
native byte order. On a little endian system (like the Dreamcast), this
94
should just call arch_swap32(). On a big endian system, this should be a
95
no-op.
96
97
\param x The value to be converted. This should be a uint32,
98
or equivalent.
99
\return The converted value.
100
*/
101
#define arch_ntohl(x) arch_swap32(x)
102
103
/** \brief Convert host-to-network short.
104
105
This macro converts a value in the host's native byte order to network byte
106
order (big endian). On a little endian system (like the Dreamcast), this
107
should just call arch_swap16(). On a big endian system, this should be a
108
no-op.
109
110
\param x The value to be converted. This should be a uint16,
111
or equivalent.
112
\return The converted value.
113
*/
114
#define arch_htons(x) arch_swap16(x)
115
116
/** \brief Convert host-to-network long.
117
118
This macro converts a value in the host's native byte order to network byte
119
order (big endian). On a little endian system (like the Dreamcast), this
120
should just call arch_swap32(). On a big endian system, this should be a
121
no-op.
122
123
\param x The value to be converted. This should be a uint32,
124
or equivalent.
125
\return The converted value.
126
*/
127
#define arch_htonl(x) arch_swap32(x)
128
129
/** @} */
130
131
__END_DECLS
132
133
#endif
/* !__ARCH_BYTEORDER_H */
_types.h
Internal typedefs.
kernel
arch
dreamcast
include
arch
byteorder.h
Generated by
1.12.0