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" #include "video.c"
dword timer = 0; dword timer = 0;
dword addresses[256];
void type();
void k_init() void k_init()
{ {
@ -35,10 +34,25 @@ void k_init()
outportb(0x40, 0x9c); //lsb outportb(0x40, 0x9c); //lsb
outportb(0x40, 0x2e); //msb outportb(0x40, 0x2e); //msb
video_init((ModeInfoBlock *) 0x90306); 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(); mm_init();
enable_ints(); enable_ints();
console_cls(); 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; dword key = 0;
for (;;) for (;;)
{ {
@ -51,37 +65,13 @@ void isr(dword num)
{ {
switch(num) switch(num)
{ {
case 0x20: case 0x20: // IRQ0 - timer interrupt
timer++; timer++;
(*(byte *)0xb8000)++; (*(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(); eoi();
break; break;
case 0x21: case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); isr_keyboard(); //isr_keybard() takes care of calling eoi()
break; break;
} }
} }

33
mm.c
View File

@ -5,7 +5,7 @@
pageblock *first_pageblock = (pageblock *) 0; pageblock *first_pageblock = (pageblock *) 0;
dword mm_totalmem = 0x100000; //assume 1mb dword mm_totalmem = 0x100000; //start counting from 1mb
void mm_init() 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 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].base.lowdword += 4096;
maps[a].limit.lowdword -= 4096; maps[a].limit.lowdword -= 4096;
mm_init_pageblockpage(first_pageblock); mm_init_pageblockpage(first_pageblock);
@ -53,9 +53,11 @@ void mm_init()
} }
if (first_pageblock == 0) if (first_pageblock == 0)
{ {
printf("ERROR! NO INITIAL PAGE BLOCK COULD BE CREATED."); printf("ERROR! NO INITIAL PAGE BLOCK CREATED.");
asm("cli"); asm("cli");
asm("hlt"); asm("hlt");
for (;;)
;
} }
} }
@ -64,18 +66,16 @@ void mm_init()
void mm_init_pageblockpage(pageblock *pbp) void mm_init_pageblockpage(pageblock *pbp)
{ {
pageblock *pb = pbp;
int a; 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; pbp[a].base = 0;
pb->length = 0; pbp[a].length = 0;
pb->flags = MM_PB_NP; pbp[a].flags = MM_PB_NP;
if (a<511) if (a<255)
pb->link = (dword)pb + sizeof(pageblock); pbp[a].link = (dword)(&pbp[a+1]);
else else
pb->link = 0; pbp[a].link = 0;
pb++;
} }
} }
@ -83,8 +83,7 @@ void mm_init_pageblockpage(pageblock *pbp)
void *mm_palloc(dword numpages) void *mm_palloc(dword numpages)
{ {
pageblock *pb = first_pageblock; pageblock *pb = first_pageblock;
dword freeentries = mm_freeentries(); if (mm_freeentries() < 2)
if (freeentries < 2)
{ {
if(mm_new_pageblock_page() == 0) if(mm_new_pageblock_page() == 0)
return 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; pageblock *pb = first_pageblock;
for (;;) for (;;)
@ -153,11 +152,13 @@ pageblock *mm_new_pageblock_page()
int mm_pfree(void *ptr) int mm_pfree(void *ptr)
{ {
if (ptr == 0)
return 2;
pageblock *pb = first_pageblock; pageblock *pb = first_pageblock;
dword tofree = (dword) ptr; dword tofree = (dword) ptr;
for (;;) 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 pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
pageblock *pbc = first_pageblock; pageblock *pbc = first_pageblock;

6
mm.h
View File

@ -11,8 +11,8 @@ typedef struct {
dword base; dword base;
dword length; //in pages dword length; //in pages
dword flags; dword flags;
dword link; dword link; //leave dword instead of pointer so i dont have to worry about pointer arithmetic
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page } __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 256 entries = 1 page
void mm_init(); void mm_init();
@ -20,10 +20,10 @@ 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(); dword mm_freeentries();
dword mm_freemem();
pageblock *mm_new_pageblock_page(); pageblock *mm_new_pageblock_page();
pageblock *mm_lastpageblockentry(); pageblock *mm_lastpageblockentry();
pageblock *mm_nextpageblockentry(); pageblock *mm_nextpageblockentry();
dword mm_freemem();
#define MM_PB_FLAGMASK 0x03 //00000011 #define MM_PB_FLAGMASK 0x03 //00000011