| 1 | /* $Id: debug.c 151 2000-05-28 16:50:46Z sandervl $ */
|
|---|
| 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 | char hextab[]="0123456789ABCDEF";
|
|---|
| 52 |
|
|---|
| 53 | //-------------------- DecLongToASCII -
|
|---|
| 54 | char * DecLongToASCII(char *StrPtr, ULONG lDecVal,USHORT Option)
|
|---|
| 55 | {
|
|---|
| 56 | BOOL fNonZero=FALSE;
|
|---|
| 57 | ULONG Digit;
|
|---|
| 58 | ULONG Power=1000000000; // 1 billion
|
|---|
| 59 |
|
|---|
| 60 | while (Power)
|
|---|
| 61 | {
|
|---|
| 62 | Digit=0; // Digit=lDecVal/Power
|
|---|
| 63 | while (lDecVal >=Power) // replaced with while loop
|
|---|
| 64 | {
|
|---|
| 65 | Digit++;
|
|---|
| 66 | lDecVal-=Power;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | if (Digit)
|
|---|
| 70 | fNonZero=TRUE;
|
|---|
| 71 |
|
|---|
| 72 | if (Digit ||
|
|---|
| 73 | fNonZero ||
|
|---|
| 74 | (Option & LEADING_ZEROES) ||
|
|---|
| 75 | ((Power==1) && (fNonZero==FALSE)))
|
|---|
| 76 | {
|
|---|
| 77 | *StrPtr=(char)('0'+Digit);
|
|---|
| 78 | StrPtr++;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | if (Power==1000000000) // 1 billion
|
|---|
| 82 | Power=100000000;
|
|---|
| 83 | else if (Power==100000000)
|
|---|
| 84 | Power=10000000;
|
|---|
| 85 | else if (Power==10000000)
|
|---|
| 86 | Power=1000000;
|
|---|
| 87 | else if (Power==1000000)
|
|---|
| 88 | Power=100000;
|
|---|
| 89 | else if (Power==100000)
|
|---|
| 90 | Power=10000;
|
|---|
| 91 | else if (Power==10000)
|
|---|
| 92 | Power=1000;
|
|---|
| 93 | else if (Power==1000)
|
|---|
| 94 | Power=100;
|
|---|
| 95 | else if (Power==100)
|
|---|
| 96 | Power=10;
|
|---|
| 97 | else if (Power==10)
|
|---|
| 98 | Power=1;
|
|---|
| 99 | else
|
|---|
| 100 | Power=0;
|
|---|
| 101 | }
|
|---|
| 102 | return (StrPtr);
|
|---|
| 103 | }
|
|---|
| 104 | //-------------------- HexWordToASCII -
|
|---|
| 105 | //-------------------- HexLongToASCII -
|
|---|
| 106 | char * HexLongToASCII(char *StrPtr, ULONG wHexVal, USHORT Option)
|
|---|
| 107 | {
|
|---|
| 108 | BOOL fNonZero=FALSE;
|
|---|
| 109 | ULONG Digit;
|
|---|
| 110 | ULONG Power=0xF0000000;
|
|---|
| 111 | ULONG ShiftVal=28;
|
|---|
| 112 |
|
|---|
| 113 | while (Power)
|
|---|
| 114 | {
|
|---|
| 115 | Digit=(wHexVal & Power)>>ShiftVal;
|
|---|
| 116 | if (Digit)
|
|---|
| 117 | fNonZero=TRUE;
|
|---|
| 118 |
|
|---|
| 119 | if (Digit ||
|
|---|
| 120 | fNonZero ||
|
|---|
| 121 | (Option & LEADING_ZEROES) ||
|
|---|
| 122 | ((Power==0x0F) && (fNonZero==FALSE)))
|
|---|
| 123 | *StrPtr++=hextab[Digit];
|
|---|
| 124 |
|
|---|
| 125 | if (Power==0xF0000000) // 1 billion
|
|---|
| 126 | Power=0xF000000;
|
|---|
| 127 | else if (Power==0xF000000)
|
|---|
| 128 | Power=0xF00000;
|
|---|
| 129 | else if (Power==0xF00000)
|
|---|
| 130 | Power=0xF0000;
|
|---|
| 131 | else if (Power==0xF0000)
|
|---|
| 132 | Power=0xF000;
|
|---|
| 133 | else if (Power==0xF000)
|
|---|
| 134 | Power=0xF00;
|
|---|
| 135 | else if (Power==0xF00)
|
|---|
| 136 | Power=0xF0;
|
|---|
| 137 | else if (Power==0xF0)
|
|---|
| 138 | Power=0xF;
|
|---|
| 139 | else Power=0;
|
|---|
| 140 |
|
|---|
| 141 | ShiftVal-=4;
|
|---|
| 142 | } // end while
|
|---|
| 143 |
|
|---|
| 144 | return (StrPtr);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | #ifdef DEBUG
|
|---|
| 148 | char BuildString[1024];
|
|---|
| 149 | #endif // DEBUG
|
|---|
| 150 |
|
|---|
| 151 | //------------------------- PrintfOut -
|
|---|
| 152 | void _cdecl DPD(int level, char *DbgStr, ...)
|
|---|
| 153 | {
|
|---|
| 154 | #ifdef DEBUG
|
|---|
| 155 | char *BuildPtr=BuildString;
|
|---|
| 156 | char *pStr=(char *) DbgStr;
|
|---|
| 157 | char *SubStr;
|
|---|
| 158 | union {
|
|---|
| 159 | void *VoidPtr;
|
|---|
| 160 | USHORT *WordPtr;
|
|---|
| 161 | ULONG *LongPtr;
|
|---|
| 162 | ULONG *StringPtr;
|
|---|
| 163 | } Parm;
|
|---|
| 164 | USHORT wBuildOption;
|
|---|
| 165 |
|
|---|
| 166 | Parm.VoidPtr=(void *) &DbgStr;
|
|---|
| 167 | Parm.StringPtr++; // skip size of string pointer
|
|---|
| 168 |
|
|---|
| 169 | while (*pStr)
|
|---|
| 170 | {
|
|---|
| 171 | // don't overflow target
|
|---|
| 172 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
|---|
| 173 | break;
|
|---|
| 174 |
|
|---|
| 175 | switch (*pStr)
|
|---|
| 176 | {
|
|---|
| 177 | case '%':
|
|---|
| 178 | wBuildOption=0;
|
|---|
| 179 | pStr++;
|
|---|
| 180 | if (*pStr=='0')
|
|---|
| 181 | {
|
|---|
| 182 | wBuildOption|=LEADING_ZEROES;
|
|---|
| 183 | pStr++;
|
|---|
| 184 | }
|
|---|
| 185 | if (*pStr=='u') // always unsigned
|
|---|
| 186 | pStr++;
|
|---|
| 187 | if (*pStr=='#')
|
|---|
| 188 | pStr++;
|
|---|
| 189 |
|
|---|
| 190 | switch(*pStr)
|
|---|
| 191 | {
|
|---|
| 192 | case 'x':
|
|---|
| 193 | case 'X':
|
|---|
| 194 | case 'p':
|
|---|
| 195 | case 'P':
|
|---|
| 196 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 197 | pStr++;
|
|---|
| 198 | continue;
|
|---|
| 199 |
|
|---|
| 200 | case 'd':
|
|---|
| 201 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 202 | pStr++;
|
|---|
| 203 | continue;
|
|---|
| 204 |
|
|---|
| 205 | case 's':
|
|---|
| 206 | SubStr=(char *)*Parm.StringPtr;
|
|---|
| 207 | while (*BuildPtr++ = *SubStr++);
|
|---|
| 208 | Parm.StringPtr++;
|
|---|
| 209 | BuildPtr--; // remove the \0
|
|---|
| 210 | pStr++;
|
|---|
| 211 | continue;
|
|---|
| 212 |
|
|---|
| 213 | case 'l':
|
|---|
| 214 | pStr++;
|
|---|
| 215 | switch (*pStr)
|
|---|
| 216 | {
|
|---|
| 217 | case 'x':
|
|---|
| 218 | case 'X':
|
|---|
| 219 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 220 | pStr++;
|
|---|
| 221 | continue;
|
|---|
| 222 |
|
|---|
| 223 | case 'd':
|
|---|
| 224 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 225 | pStr++;
|
|---|
| 226 | continue;
|
|---|
| 227 | } // end switch
|
|---|
| 228 | continue; // dunno what he wants
|
|---|
| 229 |
|
|---|
| 230 | case 0:
|
|---|
| 231 | continue;
|
|---|
| 232 | } // end switch
|
|---|
| 233 | break;
|
|---|
| 234 |
|
|---|
| 235 | case '\\':
|
|---|
| 236 | pStr++;
|
|---|
| 237 | switch (*pStr)
|
|---|
| 238 | {
|
|---|
| 239 | case 'n':
|
|---|
| 240 | *BuildPtr++=LF;
|
|---|
| 241 | pStr++;
|
|---|
| 242 | continue;
|
|---|
| 243 |
|
|---|
| 244 | case 'r':
|
|---|
| 245 | *BuildPtr++=CR;
|
|---|
| 246 | pStr++;
|
|---|
| 247 | continue;
|
|---|
| 248 |
|
|---|
| 249 | case 0:
|
|---|
| 250 | continue;
|
|---|
| 251 | break;
|
|---|
| 252 | } // end switch
|
|---|
| 253 |
|
|---|
| 254 | break;
|
|---|
| 255 | } // end switch
|
|---|
| 256 |
|
|---|
| 257 | *BuildPtr++=*pStr++;
|
|---|
| 258 | } // end while
|
|---|
| 259 |
|
|---|
| 260 | *BuildPtr=0; // cauterize the string
|
|---|
| 261 | StringOut((char *) BuildString); // print to comm port
|
|---|
| 262 | #endif //DEBUG
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | void _cdecl DPE(char *DbgStr, ...)
|
|---|
| 267 | {
|
|---|
| 268 | #ifdef DEBUG
|
|---|
| 269 | char *BuildPtr=BuildString;
|
|---|
| 270 | char *pStr = (char *) DbgStr;
|
|---|
| 271 | char *SubStr;
|
|---|
| 272 | union {
|
|---|
| 273 | void *VoidPtr;
|
|---|
| 274 | USHORT *WordPtr;
|
|---|
| 275 | ULONG *LongPtr;
|
|---|
| 276 | ULONG *StringPtr;
|
|---|
| 277 | } Parm;
|
|---|
| 278 | USHORT wBuildOption;
|
|---|
| 279 |
|
|---|
| 280 | Parm.VoidPtr=(void *) &DbgStr;
|
|---|
| 281 | Parm.StringPtr++; // skip size of string pointer
|
|---|
| 282 |
|
|---|
| 283 | while (*pStr)
|
|---|
| 284 | {
|
|---|
| 285 | // don't overflow target
|
|---|
| 286 | if (BuildPtr >= (char *) &BuildString[1024-2])
|
|---|
| 287 | break;
|
|---|
| 288 |
|
|---|
| 289 | switch (*pStr)
|
|---|
| 290 | {
|
|---|
| 291 | case '%':
|
|---|
| 292 | wBuildOption=0;
|
|---|
| 293 | pStr++;
|
|---|
| 294 | if (*pStr=='0')
|
|---|
| 295 | {
|
|---|
| 296 | wBuildOption|=LEADING_ZEROES;
|
|---|
| 297 | pStr++;
|
|---|
| 298 | }
|
|---|
| 299 | if (*pStr=='u') // always unsigned
|
|---|
| 300 | pStr++;
|
|---|
| 301 |
|
|---|
| 302 | switch(*pStr)
|
|---|
| 303 | {
|
|---|
| 304 | case 'x':
|
|---|
| 305 | case 'X':
|
|---|
| 306 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 307 | pStr++;
|
|---|
| 308 | continue;
|
|---|
| 309 |
|
|---|
| 310 | case 'd':
|
|---|
| 311 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 312 | pStr++;
|
|---|
| 313 | continue;
|
|---|
| 314 |
|
|---|
| 315 | case 's':
|
|---|
| 316 | SubStr=(char *)*Parm.StringPtr;
|
|---|
| 317 | while (*BuildPtr++ = *SubStr++);
|
|---|
| 318 | Parm.StringPtr++;
|
|---|
| 319 | BuildPtr--; // remove the \0
|
|---|
| 320 | pStr++;
|
|---|
| 321 | continue;
|
|---|
| 322 |
|
|---|
| 323 | case 'l':
|
|---|
| 324 | pStr++;
|
|---|
| 325 | switch (*pStr)
|
|---|
| 326 | {
|
|---|
| 327 | case 'x':
|
|---|
| 328 | case 'X':
|
|---|
| 329 | BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 330 | pStr++;
|
|---|
| 331 | continue;
|
|---|
| 332 |
|
|---|
| 333 | case 'd':
|
|---|
| 334 | BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
|
|---|
| 335 | pStr++;
|
|---|
| 336 | continue;
|
|---|
| 337 | } // end switch
|
|---|
| 338 | continue; // dunno what he wants
|
|---|
| 339 |
|
|---|
| 340 | case 0:
|
|---|
| 341 | continue;
|
|---|
| 342 | } // end switch
|
|---|
| 343 | break;
|
|---|
| 344 |
|
|---|
| 345 | case '\\':
|
|---|
| 346 | pStr++;
|
|---|
| 347 | switch (*pStr)
|
|---|
| 348 | {
|
|---|
| 349 | case 'n':
|
|---|
| 350 | *BuildPtr++=LF;
|
|---|
| 351 | pStr++;
|
|---|
| 352 | continue;
|
|---|
| 353 |
|
|---|
| 354 | case 'r':
|
|---|
| 355 | *BuildPtr++=CR;
|
|---|
| 356 | pStr++;
|
|---|
| 357 | continue;
|
|---|
| 358 |
|
|---|
| 359 | case 0:
|
|---|
| 360 | continue;
|
|---|
| 361 | break;
|
|---|
| 362 | } // end switch
|
|---|
| 363 |
|
|---|
| 364 | break;
|
|---|
| 365 | } // end switch
|
|---|
| 366 |
|
|---|
| 367 | *BuildPtr++=*pStr++;
|
|---|
| 368 | } // end while
|
|---|
| 369 |
|
|---|
| 370 | *BuildPtr=0; // cauterize the string
|
|---|
| 371 | StringOut((char *) BuildString); // print to comm port
|
|---|
| 372 | #endif //DEBUG
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | #ifdef DEBUG //------------------------- StringOut -
|
|---|
| 376 | void StringOut(char *DbgStr)
|
|---|
| 377 | {
|
|---|
| 378 | while (*DbgStr)
|
|---|
| 379 | CharOut(*DbgStr++);
|
|---|
| 380 |
|
|---|
| 381 | if (fLineTerminate)
|
|---|
| 382 | {
|
|---|
| 383 | CharOut(CR); // append carriage return,
|
|---|
| 384 | CharOut(LF); // linefeed
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 | #endif
|
|---|
| 388 |
|
|---|
| 389 | #ifdef DEBUG
|
|---|
| 390 | //#define MAGIC_COMM_PORT 0x3f8 // pulled from word ptr 40:0
|
|---|
| 391 | #define MAGIC_COMM_PORT 0x2f8 // pulled from word ptr 40:0
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 | #define UART_DATA 0x00 // UART Data port
|
|---|
| 395 | #define UART_INT_ENAB 0x01 // UART Interrupt enable
|
|---|
| 396 | #define UART_INT_ID 0x02 // interrupt ID
|
|---|
| 397 | #define UART_LINE_CTRL 0x03 // line control registers
|
|---|
| 398 | #define UART_MODEM_CTRL 0x04 // modem control register
|
|---|
| 399 | #define UART_LINE_STAT 0x05 // line status register
|
|---|
| 400 | #define UART_MODEM_STAT 0x06 // modem status regiser
|
|---|
| 401 | #define UART_DIVISOR_LO 0x00 // divisor latch least sig
|
|---|
| 402 | #define UART_DIVISOR_HI 0x01h // divisor latch most sig
|
|---|
| 403 |
|
|---|
| 404 | #define DELAY nop
|
|---|
| 405 | #endif
|
|---|
| 406 |
|
|---|
| 407 | #ifdef DEBUG //--------------------------- CharOut -
|
|---|
| 408 | void CharOut(char c)
|
|---|
| 409 | {
|
|---|
| 410 | _asm {
|
|---|
| 411 |
|
|---|
| 412 | mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
|
|---|
| 413 | add dx, UART_LINE_STAT
|
|---|
| 414 |
|
|---|
| 415 | ReadyCheck:
|
|---|
| 416 | in al, dx // wait for comm port ready signal
|
|---|
| 417 |
|
|---|
| 418 | DELAY
|
|---|
| 419 | DELAY
|
|---|
| 420 | DELAY
|
|---|
| 421 |
|
|---|
| 422 | test al, 020h
|
|---|
| 423 | jz ReadyCheck
|
|---|
| 424 |
|
|---|
| 425 | // Send the character
|
|---|
| 426 |
|
|---|
| 427 | add dx, UART_DATA - UART_LINE_STAT
|
|---|
| 428 | mov al,c
|
|---|
| 429 | out dx, al
|
|---|
| 430 |
|
|---|
| 431 | DELAY
|
|---|
| 432 | DELAY
|
|---|
| 433 | DELAY
|
|---|
| 434 | }
|
|---|
| 435 | }
|
|---|
| 436 | #endif
|
|---|