ReactOS  0.4.10-dev-479-g13a3cf0
utils.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  utils.h
8 
9 Abstract:
10 
11  HEADER for utils.c
12 
13 Environment:
14 
15  LINUX 2.2.X
16  Kernel mode only
17 
18 Author:
19 
20  Klaus P. Gerlicher
21 
22 Revision History:
23 
24  15-Nov-2000: general cleanup of source files
25 
26 Copyright notice:
27 
28  This file may be distributed under the terms of the GNU Public License.
29 
30 --*/
31 #include <stdarg.h>
32 #include "../../../../ntoskrnl/include/internal/ps.h"
33 #define __STR(x) #x
34 #define STR(x) __STR(x)
35 
36 typedef enum {
42 
43 // scancode to ASCII conversion
44 typedef struct tagSCANTOASCII
45 {
46  UCHAR s; // 0 terminates the table
49 
50 typedef struct tagKEYBOARD_LAYOUT
51 {
53  PSCANTOASCII normal;
54  PSCANTOASCII shifted;
55  PSCANTOASCII alted;
57 
58 extern PKEYBOARD_LAYOUT CurrentKeyboard;
59 
60 typedef struct _FRAME
61 {
66 }FRAME;
67 
68 #define SHOW_FIELD_BYTE(ptr,field,wait)\
69 {\
70  if(wait && WaitForKey()==FALSE)\
71  return TRUE;\
72  PICE_sprintf(tempCmd,#field" = %.2x\n",ptr->##field);\
73  Print(OUTPUT_WINDOW,tempCmd);\
74 }
75 
76 #define SHOW_FIELD_WORD(ptr,field,wait)\
77 {\
78  if(wait && WaitForKey()==FALSE)\
79  return TRUE;\
80  PICE_sprintf(tempCmd,#field" = %.4x\n",ptr->##field);\
81  Print(OUTPUT_WINDOW,tempCmd);\
82 }
83 
84 #define SHOW_FIELD_DWORD(ptr,field,wait)\
85 {\
86  if(wait && WaitForKey()==FALSE)\
87  return TRUE;\
88  PICE_sprintf(tempCmd,#field" = %.8x\n",ptr->##field);\
89  Print(OUTPUT_WINDOW,tempCmd);\
90 }
91 
92 #define SHOW_FIELD_SEG_OFS(ptr,field1,field2,wait)\
93 {\
94  if(wait && WaitForKey()==FALSE)\
95  return TRUE;\
96  PICE_sprintf(tempCmd,#field1":"#field2" = %.4x:%.8x\n",ptr->##field1,ptr->##field2);\
97  Print(OUTPUT_WINDOW,tempCmd);\
98 }
99 
100 typedef struct _PCI_NUMBER
101 {
102  union {
103  struct
104  {
105  ULONG res2 : 2;
106  ULONG reg : 6; // 64 regs per function
107  ULONG func : 3; // 8 functions per device
108  ULONG dev : 5; // 32 device per bus
109  ULONG bus : 8; // 256 buses
110  ULONG res1 : 7;
111  ULONG ce : 1; // 1 to enable
112  }bits;
114  }u;
115 }PCI_NUMBER;
116 /*
117 typedef struct _PCI_COMMON_CONFIG {
118  USHORT VendorID; // (ro)
119  USHORT DeviceID; // (ro)
120  USHORT Command; // Device control
121  USHORT Status;
122  UCHAR RevisionID; // (ro)
123  UCHAR ProgIf; // (ro)
124  UCHAR SubClass; // (ro)
125  UCHAR BaseClass; // (ro)
126  UCHAR CacheLineSize; // (ro+)
127  UCHAR LatencyTimer; // (ro+)
128  UCHAR HeaderType; // (ro)
129  UCHAR BIST; // Built in self test
130  ULONG BaseAddresses[6];
131  ULONG CIS;
132  USHORT SubVendorID;
133  USHORT SubSystemID;
134  ULONG ROMBaseAddress;
135  UCHAR CapabilitiesPtr;
136  UCHAR Reserved1[3];
137  ULONG Reserved2;
138  UCHAR InterruptLine; //
139  UCHAR InterruptPin; // (ro)
140  UCHAR MinimumGrant; // (ro)
141  UCHAR MaximumLatency; // (ro)
142 }PCI_COMMON_CONFIG;
143 */
144 
145 typedef struct tagPageDir
146 {
147  ULONG P :1;
148  ULONG RW :1;
149  ULONG US :1;
150  ULONG PWT :1;
151  ULONG PCD :1;
152  ULONG A :1;
154  ULONG PS :1;
155  ULONG G :1;
158 }PAGEDIR,*PPAGEDIR;
159 
160 typedef struct tagGdt
161 {
167  ULONG Dpl :2;
170  ULONG Avl :1;
175 }GDT,*PGDT;
176 
177 typedef struct tagIdt
178 {
183  ULONG Dpl :2;
186 }IDT,*PIDT;
187 
188 typedef struct tagDESCRIPTOR
189 {
190  USHORT Cpl :2; // current privilege level
191  USHORT Ti :1; // table index (GDT=0 LDT=1)
192  USHORT Val :13; // index into table
194 
195 PKEYBOARD_LAYOUT GetKeyboardLayout();
196 PKEYBOARD_LAYOUT SetKeyboardLayoutByName(LPSTR Name);
197 void PICE_memset(void* p,unsigned char c,int sz);
198 void PICE_memcpy(void* t,void* s,int sz);
199 char *PICE_strrev(char *);
200 ULONG PICE_strcmp(char* s1,char* s2);
201 ULONG PICE_strcmpi(char* s1,char* s2);
202 ULONG PICE_strncmpi(char* s1,char* s2,ULONG len);
203 USHORT PICE_strlen(const char* s);
204 char* PICE_strcat(char* s1,char* s2);
205 BOOLEAN PICE_isprint(char c);
206 char* PICE_strcpy(char* s1,char* s2);
207 char* PICE_strncpy(char* s1,char* s2,int len);
208 char* PICE_strchr(char* s,char c);
209 int PICE_isdigit( int c );
210 int PICE_isxdigit( int c );
211 int PICE_islower( int c );
212 int PICE_isalpha( int c );
213 
214 int PICE_sprintf(char * buf, const char *fmt, ...);
215 int PICE_vsprintf(char *buf, const char *fmt, va_list args);
216 
221 void IntelStackWalk(ULONG pc,ULONG ebp,ULONG esp);
222 
224 void WritePhysMem(ULONG Address,ULONG Datum,ULONG ulSize);
225 
226 BOOLEAN IsRetAtEIP(void);
228 
230 
231 #define OUTPUT_BUFFER_FULL 0x01
232 #define INPUT_BUFFER_FULL 0x02
233 #define MOUSE_OUTPUT_BUFFER_FULL 0x20
234 
235 void ShowStoppedMsg(void);
236 void ShowRunningMsg(void);
237 
238 void SetHardwareBreakPoints(void);
239 void SetHardwareBreakPoint(ULONG ulAddress,ULONG ulReg);
240 
241 // this should be in disasm.h but someone misused the header files
242 BOOLEAN Disasm(PULONG pOffset, PUCHAR pchDst);
244 
245 //segments defined in \include\napi\i386\segment.h
246 #define GLOBAL_CODE_SEGMENT (KERNEL_CS)
247 #define GLOBAL_DATA_SEGMENT (KERNEL_DS)
248 
249 //#define OVR_CS .byte 0x2e
250 //#define OVR_FS .byte 0x64
251 
252 void DisplayRegs(void);
253 void SaveOldRegs(void);
254 
255 BOOLEAN CheckLoadAbort(void);
256 
258 void KeyboardFlushKeyboardQueue(void);
259 
260 #define _PAGE_PRESENT 0x001
261 #define _PAGE_RW 0x002
262 #define _PAGE_USER 0x004
263 #define _PAGE_PWT 0x008
264 #define _PAGE_PCD 0x010
265 #define _PAGE_ACCESSED 0x020
266 #define _PAGE_DIRTY 0x040
267 #define _PAGE_PSE 0x080
268 #define _PAGE_4M _PAGE_PSE
269 #define _PAGE_SIZE 0x1000
270 
271 
274 
277 
278 void outb_p(UCHAR data, PUCHAR port);
280 
283 
284 
285 #define save_flags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
286 #define restore_flags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
287 #define cli() __asm__ __volatile__("cli": : :"memory")
288 #define sti() __asm__ __volatile__("sti": : :"memory")
289 
290 #ifdef NDEBUG
291 #define ASSERT(x)
292 #else
293 #define ASSERT(x) if (!(x)) { DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__, __LINE__); KeBugCheck(0); }
294 #endif
295 
296 //extern unsigned long sys_call_table[];
297 
298 //struct mm_struct *GetInitMm(void);
299 
300 PMADDRESS_SPACE my_init_mm;
302 
303 void EnablePassThrough(void);
304 
305 #define PAGEDPOOL (1)
306 #define NONPAGEDPOOL (0)
307 
308 void * PICE_malloc( size_t numBytes, BOOLEAN fromPaged );
309 void PICE_free( void* p );
310 
311 HANDLE PICE_open (LPCWSTR lpPathName, int iReadWrite);
312 long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes);
313 int PICE_close (HANDLE hFile);
314 size_t PICE_len( HANDLE hFile );
315 WCHAR * PICE_wcscpy(WCHAR * str1,const WCHAR * str2);
316 INT
317 WINAPI
319  UINT CodePage,
320  DWORD dwFlags,
321  LPCSTR lpMultiByteStr,
322  int cchMultiByte,
323  LPWSTR lpWideCharStr,
324  int cchWideChar
325  );
ULONG P
Definition: utils.h:147
struct tagIdt * PIDT
PKEYBOARD_LAYOUT SetKeyboardLayoutByName(LPSTR Name)
Definition: utils.c:208
long PICE_read(HANDLE hFile, LPVOID lpBuffer, long lBytes)
Definition: utils.c:2228
struct tagPageDir PAGEDIR
struct tagIdt IDT
int PICE_isxdigit(int c)
Definition: utils.c:342
struct S2 s2
int PICE_vsprintf(char *buf, const char *fmt, va_list args)
Definition: utils.c:1850
PVOID ULONG Address
Definition: oprghdlr.h:14
ULONG error_code
Definition: utils.h:62
INT WINAPI PICE_MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar)
Definition: utils.c:2335
ULONG DescType
Definition: utils.h:166
WCHAR * PICE_wcscpy(WCHAR *str1, const WCHAR *str2)
Definition: utils.c:559
BOOLEAN Disasm(PULONG pOffset, PUCHAR pchDst)
Definition: disassembler.c:705
void ShowStoppedMsg(void)
Definition: utils.c:861
ULONG Gran
Definition: utils.h:173
char * PICE_strcat(char *s1, char *s2)
Definition: utils.c:315
ULONG Present
Definition: utils.h:168
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm0 paddd mm4 mm0 mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm0 mm0 packssdw mm0 movd eax movw edi esi edx esi ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm1 paddd mm5 mm1 mm5 packssdw mm1 packssdw mm5 psubd mm0 psubd mm4 psubsw mm0 psubsw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm1 mm1 packssdw mm1 psubd mm0 psubsw mm0 movd eax movw edi emms popl ebx popl esi popl edi mov ebp
Definition: synth_sse3d.h:248
BOOLEAN IsAddressValid(ULONG Addr)
Definition: utils.c:611
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
void WritePhysMem(ULONG Address, ULONG Datum, ULONG ulSize)
Definition: utils.c:1680
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct tagDESCRIPTOR DESCRIPTOR
BOOLEAN IsAddressWriteable(ULONG Addr)
Definition: utils.c:650
void outb_p(UCHAR data, PUCHAR port)
Definition: utils.c:2159
unsigned char * PUCHAR
Definition: retypes.h:3
UCHAR AsciiToScan(UCHAR s)
Definition: utils.c:2113
HANDLE PICE_open(LPCWSTR lpPathName, int iReadWrite)
Definition: utils.c:2250
UCHAR a
Definition: utils.h:47
void SetHardwareBreakPoints(void)
Definition: utils.c:952
char * PICE_strncpy(char *s1, char *s2, int len)
Definition: utils.c:286
GLdouble GLdouble t
Definition: gl.h:2047
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
void PICE_memset(void *p, unsigned char c, int sz)
Definition: utils.c:228
BOOLEAN IsRetAtEIP(void)
Definition: utils.c:1038
ULONG SegType
Definition: utils.h:165
char * LPSTR
Definition: xmlstorage.h:182
ULONG Base_15_0
Definition: utils.h:163
Definition: match.c:390
void outportb(PUCHAR port, UCHAR data)
Definition: utils.c:2154
void KeyboardFlushKeyboardQueue(void)
Definition: utils.c:1455
int32_t INT
Definition: typedefs.h:56
ULONG eflags
Definition: utils.h:65
ULONG bus
Definition: utils.h:109
DWORD DWORD
Definition: winlogon.h:83
struct tagGdt GDT
struct tagKEYBOARD_LAYOUT * PKEYBOARD_LAYOUT
UCHAR inportb(PUCHAR port)
Definition: utils.c:2174
char * PICE_strrev(char *)
Definition: utils.c:527
PMADDRESS_SPACE my_init_mm
Definition: utils.h:300
union _PCI_NUMBER::@1470 u
ULONG res2
Definition: utils.h:105
UCHAR inb_p(PUCHAR port)
Definition: utils.c:2179
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
void PICE_memcpy(void *t, void *s, int sz)
Definition: utils.c:239
ULONG PWT
Definition: utils.h:150
PKEYBOARD_LAYOUT GetKeyboardLayout()
Definition: utils.c:194
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:163
ULONG dummy
Definition: utils.h:153
ULONG Selector
Definition: utils.h:180
Definition: utils.h:38
int PICE_close(HANDLE hFile)
Definition: utils.c:2300
char * va_list
Definition: acmsvcex.h:78
ULONG Dpl
Definition: utils.h:167
ULONG PICE_strcmp(char *s1, char *s2)
Definition: utils.c:410
const char * LPCSTR
Definition: xmlstorage.h:183
ULONG US
Definition: utils.h:149
BOOLEAN PICE_isprint(char c)
Definition: utils.c:248
ULONG RW
Definition: utils.h:148
char * PICE_strchr(char *s, char c)
Definition: utils.c:262
Definition: utils.h:37
_Inout_ PVOID Segment
Definition: exfuncs.h:893
Definition: utils.h:160
Definition: utils.h:177
struct tagKEYBOARD_LAYOUT KEYBOARD_LAYOUT
r l[0]
Definition: byte_order.h:167
unsigned char BOOLEAN
ULONG PCD
Definition: utils.h:151
size_t PICE_len(HANDLE hFile)
Definition: utils.c:2310
PSCANTOASCII alted
Definition: utils.h:55
ULONG eip
Definition: utils.h:63
VOID outl(ULONG l, PULONG port)
Definition: utils.c:2164
struct S1 s1
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
void SaveOldRegs(void)
Definition: utils.c:1324
PKEYBOARD_LAYOUT CurrentKeyboard
Definition: utils.c:183
ULONG ce
Definition: utils.h:111
const GLubyte * c
Definition: glext.h:8905
LIST_ENTRY * pPsProcessListHead
Definition: utils.h:301
struct tagGdt * PGDT
BOOLEAN CheckLoadAbort(void)
Definition: utils.c:1471
struct _PCI_NUMBER PCI_NUMBER
GLuint address
Definition: glext.h:9393
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
ULONG inl(PULONG port)
Definition: utils.c:2184
BOOLEAN SetAddressWriteable(ULONG address, BOOLEAN bSet)
Definition: utils.c:688
int PICE_isalpha(int c)
Definition: utils.c:352
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
UCHAR AsciiFromScan(UCHAR s)
Definition: utils.c:2069
ULONG reg
Definition: utils.h:106
_In_ PUNICODE_STRING Name
Definition: mrx.h:218
ULONG PVOID Reserved
Definition: ntimage.h:533
ULONG DefOp
Definition: utils.h:172
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _PCI_NUMBER::@1470::@1471 bits
ULONG PICE_strncmpi(char *s1, char *s2, ULONG len)
Definition: utils.c:362
Definition: ttei1.cpp:12
GLenum const GLvoid * addr
Definition: glext.h:9621
ULONG PTBase
Definition: utils.h:157
VOID UINTN Length
Definition: acefiex.h:744
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
ULONG Offset_15_0
Definition: utils.h:179
USHORT Cpl
Definition: utils.h:190
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
Definition: typedefs.h:117
_In_ HANDLE hFile
Definition: mswsock.h:90
UCHAR KeyboardGetKeyPolled(void)
Definition: utils.c:1375
void ShowRunningMsg(void)
Definition: utils.c:843
#define WINAPI
Definition: msvc.h:20
void EnablePassThrough(void)
Definition: utils.c:2194
PSCANTOASCII normal
Definition: utils.h:53
BOOLEAN IsCallInstrAtEIP(void)
Definition: utils.c:1008
struct tagPageDir * PPAGEDIR
struct _FRAME FRAME
ULONG Offset_31_16
Definition: utils.h:185
ULONG res1
Definition: utils.h:110
struct tagDESCRIPTOR * PDESCRIPTOR
ULONG Avl
Definition: utils.h:170
DWORD *typedef HANDLE
Definition: winlogon.h:60
ULONG Limit_15_0
Definition: utils.h:162
unsigned short USHORT
Definition: pedump.c:61
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
ULONG PICE_strcmpi(char *s1, char *s2)
Definition: utils.c:387
USHORT Ti
Definition: utils.h:191
unsigned int * PULONG
Definition: retypes.h:1
int PICE_islower(int c)
Definition: utils.c:347
unsigned int UINT
Definition: ndis.h:50
ULONG G
Definition: utils.h:155
ULONG Base_31_24
Definition: utils.h:174
void * PICE_malloc(size_t numBytes, BOOLEAN fromPaged)
Definition: utils.c:2212
ULONG PS
Definition: utils.h:154
ULONG Avail
Definition: utils.h:156
USHORT Val
Definition: utils.h:192
Definition: utils.h:39
int PICE_isdigit(int c)
Definition: utils.c:337
ULONG GetLinearAddress(USHORT Segment, ULONG Offset)
Definition: utils.c:782
unsigned int ULONG
Definition: retypes.h:1
ULONG Limit_19_16
Definition: utils.h:169
ULONG ReadPhysMem(ULONG Address, ULONG ulSize)
Definition: utils.c:1633
ULONG Base_23_16
Definition: utils.h:164
ULONG Dpl
Definition: utils.h:183
void DisplayRegs(void)
Definition: utils.c:1097
GLfloat GLfloat p
Definition: glext.h:8902
void SetHardwareBreakPoint(ULONG ulAddress, ULONG ulReg)
Definition: utils.c:878
BOOLEAN IsRangeValid(ULONG addr, ULONG Length)
Definition: utils.c:735
void IntelStackWalk(ULONG pc, ULONG ebp, ULONG esp)
Definition: utils.c:1530
PSCANTOASCII shifted
Definition: utils.h:54
ULONG DescType
Definition: utils.h:182
USHORT port
Definition: uri.c:227
WCHAR * LPWSTR
Definition: xmlstorage.h:184
ULONG AsUlong
Definition: utils.h:113
ULONG Present
Definition: utils.h:184
Definition: dsound.c:943
struct tagSCANTOASCII * PSCANTOASCII
struct tagSCANTOASCII SCANTOASCII
UCHAR s
Definition: utils.h:46
KeyboardLayout
Definition: utils.h:36
Definition: i386bug.c:6
void PICE_free(void *p)
Definition: utils.c:2222
ULONG cs
Definition: utils.h:64