1 6206 ab196087 /* 2 6206 ab196087 * CDDL HEADER START 3 6206 ab196087 * 4 6206 ab196087 * The contents of this file are subject to the terms of the 5 6206 ab196087 * Common Development and Distribution License (the "License"). 6 6206 ab196087 * You may not use this file except in compliance with the License. 7 6206 ab196087 * 8 6206 ab196087 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 6206 ab196087 * or http://www.opensolaris.org/os/licensing. 10 6206 ab196087 * See the License for the specific language governing permissions 11 6206 ab196087 * and limitations under the License. 12 6206 ab196087 * 13 6206 ab196087 * When distributing Covered Code, include this CDDL HEADER in each 14 6206 ab196087 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 6206 ab196087 * If applicable, add the following below this CDDL HEADER, with the 16 6206 ab196087 * fields enclosed by brackets "[]" replaced with your own identifying 17 6206 ab196087 * information: Portions Copyright [yyyy] [name of copyright owner] 18 6206 ab196087 * 19 6206 ab196087 * CDDL HEADER END 20 6206 ab196087 */ 21 6206 ab196087 22 6206 ab196087 /* 23 6206 ab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 6206 ab196087 * Use is subject to license terms. 25 6206 ab196087 * 26 6206 ab196087 * Wrapper around the <sys/machelf.h> header that adds 27 6206 ab196087 * definitions used by SGS. 28 6206 ab196087 */ 29 6206 ab196087 30 6206 ab196087 #ifndef _MACHELF_H 31 6206 ab196087 #define _MACHELF_H 32 6206 ab196087 33 6206 ab196087 #pragma ident "%Z%%M% %I% %E% SMI" 34 6206 ab196087 35 6206 ab196087 #include <sys/machelf.h> 36 6206 ab196087 #include <string.h> /* memcpy() */ 37 6206 ab196087 38 6206 ab196087 /* 39 6206 ab196087 * Make machine class dependent functions transparent to the common code 40 6206 ab196087 */ 41 6206 ab196087 42 6206 ab196087 /* 43 6206 ab196087 * Note on ELF_R_TYPE: 64-bit sparc relocations require the use of 44 6206 ab196087 * ELF64_R_TYPE_ID instead of the ELF64_R_TYPE macro used for all 45 6206 ab196087 * other platforms. So our ELF_R_TYPE macro requires the caller to 46 6206 ab196087 * supply the machine type. 47 6206 ab196087 */ 48 6206 ab196087 49 6206 ab196087 50 6206 ab196087 #if defined(_ELF64) 51 6206 ab196087 #define ELF_R_TYPE(_info, _mach) \ 52 6206 ab196087 (((_mach) == EM_SPARCV9) ? ELF64_R_TYPE_ID(_info) : ELF64_R_TYPE(_info)) 53 6206 ab196087 #define ELF_R_INFO ELF64_R_INFO 54 6206 ab196087 #define ELF_R_SYM ELF64_R_SYM 55 6206 ab196087 #define ELF_R_TYPE_DATA(x) ELF64_R_TYPE_DATA(x) 56 6206 ab196087 #define ELF_R_TYPE_INFO(xoff, type) ELF64_R_TYPE_INFO(xoff, type) 57 6206 ab196087 #define ELF_ST_BIND ELF64_ST_BIND 58 6206 ab196087 #define ELF_ST_TYPE ELF64_ST_TYPE 59 6206 ab196087 #define ELF_ST_INFO ELF64_ST_INFO 60 6206 ab196087 #define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY 61 6206 ab196087 #define ELF_M_SYM ELF64_M_SYM 62 6206 ab196087 #define ELF_M_SIZE ELF64_M_SIZE 63 6206 ab196087 #define ELF_M_INFO ELF64_M_INFO 64 6206 ab196087 #define elf_checksum elf64_checksum 65 6206 ab196087 #define elf_fsize elf64_fsize 66 6206 ab196087 #define elf_getehdr elf64_getehdr 67 6206 ab196087 #define elf_getphdr elf64_getphdr 68 6206 ab196087 #define elf_newehdr elf64_newehdr 69 6206 ab196087 #define elf_newphdr elf64_newphdr 70 6206 ab196087 #define elf_getshdr elf64_getshdr 71 6206 ab196087 #define elf_xlatetof elf64_xlatetof 72 6206 ab196087 #define elf_xlatetom elf64_xlatetom 73 6206 ab196087 #else /* _ELF64 */ 74 6206 ab196087 #define ELF_R_TYPE(_info, _mach) ELF32_R_TYPE(_info) 75 6206 ab196087 #define ELF_R_INFO ELF32_R_INFO 76 6206 ab196087 #define ELF_R_SYM ELF32_R_SYM 77 6206 ab196087 /* Elf64 can hide extra offset in r_info */ 78 6206 ab196087 #define ELF_R_TYPE_DATA(x) (0) 79 6206 ab196087 #define ELF_R_TYPE_INFO(xoff, type) (type) 80 6206 ab196087 #define ELF_ST_BIND ELF32_ST_BIND 81 6206 ab196087 #define ELF_ST_TYPE ELF32_ST_TYPE 82 6206 ab196087 #define ELF_ST_INFO ELF32_ST_INFO 83 6206 ab196087 #define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY 84 6206 ab196087 #define ELF_M_SYM ELF32_M_SYM 85 6206 ab196087 #define ELF_M_SIZE ELF32_M_SIZE 86 6206 ab196087 #define ELF_M_INFO ELF32_M_INFO 87 6206 ab196087 #define elf_checksum elf32_checksum 88 6206 ab196087 #define elf_fsize elf32_fsize 89 6206 ab196087 #define elf_getehdr elf32_getehdr 90 6206 ab196087 #define elf_getphdr elf32_getphdr 91 6206 ab196087 #define elf_newehdr elf32_newehdr 92 6206 ab196087 #define elf_newphdr elf32_newphdr 93 6206 ab196087 #define elf_getshdr elf32_getshdr 94 6206 ab196087 #define elf_xlatetof elf32_xlatetof 95 6206 ab196087 #define elf_xlatetom elf32_xlatetom 96 6206 ab196087 #endif /* _ELF32 */ 97 6206 ab196087 98 6206 ab196087 99 6206 ab196087 /* 100 6206 ab196087 * Macros for swapping bytes. The type of the argument must 101 6206 ab196087 * match the type given in the macro name. 102 6206 ab196087 */ 103 6206 ab196087 #define BSWAP_HALF(_half) \ 104 6206 ab196087 (((_half) << 8) | ((_half) >> 8)) 105 6206 ab196087 106 6206 ab196087 #define BSWAP_WORD(_word) \ 107 6206 ab196087 ((((_word) << 24) | (((_word) & 0xff00) << 8) | \ 108 6206 ab196087 (((_word) >> 8) & 0xff00) | ((_word) >> 24))) 109 6206 ab196087 110 6635 ab196087 #define BSWAP_LWORD(_lword) \ 111 6635 ab196087 (((_lword) << 56) | \ 112 6635 ab196087 (((_lword) & 0x0000ff00) << 40) | \ 113 6635 ab196087 (((_lword) & 0x00ff0000) << 24) | \ 114 6635 ab196087 (((_lword) & 0xff000000) << 8) | \ 115 6635 ab196087 (((_lword) >> 8) & 0xff000000) | \ 116 6635 ab196087 (((_lword) >> 24) & 0x00ff0000) | \ 117 6635 ab196087 (((_lword) >> 40) & 0x0000ff00) | \ 118 6635 ab196087 ((_lword) >> 56)) /* Lword is unsigned - 0 bits enter from left */ 119 6635 ab196087 120 6635 ab196087 121 6206 ab196087 #if defined(_ELF64) 122 6635 ab196087 #define BSWAP_XWORD(_xword) BSWAP_LWORD(_xword) 123 6206 ab196087 #else 124 6206 ab196087 #define BSWAP_XWORD(_xword) BSWAP_WORD(_xword) 125 6206 ab196087 #endif 126 6206 ab196087 127 6206 ab196087 /* 128 6206 ab196087 * Macros for assigning Half/Word/Xword items from one location to 129 6206 ab196087 * another that are safe no matter what the data alignment rules of the 130 6206 ab196087 * running platform are. Variants exist to swap the data byteorder 131 6206 ab196087 * at the same time, or not. 132 6206 ab196087 * 133 6206 ab196087 * These macros are useful for code that accesses data that is aligned 134 6206 ab196087 * for a different system architecture, as occurs in cross linking. 135 6206 ab196087 * 136 6206 ab196087 * All of these macros assume the arguments are passed as pointers to 137 6206 ab196087 * bytes (signed or unsigned). 138 6206 ab196087 */ 139 6206 ab196087 140 6206 ab196087 #define UL_ASSIGN_HALF(_dst, _src) (void) \ 141 6206 ab196087 ((_dst)[0] = (_src)[0], (_dst)[1] = (_src)[1]) 142 6206 ab196087 #define UL_ASSIGN_WORD(_dst, _src) (void) \ 143 6206 ab196087 ((_dst)[0] = (_src)[0], (_dst)[1] = (_src)[1], \ 144 6206 ab196087 (_dst)[2] = (_src)[2], (_dst)[3] = (_src)[3]) 145 6635 ab196087 #define UL_ASSIGN_LWORD(_dst, _src) (void) memcpy(_dst, (_src), sizeof (Lword)) 146 6206 ab196087 #if defined(_ELF64) 147 6635 ab196087 #define UL_ASSIGN_XWORD(_dst, _src) UL_ASSIGN_LWORD(_dst, _src) 148 6206 ab196087 #else 149 6206 ab196087 #define UL_ASSIGN_XWORD(_xword) UL_ASSIGN_WORD(_xword) 150 6206 ab196087 #endif 151 6206 ab196087 152 6206 ab196087 #define UL_ASSIGN_BSWAP_HALF(_dst, _src) (void) \ 153 6206 ab196087 ((_dst)[0] = (_src)[1], (_dst)[1] = (_src)[0]) 154 6206 ab196087 #define UL_ASSIGN_BSWAP_WORD(_dst, _src) (void) \ 155 6206 ab196087 ((_dst)[0] = (_src)[3], (_dst)[1] = (_src)[2], \ 156 6206 ab196087 (_dst)[2] = (_src)[1], (_dst)[3] = (_src)[0]) 157 6635 ab196087 #define UL_ASSIGN_BSWAP_LWORD(_dst, _src) (void) \ 158 6206 ab196087 ((_dst)[0] = (_src)[7], (_dst)[1] = (_src)[6], \ 159 6206 ab196087 (_dst)[2] = (_src)[5], (_dst)[3] = (_src)[4], \ 160 6206 ab196087 (_dst)[4] = (_src)[3], (_dst)[5] = (_src)[2], \ 161 6206 ab196087 (_dst)[6] = (_src)[1], (_dst)[7] = (_src)[0]) 162 6635 ab196087 #if defined(_ELF64) 163 6635 ab196087 #define UL_ASSIGN_BSWAP_XWORD(_dst, _src) UL_ASSIGN_BSWAP_LWORD(_dst, _src) 164 6206 ab196087 #else 165 6206 ab196087 #define UL_ASSIGN_BSWAP_XWORD(_dst, _src) UL_ASSIGN_BSWAP_WORD(_dst, _src) 166 6206 ab196087 #endif 167 6206 ab196087 168 6206 ab196087 169 6206 ab196087 #endif /* _MACHELF_H */ 170