10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54292Sab196087 * Common Development and Distribution License (the "License"). 64292Sab196087 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate/* 224292Sab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 26*7298SMark.J.Nelson@Sun.COM .file "byteorder.s" 270Sstevel@tonic-gate 280Sstevel@tonic-gate#include "SYS.h" 290Sstevel@tonic-gate 304292Sab196087 /* 314292Sab196087 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs. 324292Sab196087 * As such, they could be implemented as a single routine, using 334292Sab196087 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so 344292Sab196087 * that they will have unique addresses, allowing DTrace and 354292Sab196087 * other debuggers to tell them apart. 364292Sab196087 */ 374292Sab196087 380Sstevel@tonic-gate/ unsigned long htonl( hl ) 390Sstevel@tonic-gate/ unsigned long ntohl( hl ) 400Sstevel@tonic-gate/ long hl; 410Sstevel@tonic-gate/ reverses the byte order of 'long hl' 420Sstevel@tonic-gate/ 430Sstevel@tonic-gate ENTRY(htonl) 444292Sab196087 movl 4(%esp), %eax / %eax = hl 454292Sab196087 bswap %eax / reverses the byte order of %eax 464292Sab196087 ret / return (%eax) 474292Sab196087 SET_SIZE(htonl) 484292Sab196087 490Sstevel@tonic-gate ENTRY(ntohl) 500Sstevel@tonic-gate movl 4(%esp), %eax / %eax = hl 510Sstevel@tonic-gate bswap %eax / reverses the byte order of %eax 520Sstevel@tonic-gate ret / return (%eax) 530Sstevel@tonic-gate SET_SIZE(ntohl) 540Sstevel@tonic-gate 550Sstevel@tonic-gate/ unsigned short htons( hs ) 560Sstevel@tonic-gate/ short hs; 570Sstevel@tonic-gate/ 580Sstevel@tonic-gate/ reverses the byte order in hs. 590Sstevel@tonic-gate/ 600Sstevel@tonic-gate ENTRY(htons) 614292Sab196087 movl 4(%esp), %eax / %eax = hs 624292Sab196087 bswap %eax / reverses the byte order of %eax 634292Sab196087 shrl $16, %eax / moves high 16-bit to low 16-bit 644292Sab196087 ret / return (%eax) 654292Sab196087 SET_SIZE(htons) 664292Sab196087 670Sstevel@tonic-gate ENTRY(ntohs) 680Sstevel@tonic-gate movl 4(%esp), %eax / %eax = hs 690Sstevel@tonic-gate bswap %eax / reverses the byte order of %eax 700Sstevel@tonic-gate shrl $16, %eax / moves high 16-bit to low 16-bit 710Sstevel@tonic-gate ret / return (%eax) 720Sstevel@tonic-gate SET_SIZE(ntohs) 73