Import backup from 2003-09-26

This commit is contained in:
Josh Holtrop 2003-09-26 22:00:00 -04:00
parent c3309d4e5d
commit 68fd6cad70
3 changed files with 41 additions and 50 deletions

View File

@ -24,8 +24,7 @@ void k_init();
#include "video.c"
dword timer = 0;
void type();
dword addresses[256];
void k_init()
{
@ -35,10 +34,25 @@ void k_init()
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);
mm_init();
enable_ints();
console_cls();
//printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
int a = 0;
for (;;)
{
addresses[a] = (dword)mm_palloc(256);
printf("%x\t", addresses[a]);
if (addresses[a++] == 0)
break;
}
dword key = 0;
for (;;)
{
@ -51,37 +65,13 @@ void isr(dword num)
{
switch(num)
{
case 0x20:
case 0x20: // IRQ0 - timer interrupt
timer++;
(*(byte *)0xb8000)++;
switch(timer)
{
case 150:
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088);
break;
case 200:
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
break;
case 250:
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
break;
case 300:
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
break;
case 350:
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
break;
case 400:
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
break;
case 450:
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
break;
}
eoi();
break;
case 0x21:
isr_keyboard();
case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); //isr_keybard() takes care of calling eoi()
break;
}
}

33
mm.c
View File

@ -5,7 +5,7 @@
pageblock *first_pageblock = (pageblock *) 0;
dword mm_totalmem = 0x100000; //assume 1mb
dword mm_totalmem = 0x100000; //start counting from 1mb
void mm_init()
{
@ -26,7 +26,7 @@ void mm_init()
}
if (first_pageblock == 0) //no pageblock page set up yet, so set it up here
{
first_pageblock = (pageblock *) maps[a].base.lowdword ;
first_pageblock = (pageblock *) maps[a].base.lowdword;
maps[a].base.lowdword += 4096;
maps[a].limit.lowdword -= 4096;
mm_init_pageblockpage(first_pageblock);
@ -53,9 +53,11 @@ void mm_init()
}
if (first_pageblock == 0)
{
printf("ERROR! NO INITIAL PAGE BLOCK COULD BE CREATED.");
printf("ERROR! NO INITIAL PAGE BLOCK CREATED.");
asm("cli");
asm("hlt");
for (;;)
;
}
}
@ -64,18 +66,16 @@ void mm_init()
void mm_init_pageblockpage(pageblock *pbp)
{
pageblock *pb = pbp;
int a;
for (a=0; a<512; a++)
for (a=0; a<256; a++) // 256 pageblock entries * 16 bytes per page block entry = 4096 bytes (1 page of pageblock entries)
{
pb->base = 0;
pb->length = 0;
pb->flags = MM_PB_NP;
if (a<511)
pb->link = (dword)pb + sizeof(pageblock);
pbp[a].base = 0;
pbp[a].length = 0;
pbp[a].flags = MM_PB_NP;
if (a<255)
pbp[a].link = (dword)(&pbp[a+1]);
else
pb->link = 0;
pb++;
pbp[a].link = 0;
}
}
@ -83,8 +83,7 @@ void mm_init_pageblockpage(pageblock *pbp)
void *mm_palloc(dword numpages)
{
pageblock *pb = first_pageblock;
dword freeentries = mm_freeentries();
if (freeentries < 2)
if (mm_freeentries() < 2)
{
if(mm_new_pageblock_page() == 0)
return 0;
@ -130,7 +129,7 @@ dword mm_freeentries()
}
pageblock *mm_new_pageblock_page()
pageblock *mm_new_pageblock_page() //as of 09/26/03 this method leaks 4kb main memory per call, unrecoverable
{
pageblock *pb = first_pageblock;
for (;;)
@ -153,11 +152,13 @@ pageblock *mm_new_pageblock_page()
int mm_pfree(void *ptr)
{
if (ptr == 0)
return 2;
pageblock *pb = first_pageblock;
dword tofree = (dword) ptr;
for (;;)
{
if ((pb->base == tofree) && (pb->flags == MM_PB_USED))
if (pb->base == tofree) // && (pb->flags == MM_PB_USED))
{
pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
pageblock *pbc = first_pageblock;

8
mm.h
View File

@ -9,10 +9,10 @@ typedef struct {
typedef struct {
dword base;
dword length; //in pages
dword length; //in pages
dword flags;
dword link;
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page
dword link; //leave dword instead of pointer so i dont have to worry about pointer arithmetic
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 256 entries = 1 page
void mm_init();
@ -20,10 +20,10 @@ void mm_init_pageblockpage(pageblock *pbp);
void *mm_palloc(dword numpages);
int mm_pfree(void *ptr);
dword mm_freeentries();
dword mm_freemem();
pageblock *mm_new_pageblock_page();
pageblock *mm_lastpageblockentry();
pageblock *mm_nextpageblockentry();
dword mm_freemem();
#define MM_PB_FLAGMASK 0x03 //00000011