Import backup from 2003-09-03

This commit is contained in:
Josh Holtrop 2003-09-03 22:00:00 -04:00
parent 5ffee3c2d8
commit e147635333
2 changed files with 47 additions and 8 deletions

View File

@ -19,7 +19,10 @@ void k_init();
#include "video.c" #include "video.c"
dword timer = 0; dword timer = 0;
dword pagesa = 0; word index = 0;
dword ptrs[512];
dword goon = 1;
dword req = 0;
void k_init() void k_init()
{ {
@ -28,9 +31,12 @@ void k_init()
outportb(0x43, 0x34); outportb(0x43, 0x34);
outportb(0x40, 0x9c); //lsb outportb(0x40, 0x9c); //lsb
outportb(0x40, 0x2e); //msb outportb(0x40, 0x2e); //msb
enable_ints(); // video_init((ModeInfoBlock *) 0x90306);
video_init((ModeInfoBlock *) 0x90306);
mm_init(); mm_init();
int a;
for (a=0; a<512; a++)
ptrs[a] = 0;
enable_ints();
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;
@ -51,8 +57,28 @@ void isr(dword num)
(*(byte *)0xb8000)++; (*(byte *)0xb8000)++;
if ((timer%50)==0) 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()); if (goon)
pagesa++; {
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(); eoi();
} }

19
mm.c
View File

@ -157,14 +157,27 @@ int mm_pfree(void *ptr)
dword tofree = (dword) ptr; dword tofree = (dword) ptr;
for (;;) for (;;)
{ {
if (pb->base == tofree) if ((pb->base == tofree) && (pb->flags == MM_PB_USED))
{ {
pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
pageblock *pbc = first_pageblock; pageblock *pbc = first_pageblock;
for (;;) for (;;)
{ {
if ((pbc->base + (pbc->length * 4096)) == pb->base) //pbc ends where pb starts
{
pbc->length += pb->length; //extend pbc's length by pb's length
pb->flags = MM_PB_NP; //mark pb as an unused entry
return 0;
}
if ((pb->base + (pb->length * 4096)) == pbc->base) //pb ends where pb starts
{
pb->length += pbc->length;
pbc->flags = MM_PB_NP;
return 0;
}
if (pbc->link == 0) //no entry found to consolidate...
return 0;
pbc = (pageblock *) pbc->link; //next entry to test
} }
} }
if (pb->link == 0) if (pb->link == 0)