1 | /* SCCSID = src/dev/mme/tropez/log.hpp, tropez, c.basedd 97/07/17 */
|
---|
2 | /****************************************************************************
|
---|
3 | * *
|
---|
4 | * Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
5 | * *
|
---|
6 | * The following IBM OS/2 source code is provided to you solely for the *
|
---|
7 | * the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
8 | * You may use this code in accordance with the IBM License Agreement *
|
---|
9 | * provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
10 | * *
|
---|
11 | ****************************************************************************/
|
---|
12 | /**@internal src/dev/mme/tropez/log.hpp, tropez, c.basedd
|
---|
13 | * LOG, BINARYLOG, PERFLOG definitions.
|
---|
14 | * @version 1.6
|
---|
15 | * @context
|
---|
16 | * Unless otherwise noted, all interfaces are Ring-0, 16-bit, kernel stack.
|
---|
17 | * @notes
|
---|
18 | * ### More is coming in this area.
|
---|
19 | * @history
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef LOG_INCLUDED
|
---|
23 | #define LOG_INCLUDED
|
---|
24 |
|
---|
25 | #ifdef __cplusplus
|
---|
26 | extern "C" {
|
---|
27 | #endif
|
---|
28 | #ifndef OS2_INCLUDED
|
---|
29 | #define INCL_NOPMAPI
|
---|
30 | #define INCL_DOSMISC
|
---|
31 | #include <os2.h>
|
---|
32 | #endif // OS2_INCLUDED
|
---|
33 | #ifdef __cplusplus
|
---|
34 | }
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | typedef unsigned short WORD;
|
---|
38 | typedef unsigned long DWORD;
|
---|
39 |
|
---|
40 | // This structure is used to walk the parameters on the stack.
|
---|
41 | typedef union {
|
---|
42 | void far *VoidPtr;
|
---|
43 | BYTE far *BytePtr;
|
---|
44 | WORD far *WordPtr;
|
---|
45 | DWORD far *LongPtr;
|
---|
46 | DWORD far *StringPtr; //### Why did this break when made
|
---|
47 | //### into a 'char far *?
|
---|
48 | } STACK_ADR, FAR *PSTACK_ADR;
|
---|
49 |
|
---|
50 |
|
---|
51 | // Maximum length of a message.
|
---|
52 | const int MAX_MsgLen = 255;
|
---|
53 |
|
---|
54 | // Enumerate the places where logging messages can be saved.
|
---|
55 | enum _MessageSink { _Display, _SerialLine, _ErrorLog, _TraceLog };
|
---|
56 | const int _nMsgSinks = _TraceLog + 1;
|
---|
57 |
|
---|
58 | class LOG {
|
---|
59 | public:
|
---|
60 | //--- Data.
|
---|
61 |
|
---|
62 | // This vector indicates whether or not the messages should be streamed
|
---|
63 | // to a particular message sink. Initialized to all TRUE.
|
---|
64 | BOOL bMsgSink[_nMsgSinks];
|
---|
65 |
|
---|
66 | //--- Public methods.
|
---|
67 |
|
---|
68 | // Create a log.
|
---|
69 | LOG( USHORT DosTraceLogMajor, PSZ* apszMsgText );
|
---|
70 |
|
---|
71 | // Log an event without data.
|
---|
72 | virtual void vTrace( USHORT errNum );
|
---|
73 |
|
---|
74 | // Log an event with data.
|
---|
75 | virtual void vLog( USHORT errNum, ... );
|
---|
76 |
|
---|
77 | protected:
|
---|
78 |
|
---|
79 | //--- Private and protected data.
|
---|
80 |
|
---|
81 | // This is the major code (must be in range of 240 to 255) under which
|
---|
82 | // messages will be saved in the System Trace log. Messages can be retrieved
|
---|
83 | // using the OS/2 TRACEFMT utility.
|
---|
84 | const USHORT _DosTraceMajorCode;
|
---|
85 |
|
---|
86 | // This vbls is a pointer to an array of NLV messages. An array of messages
|
---|
87 | // is assoicated with this LOG object when the object is created.
|
---|
88 | PSZ* _apszMsgText;
|
---|
89 |
|
---|
90 | // Private scratch area. We build up the log entries in this string.
|
---|
91 | UCHAR _dd_BuildString[ MAX_MsgLen ];
|
---|
92 |
|
---|
93 | private:
|
---|
94 |
|
---|
95 | // Keep track of whether we're executing at Ring3 or 0.
|
---|
96 | BOOL _bInRing3;
|
---|
97 |
|
---|
98 | // Comm port (COM1: or COM2:) to send messages out of (used only if
|
---|
99 | // the Serial line is selected as a message sink.
|
---|
100 | USHORT _ComPort;
|
---|
101 |
|
---|
102 | //--- Private member functions
|
---|
103 |
|
---|
104 | // Binary to Ascii conversion routines.
|
---|
105 | PSZ _DecWordToASCII( PSZ StrPtr, WORD wDecVal, WORD Option );
|
---|
106 | PSZ _DecLongToASCII( PSZ StrPtr, DWORD lDecVal,WORD Option );
|
---|
107 | PSZ _HexWordToASCII( PSZ StrPtr, WORD wHexVal, WORD Option );
|
---|
108 | PSZ _HexLongToASCII( PSZ StrPtr, DWORD wHexVal, WORD Option );
|
---|
109 |
|
---|
110 | // Send a character out the COM port.
|
---|
111 | void _CharOut( char );
|
---|
112 |
|
---|
113 | // Save the message in one or more destinations.
|
---|
114 | void _ddputstring ( USHORT iMsgNum, PSZ St);
|
---|
115 |
|
---|
116 | // Formatting routine - converts binary->ASCII & merges with PII.
|
---|
117 | USHORT _ddsprintf ( PSZ pszOutString, PSZ pszFmtString, STACK_ADR Parm );
|
---|
118 |
|
---|
119 | }; // class LOG
|
---|
120 |
|
---|
121 |
|
---|
122 | class BINARYLOG : public LOG {
|
---|
123 | public:
|
---|
124 |
|
---|
125 | // Create a log.
|
---|
126 | BINARYLOG( USHORT DosTraceLogMajor, PSZ* apszMsgText );
|
---|
127 |
|
---|
128 | // Log a trace point.
|
---|
129 | virtual void vTrace( USHORT eventNum );
|
---|
130 |
|
---|
131 | // Log an event with data.
|
---|
132 | virtual void vLog( USHORT eventNum, ... );
|
---|
133 |
|
---|
134 | private:
|
---|
135 |
|
---|
136 | // Formatting routine - converts binary->ASCII & merges with PII.
|
---|
137 | USHORT _ddsprintf ( PSZ pszOutString, PSZ pszFmtString, STACK_ADR Parm );
|
---|
138 |
|
---|
139 | }; // class BINARYLOG
|
---|
140 |
|
---|
141 |
|
---|
142 | class PERFLOG : public LOG {
|
---|
143 | public:
|
---|
144 |
|
---|
145 | // Create a log.
|
---|
146 | PERFLOG( USHORT DosTraceLogMajor, PSZ* apszMsgText );
|
---|
147 |
|
---|
148 | // Record current RDTSC cycle count (from Intel processor) into system Trace log.
|
---|
149 | virtual void vTrace( USHORT eventNum );
|
---|
150 |
|
---|
151 | }; // class PERFLOG
|
---|
152 |
|
---|
153 |
|
---|
154 | extern LOG* pStatus; // Status log.
|
---|
155 | extern LOG* pError; // Error log.
|
---|
156 | extern LOG* pSoftError; // Error log.
|
---|
157 | extern BINARYLOG* pTrace; // Trace log.
|
---|
158 | extern PERFLOG* pPerfLog; // Performance trace log.
|
---|
159 |
|
---|
160 | #endif // LOG_INCLUDED
|
---|
161 |
|
---|