Tiberiu Chibici
913e65b856
==================================================== + 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
132 lines
2.7 KiB
C
132 lines
2.7 KiB
C
#include <debugio.h>
|
|
#include <memory.h>
|
|
#include <stdio.h>
|
|
|
|
uint8* VideoPtr = (uint8*) 0xb8000;
|
|
|
|
Point ConsoleCursor = {0, 0};
|
|
UPoint ConsoleSize = {80, 25};
|
|
|
|
uint8 ConsoleDefaultColor = CONSOLE_DEFAULT_COLOR;
|
|
|
|
/**************************************
|
|
* Basic console operations *
|
|
**************************************/
|
|
void ConsoleClear()
|
|
{
|
|
uint32 temp;
|
|
|
|
for (temp = 0; temp < ConsoleSize.X * ConsoleSize.Y; temp++)
|
|
{
|
|
VideoPtr[2 * temp] = 0;
|
|
VideoPtr[2 * temp + 1] = ConsoleDefaultColor;
|
|
}
|
|
|
|
ConsoleCursor.X = ConsoleCursor.Y = 0;
|
|
ConsoleCursorUpdateHardware();
|
|
}
|
|
|
|
void ConsoleScroll (uint32 lines)
|
|
{
|
|
// Sanity check, don't scroll too much
|
|
if (lines > ConsoleSize.Y) lines = ConsoleSize.Y;
|
|
|
|
uint32 x, y;
|
|
for (y = 0; y < ConsoleSize.Y - lines; y++)
|
|
for (x = 0; x < 2*ConsoleSize.X; x++)
|
|
VideoPtr[y * ConsoleSize.X * 2 + x] = VideoPtr[(y+lines)*ConsoleSize.X*2 + x];
|
|
|
|
for (y = ConsoleSize.Y - lines; y < ConsoleSize.Y; y++)
|
|
for (x = 0; x < ConsoleSize.X; x++)
|
|
{
|
|
VideoPtr[2 * (y * ConsoleSize.X + x)] = 0;
|
|
VideoPtr[2 * (y * ConsoleSize.X + x) + 1] = ConsoleDefaultColor;
|
|
}
|
|
|
|
ConsoleCursor.Y -= lines;
|
|
}
|
|
|
|
|
|
/**************************************
|
|
* Cursor position *
|
|
**************************************/
|
|
Point ConsoleGetCursor()
|
|
{
|
|
return ConsoleCursor;
|
|
}
|
|
|
|
extern void ConsoleSetCursor(Point p)
|
|
{
|
|
ConsoleCursor = p;
|
|
}
|
|
|
|
void ConsoleCursorIncreasePos (int32 delta)
|
|
{
|
|
// Increase X, Y positions
|
|
ConsoleCursor.Y += delta / ConsoleSize.X;
|
|
ConsoleCursor.X += delta % ConsoleSize.X;
|
|
|
|
// Next line if X > Screen width
|
|
while (ConsoleCursor.X >= (int32)ConsoleSize.X)
|
|
{
|
|
ConsoleCursor.Y++;
|
|
ConsoleCursor.X -= ConsoleSize.X;
|
|
}
|
|
|
|
// Previous line if X < 0
|
|
while (ConsoleCursor.X < 0)
|
|
{
|
|
ConsoleCursor.Y--;
|
|
ConsoleCursor.X += ConsoleSize.X;
|
|
}
|
|
|
|
// Scroll if Y > Screen height
|
|
if (ConsoleCursor.Y >= (int32)ConsoleSize.Y)
|
|
ConsoleScroll(1);
|
|
}
|
|
|
|
void ConsoleCursorNewline()
|
|
{
|
|
ConsoleCursor.X = 0;
|
|
|
|
if (++ConsoleCursor.Y >= (int32)ConsoleSize.Y)
|
|
ConsoleScroll(1);
|
|
}
|
|
|
|
void ConsoleCursorUpdateHardware()
|
|
{
|
|
uint16 temp = (uint16) (ConsoleCursor.Y * ConsoleSize.X + ConsoleCursor.X);
|
|
uint16* port = (uint16*) 0x463 ;
|
|
|
|
outportb(*port, 14);
|
|
outportb(*port + 1, (temp >> 8) & 0xff);
|
|
outportb(*port, 15);
|
|
outportb(*port + 1, temp & 0xff);
|
|
}
|
|
|
|
uint8 Color (uint8 back, uint8 fore)
|
|
{
|
|
return ((back<<4) | fore);
|
|
}
|
|
|
|
void ConsoleSetDefaultColor(uint8 color)
|
|
{
|
|
ConsoleDefaultColor = color;
|
|
}
|
|
|
|
uint8 ConsoleGetDefaultColor ()
|
|
{
|
|
return ConsoleDefaultColor;
|
|
}
|
|
|
|
UPoint ConsoleGetSize()
|
|
{
|
|
return ConsoleSize;
|
|
}
|
|
|
|
void ConsoleCursorGoto(Point p)
|
|
{
|
|
if (p.X >= 0 && p.X < (int32)ConsoleSize.X) ConsoleCursor.X = p.X;
|
|
if (p.Y >= 0 && p.Y < (int32)ConsoleSize.Y) ConsoleCursor.Y = p.Y;
|
|
}
|