1 | /* $Id: debug.c,v 1.2 2000/05/28 16:50:44 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /******************************************************************************
|
---|
4 | * Jazz16 Physical Device Driver
|
---|
5 | * Production code and toolkit sample
|
---|
6 | *
|
---|
7 | * (c) Copyright IBM Corporation 1993. All rights reserved
|
---|
8 | * (c) Copyright Media Vision Corporation 1993, 1994. All rights reserved
|
---|
9 | *
|
---|
10 | * DISCLAIMER OF WARRANTIES. The following [enclosed] code is
|
---|
11 | * sample code created by IBM Corporation and Media Vision Corporation.
|
---|
12 | * It is provided to you solely for the purpose of assisting you in the
|
---|
13 | * development of your applications.
|
---|
14 | * The code is provided "AS IS", without warranty of any kind.
|
---|
15 | * IBM and Media Vision shall not be liable for any damages arising out of
|
---|
16 | * your use of the sample code, even if they have been advised of the
|
---|
17 | * possibility of such damages.
|
---|
18 | *
|
---|
19 | *******************************************************************************
|
---|
20 | *
|
---|
21 | * commdbg.c = debug routines to send data to COM: port
|
---|
22 | *
|
---|
23 | * This file contains routines to send debug information to COM: ports
|
---|
24 | * during execution of device driver.
|
---|
25 | * The routines provide 'C' printf like functions that send their output
|
---|
26 | * to the serial port rather than stdout.
|
---|
27 | * The calls to these routines are only called for debug versions of the
|
---|
28 | * driver. See file debug.h for flags to turn on/off different debug options.
|
---|
29 | *
|
---|
30 | * MODIFICATION HISTORY:
|
---|
31 | * DATE CHANGE DESCRIPTION
|
---|
32 | * unknown Creation (Media Vision)
|
---|
33 | * 07/30/93 Add headers for toolkit
|
---|
34 | * 09/21/93 Header modifications
|
---|
35 | ******************************************************************************/
|
---|
36 |
|
---|
37 | #define INCL_NOPMAPI
|
---|
38 | #define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
|
---|
39 | #include <os2.h>
|
---|
40 |
|
---|
41 |
|
---|
42 | #define CR 0x0d
|
---|
43 | #define LF 0x0a
|
---|
44 |
|
---|
45 |
|
---|
46 | #define LEADING_ZEROES 0x8000
|
---|
47 | #define SIGNIFICANT_FIELD 0x0007
|
---|
48 |
|
---|
49 | BOOL fLineTerminate = TRUE;
|
---|
50 |
|
---|
51 | static char hextab[]="0123456789ABCDEF";
|
---|
52 |
|
---|
53 | #ifdef DEBUG
|
---|
54 | #define MAGIC_COMM_PORT 0x3f8 // pulled from word ptr 40:0
|
---|
55 | //#define MAGIC_COMM_PORT 0x2f8 // pulled from word ptr 40:0
|
---|
56 |
|
---|
57 |
|
---|
58 | #define UART_DATA 0x00 // UART Data port
|
---|
59 | #define UART_INT_ENAB 0x01 // UART Interrupt enable
|
---|
60 | #define UART_INT_ID 0x02 // interrupt ID
|
---|
61 | #define UART_LINE_CTRL 0x03 // line control registers
|
---|
62 | #define UART_MODEM_CTRL 0x04 // modem control register
|
---|
63 | #define UART_LINE_STAT 0x05 // line status register
|
---|
64 | #define UART_MODEM_STAT 0x06 // modem status regiser
|
---|
65 | #define UART_DIVISOR_LO 0x00 // divisor latch least sig
|
---|
66 | #define UART_DIVISOR_HI 0x01h // divisor latch most sig
|
---|
67 |
|
---|
68 | #define DELAY nop
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | #ifdef DEBUG //--------------------------- CharOut -
|
---|
72 | void CharOut(char c)
|
---|
73 | {
|
---|
74 | _asm {
|
---|
75 |
|
---|
76 | mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
|
---|
77 | add dx, UART_LINE_STAT
|
---|
78 |
|
---|
79 | ReadyCheck:
|
---|
80 | in al, dx // wait for comm port ready signal
|
---|
81 |
|
---|
82 | DELAY
|
---|
83 | DELAY
|
---|
84 | DELAY
|
---|
85 |
|
---|
86 | test al, 020h
|
---|
87 | jz ReadyCheck
|
---|
88 |
|
---|
89 | // Send the character
|
---|
90 |
|
---|
91 | add dx, UART_DATA - UART_LINE_STAT
|
---|
92 | mov al,c
|
---|
93 | out dx, al
|
---|
94 |
|
---|
95 | DELAY
|
---|
96 | DELAY
|
---|
97 | DELAY
|
---|
98 | }
|
---|
99 | }
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | #ifdef DEBUG //------------------------- StringOut -
|
---|
103 | void StringOut(char *DbgStr)
|
---|
104 | {
|
---|
105 | while (*DbgStr)
|
---|
106 | CharOut(*DbgStr++);
|
---|
107 |
|
---|
108 | if (fLineTerminate)
|
---|
109 | {
|
---|
110 | CharOut(CR); // append carriage return,
|
---|
111 | CharOut(LF); // linefeed
|
---|
112 | }
|
---|
113 | }
|
---|
114 | #endif
|
---|
115 | //-------------------- DecLongToASCII -
|
---|
116 | char * DecLongToASCII(char *StrPtr, ULONG lDecVal, USHORT Option)
|
---|
117 | {
|
---|
118 | ULONG Power;
|
---|
119 | USHORT Digit;
|
---|
120 | USHORT fNonZero = Option & LEADING_ZEROES;
|
---|
121 |
|
---|
122 | for( Power = 1000000000L; Power; Power /= 10 )
|
---|
123 | {
|
---|
124 | Digit = 0;
|
---|
125 | while( lDecVal >= Power ) { Digit++; lDecVal -= Power; }
|
---|
126 | fNonZero |= Digit;
|
---|
127 |
|
---|
128 | if( fNonZero || Power == 1 ) *StrPtr++ = (char)('0' + Digit);
|
---|
129 | }
|
---|
130 |
|
---|
131 | return StrPtr;
|
---|
132 | }
|
---|
133 |
|
---|
134 | //-------------------- HexLongToASCII -
|
---|
135 | char * HexLongToASCII(char *StrPtr, ULONG lHexVal, USHORT Option)
|
---|
136 | {
|
---|
137 | USHORT Digit;
|
---|
138 | SHORT ShiftVal;
|
---|
139 | USHORT fNonZero = Option & LEADING_ZEROES;
|
---|
140 |
|
---|
141 | for( ShiftVal = 28; ShiftVal >= 0; ShiftVal -= 4 )
|
---|
142 | {
|
---|
143 | Digit = (USHORT)(lHexVal >> ShiftVal) & 0xf;
|
---|
144 | fNonZero |= Digit;
|
---|
145 |
|
---|
146 | if( fNonZero || !ShiftVal ) *StrPtr++ = hextab[Digit];
|
---|
147 | }
|
---|
148 |
|
---|
149 | return StrPtr;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | #ifdef DEBUG
|
---|
154 | char BuildString[1024];
|
---|
155 | #endif // DEBUG
|
---|
156 |
|
---|
157 | //------------------------- PrintfOut -
|
---|
158 | void _cdecl DPD(int level, char *DbgStr, ...)
|
---|
159 | {
|
---|
160 | #ifdef DEBUG
|
---|
161 | char *BuildPtr=BuildString;
|
---|
162 | char *pStr=(char *) DbgStr;
|
---|
163 | char *SubStr;
|
---|
164 | union {
|
---|
165 | void *VoidPtr;
|
---|
166 | USHORT *WordPtr;
|
---|
167 | ULONG *LongPtr;
|
---|
168 | ULONG *StringPtr;
|
---|
169 | } Parm;
|
---|
170 | USHORT wBuildOption;
|
---|
171 |
|
---|
172 | Parm.VoidPtr=(void *) &DbgStr;
|
---|
173 | Parm.StringPtr++; // skip size of string pointer
|
---|
174 |
|
---|
175 | while (*pStr)
|
---|
176 | {
|
---|
177 | // don't overflow target
|
---|
178 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
---|
179 | break;
|
---|
180 |
|
---|
181 | switch (*pStr)
|
---|
182 | {
|
---|
183 | case '%':
|
---|
184 | wBuildOption=0;
|
---|
185 | pStr++;
|
---|
186 |
|
---|
187 | if (*pStr=='#')
|
---|
188 | pStr++;
|
---|
189 | /*
|
---|
190 | if (*pStr=='u') // always unsigned
|
---|
191 | pStr++;
|
---|
192 | */
|
---|
193 | if (*pStr=='0')
|
---|
194 | {
|
---|
195 | wBuildOption|=LEADING_ZEROES;
|
---|
196 | pStr++;
|
---|
197 | }
|
---|
198 |
|
---|
199 | while( *pStr >= '1' && *pStr <= '9' ) pStr++;
|
---|
200 |
|
---|
201 | switch(*pStr)
|
---|
202 | {
|
---|
203 | case 'x':
|
---|
204 | case 'X':
|
---|
205 | case 'p':
|
---|
206 | case 'P':
|
---|
207 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
208 | pStr++;
|
---|
209 | continue;
|
---|
210 |
|
---|
211 | case 'u':
|
---|
212 | case 'd':
|
---|
213 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
214 | pStr++;
|
---|
215 | continue;
|
---|
216 |
|
---|
217 | case 's':
|
---|
218 | SubStr=(char *)*Parm.StringPtr;
|
---|
219 | while (*BuildPtr++ = *SubStr++);
|
---|
220 | Parm.StringPtr++;
|
---|
221 | BuildPtr--; // remove the \0
|
---|
222 | pStr++;
|
---|
223 | continue;
|
---|
224 |
|
---|
225 | case 'l':
|
---|
226 | pStr++;
|
---|
227 | switch (*pStr)
|
---|
228 | {
|
---|
229 | case 'x':
|
---|
230 | case 'X':
|
---|
231 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
232 | pStr++;
|
---|
233 | continue;
|
---|
234 |
|
---|
235 | case 'd':
|
---|
236 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
237 | pStr++;
|
---|
238 | continue;
|
---|
239 | } // end switch
|
---|
240 | continue; // dunno what he wants
|
---|
241 |
|
---|
242 | case 0:
|
---|
243 | continue;
|
---|
244 | } // end switch
|
---|
245 | break;
|
---|
246 |
|
---|
247 | case '\\':
|
---|
248 | pStr++;
|
---|
249 | switch (*pStr)
|
---|
250 | {
|
---|
251 | case 'n':
|
---|
252 | *BuildPtr++=LF;
|
---|
253 | pStr++;
|
---|
254 | continue;
|
---|
255 |
|
---|
256 | case 'r':
|
---|
257 | *BuildPtr++=CR;
|
---|
258 | pStr++;
|
---|
259 | continue;
|
---|
260 |
|
---|
261 | case 0:
|
---|
262 | continue;
|
---|
263 | break;
|
---|
264 | } // end switch
|
---|
265 |
|
---|
266 | break;
|
---|
267 | } // end switch
|
---|
268 |
|
---|
269 | *BuildPtr++=*pStr++;
|
---|
270 | } // end while
|
---|
271 |
|
---|
272 | *BuildPtr=0; // cauterize the string
|
---|
273 | StringOut((char *) BuildString); // print to comm port
|
---|
274 | #endif //DEBUG
|
---|
275 | }
|
---|
276 |
|
---|
277 |
|
---|
278 | void _cdecl DPE(char *DbgStr, ...)
|
---|
279 | {
|
---|
280 | #ifdef DEBUG
|
---|
281 | char *BuildPtr=BuildString;
|
---|
282 | char *pStr=(char *) DbgStr;
|
---|
283 | char *SubStr;
|
---|
284 | union {
|
---|
285 | void *VoidPtr;
|
---|
286 | USHORT *WordPtr;
|
---|
287 | ULONG *LongPtr;
|
---|
288 | ULONG *StringPtr;
|
---|
289 | } Parm;
|
---|
290 | USHORT wBuildOption;
|
---|
291 |
|
---|
292 | Parm.VoidPtr=(void *) &DbgStr;
|
---|
293 | Parm.StringPtr++; // skip size of string pointer
|
---|
294 |
|
---|
295 | while (*pStr)
|
---|
296 | {
|
---|
297 | // don't overflow target
|
---|
298 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
---|
299 | break;
|
---|
300 |
|
---|
301 | switch (*pStr)
|
---|
302 | {
|
---|
303 | case '%':
|
---|
304 | wBuildOption=0;
|
---|
305 | pStr++;
|
---|
306 |
|
---|
307 | if (*pStr=='#')
|
---|
308 | pStr++;
|
---|
309 | /*
|
---|
310 | if (*pStr=='u') // always unsigned
|
---|
311 | pStr++;
|
---|
312 | */
|
---|
313 | if (*pStr=='0')
|
---|
314 | {
|
---|
315 | wBuildOption|=LEADING_ZEROES;
|
---|
316 | pStr++;
|
---|
317 | }
|
---|
318 |
|
---|
319 | while( *pStr >= '1' && *pStr <= '9' ) pStr++;
|
---|
320 |
|
---|
321 | switch(*pStr)
|
---|
322 | {
|
---|
323 | case 'x':
|
---|
324 | case 'X':
|
---|
325 | case 'p':
|
---|
326 | case 'P':
|
---|
327 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
328 | pStr++;
|
---|
329 | continue;
|
---|
330 |
|
---|
331 | case 'u':
|
---|
332 | case 'd':
|
---|
333 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
334 | pStr++;
|
---|
335 | continue;
|
---|
336 |
|
---|
337 | case 's':
|
---|
338 | SubStr=(char *)*Parm.StringPtr;
|
---|
339 | while (*BuildPtr++ = *SubStr++);
|
---|
340 | Parm.StringPtr++;
|
---|
341 | BuildPtr--; // remove the \0
|
---|
342 | pStr++;
|
---|
343 | continue;
|
---|
344 |
|
---|
345 | case 'l':
|
---|
346 | pStr++;
|
---|
347 | switch (*pStr)
|
---|
348 | {
|
---|
349 | case 'x':
|
---|
350 | case 'X':
|
---|
351 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
352 | pStr++;
|
---|
353 | continue;
|
---|
354 |
|
---|
355 | case 'd':
|
---|
356 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
---|
357 | pStr++;
|
---|
358 | continue;
|
---|
359 | } // end switch
|
---|
360 | continue; // dunno what he wants
|
---|
361 |
|
---|
362 | case 0:
|
---|
363 | continue;
|
---|
364 | } // end switch
|
---|
365 | break;
|
---|
366 |
|
---|
367 | case '\\':
|
---|
368 | pStr++;
|
---|
369 | switch (*pStr)
|
---|
370 | {
|
---|
371 | case 'n':
|
---|
372 | *BuildPtr++=LF;
|
---|
373 | pStr++;
|
---|
374 | continue;
|
---|
375 |
|
---|
376 | case 'r':
|
---|
377 | *BuildPtr++=CR;
|
---|
378 | pStr++;
|
---|
379 | continue;
|
---|
380 |
|
---|
381 | case 0:
|
---|
382 | continue;
|
---|
383 | break;
|
---|
384 | } // end switch
|
---|
385 |
|
---|
386 | break;
|
---|
387 | } // end switch
|
---|
388 |
|
---|
389 | *BuildPtr++=*pStr++;
|
---|
390 | } // end while
|
---|
391 |
|
---|
392 | *BuildPtr=0; // cauterize the string
|
---|
393 | StringOut((char *) BuildString); // print to comm port
|
---|
394 | #endif //DEBUG
|
---|
395 | }
|
---|
396 |
|
---|