93 lines
1.8 KiB
C
93 lines
1.8 KiB
C
//kernel.c
|
|
//08/13/03 Josh Holtrop
|
|
//Holtrop's Operating System
|
|
|
|
#include "k_defines.h"
|
|
|
|
#include "lib/string.h"
|
|
#include "lib/io.h"
|
|
|
|
#include "functions.h"
|
|
#include "video.h"
|
|
#include "mm.h"
|
|
|
|
void isr(dword num);
|
|
void k_init();
|
|
|
|
#include "mm.c"
|
|
#include "functions.c"
|
|
#include "video.c"
|
|
|
|
dword timer = 0;
|
|
word index = 0;
|
|
dword ptrs[512];
|
|
dword goon = 1;
|
|
dword req = 0;
|
|
|
|
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);
|
|
mm_init();
|
|
int a;
|
|
for (a=0; a<512; a++)
|
|
ptrs[a] = 0;
|
|
enable_ints();
|
|
console_cls();
|
|
printf("Memory available to OS: %d MB", mm_totalmem/0x100000);
|
|
/* pageblock *pb = first_pageblock;
|
|
for (;;)
|
|
{
|
|
if (pb->flags == MM_PB_NP)
|
|
break;
|
|
printf("\nBase: 0x%x; Limit: 0x%x; Flags: 0x%x, Link: 0x%x", pb->base, pb->length, pb->flags, pb->link);
|
|
pb = (pageblock *) pb->link;
|
|
} */
|
|
}
|
|
|
|
void isr(dword num)
|
|
{
|
|
if (num == 0x20)
|
|
{
|
|
timer++;
|
|
(*(byte *)0xb8000)++;
|
|
if ((timer%50)==0)
|
|
{
|
|
if (goon)
|
|
{
|
|
if(ptrs[index] = (dword)mm_palloc(1024))
|
|
printf("\nReq:%d\tAddr: %x\tEntries: %x\tMem: %x\tIndex: %x", req++, ptrs[index++], mm_freeentries(), mm_freemem(), index);
|
|
else
|
|
{
|
|
goon = 0;
|
|
index = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dword reslt = mm_pfree((void *)ptrs[index]); //zero returned means chunk freed successfully
|
|
printf("\nReq:%d\tFree(): %x\tEntries: %x\tMem: %x\tIndex: %x", req++, reslt, mm_freeentries(), mm_freemem(), index++);
|
|
if (reslt)
|
|
{
|
|
for (index=0; index<512; index++)
|
|
ptrs[index] = 0;
|
|
index = 0;
|
|
goon = 1;
|
|
}
|
|
}
|
|
}
|
|
eoi();
|
|
}
|
|
//if (num == 0x21)
|
|
// restart();
|
|
}
|
|
|
|
|
|
|
|
|
|
|