Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentools.h
Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 2002-2005 Alexandr A. Telyatnikov (Alter) 00004 00005 Module Name: 00006 tools.h 00007 00008 Abstract: 00009 This header contains some useful definitions for data manipulation. 00010 00011 Author: 00012 Alexander A. Telyatnikov (Alter) 00013 00014 Environment: 00015 kernel mode only 00016 00017 Notes: 00018 00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00030 Revision History: 00031 00032 --*/ 00033 00034 #ifndef __TOOLS_H__ 00035 #define __TOOLS_H__ 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif //__cplusplus 00040 00041 //---------------- 00042 00043 #ifndef USER_MODE 00044 #include <ntddk.h> // various NT definitions 00045 #endif //USER_MODE 00046 00047 //---------------- 00048 00049 #ifndef FOUR_BYTE_DEFINED 00050 #define FOUR_BYTE_DEFINED 00051 typedef struct _FOUR_BYTE { 00052 UCHAR Byte0; 00053 UCHAR Byte1; 00054 UCHAR Byte2; 00055 UCHAR Byte3; 00056 } FOUR_BYTE, *PFOUR_BYTE; 00057 #endif //FOUR_BYTE_DEFINED 00058 00059 #ifdef _DEBUG 00060 00061 #ifndef DBG 00062 #define DBG 00063 #endif // DBG 00064 00065 #else // _DEBUG 00066 00067 #ifdef DBG 00068 #undef DBG 00069 #endif // DBG 00070 00071 #endif // _DEBUG 00072 00073 // This macro has the effect of Bit = log2(Data) 00074 00075 #define WHICH_BIT(Data, Bit) { \ 00076 for (Bit = 0; Bit < 32; Bit++) { \ 00077 if ((Data >> Bit) == 1) { \ 00078 break; \ 00079 } \ 00080 } \ 00081 } 00082 00083 #define PAGE_MASK (PAGE_SIZE-1) 00084 00085 #define ntohs(x) ( (((USHORT)x[0])<<8) | x[1] ) 00086 #define PLAY_ACTIVE(DeviceExtension) (((PCDROM_DATA)(DeviceExtension + 1))->PlayActive) 00087 #define MSF_TO_LBA(Minutes,Seconds,Frames) \ 00088 (ULONG)((60 * 75 * (Minutes)) + (75 * (Seconds)) + ((Frames) - 150)) 00089 #define LBA_TO_MSF(Lba,Minutes,Seconds,Frames) \ 00090 { \ 00091 (Minutes) = (UCHAR)(Lba / (60 * 75)); \ 00092 (Seconds) = (UCHAR)((Lba % (60 * 75)) / 75); \ 00093 (Frames) = (UCHAR)((Lba % (60 * 75)) % 75); \ 00094 } 00095 #define DEC_TO_BCD(x) (((x / 10) << 4) + (x % 10)) 00096 00097 /* 00098 00099 #if defined _X86_ && !defined(__GNUC__) 00100 00101 #define MOV_DD_SWP(a,b) \ 00102 { \ 00103 PFOUR_BYTE _from_, _to_; \ 00104 _from_ = ((PFOUR_BYTE)&(b)); \ 00105 _to_ = ((PFOUR_BYTE)&(a)); \ 00106 __asm mov ebx,_from_ \ 00107 __asm mov eax,[ebx] \ 00108 __asm bswap eax \ 00109 __asm mov ebx,_to_ \ 00110 __asm mov [ebx],eax \ 00111 } 00112 00113 #define MOV_DW_SWP(a,b) \ 00114 { \ 00115 PFOUR_BYTE _from_, _to_; \ 00116 _from_ = ((PFOUR_BYTE)&(b)); \ 00117 _to_ = ((PFOUR_BYTE)&(a)); \ 00118 __asm mov ebx,_from_ \ 00119 __asm mov ax,[ebx] \ 00120 __asm rol ax,8 \ 00121 __asm mov ebx,_to_ \ 00122 __asm mov [ebx],ax \ 00123 } 00124 00125 #define REVERSE_DD(a) { \ 00126 PFOUR_BYTE _from_; \ 00127 _from_ = ((PFOUR_BYTE)&(a)); \ 00128 __asm mov ebx,_from_ \ 00129 __asm mov eax,[ebx] \ 00130 __asm bswap eax \ 00131 __asm mov [ebx],eax \ 00132 } 00133 00134 #define REVERSE_DW(a) { \ 00135 PFOUR_BYTE _from_; \ 00136 _from_ = ((PFOUR_BYTE)&(a)); \ 00137 __asm mov eax,_from_ \ 00138 __asm rol word ptr [eax],8 \ 00139 } 00140 00141 #define MOV_DW2DD_SWP(a,b) \ 00142 { \ 00143 PFOUR_BYTE _from_, _to_; \ 00144 _from_ = ((PFOUR_BYTE)&(b)); \ 00145 _to_ = ((PFOUR_BYTE)&(a)); \ 00146 __asm mov ebx,_from_ \ 00147 __asm mov ax,[ebx] \ 00148 __asm rol ax,8 \ 00149 __asm mov ebx,_to_ \ 00150 __asm mov [ebx+2],ax \ 00151 __asm mov [ebx],0 \ 00152 } 00153 00154 #define MOV_SWP_DW2DD(a,b) \ 00155 { \ 00156 PFOUR_BYTE _from_, _to_; \ 00157 _from_ = ((PFOUR_BYTE)&(b)); \ 00158 _to_ = ((PFOUR_BYTE)&(a)); \ 00159 __asm mov ebx,_from_ \ 00160 __asm xor eax,eax \ 00161 __asm mov ax,[ebx] \ 00162 __asm rol ax,8 \ 00163 __asm mov ebx,_to_ \ 00164 __asm mov [ebx],eax \ 00165 } 00166 00167 #define MOV_MSF(a,b) \ 00168 { \ 00169 PFOUR_BYTE _from_, _to_; \ 00170 _from_ = ((PFOUR_BYTE)&(b)); \ 00171 _to_ = ((PFOUR_BYTE)&(a)); \ 00172 __asm mov ebx,_from_ \ 00173 __asm mov eax,[ebx] \ 00174 __asm mov ebx,_to_ \ 00175 __asm mov [ebx],ax \ 00176 __asm shr eax,16 \ 00177 __asm mov [ebx+2],al \ 00178 } 00179 00180 #define MOV_MSF_SWP(a,b) \ 00181 { \ 00182 PFOUR_BYTE _from_, _to_; \ 00183 _from_ = ((PFOUR_BYTE)&(b)); \ 00184 _to_ = ((PFOUR_BYTE)&(a)); \ 00185 __asm mov ebx,_from_ \ 00186 __asm mov eax,[ebx] \ 00187 __asm mov ebx,_to_ \ 00188 __asm mov [ebx+2],al \ 00189 __asm bswap eax \ 00190 __asm shr eax,8 \ 00191 __asm mov [ebx],ax \ 00192 } 00193 00194 #define XCHG_DD(a,b) \ 00195 { \ 00196 PULONG _from_, _to_; \ 00197 _from_ = ((PULONG)&(b)); \ 00198 _to_ = ((PULONG)&(a)); \ 00199 __asm mov ebx,_from_ \ 00200 __asm mov ecx,_to_ \ 00201 __asm mov eax,[ebx] \ 00202 __asm xchg eax,[ecx] \ 00203 __asm mov [ebx],eax \ 00204 } 00205 00206 #else // NO X86 optimization , use generic C/C++ 00207 00208 #define MOV_DD_SWP(a,b) \ 00209 { \ 00210 PFOUR_BYTE _from_, _to_; \ 00211 _from_ = ((PFOUR_BYTE)&(b)); \ 00212 _to_ = ((PFOUR_BYTE)&(a)); \ 00213 _to_->Byte0 = _from_->Byte3; \ 00214 _to_->Byte1 = _from_->Byte2; \ 00215 _to_->Byte2 = _from_->Byte1; \ 00216 _to_->Byte3 = _from_->Byte0; \ 00217 } 00218 00219 #define MOV_DW_SWP(a,b) \ 00220 { \ 00221 PFOUR_BYTE _from_, _to_; \ 00222 _from_ = ((PFOUR_BYTE)&(b)); \ 00223 _to_ = ((PFOUR_BYTE)&(a)); \ 00224 _to_->Byte0 = _from_->Byte1; \ 00225 _to_->Byte1 = _from_->Byte0; \ 00226 } 00227 00228 #define REVERSE_DD(a) { \ 00229 ULONG _i_; \ 00230 MOV_DD_SWP(_i_,(a)); \ 00231 *((PULONG)&(a)) = _i_; \ 00232 } 00233 00234 #define REVERSE_DW(a) { \ 00235 USHORT _i_; \ 00236 MOV_DW_SWP(_i_,(a)); \ 00237 *((PUSHORT)&(a)) = _i_; \ 00238 } 00239 00240 #define MOV_DW2DD_SWP(a,b) \ 00241 { \ 00242 PFOUR_BYTE _from_, _to_; \ 00243 _from_ = ((PFOUR_BYTE)&(b)); \ 00244 _to_ = ((PFOUR_BYTE)&(a)); \ 00245 *((PUSHORT)_to_) = 0; \ 00246 _to_->Byte2 = _from_->Byte1; \ 00247 _to_->Byte3 = _from_->Byte0; \ 00248 } 00249 00250 #define MOV_MSF(a,b) \ 00251 { \ 00252 PFOUR_BYTE _from_, _to_; \ 00253 _from_ = ((PFOUR_BYTE)&(b)); \ 00254 _to_ = ((PFOUR_BYTE)&(a)); \ 00255 _to_->Byte0 = _from_->Byte0; \ 00256 _to_->Byte1 = _from_->Byte1; \ 00257 _to_->Byte2 = _from_->Byte2; \ 00258 } 00259 00260 #define MOV_MSF_SWP(a,b) \ 00261 { \ 00262 PFOUR_BYTE _from_, _to_; \ 00263 _from_ = ((PFOUR_BYTE)&(b)); \ 00264 _to_ = ((PFOUR_BYTE)&(a)); \ 00265 _to_->Byte0 = _from_->Byte2; \ 00266 _to_->Byte1 = _from_->Byte1; \ 00267 _to_->Byte2 = _from_->Byte0; \ 00268 } 00269 00270 #define XCHG_DD(a,b) \ 00271 { \ 00272 ULONG _temp_; \ 00273 PULONG _from_, _to_; \ 00274 _from_ = ((PULONG)&(b)); \ 00275 _to_ = ((PULONG)&(a)); \ 00276 _temp_ = *_from_; \ 00277 *_from_ = *_to_; \ 00278 *_to_ = _temp_; \ 00279 } 00280 00281 #endif // _X86_ 00282 00283 #define MOV_3B_SWP(a,b) MOV_MSF_SWP(a,b) 00284 00285 */ 00286 00287 #ifdef DBG 00288 00289 #define KdDump(a,b) \ 00290 if((a)!=NULL) { \ 00291 ULONG i; \ 00292 for(i=0; i<(b); i++) { \ 00293 ULONG c; \ 00294 c = (ULONG)(*(((PUCHAR)(a))+i)); \ 00295 KdPrint(("%2.2x ",c)); \ 00296 if ((i & 0x0f) == 0x0f) KdPrint(("\n")); \ 00297 } \ 00298 KdPrint(("\n")); \ 00299 } 00300 00301 #define BrutePoint() {} 00302 00303 #define DbgAllocatePool(x,y) ExAllocatePool(x,y) 00304 #define DbgFreePool(x) ExFreePool(x) 00305 #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c) 00306 00307 #else 00308 00309 #define KdDump(a,b) {} 00310 00311 #define DbgAllocatePool(x,y) ExAllocatePool(x,y) 00312 #define DbgFreePool(x) ExFreePool(x) 00313 #define DbgAllocatePoolWithTag(a,b,c) ExAllocatePoolWithTag(a,b,c) 00314 00315 #define BrutePoint() {} 00316 00317 #endif //DBG 00318 00319 00320 00321 #define WAIT_FOR_XXX_EMU_DELAY DEF_I64(5000000) // 0.5 s 00322 00323 // neat little hacks to count number of bits set efficiently 00324 __inline ULONG CountOfSetBitsUChar(UCHAR _X) 00325 { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; } 00326 __inline ULONG CountOfSetBitsULong(ULONG _X) 00327 { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; } 00328 00329 #ifndef max 00330 #define max(a,b) (((a) > (b)) ? (a) : (b)) 00331 #endif //max 00332 00333 #ifndef min 00334 #define min(a,b) (((a) < (b)) ? (a) : (b)) 00335 #endif //min 00336 //#define abs(a) (((a) < 0) ? (-(a)) : (a)) 00337 00338 /* 00339 extern ULONG MajorVersion; 00340 extern ULONG MinorVersion; 00341 extern ULONG BuildNumber; 00342 extern ULONG SPVersion; 00343 */ 00344 00345 #ifdef __cplusplus 00346 }; 00347 #endif //__cplusplus 00348 00349 #ifndef USER_MODE 00350 extern UNICODE_STRING SavedSPString; 00351 #endif //USER_MODE 00352 00353 /* 00354 #define WinVer_Is351 (MajorVersion==0x03) 00355 #define WinVer_IsNT (MajorVersion==0x04) 00356 #define WinVer_Is2k (MajorVersion==0x05 && MinorVersion==0x00) 00357 #define WinVer_IsXP (MajorVersion==0x05 && MinorVersion==0x01) 00358 #define WinVer_IsdNET (MajorVersion==0x05 && MinorVersion==0x02) 00359 00360 #define WinVer_Id() ((MajorVersion << 8) | MinorVersion) 00361 00362 #define WinVer_351 (0x0351) 00363 #define WinVer_NT (0x0400) 00364 #define WinVer_2k (0x0500) 00365 #define WinVer_XP (0x0501) 00366 #define WinVer_dNET (0x0502) 00367 */ 00368 00369 #define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG)(OFFSET) - (ULONG)(BASE))) 00370 00371 #ifndef offsetof 00372 #define offsetof(type, field) (ULONG)&(((type *)0)->field) 00373 #endif //offsetof 00374 00375 #endif // __TOOLS_H__ Generated on Sat May 26 2012 04:27:00 for ReactOS by
1.7.6.1
|