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