17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5dfb96a4fSab196087 * Common Development and Distribution License (the "License"). 6dfb96a4fSab196087 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate/* 22dfb96a4fSab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*3b4b8bdaSRobert Mustacchi * Copyright (c) 2015, Joyent, Inc. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 279a70fc3bSMark J. Nelson .file "byteorder.s" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate#include "SYS.h" 307c478bd9Sstevel@tonic-gate 31dfb96a4fSab196087 /* 32dfb96a4fSab196087 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs. 33dfb96a4fSab196087 * As such, they could be implemented as a single routine, using 34dfb96a4fSab196087 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so 35dfb96a4fSab196087 * that they will have unique addresses, allowing DTrace and 36*3b4b8bdaSRobert Mustacchi * other debuggers to tell them apart. With the endian 37*3b4b8bdaSRobert Mustacchi * functions we do the same, even though it's similarly 38*3b4b8bdaSRobert Mustacchi * repetitive. 39dfb96a4fSab196087 */ 40dfb96a4fSab196087 417c478bd9Sstevel@tonic-gate/ unsigned long htonl( hl ) 427c478bd9Sstevel@tonic-gate/ unsigned long ntohl( hl ) 437c478bd9Sstevel@tonic-gate/ long hl; 447c478bd9Sstevel@tonic-gate/ reverses the byte order of 'long hl' 457c478bd9Sstevel@tonic-gate/ 467c478bd9Sstevel@tonic-gate ENTRY(htonl) 477c478bd9Sstevel@tonic-gate movl 4(%esp), %eax / %eax = hl 487c478bd9Sstevel@tonic-gate bswap %eax / reverses the byte order of %eax 497c478bd9Sstevel@tonic-gate ret / return (%eax) 507c478bd9Sstevel@tonic-gate SET_SIZE(htonl) 51dfb96a4fSab196087 52dfb96a4fSab196087 ENTRY(ntohl) 53dfb96a4fSab196087 movl 4(%esp), %eax / %eax = hl 54dfb96a4fSab196087 bswap %eax / reverses the byte order of %eax 55dfb96a4fSab196087 ret / return (%eax) 567c478bd9Sstevel@tonic-gate SET_SIZE(ntohl) 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate/ unsigned short htons( hs ) 597c478bd9Sstevel@tonic-gate/ short hs; 607c478bd9Sstevel@tonic-gate/ 617c478bd9Sstevel@tonic-gate/ reverses the byte order in hs. 627c478bd9Sstevel@tonic-gate/ 637c478bd9Sstevel@tonic-gate ENTRY(htons) 647c478bd9Sstevel@tonic-gate movl 4(%esp), %eax / %eax = hs 657c478bd9Sstevel@tonic-gate bswap %eax / reverses the byte order of %eax 667c478bd9Sstevel@tonic-gate shrl $16, %eax / moves high 16-bit to low 16-bit 677c478bd9Sstevel@tonic-gate ret / return (%eax) 687c478bd9Sstevel@tonic-gate SET_SIZE(htons) 69dfb96a4fSab196087 70dfb96a4fSab196087 ENTRY(ntohs) 71dfb96a4fSab196087 movl 4(%esp), %eax / %eax = hs 72dfb96a4fSab196087 bswap %eax / reverses the byte order of %eax 73dfb96a4fSab196087 shrl $16, %eax / moves high 16-bit to low 16-bit 74dfb96a4fSab196087 ret / return (%eax) 757c478bd9Sstevel@tonic-gate SET_SIZE(ntohs) 76*3b4b8bdaSRobert Mustacchi 77*3b4b8bdaSRobert Mustacchi/ uint16_t htobe16(uint16_t in) 78*3b4b8bdaSRobert Mustacchi/ 79*3b4b8bdaSRobert Mustacchi/ Convert in to big endian, eg. htons() 80*3b4b8bdaSRobert Mustacchi/ 81*3b4b8bdaSRobert Mustacchi ENTRY(htobe16) 82*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hs 83*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 84*3b4b8bdaSRobert Mustacchi shrl $16, %eax / moves high 16-bit to low 16-bit 85*3b4b8bdaSRobert Mustacchi ret / return (%eax) 86*3b4b8bdaSRobert Mustacchi SET_SIZE(htobe16) 87*3b4b8bdaSRobert Mustacchi 88*3b4b8bdaSRobert Mustacchi/ uint32_t htobe32(uint32_t in) 89*3b4b8bdaSRobert Mustacchi/ 90*3b4b8bdaSRobert Mustacchi/ Convert in to big endian, eg. htonl() 91*3b4b8bdaSRobert Mustacchi/ 92*3b4b8bdaSRobert Mustacchi ENTRY(htobe32) 93*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hl 94*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 95*3b4b8bdaSRobert Mustacchi ret / return (%eax) 96*3b4b8bdaSRobert Mustacchi SET_SIZE(htobe32) 97*3b4b8bdaSRobert Mustacchi 98*3b4b8bdaSRobert Mustacchi/ uint16_t betoh16(uint16_t in) 99*3b4b8bdaSRobert Mustacchi/ uint16_t be16toh(uint16_t in) 100*3b4b8bdaSRobert Mustacchi/ 101*3b4b8bdaSRobert Mustacchi/ Convert in to little endian, eg. ntohs() 102*3b4b8bdaSRobert Mustacchi/ 103*3b4b8bdaSRobert Mustacchi ENTRY(betoh16) 104*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hs 105*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 106*3b4b8bdaSRobert Mustacchi shrl $16, %eax / moves high 16-bit to low 16-bit 107*3b4b8bdaSRobert Mustacchi ret / return (%eax) 108*3b4b8bdaSRobert Mustacchi SET_SIZE(betoh16) 109*3b4b8bdaSRobert Mustacchi 110*3b4b8bdaSRobert Mustacchi ENTRY(be16toh) 111*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hs 112*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 113*3b4b8bdaSRobert Mustacchi shrl $16, %eax / moves high 16-bit to low 16-bit 114*3b4b8bdaSRobert Mustacchi ret / return (%eax) 115*3b4b8bdaSRobert Mustacchi SET_SIZE(be16toh) 116*3b4b8bdaSRobert Mustacchi 117*3b4b8bdaSRobert Mustacchi 118*3b4b8bdaSRobert Mustacchi/ uint32_t be32toh(uint32_t in) 119*3b4b8bdaSRobert Mustacchi/ uint32_t betoh32(uint32_t in) 120*3b4b8bdaSRobert Mustacchi/ 121*3b4b8bdaSRobert Mustacchi/ Convert in to little endian, eg. ntohl() 122*3b4b8bdaSRobert Mustacchi/ 123*3b4b8bdaSRobert Mustacchi ENTRY(be32toh) 124*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hl 125*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 126*3b4b8bdaSRobert Mustacchi ret / return (%eax) 127*3b4b8bdaSRobert Mustacchi SET_SIZE(be32toh) 128*3b4b8bdaSRobert Mustacchi 129*3b4b8bdaSRobert Mustacchi ENTRY(betoh32) 130*3b4b8bdaSRobert Mustacchi movl 4(%esp), %eax / %eax = hl 131*3b4b8bdaSRobert Mustacchi bswap %eax / reverses the byte order of %eax 132*3b4b8bdaSRobert Mustacchi ret / return (%eax) 133*3b4b8bdaSRobert Mustacchi SET_SIZE(betoh32) 134