1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A
1N/A/*
1N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A *
1N/A * Wrapper around the <sys/machelf.h> header that adds
1N/A * definitions used by SGS.
1N/A */
1N/A
1N/A#ifndef _MACHELF_H
1N/A#define _MACHELF_H
1N/A
1N/A#include <sys/machelf.h>
1N/A#include <string.h> /* memcpy() */
1N/A
1N/A/*
1N/A * Make machine class dependent functions transparent to the common code
1N/A */
1N/A
1N/A/*
1N/A * Note on ELF_R_TYPE: 64-bit sparc relocations require the use of
1N/A * ELF64_R_TYPE_ID instead of the ELF64_R_TYPE macro used for all
1N/A * other platforms. So our ELF_R_TYPE macro requires the caller to
1N/A * supply the machine type.
1N/A */
1N/A
1N/A
1N/A#if defined(_ELF64)
1N/A#define ELF_R_TYPE(_info, _mach) \
1N/A (((_mach) == EM_SPARCV9) ? ELF64_R_TYPE_ID(_info) : ELF64_R_TYPE(_info))
1N/A#define ELF_R_INFO ELF64_R_INFO
1N/A#define ELF_R_SYM ELF64_R_SYM
1N/A#define ELF_R_TYPE_DATA(x) ELF64_R_TYPE_DATA(x)
1N/A#define ELF_R_TYPE_INFO(xoff, type) ELF64_R_TYPE_INFO(xoff, type)
1N/A#define ELF_ST_BIND ELF64_ST_BIND
1N/A#define ELF_ST_TYPE ELF64_ST_TYPE
1N/A#define ELF_ST_INFO ELF64_ST_INFO
1N/A#define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY
1N/A#define ELF_M_SYM ELF64_M_SYM
1N/A#define ELF_M_SIZE ELF64_M_SIZE
1N/A#define ELF_M_INFO ELF64_M_INFO
1N/A#define ELF_C_SYM ELF64_C_SYM
1N/A#define ELF_C_GROUP ELF64_C_GROUP
1N/A#define ELF_C_INFO ELF64_C_INFO
1N/A#define elf_checksum elf64_checksum
1N/A#define elf_fsize elf64_fsize
1N/A#define elf_getehdr elf64_getehdr
1N/A#define elf_getphdr elf64_getphdr
1N/A#define elf_newehdr elf64_newehdr
1N/A#define elf_newphdr elf64_newphdr
1N/A#define elf_getshdr elf64_getshdr
1N/A#define elf_xlatetof elf64_xlatetof
1N/A#define elf_xlatetom elf64_xlatetom
1N/A#else /* _ELF64 */
1N/A#define ELF_R_TYPE(_info, _mach) ELF32_R_TYPE(_info)
1N/A#define ELF_R_INFO ELF32_R_INFO
1N/A#define ELF_R_SYM ELF32_R_SYM
1N/A/* Elf64 can hide extra offset in r_info */
1N/A#define ELF_R_TYPE_DATA(x) (0)
1N/A#define ELF_R_TYPE_INFO(xoff, type) (type)
1N/A#define ELF_ST_BIND ELF32_ST_BIND
1N/A#define ELF_ST_TYPE ELF32_ST_TYPE
1N/A#define ELF_ST_INFO ELF32_ST_INFO
1N/A#define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY
1N/A#define ELF_M_SYM ELF32_M_SYM
1N/A#define ELF_M_SIZE ELF32_M_SIZE
1N/A#define ELF_M_INFO ELF32_M_INFO
1N/A#define ELF_C_SYM ELF32_C_SYM
1N/A#define ELF_C_GROUP ELF32_C_GROUP
1N/A#define ELF_C_INFO ELF32_C_INFO
1N/A#define elf_checksum elf32_checksum
1N/A#define elf_fsize elf32_fsize
1N/A#define elf_getehdr elf32_getehdr
1N/A#define elf_getphdr elf32_getphdr
1N/A#define elf_newehdr elf32_newehdr
1N/A#define elf_newphdr elf32_newphdr
1N/A#define elf_getshdr elf32_getshdr
1N/A#define elf_xlatetof elf32_xlatetof
1N/A#define elf_xlatetom elf32_xlatetom
1N/A#endif /* _ELF32 */
1N/A
1N/A
1N/A/*
1N/A * Macros for swapping bytes. The type of the argument must
1N/A * match the type given in the macro name.
1N/A */
1N/A#define BSWAP_HALF(_half) \
1N/A (((_half) << 8) | ((_half) >> 8))
1N/A
1N/A#define BSWAP_WORD(_word) \
1N/A ((((_word) << 24) | (((_word) & 0xff00) << 8) | \
1N/A (((_word) >> 8) & 0xff00) | ((_word) >> 24)))
1N/A
1N/A#define BSWAP_LWORD(_lword) \
1N/A (((_lword) << 56) | \
1N/A (((_lword) & 0x0000ff00) << 40) | \
1N/A (((_lword) & 0x00ff0000) << 24) | \
1N/A (((_lword) & 0xff000000) << 8) | \
1N/A (((_lword) >> 8) & 0xff000000) | \
1N/A (((_lword) >> 24) & 0x00ff0000) | \
1N/A (((_lword) >> 40) & 0x0000ff00) | \
1N/A ((_lword) >> 56)) /* Lword is unsigned - 0 bits enter from left */
1N/A
1N/A
1N/A#if defined(_ELF64)
1N/A#define BSWAP_XWORD(_xword) BSWAP_LWORD(_xword)
1N/A#else
1N/A#define BSWAP_XWORD(_xword) BSWAP_WORD(_xword)
1N/A#endif
1N/A
1N/A/*
1N/A * Macros for assigning Half/Word/Xword items from one location to
1N/A * another that are safe no matter what the data alignment rules of the
1N/A * running platform are. Variants exist to swap the data byteorder
1N/A * at the same time, or not.
1N/A *
1N/A * These macros are useful for code that accesses data that is aligned
1N/A * for a different system architecture, as occurs in cross linking.
1N/A *
1N/A * All of these macros assume the arguments are passed as pointers to
1N/A * bytes (signed or unsigned).
1N/A */
1N/A
1N/A#define UL_ASSIGN_HALF(_dst, _src) (void) \
1N/A ((_dst)[0] = (_src)[0], (_dst)[1] = (_src)[1])
1N/A#define UL_ASSIGN_WORD(_dst, _src) (void) \
1N/A ((_dst)[0] = (_src)[0], (_dst)[1] = (_src)[1], \
1N/A (_dst)[2] = (_src)[2], (_dst)[3] = (_src)[3])
1N/A#define UL_ASSIGN_LWORD(_dst, _src) (void) memcpy(_dst, (_src), sizeof (Lword))
1N/A#if defined(_ELF64)
1N/A#define UL_ASSIGN_XWORD(_dst, _src) UL_ASSIGN_LWORD(_dst, _src)
1N/A#else
1N/A#define UL_ASSIGN_XWORD(_xword) UL_ASSIGN_WORD(_xword)
1N/A#endif
1N/A
1N/A#define UL_ASSIGN_BSWAP_HALF(_dst, _src) (void) \
1N/A ((_dst)[0] = (_src)[1], (_dst)[1] = (_src)[0])
1N/A#define UL_ASSIGN_BSWAP_WORD(_dst, _src) (void) \
1N/A ((_dst)[0] = (_src)[3], (_dst)[1] = (_src)[2], \
1N/A (_dst)[2] = (_src)[1], (_dst)[3] = (_src)[0])
1N/A#define UL_ASSIGN_BSWAP_LWORD(_dst, _src) (void) \
1N/A ((_dst)[0] = (_src)[7], (_dst)[1] = (_src)[6], \
1N/A (_dst)[2] = (_src)[5], (_dst)[3] = (_src)[4], \
1N/A (_dst)[4] = (_src)[3], (_dst)[5] = (_src)[2], \
1N/A (_dst)[6] = (_src)[1], (_dst)[7] = (_src)[0])
1N/A#if defined(_ELF64)
1N/A#define UL_ASSIGN_BSWAP_XWORD(_dst, _src) UL_ASSIGN_BSWAP_LWORD(_dst, _src)
1N/A#else
1N/A#define UL_ASSIGN_BSWAP_XWORD(_dst, _src) UL_ASSIGN_BSWAP_WORD(_dst, _src)
1N/A#endif
1N/A
1N/A
1N/A#endif /* _MACHELF_H */
1N/A