Import backup from 2003-09-02

This commit is contained in:
Josh Holtrop 2003-09-02 22:00:00 -04:00
parent 9076a15f08
commit 5ffee3c2d8
3 changed files with 136 additions and 7 deletions

View File

@ -19,6 +19,7 @@ void k_init();
#include "video.c" #include "video.c"
dword timer = 0; dword timer = 0;
dword pagesa = 0;
void k_init() void k_init()
{ {
@ -32,18 +33,14 @@ void k_init()
mm_init(); mm_init();
console_cls(); console_cls();
printf("Memory available to OS: %d MB", mm_totalmem/0x100000); printf("Memory available to OS: %d MB", mm_totalmem/0x100000);
pageblock *pb = first_pageblock; /* pageblock *pb = first_pageblock;
for (;;) for (;;)
{ {
if (pb->flags == MM_PB_NP) if (pb->flags == MM_PB_NP)
break; break;
printf("\nBase: 0x%x; Limit: 0x%x; Flags: 0x%x, Link: 0x%x", pb->base, pb->length, pb->flags, pb->link); 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; pb = (pageblock *) pb->link;
} } */
int a;
for (a = -1024; a < 778; a += 98)
printf("\n%u\t%d\t%x", a, a, a);
//printf("\n%d\t%d", -123, -23456);
} }
void isr(dword num) void isr(dword num)
@ -51,6 +48,12 @@ void isr(dword num)
if (num == 0x20) if (num == 0x20)
{ {
timer++; timer++;
(*(byte *)0xb8000)++;
if ((timer%50)==0)
{
printf("\nReq: 0x%x\t Addr: 0x%x\tEntries: 0x%x\tMem: 0x%x", pagesa, (dword)mm_palloc(1024), mm_freeentries(), mm_freemem());
pagesa++;
}
eoi(); eoi();
} }
//if (num == 0x21) //if (num == 0x21)

123
mm.c
View File

@ -72,25 +72,146 @@ void mm_init_pageblockpage(pageblock *pbp)
pb->length = 0; pb->length = 0;
pb->flags = MM_PB_NP; pb->flags = MM_PB_NP;
if (a<511) if (a<511)
pb->link = (dword)++pb + sizeof(pageblock); pb->link = (dword)pb + sizeof(pageblock);
else else
pb->link = 0; pb->link = 0;
pb++;
} }
} }
void *mm_palloc(dword numpages) void *mm_palloc(dword numpages)
{ {
pageblock *pb = first_pageblock;
dword freeentries = mm_freeentries();
if (freeentries < 2)
{
if(mm_new_pageblock_page() == 0)
return 0;
}
pageblock *newentry = mm_nextpageblockentry();
for (;;)
{
if ((pb->flags == MM_PB_AVAIL) && (pb->length >= numpages))
break;
if (pb->link == 0)
return 0;
pb = (pageblock *)pb->link;
}
if (pb->length == numpages) //dont need a new entry, just mark this one as used :)
{
pb->flags = MM_PB_USED;
return pb;
}
else //subtract out allocated number of pages from length
{
newentry->base = pb->base;
newentry->length = numpages;
newentry->flags = MM_PB_USED;
pb->base += (numpages * 4096);
pb->length -= numpages;
return (void *)newentry->base;
}
}
dword mm_freeentries()
{
pageblock *pb = first_pageblock;
dword counter = 0;
for (;;)
{
if (pb->flags == MM_PB_NP)
counter++;
if (pb->link == 0)
return counter;
pb = (pageblock *) pb->link;
}
}
pageblock *mm_new_pageblock_page()
{
pageblock *pb = first_pageblock;
for (;;)
{
if ((pb->flags == MM_PB_AVAIL) && (pb->length > 1))
{
pageblock *retval = (pageblock *)pb->base;
pb->base += 4096;
pb->length--;
mm_init_pageblockpage(retval); //zeros out, links new pageblock page
mm_lastpageblockentry()->link = (dword)retval; //set up link to new pageblock page
return retval;
}
pb = (pageblock *) pb->link;
if (pb == 0)
return 0;
}
} }
int mm_pfree(void *ptr) int mm_pfree(void *ptr)
{
pageblock *pb = first_pageblock;
dword tofree = (dword) ptr;
for (;;)
{
if (pb->base == tofree)
{
pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
pageblock *pbc = first_pageblock;
for (;;)
{ {
}
}
if (pb->link == 0)
return 1;
pb = (pageblock *) pb->link;
}
}
pageblock *mm_lastpageblockentry()
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->link == 0)
return pb;
pb = (pageblock *)pb->link;
}
}
pageblock *mm_nextpageblockentry()
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
return pb;
if (pb->link == 0)
return 0;
pb = (pageblock *)pb->link;
}
}
dword mm_freemem()
{
dword amount = 0;
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_AVAIL)
amount += (pb->length)*4096;
if (pb->link == 0)
return amount;
pb = (pageblock *) pb->link;
}
} }

5
mm.h
View File

@ -19,6 +19,11 @@ void mm_init();
void mm_init_pageblockpage(pageblock *pbp); void mm_init_pageblockpage(pageblock *pbp);
void *mm_palloc(dword numpages); void *mm_palloc(dword numpages);
int mm_pfree(void *ptr); int mm_pfree(void *ptr);
dword mm_freeentries();
pageblock *mm_new_pageblock_page();
pageblock *mm_lastpageblockentry();
pageblock *mm_nextpageblockentry();
dword mm_freemem();
#define MM_PB_FLAGMASK 0x03 //00000011 #define MM_PB_FLAGMASK 0x03 //00000011