1*6ca2c52aSchristos /* This file is part of the program psim. 2*6ca2c52aSchristos 3*6ca2c52aSchristos Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> 4*6ca2c52aSchristos 5*6ca2c52aSchristos This program is free software; you can redistribute it and/or modify 6*6ca2c52aSchristos it under the terms of the GNU General Public License as published by 7*6ca2c52aSchristos the Free Software Foundation; either version 3 of the License, or 8*6ca2c52aSchristos (at your option) any later version. 9*6ca2c52aSchristos 10*6ca2c52aSchristos This program is distributed in the hope that it will be useful, 11*6ca2c52aSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6ca2c52aSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6ca2c52aSchristos GNU General Public License for more details. 14*6ca2c52aSchristos 15*6ca2c52aSchristos You should have received a copy of the GNU General Public License 16*6ca2c52aSchristos along with this program; if not, see <http://www.gnu.org/licenses/>. 17*6ca2c52aSchristos 18*6ca2c52aSchristos */ 19*6ca2c52aSchristos 20*6ca2c52aSchristos 21*6ca2c52aSchristos #ifndef _SIM_ENDIAN_C_ 22*6ca2c52aSchristos #define _SIM_ENDIAN_C_ 23*6ca2c52aSchristos 24*6ca2c52aSchristos #include "config.h" 25*6ca2c52aSchristos #include "basics.h" 26*6ca2c52aSchristos 27*6ca2c52aSchristos 28*6ca2c52aSchristos #if !defined(_SWAP_1) 29*6ca2c52aSchristos #define _SWAP_1(SET,RAW) SET (RAW) 30*6ca2c52aSchristos #endif 31*6ca2c52aSchristos 32*6ca2c52aSchristos #if !defined(_SWAP_2) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htons) 33*6ca2c52aSchristos #define _SWAP_2(SET,RAW) SET htons (RAW) 34*6ca2c52aSchristos #endif 35*6ca2c52aSchristos 36*6ca2c52aSchristos #ifndef _SWAP_2 37*6ca2c52aSchristos #define _SWAP_2(SET,RAW) SET (((RAW) >> 8) | ((RAW) << 8)) 38*6ca2c52aSchristos #endif 39*6ca2c52aSchristos 40*6ca2c52aSchristos #if !defined(_SWAP_4) && (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN) && defined(htonl) 41*6ca2c52aSchristos #define _SWAP_4(SET,RAW) SET htonl (RAW) 42*6ca2c52aSchristos #endif 43*6ca2c52aSchristos 44*6ca2c52aSchristos #ifndef _SWAP_4 45*6ca2c52aSchristos #define _SWAP_4(SET,RAW) SET (((RAW) << 24) | (((RAW) & 0xff00) << 8) | (((RAW) & 0xff0000) >> 8) | ((RAW) >> 24)) 46*6ca2c52aSchristos #endif 47*6ca2c52aSchristos 48*6ca2c52aSchristos #ifndef _SWAP_8 49*6ca2c52aSchristos #define _SWAP_8(SET,RAW) \ 50*6ca2c52aSchristos union { unsigned_8 dword; unsigned_4 words[2]; } in, out; \ 51*6ca2c52aSchristos in.dword = RAW; \ 52*6ca2c52aSchristos _SWAP_4 (out.words[0] =, in.words[1]); \ 53*6ca2c52aSchristos _SWAP_4 (out.words[1] =, in.words[0]); \ 54*6ca2c52aSchristos SET out.dword; 55*6ca2c52aSchristos #endif 56*6ca2c52aSchristos 57*6ca2c52aSchristos #define N 1 58*6ca2c52aSchristos #include "sim-endian-n.h" 59*6ca2c52aSchristos #undef N 60*6ca2c52aSchristos 61*6ca2c52aSchristos #define N 2 62*6ca2c52aSchristos #include "sim-endian-n.h" 63*6ca2c52aSchristos #undef N 64*6ca2c52aSchristos 65*6ca2c52aSchristos #define N 4 66*6ca2c52aSchristos #include "sim-endian-n.h" 67*6ca2c52aSchristos #undef N 68*6ca2c52aSchristos 69*6ca2c52aSchristos #define N 8 70*6ca2c52aSchristos #include "sim-endian-n.h" 71*6ca2c52aSchristos #undef N 72*6ca2c52aSchristos 73*6ca2c52aSchristos #endif /* _SIM_ENDIAN_C_ */ 74