ReactOS  0.4.14-dev-52-g6116262
output.c
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4 
5 Module Name:
6 
7  output.c
8 
9 Abstract:
10 
11  catch debugging outputs
12 
13 Environment:
14 
15  Kernel mode only
16 
17 Author:
18 
19  Klaus P. Gerlicher
20 
21 Revision History:
22 
23  14-Nov-1999: created
24  15-Nov-2000: general cleanup of source files
25 
26 Copyright notice:
27 
28  This file may be distributed under the terms of the GNU Public License.
29 
30 --*/
31 
33 // INCLUDES
35 #include "remods.h"
36 #include "precomp.h"
37 /*
38 #include <linux/sched.h>
39 #include <asm/io.h>
40 #include <asm/page.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>
46 */
47 
48 char tempOutput[1024],tempOutput2[1024];
49 
50 //ULONG ulPrintk=0;
51 
53 
57 
59 
60 #ifdef __cplusplus
61 #define CPP_ASMLINKAGE extern "C"
62 #else
63 #define CPP_ASMLINKAGE
64 #endif
65 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
66 
67 asmlinkage int printk(const char *fmt, ...);
68 
69 //EXPORT_SYMBOL(printk);
70 
71 //*************************************************************************
72 // printk()
73 //
74 // this function overrides printk() in the kernel
75 //*************************************************************************
76 asmlinkage int printk(const char *fmt, ...)
77 {
78  ULONG len,ulRingBufferLock;
79  static LONGLONG ulOldJiffies = 0;
81 
82  va_list args;
83  va_start(args, fmt);
84 
85  if((len = PICE_strlen((LPSTR)fmt)) )
86  {
87  save_flags(ulRingBufferLock);
88  cli();
89 
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.
96  if( (jiffies.QuadPart-ulOldJiffies) > 10000*(1*wWindow[OUTPUT_WINDOW].cy)/2)
97  {
98  ulOldJiffies = jiffies.QuadPart;
100  }
101  else
102  {
104  }
105 
107  restore_flags(ulRingBufferLock);
108  }
109  va_end(args);
110 
111  return 0;
112 }
113 
114 //*************************************************************************
115 // CountArgs()
116 //
117 // count occurrence of '%' in format string (except %%)
118 // validity of whole format string must have been enforced
119 //*************************************************************************
121 {
122  ULONG count=0;
123 
124  while(*fmt)
125  {
126  if(*fmt=='%' && *(fmt+1)!='%')
127  count++;
128  fmt++;
129  }
130  return count;
131 }
132 
133 //***********************************************************************************
134 // Our replacement of kernel function.
135 // Must not make any calls to KdpPrintString (e.g. by calling DbgPrint).
136 //***********************************************************************************
138 {
139  ULONG ulRingBufferLock;
140 
141  save_flags(ulRingBufferLock);
142  cli();
143 
144  /* CH: What is bIsDebugPrint used for? */
146 
147  DPRINT((0,"PICE_KdpPrintString\n\n\n"));
148  AddToRingBuffer(String->Buffer);
149  restore_flags(ulRingBufferLock);
150 }
151 //*************************************************************************
152 // PrintkCallback()
153 //
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)
158 {
159  LPSTR fmt,args;
160  ULONG ulAddress;
161  ULONG countArgs,i,len;
163  CHAR buf[128];
164 
165  DPRINT((0,"In PrintkCallback\n"));
166 
167  bInPrintk = TRUE;
168 
169  // get the linear address of stack where string resides
171  if(ulAddress)
172  {
173  DPRINT((0,"In PrintkCallback: ulAddress: %x\n", ulAddress));
174  if(IsAddressValid(ulAddress+sizeof(char *)) )
175  {
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() */
181  }
182  }
183  bInPrintk = FALSE;
184 }
185 
186 //*************************************************************************
187 // PiceRunningTimer()
188 //
189 //*************************************************************************
190 
193 
194 // do I need it here? Have to keep DPC memory resident #pragma code_seg()
199 {
200  CheckRingBuffer();
201 
202  if(ulCountTimerEvents++ > 10)
203  {
205 
206  ulCountTimerEvents = 0;
207 
211  PICE_sprintf(tempOutput,"jiffies = %.8X\n",jiffies.u.LowPart);
213  ResetColor();
214  }
215 }
216 
217 //*************************************************************************
218 // InitPiceRunningTimer()
219 //
220 //*************************************************************************
222 {
224 
225  ENTER_FUNC();
226 #if 0 //won't work. we have to intercept timer interrupt so dpc will never fire while we are in pice
229 
230  Interval.QuadPart=-1000000L; // 100 millisec. (unit is 100 nanosec.)
231 
233  Interval, 1000000L,
234  &PiceTimerDpc);
235 #endif
236  LEAVE_FUNC();
237 }
238 
239 //*************************************************************************
240 // RemovePiceRunningTimer()
241 //
242 //*************************************************************************
244 {
246 }
247 
248 //*************************************************************************
249 // InstallPrintkHook()
250 //
251 //*************************************************************************
253 {
254 
255  ENTER_FUNC();
256 
257  if( bIsPrintkPatched )
258  return;
259 
260  DPRINT((0,"installing PrintString hook\n"));
261  ScanExports("_KdpPrintString",(PULONG)&ulPrintk);
262 
263  DPRINT((0,"_KdpPrintString @ %x\n", ulPrintk));
264  ASSERT( ulPrintk ); // temporary
265  if(ulPrintk)
266  {
268  DPRINT((0,"KdpPrintStringTest breakpoint installed? %d\n", bIsPrintkPatched));
269  }
270 
271  LEAVE_FUNC();
272 }
273 
274 //*************************************************************************
275 // DeInstallPrintkHook()
276 //
277 //*************************************************************************
279 {
280  ENTER_FUNC();
281 
282  DPRINT((0,"enter DeInstallPrintkHook()\n"));
284  {
285  // will be done on exit debugger
288  }
289  LEAVE_FUNC();
290 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
void SetForegroundColor(ECOLORS c)
Definition: hardware.c:576
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
USHORT CurrentSS
Definition: shell.c:116
ULONG GLOBAL_SCREEN_WIDTH
Definition: hardware.c:62
GLuint GLuint GLsizei count
Definition: gl.h:1545
BOOLEAN bInPrintk
Definition: output.c:54
char CHAR
Definition: xmlstorage.h:175
int PICE_sprintf(char *buf, const char *fmt,...)
Definition: utils.c:2053
#define jiffies
Definition: module.h:1075
ULONG GLOBAL_SCREEN_HEIGHT
Definition: hardware.c:62
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
const char * fmt
Definition: wsprintf.c:30
USHORT cy
Definition: hardware.h:33
#define LEAVE_FUNC()
Definition: debug.h:43
void RemovePiceRunningTimer(void)
Definition: output.c:243
static WCHAR String[]
Definition: stringtable.c:55
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
char * LPSTR
Definition: xmlstorage.h:182
Definition: match.c:390
void Print(USHORT Window, LPSTR p)
Definition: hardware.c:797
#define save_flags(x)
Definition: utils.h:285
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOLEAN InstallSWBreakpoint(ULONG ulAddress, BOOLEAN bPermanent, void(*SWBreakpointCallback)(void))
Definition: bp.c:236
#define va_end(ap)
Definition: acmsvcex.h:90
void InitPiceRunningTimer(void)
Definition: output.c:221
void DeInstallPrintkHook(void)
Definition: output.c:278
char tempOutput2[1024]
Definition: output.c:48
unsigned char BOOLEAN
ULONG ulCountTimerEvents
Definition: output.c:58
#define COLOR_TEXT
Definition: hardware.h:158
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
char * va_list
Definition: acmsvcex.h:78
void DPRINT(...)
Definition: polytest.cpp:61
WINDOW wWindow[4]
Definition: hardware.c:59
void PrintkCallback(void)
Definition: output.c:157
int PICE_vsprintf(char *buf, const char *fmt, va_list args)
Definition: utils.c:1850
DWORD Interval
Definition: netstat.c:33
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
int64_t LONGLONG
Definition: typedefs.h:66
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:524
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
VOID PiceRunningTimer(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: output.c:195
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
ANSI_STRING * PANSI_STRING
Definition: env_spec_w32.h:380
char tempOutput[1024]
Definition: output.c:48
RECT cli
Definition: sndrec32.cpp:79
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN bIsPrintkPatched
Definition: output.c:56
BOOLEAN bIsDebugPrint
Definition: output.c:55
static const WCHAR L[]
Definition: oid.c:1250
ULONG GetLinearAddress(USHORT Segment, ULONG Offset)
Definition: utils.c:782
Definition: ketypes.h:687
GLenum GLsizei len
Definition: glext.h:6722
void InstallPrintkHook(void)
Definition: output.c:252
#define asmlinkage
Definition: output.c:65
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
KDPC PiceTimerDPC
Definition: output.c:192
void PutChar(LPSTR p, ULONG x, ULONG y)
Definition: hardware.c:604
KTIMER PiceTimer
Definition: output.c:191
ULONG CountArgs(LPSTR fmt)
Definition: output.c:120
ULONG PICE_KdpPrintString(PANSI_STRING String)
Definition: output.c:137
static calc_node_t temp
Definition: rpn_ieee.c:38
BOOLEAN ScanExports(const char *pFind, PULONG pValue)
Definition: symbols.c:327
ULONG CurrentEIP
Definition: shell.c:113
unsigned int * PULONG
Definition: retypes.h:1
#define va_start(ap, A)
Definition: acmsvcex.h:91
BOOLEAN DeInstallSWBreakpoint(ULONG ulAddress)
Definition: bp.c:428
void CheckRingBuffer(void)
Definition: hardware.c:133
void SetBackgroundColor(ECOLORS c)
Definition: hardware.c:590
#define restore_flags(x)
Definition: utils.h:286
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define ENTER_FUNC()
Definition: debug.h:42
ULONG CurrentESP
Definition: shell.c:115
void ResetColor(void)
Definition: hardware.c:500
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
#define COLOR_CAPTION
Definition: hardware.h:156
BOOLEAN AddToRingBuffer(LPSTR p)
Definition: hardware.c:154
#define args
Definition: format.c:66
Definition: dsound.c:943
BOOLEAN IsAddressValid(ULONG address)
Definition: utils.c:611
ULONG(* ulPrintk)(PANSI_STRING String)
Definition: output.c:52
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675