1/* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 .file "byteorder.s" 27 28#include "SYS.h" 29 30 /* 31 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs. 32 * As such, they could be implemented as a single routine, using 33 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so 34 * that they will have unique addresses, allowing DTrace and 35 * other debuggers to tell them apart. 36 */ 37 38/ unsigned long htonl( hl ) 39/ unsigned long ntohl( hl ) 40/ long hl; 41/ reverses the byte order of 'long hl' 42/ 43 ENTRY(htonl) 44 movl 4(%esp), %eax / %eax = hl 45 bswap %eax / reverses the byte order of %eax 46 ret / return (%eax) 47 SET_SIZE(htonl) 48 49 ENTRY(ntohl) 50 movl 4(%esp), %eax / %eax = hl 51 bswap %eax / reverses the byte order of %eax 52 ret / return (%eax) 53 SET_SIZE(ntohl) 54 55/ unsigned short htons( hs ) 56/ short hs; 57/ 58/ reverses the byte order in hs. 59/ 60 ENTRY(htons) 61 movl 4(%esp), %eax / %eax = hs 62 bswap %eax / reverses the byte order of %eax 63 shrl $16, %eax / moves high 16-bit to low 16-bit 64 ret / return (%eax) 65 SET_SIZE(htons) 66 67 ENTRY(ntohs) 68 movl 4(%esp), %eax / %eax = hs 69 bswap %eax / reverses the byte order of %eax 70 shrl $16, %eax / moves high 16-bit to low 16-bit 71 ret / return (%eax) 72 SET_SIZE(ntohs) 73