2 * AcessOS Microkernel Version
9 extern void Threads_Dump();
13 int giDebug_KTerm = -1;
16 static void E9(char ch)
18 if(giDebug_KTerm != -1)
19 VFS_Write(giDebug_KTerm, 1, &ch);
20 __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) );
23 static void E9_Str(char *Str)
25 while(*Str) E9(*Str++);
28 void E9_Fmt(const char *format, va_list *args)
32 char tmpBuf[34]; // For Integers
37 while((c = *format++) != 0)
39 // Non control character
55 Uint ptr = va_arg(*args, Uint);
56 E9('*'); E9('0'); E9('x');
58 itoa(p, ptr, 16, BITS/4, '0');
63 arg = va_arg(*args, Uint);
74 if('1' <= c && c <= '9')
77 while('0' <= c && c <= '9')
91 arg |= va_arg(*args, Uint);
102 if( (isLongLong && arg >> 63) || (!isLongLong && arg >> 31) ) {
106 itoa(p, arg, 10, minSize, pad);
109 itoa(p, arg, 10, minSize, pad);
112 itoa(p, arg, 16, minSize, pad);
115 itoa(p, arg, 8, minSize, pad);
118 itoa(p, arg, 2, minSize, pad);
122 if(arg) E9_Str("True");
123 else E9_Str("False");
127 p = (char*)(Uint)arg;
133 default: E9(arg); break;
139 * \fn void LogV(char *Fmt, va_list Args)
141 void LogV(char *Fmt, va_list Args)
148 * \fn void LogF(char *Msg, ...)
150 void LogF(char *Fmt, ...)
161 * \fn void Log(char *Msg, ...)
163 void Log(char *Fmt, ...)
173 void Warning(char *Fmt, ...)
182 void Panic(char *Fmt, ...)
193 __asm__ __volatile__ ("xchg %bx, %bx");
194 __asm__ __volatile__ ("cli;\n\thlt");
195 for(;;) __asm__ __volatile__ ("hlt");
198 void Debug_SetKTerminal(char *File)
200 if(giDebug_KTerm != -1)
201 VFS_Close(giDebug_KTerm);
202 giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
203 Log("Opened '%s' as %i\n", File, giDebug_KTerm);
206 void Debug_Enter(char *FuncName, char *ArgTypes, ...)
209 int i = gDebug_Level ++;
212 va_start(args, ArgTypes);
216 E9_Str(FuncName); E9_Str(": (");
220 pos = strpos(ArgTypes, ' ');
221 if(pos != -1) ArgTypes[pos] = '\0';
222 if(pos == -1 || pos > 1) {
226 if(pos != -1) ArgTypes[pos] = ' ';
229 case 'p': E9_Fmt("%p", &args); break;
230 case 's': E9_Fmt("'%s'", &args); break;
231 case 'i': E9_Fmt("%i", &args); break;
232 case 'u': E9_Fmt("%u", &args); break;
233 case 'x': E9_Fmt("0x%x", &args); break;
234 case 'b': E9_Fmt("0b%b", &args); break;
236 case 'X': E9_Fmt("0x%llx", &args); break;
237 case 'B': E9_Fmt("0b%llb", &args); break;
244 ArgTypes = &ArgTypes[pos+1];
251 void Debug_Log(char *FuncName, char *Fmt, ...)
254 int i = gDebug_Level;
260 E9_Str(FuncName); E9_Str(": ");
267 void Debug_Leave(char *FuncName, char RetType, ...)
270 int i = --gDebug_Level;
272 va_start(args, RetType);
277 E9_Str(FuncName); E9_Str(": RETURN");
288 case 'n': E9_Str("NULL"); break;
289 case 'p': E9_Fmt("%p", &args); break;
290 case 's': E9_Fmt("'%s'", &args); break;
291 case 'i': E9_Fmt("%i", &args); break;
292 case 'u': E9_Fmt("%u", &args); break;
293 case 'x': E9_Fmt("0x%x", &args); break;
295 case 'X': E9_Fmt("0x%llx", &args); break;
302 void Debug_HexDump(char *Header, void *Data, Uint Length)
307 LogF(" (Hexdump of %p)\n", Data);
311 Log("%04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
313 cdat[0], cdat[1], cdat[2], cdat[3], cdat[4], cdat[5], cdat[6], cdat[7],
314 cdat[8], cdat[9], cdat[10], cdat[11], cdat[12], cdat[13], cdat[14], cdat[15]
321 LogF("Log: %04x: ", pos);