import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / i386 / gen / byteorder.s
blob2b1204d1ba4ce58fea6b7213b19484ee899357d8
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2015, Joyent, Inc.
27 .file "byteorder.s"
29 #include "SYS.h"
32 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
33 * As such, they could be implemented as a single routine, using
34 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
35 * that they will have unique addresses, allowing DTrace and
36 * other debuggers to tell them apart. With the endian
37 * functions we do the same, even though it's similarly
38 * repetitive.
41 / unsigned long htonl( hl )
42 / unsigned long ntohl( hl )
43 / long hl;
44 / reverses the byte order of 'long hl'
46 ENTRY(htonl)
47 movl 4(%esp), %eax / %eax = hl
48 bswap %eax / reverses the byte order of %eax
49 ret / return (%eax)
50 SET_SIZE(htonl)
52 ENTRY(ntohl)
53 movl 4(%esp), %eax / %eax = hl
54 bswap %eax / reverses the byte order of %eax
55 ret / return (%eax)
56 SET_SIZE(ntohl)
58 / unsigned short htons( hs )
59 / short hs;
61 / reverses the byte order in hs.
63 ENTRY(htons)
64 movl 4(%esp), %eax / %eax = hs
65 bswap %eax / reverses the byte order of %eax
66 shrl $16, %eax / moves high 16-bit to low 16-bit
67 ret / return (%eax)
68 SET_SIZE(htons)
70 ENTRY(ntohs)
71 movl 4(%esp), %eax / %eax = hs
72 bswap %eax / reverses the byte order of %eax
73 shrl $16, %eax / moves high 16-bit to low 16-bit
74 ret / return (%eax)
75 SET_SIZE(ntohs)
77 / uint16_t htobe16(uint16_t in)
79 / Convert in to big endian, eg. htons()
81 ENTRY(htobe16)
82 movl 4(%esp), %eax / %eax = hs
83 bswap %eax / reverses the byte order of %eax
84 shrl $16, %eax / moves high 16-bit to low 16-bit
85 ret / return (%eax)
86 SET_SIZE(htobe16)
88 / uint32_t htobe32(uint32_t in)
90 / Convert in to big endian, eg. htonl()
92 ENTRY(htobe32)
93 movl 4(%esp), %eax / %eax = hl
94 bswap %eax / reverses the byte order of %eax
95 ret / return (%eax)
96 SET_SIZE(htobe32)
98 / uint16_t betoh16(uint16_t in)
99 / uint16_t be16toh(uint16_t in)
101 / Convert in to little endian, eg. ntohs()
103 ENTRY(betoh16)
104 movl 4(%esp), %eax / %eax = hs
105 bswap %eax / reverses the byte order of %eax
106 shrl $16, %eax / moves high 16-bit to low 16-bit
107 ret / return (%eax)
108 SET_SIZE(betoh16)
110 ENTRY(be16toh)
111 movl 4(%esp), %eax / %eax = hs
112 bswap %eax / reverses the byte order of %eax
113 shrl $16, %eax / moves high 16-bit to low 16-bit
114 ret / return (%eax)
115 SET_SIZE(be16toh)
118 / uint32_t be32toh(uint32_t in)
119 / uint32_t betoh32(uint32_t in)
121 / Convert in to little endian, eg. ntohl()
123 ENTRY(be32toh)
124 movl 4(%esp), %eax / %eax = hl
125 bswap %eax / reverses the byte order of %eax
126 ret / return (%eax)
127 SET_SIZE(be32toh)
129 ENTRY(betoh32)
130 movl 4(%esp), %eax / %eax = hl
131 bswap %eax / reverses the byte order of %eax
132 ret / return (%eax)
133 SET_SIZE(betoh32)