luxos/Kernel/debug/logger.c
Tiberiu Chibici 17342b6665 [????] BUILD 0.1.1.50 DATE 9/20/2011 AT 12:43 PM
====================================================
Mainly changed: Tasking
+ Implemented multitasking
+ Switching works
? TODO: Fix other not working tasking routines
2021-09-14 18:58:06 +03:00

127 lines
2.4 KiB
C

/*
* logger.c
*
* Created on: Sep 2, 2011
* Author: Tiberiu
*/
#include <debugio.h>
#include <stdlib.h>
string LogAllowedDevices[] = {
"drivers",
//"floppy",
"hal",
"fat",
"initrd",
"system",
"vfs",
//"mem",
"console",
0x0,
0x0
};
extern uint8 ConsoleDefaultColor;
extern void _write_char(char c);
extern void _write_string (string s);
int32 LogWrite (uint8 error, string device, string format, ...)
{
if (!format || !*format || !device || !*device) return 0;
// Print logged information
va_list args;
va_start (args, format);
uint32 i, len = strlen(format);
uint8 temp_color = ConsoleDefaultColor;
// Check if device is allowed. Errors are allowed
uint8 allowed = error;
for (i = 0; LogAllowedDevices[i] != 0 && !allowed; i++)
if (strcasecmp(device, LogAllowedDevices[i]) == 0) allowed = 1;
if (allowed)
{
ConsoleDefaultColor = (error) ? Color(ColorRed, ColorWhite) : (1 + (i % 15)) ;
_write_char('[');
_write_string(device);
_write_char(']');
ConsoleDefaultColor = temp_color;
_write_char(' ');
}
else return 0;
for (i = 0; i < len; i++)
if (format[i] != '%' && allowed) _write_char(format[i]);
else
{
++i;
switch (format[i]) {
// Character
case 'c': {
char c = va_arg (args, char);
_write_char(c);
break;
}
// String
case 's': {
int32* c = (int32*) va_arg (args, string);
_write_string((string)c);
break;
}
// Integers
case 'd':
case 'i': {
int32 c = va_arg(args, int32); char temp[32];
ConvertIntToString(temp, c, 10);
_write_string(temp);
break;
}
// Integers - hex
case 'X':
case 'x': {
int32 c = va_arg(args, int32); char temp[32];
ConvertUIntToString(temp, c, 16);
_write_string(temp);
break;
}
// Integers - unsigned
case 'u': {
int32 c = va_arg(args, uint32); char temp[32];
ConvertUIntToString (temp, c, 10);
_write_string(temp);
break;
}
// Colors
case '#': {
uint8 c = va_arg(args, uint8);
ConsoleDefaultColor = c;
break; }
case '%' : _write_char('%'); break;
};
}
va_end(args);
ConsoleDefaultColor = temp_color;
ConsoleCursorUpdateHardware();
return i;
}
void LogAssert (int32 condition, string file, int32 line)
{
if (!condition)
Panic("Assert", "Assertion failed in file %s line %d.\n", file, line);
}