luxos/Kernel/debug/console-out.c
Tiberiu Chibici 913e65b856 [GOOD] BUILD 0.1.0.450 DATE 8/29/2011 AT 10:30 AM
====================================================
+ Changed 'align 0x4' line above multiboot header in loader.asm to
'align 4'
+ Removed -e option for echo in build.sh
+ Modified build.sh for linux
+ Fixed triple fault when enabling paging
+ Fixed page faults at memory manager initialization
+ Fixed 'mem' console function
+ Added more info about page fault at crash screen
+ Added Panic() macro
+ Added verbose mode for memory manager

[ BAD] BUILD 0.1.0.390 DATE 8/27/2011 AT 10:54 PM
====================================================
+ Added stdlib routines, separated in different files
+ Rewritten physical memory manager
+ Added virtual mem manager
+ Added memory allocation/freeing
+ Added memory library
+ Added temporary allocation (at end of kernel), until paging is started
- Removed functionality from debug console function 'mem'
- Removed system.h, the one remaining function now in stdio.h
2021-09-14 18:48:57 +03:00

156 lines
2.8 KiB
C

#include <debugio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
extern uint8* VideoPtr;
extern UPoint ConsoleCursor;
extern UPoint ConsoleSize;
extern uint8 ConsoleDefaultColor;
/**************************************
* Write operations*
**************************************/
void _write_char(char c)
{
switch (c)
{
case '\n':
ConsoleCursorNewline(); break;
case '\r':
ConsoleCursor.X = 0; break;
case '\t':
ConsoleCursorIncreasePos(6 - ConsoleCursor.X % 6); break;
case '\b':
ConsoleCursorIncreasePos(-1);
VideoPtr[2 * (ConsoleCursor.Y * ConsoleSize.X + ConsoleCursor.X)] = 0;
break;
default:
VideoPtr[2 * (ConsoleCursor.Y * ConsoleSize.X + ConsoleCursor.X)] = c;
VideoPtr[2 * (ConsoleCursor.Y * ConsoleSize.X + ConsoleCursor.X) + 1] = ConsoleDefaultColor;
ConsoleCursorIncreasePos(1);
break;
}
}
void _write_string (string s)
{
int32 len = strlen(s), i;
for (i = 0; i < len; i++)
_write_char(s[i]);
}
void ConsoleWriteChar (char c)
{
_write_char(c);
ConsoleCursorUpdateHardware();
}
void ConsoleWriteString (string s)
{
_write_string(s);
ConsoleCursorUpdateHardware();
}
int32 ConsoleWrite (string format, ...)
{
if (!format || !*format) return 0;
va_list args;
va_start (args, format);
uint32 i, len = strlen(format);
uint8 temp_color = ConsoleDefaultColor;
for (i = 0; i < len; i++)
if (format[i] != '%') _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; }
default: va_end(args); return 1;
};
}
va_end(args);
ConsoleDefaultColor = temp_color;
ConsoleCursorUpdateHardware();
return i;
}
void ConsoleSetChar(Point pos, char c)
{
VideoPtr[2 * (pos.Y * ConsoleSize.X + pos.X)] = c;
}
void ConsoleSetColor(Point pos, uint8 color)
{
VideoPtr[2 * (pos.Y * ConsoleSize.X + pos.X) + 1] = color;
}
char ConsoleGetChar(Point pos)
{
return (char)VideoPtr[2 * (pos.Y * ConsoleSize.X + pos.X)];
}
uint8 ConsoleGetColor (Point pos)
{
return VideoPtr[2 * (pos.Y * ConsoleSize.X + pos.X) + 1];
}