00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _BYTEORDER_H
00023 #define _BYTEORDER_H
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #define RW_PCVAL(read,inbuf,outbuf,len) { if (read) { PCVAL (inbuf,0,outbuf,len); } else { PSCVAL(inbuf,0,outbuf,len); } }
00100 #define RW_PIVAL(read,big_endian,inbuf,outbuf,len) { if (read) { if (big_endian) { RPIVAL(inbuf,0,outbuf,len); } else { PIVAL(inbuf,0,outbuf,len); } } else { if (big_endian) { RPSIVAL(inbuf,0,outbuf,len); } else { PSIVAL(inbuf,0,outbuf,len); } } }
00101 #define RW_PSVAL(read,big_endian,inbuf,outbuf,len) { if (read) { if (big_endian) { RPSVAL(inbuf,0,outbuf,len); } else { PSVAL(inbuf,0,outbuf,len); } } else { if (big_endian) { RPSSVAL(inbuf,0,outbuf,len); } else { PSSVAL(inbuf,0,outbuf,len); } } }
00102 #define RW_CVAL(read, inbuf, outbuf, offset) { if (read) { (outbuf) = CVAL (inbuf,offset); } else { SCVAL(inbuf,offset,outbuf); } }
00103 #define RW_IVAL(read, big_endian, inbuf, outbuf, offset) { if (read) { (outbuf) = ((big_endian) ? RIVAL(inbuf,offset) : IVAL (inbuf,offset)); } else { if (big_endian) { RSIVAL(inbuf,offset,outbuf); } else { SIVAL(inbuf,offset,outbuf); } } }
00104 #define RW_SVAL(read, big_endian, inbuf, outbuf, offset) { if (read) { (outbuf) = ((big_endian) ? RSVAL(inbuf,offset) : SVAL (inbuf,offset)); } else { if (big_endian) { RSSVAL(inbuf,offset,outbuf); } else { SSVAL(inbuf,offset,outbuf); } } }
00105
00106 #undef CAREFUL_ALIGNMENT
00107
00108
00109
00110 #ifdef __i386__
00111 #define CAREFUL_ALIGNMENT 0
00112 #endif
00113
00114 #ifndef CAREFUL_ALIGNMENT
00115 #define CAREFUL_ALIGNMENT 1
00116 #endif
00117
00118 #define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
00119 #define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
00120 #define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
00121
00122
00123 #if CAREFUL_ALIGNMENT
00124
00125 #define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
00126 #define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
00127 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
00128 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
00129 #define SVALS(buf,pos) ((int16)SVAL(buf,pos))
00130 #define IVALS(buf,pos) ((int32)IVAL(buf,pos))
00131 #define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
00132 #define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
00133 #define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
00134 #define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
00135
00136 #else
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
00147 #define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
00148 #define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
00149 #define IVALS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
00150
00151
00152 #define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
00153 #define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val))
00154 #define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16)(val))
00155 #define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32)(val))
00156
00157 #endif
00158
00159
00160
00161 #define SMBMACRO(macro,buf,pos,val,len,size) { int l; for (l = 0; l < (len); l++) (val)[l] = macro((buf), (pos) + (size)*l); }
00162 #define SSMBMACRO(macro,buf,pos,val,len,size) { int l; for (l = 0; l < (len); l++) macro((buf), (pos) + (size)*l, (val)[l]); }
00163
00164
00165 #define PCVAL(buf,pos,val,len) SMBMACRO(CVAL,buf,pos,val,len,1)
00166 #define PSVAL(buf,pos,val,len) SMBMACRO(SVAL,buf,pos,val,len,2)
00167 #define PIVAL(buf,pos,val,len) SMBMACRO(IVAL,buf,pos,val,len,4)
00168 #define PCVALS(buf,pos,val,len) SMBMACRO(CVALS,buf,pos,val,len,1)
00169 #define PSVALS(buf,pos,val,len) SMBMACRO(SVALS,buf,pos,val,len,2)
00170 #define PIVALS(buf,pos,val,len) SMBMACRO(IVALS,buf,pos,val,len,4)
00171
00172
00173 #define PSCVAL(buf,pos,val,len) SSMBMACRO(SCVAL,buf,pos,val,len,1)
00174 #define PSSVAL(buf,pos,val,len) SSMBMACRO(SSVAL,buf,pos,val,len,2)
00175 #define PSIVAL(buf,pos,val,len) SSMBMACRO(SIVAL,buf,pos,val,len,4)
00176 #define PSCVALS(buf,pos,val,len) SSMBMACRO(SCVALS,buf,pos,val,len,1)
00177 #define PSSVALS(buf,pos,val,len) SSMBMACRO(SSVALS,buf,pos,val,len,2)
00178 #define PSIVALS(buf,pos,val,len) SSMBMACRO(SIVALS,buf,pos,val,len,4)
00179
00180
00181
00182 #define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
00183 #define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
00184
00185 #define RSVAL(buf,pos) SREV(SVAL(buf,pos))
00186 #define RSVALS(buf,pos) SREV(SVALS(buf,pos))
00187 #define RIVAL(buf,pos) IREV(IVAL(buf,pos))
00188 #define RIVALS(buf,pos) IREV(IVALS(buf,pos))
00189 #define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
00190 #define RSSVALS(buf,pos,val) SSVALS(buf,pos,SREV(val))
00191 #define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
00192 #define RSIVALS(buf,pos,val) SIVALS(buf,pos,IREV(val))
00193
00194
00195 #define RPSVAL(buf,pos,val,len) SMBMACRO(RSVAL,buf,pos,val,len,2)
00196 #define RPIVAL(buf,pos,val,len) SMBMACRO(RIVAL,buf,pos,val,len,4)
00197 #define RPSVALS(buf,pos,val,len) SMBMACRO(RSVALS,buf,pos,val,len,2)
00198 #define RPIVALS(buf,pos,val,len) SMBMACRO(RIVALS,buf,pos,val,len,4)
00199
00200
00201 #define RPSSVAL(buf,pos,val,len) SSMBMACRO(RSSVAL,buf,pos,val,len,2)
00202 #define RPSIVAL(buf,pos,val,len) SSMBMACRO(RSIVAL,buf,pos,val,len,4)
00203 #define RPSSVALS(buf,pos,val,len) SSMBMACRO(RSSVALS,buf,pos,val,len,2)
00204 #define RPSIVALS(buf,pos,val,len) SSMBMACRO(RSIVALS,buf,pos,val,len,4)
00205
00206 #define DBG_RW_PCVAL(charmode,string,depth,base,read,inbuf,outbuf,len) { RW_PCVAL(read,inbuf,outbuf,len) DEBUG(5,("%s%04x %s: ", tab_depth(depth), base,string)); if (charmode) print_asc(5, (unsigned char*)(outbuf), (len)); else { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%02x ", (outbuf)[idx])); } } DEBUG(5,("\n")); }
00207 #define DBG_RW_PSVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) { RW_PSVAL(read,big_endian,inbuf,outbuf,len) DEBUG(5,("%s%04x %s: ", tab_depth(depth), base,string)); if (charmode) print_asc(5, (unsigned char*)(outbuf), 2*(len)); else { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%04x ", (outbuf)[idx])); } } DEBUG(5,("\n")); }
00208 #define DBG_RW_PIVAL(charmode,string,depth,base,read,big_endian,inbuf,outbuf,len) { RW_PIVAL(read,big_endian,inbuf,outbuf,len) DEBUG(5,("%s%04x %s: ", tab_depth(depth), base,string)); if (charmode) print_asc(5, (unsigned char*)(outbuf), 4*(len)); else { int idx; for (idx = 0; idx < len; idx++) { DEBUG(5,("%08x ", (outbuf)[idx])); } } DEBUG(5,("\n")); }
00209 #define DBG_RW_CVAL(string,depth,base,read,inbuf,outbuf) { RW_CVAL(read,inbuf,outbuf,0) DEBUG(5,("%s%04x %s: %02x\n", tab_depth(depth), base, string, outbuf)); }
00210 #define DBG_RW_SVAL(string,depth,base,read,big_endian,inbuf,outbuf) { RW_SVAL(read,big_endian,inbuf,outbuf,0) DEBUG(5,("%s%04x %s: %04x\n", tab_depth(depth), base, string, outbuf)); }
00211 #define DBG_RW_IVAL(string,depth,base,read,big_endian,inbuf,outbuf) { RW_IVAL(read,big_endian,inbuf,outbuf,0) DEBUG(5,("%s%04x %s: %08x\n", tab_depth(depth), base, string, outbuf)); }
00212
00213 #endif