hos/kernel.c

108 lines
2.4 KiB
C

//kernel.c
//08/13/03 Josh Holtrop
//Holtrop's Operating System
#define VXR video_mode.XResolution
#define VYR video_mode.YResolution
#include "k_defines.h"
#include "lib/string.h"
#include "lib/io.h"
#include "functions.h"
#include "video.h"
#include "mm.h"
#include "keyboard.h"
void isr(dword num);
void k_init();
#include "keyboard.c"
#include "mm.c"
#include "functions.c"
#include "video.c"
dword timer = 0;
dword index = 0;
dword keepgoing = 1;
dword addresses[256];
void k_init()
{
remap_pics(0x20, 0x28);
//set timer : 2e9c = 100hz
outportb(0x43, 0x34);
outportb(0x40, 0x9c); //lsb
outportb(0x40, 0x2e); //msb
video_init((ModeInfoBlock *) 0x90306);
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088); //test rectangles, draws "HOS"
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
video_vert(10, 10, 16, 0x00ffff00); //should be yellow 'H'
video_horiz(13, 10, 14, 0x00ffff00);
video_vert(14, 10, 16, 0x00ffff00);
mm_init();
enable_ints();
console_cls();
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
dword key = 0;
for (;;)
{
key = kbdWaitKey();
putc(key);
}
}
void isr(dword num)
{
switch(num)
{
case 0x20: // IRQ0 - timer interrupt
timer++;
(*(byte *)0xb8000)++;
if ((timer%25)==0)
{
if (keepgoing)
{
addresses[index] = (dword) mm_palloc(256, KERNEL_PID);
printf("Addr: 0x%x\tEntries:\t%d\n", addresses[index], mm_freeentries());
if (addresses[index] == 0)
{
index = -1;
keepgoing = 0;
}
index++;
}
else
{
printf("Freeing %x\t", addresses[index]);
addresses[index] = mm_pfree((void *)addresses[index]);
printf("Free:\t%d\tEntries:\t%d\n", addresses[index], mm_freeentries());
if (addresses[index] != 0)
{
index = -1;
keepgoing = 1;
}
index++;
}
}
eoi();
break;
case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); //isr_keybard() takes care of calling eoi()
break;
}
}