1 /* |
1 /* |
2 * CDDL HEADER START |
2 * CDDL HEADER START |
3 * |
3 * |
4 * The contents of this file are subject to the terms of the |
4 * The contents of this file are subject to the terms of the |
5 * Common Development and Distribution License, Version 1.0 only |
5 * Common Development and Distribution License (the "License"). |
6 * (the "License"). You may not use this file except in compliance |
6 * You may not use this file except in compliance with the License. |
7 * with the License. |
|
8 * |
7 * |
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
10 * or http://www.opensolaris.org/os/licensing. |
9 * or http://www.opensolaris.org/os/licensing. |
11 * See the License for the specific language governing permissions |
10 * See the License for the specific language governing permissions |
12 * and limitations under the License. |
11 * and limitations under the License. |
18 * information: Portions Copyright [yyyy] [name of copyright owner] |
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
19 * |
18 * |
20 * CDDL HEADER END |
19 * CDDL HEADER END |
21 */ |
20 */ |
22 /* |
21 /* |
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. |
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. |
23 * Use is subject to license terms. |
25 */ |
24 */ |
26 |
25 |
27 .ident "%Z%%M% %I% %E% SMI" |
26 .ident "%Z%%M% %I% %E% SMI" |
28 |
27 |
29 .file "%M%" |
28 .file "%M%" |
30 |
29 |
31 #include "SYS.h" |
30 #include "SYS.h" |
32 |
31 |
|
32 /* |
|
33 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs. |
|
34 * As such, they could be implemented as a single routine, using |
|
35 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so |
|
36 * that they will have unique addresses, allowing DTrace and |
|
37 * other debuggers to tell them apart. |
|
38 */ |
|
39 |
|
40 |
33 /* |
41 /* |
34 * unsigned long htonl( hl ) |
42 * unsigned long htonl( hl ) |
35 * unsigned long ntohl( hl ) |
43 * unsigned long ntohl( hl ) |
36 * long hl; |
44 * long hl; |
37 * reverses the byte order of 'uint32_t hl' |
45 * reverses the byte order of 'uint32_t hl' |
38 */ |
46 */ |
39 ENTRY(htonl) |
47 ENTRY(htonl) |
40 ALTENTRY(ntohl) |
|
41 movl %edi, %eax /* %eax = hl */ |
48 movl %edi, %eax /* %eax = hl */ |
42 bswap %eax /* reverses the byte order of %eax */ |
49 bswap %eax /* reverses the byte order of %eax */ |
43 ret /* return (%eax) */ |
50 ret /* return (%eax) */ |
44 SET_SIZE(htonl) |
51 SET_SIZE(htonl) |
|
52 |
|
53 ENTRY(ntohl) |
|
54 movl %edi, %eax /* %eax = hl */ |
|
55 bswap %eax /* reverses the byte order of %eax */ |
|
56 ret /* return (%eax) */ |
45 SET_SIZE(ntohl) |
57 SET_SIZE(ntohl) |
46 |
58 |
47 /* |
59 /* |
48 * unsigned short htons( hs ) |
60 * unsigned short htons( hs ) |
49 * short hs; |
61 * short hs; |
50 * |
62 * |
51 * reverses the byte order in hs. |
63 * reverses the byte order in hs. |
52 */ |
64 */ |
53 ENTRY(htons) |
65 ENTRY(htons) |
54 ALTENTRY(ntohs) |
|
55 movl %edi, %eax /* %eax = hs */ |
66 movl %edi, %eax /* %eax = hs */ |
56 bswap %eax /* reverses the byte order of %eax */ |
67 bswap %eax /* reverses the byte order of %eax */ |
57 shrl $16, %eax /* moves high 16-bit to low 16-bit */ |
68 shrl $16, %eax /* moves high 16-bit to low 16-bit */ |
58 ret /* return (%eax) */ |
69 ret /* return (%eax) */ |
59 SET_SIZE(htons) |
70 SET_SIZE(htons) |
|
71 |
|
72 ENTRY(ntohs) |
|
73 movl %edi, %eax /* %eax = hs */ |
|
74 bswap %eax /* reverses the byte order of %eax */ |
|
75 shrl $16, %eax /* moves high 16-bit to low 16-bit */ |
|
76 ret /* return (%eax) */ |
60 SET_SIZE(ntohs) |
77 SET_SIZE(ntohs) |