3 Copyright (c) 1998-2001 Klaus P. Gerlicher
11 catch debugging outputs
24 15-Nov-2000: general cleanup of source files
28 This file may be distributed under the terms of the GNU Public License.
32 ////////////////////////////////////////////////////
38 #include <linux/sched.h>
41 #include <asm/pgtable.h>
42 #include <linux/utsname.h>
43 #include <linux/sched.h>
44 #include <linux/console.h>
45 #include <asm/delay.h>
48 char tempOutput
[1024],tempOutput2
[1024];
52 ULONG (*ulPrintk
) (PANSI_STRING String
);
54 BOOLEAN bInPrintk
= FALSE
;
55 BOOLEAN bIsDebugPrint
= FALSE
;
56 BOOLEAN bIsPrintkPatched
= FALSE
;
58 ULONG ulCountTimerEvents
= 0;
61 #define CPP_ASMLINKAGE extern "C"
63 #define CPP_ASMLINKAGE
65 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
67 asmlinkage
int printk(const char *fmt
, ...);
69 //EXPORT_SYMBOL(printk);
71 //*************************************************************************
74 // this function overrides printk() in the kernel
75 //*************************************************************************
76 asmlinkage
int printk(const char *fmt
, ...)
78 ULONG len
,ulRingBufferLock
;
79 static LONGLONG ulOldJiffies
= 0;
80 LARGE_INTEGER jiffies
;
85 if((len
= PICE_strlen((LPSTR
)fmt
)) )
87 save_flags(ulRingBufferLock
);
90 PICE_vsprintf(tempOutput
, fmt
, args
);
92 // if the last debug print was longer than 50 ms ago
93 // directly print it, else just add it to the ring buffer
94 // and let the timer process it.
95 KeQuerySystemTime(&jiffies
);
96 if( (jiffies
.QuadPart
-ulOldJiffies
) > 10000*(1*wWindow
[OUTPUT_WINDOW
].cy
)/2)
98 ulOldJiffies
= jiffies
.QuadPart
;
99 Print(OUTPUT_WINDOW
,tempOutput
);
103 AddToRingBuffer(tempOutput
);
106 bIsDebugPrint
= FALSE
;
107 restore_flags(ulRingBufferLock
);
114 //*************************************************************************
117 // count occurrence of '%' in format string (except %%)
118 // validity of whole format string must have been enforced
119 //*************************************************************************
120 ULONG
CountArgs(LPSTR fmt
)
126 if(*fmt
=='%' && *(fmt
+1)!='%')
133 //***********************************************************************************
134 // Our replacement of kernel function.
135 // Must not make any calls to KdpPrintString (e.g. by calling DbgPrint).
136 //***********************************************************************************
137 ULONG
PICE_KdpPrintString(PANSI_STRING String
)
139 ULONG ulRingBufferLock
;
141 save_flags(ulRingBufferLock
);
144 /* CH: What is bIsDebugPrint used for? */
145 bIsDebugPrint
= FALSE
;
147 DPRINT((0,"PICE_KdpPrintString\n\n\n"));
148 AddToRingBuffer(String
->Buffer
);
149 restore_flags(ulRingBufferLock
);
151 //*************************************************************************
154 // called from RealIsr() when processing INT3 placed
155 // Must not make any calls to KdpPrintString (e.g. by calling DbgPrint).
156 //*************************************************************************
157 void PrintkCallback(void)
161 ULONG countArgs
,i
,len
;
165 DPRINT((0,"In PrintkCallback\n"));
169 // get the linear address of stack where string resides
170 ulAddress
= GetLinearAddress(CurrentSS
,CurrentESP
);
173 DPRINT((0,"In PrintkCallback: ulAddress: %x\n", ulAddress
));
174 if(IsAddressValid(ulAddress
+sizeof(char *)) )
176 //KdpPrintString has PANSI_STRING as a parameter
177 temp
= (PANSI_STRING
)*(PULONG
)(ulAddress
+sizeof(char *));
178 DPRINT((0,"PrintkCallback: %s\n", temp
->Buffer
));
179 /* Call our version of KdpPrintString() */
180 CurrentEIP
= (ULONG_PTR
)PICE_KdpPrintString
;
186 //*************************************************************************
187 // PiceRunningTimer()
189 //*************************************************************************
194 // do I need it here? Have to keep DPC memory resident #pragma code_seg()
195 VOID
PiceRunningTimer(IN PKDPC Dpc
,
196 IN PVOID DeferredContext
,
197 IN PVOID SystemArgument1
,
198 IN PVOID SystemArgument2
)
202 if(ulCountTimerEvents
++ > 10)
204 LARGE_INTEGER jiffies
;
206 ulCountTimerEvents
= 0;
208 KeQuerySystemTime(&jiffies
);
209 SetForegroundColor(COLOR_TEXT
);
210 SetBackgroundColor(COLOR_CAPTION
);
211 PICE_sprintf(tempOutput
,"jiffies = %.8X\n",jiffies
.u
.LowPart
);
212 PutChar(tempOutput
,GLOBAL_SCREEN_WIDTH
-strlen(tempOutput
),GLOBAL_SCREEN_HEIGHT
-1);
217 //*************************************************************************
218 // InitPiceRunningTimer()
220 //*************************************************************************
221 void InitPiceRunningTimer(void)
223 LARGE_INTEGER Interval
;
226 #if 0 //won't work. we have to intercept timer interrupt so dpc will never fire while we are in pice
227 KeInitializeTimer( &PiceTimer
);
228 KeInitializeDpc( &PiceTimerDPC
, PiceRunningTimer
, NULL
);
230 Interval
.QuadPart
=-1000000L; // 100 millisec. (unit is 100 nanosec.)
232 KeSetTimerEx(&PiceTimer
,
239 //*************************************************************************
240 // RemovePiceRunningTimer()
242 //*************************************************************************
243 void RemovePiceRunningTimer(void)
245 KeCancelTimer( &PiceTimer
);
248 //*************************************************************************
249 // InstallPrintkHook()
251 //*************************************************************************
252 void InstallPrintkHook(void)
257 if( bIsPrintkPatched
)
260 DPRINT((0,"installing PrintString hook\n"));
261 ScanExports("_KdpPrintString",(PULONG
)&ulPrintk
);
263 DPRINT((0,"_KdpPrintString @ %x\n", ulPrintk
));
264 ASSERT( ulPrintk
); // temporary
267 bIsPrintkPatched
= InstallSWBreakpoint(ulPrintk
,TRUE
,PrintkCallback
);
268 DPRINT((0,"KdpPrintStringTest breakpoint installed? %d\n", bIsPrintkPatched
));
274 //*************************************************************************
275 // DeInstallPrintkHook()
277 //*************************************************************************
278 void DeInstallPrintkHook(void)
282 DPRINT((0,"enter DeInstallPrintkHook()\n"));
283 if(bIsPrintkPatched
&& ulPrintk
)
285 // will be done on exit debugger
286 if (DeInstallSWBreakpoint(ulPrintk
))
287 bIsPrintkPatched
= FALSE
;