diff --git a/Asuro.iso b/Asuro.iso index 87a71e02..f2ef77d4 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index 1f73006c..6261d1a3 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 0053aa03..b2038ee8 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index fc7c73a5..34685d66 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/src/lmemorymanager.pas b/src/lmemorymanager.pas new file mode 100644 index 00000000..6ddec1ed --- /dev/null +++ b/src/lmemorymanager.pas @@ -0,0 +1,105 @@ +unit lmemorymanager; + +interface + +uses + util, + vmemorymanager, + console; + +type + TBlock_Entry = packed record + Present : Boolean; + Length : uint8; + end; + +const + ALLOC_SPACE = 8; //64-Bit Allocations + MAX_ENTRIES = 0x60000; + +var + Memory_Start : uint32; + Memory_Manager : packed array[1..MAX_ENTRIES] of TBlock_Entry; + +procedure init; + +implementation + +procedure init; +var + i : uint32; + +begin + console.writestringln('VMM: INIT BEGIN.'); + For i:=0 to MAX_ENTRIES-1 do begin + Memory_Manager[i].Present:= False; + end; + Memory_Start:= uint32(@util.endptr); + console.writestringln('VMM: INIT END.'); +end; + +function kalloc(size : uint32) : void; +var + blocks : uint32; + rem : uint32; + i,j : uint32; + miss : boolean; + +begin + blocks:= size div ALLOC_SPACE; + rem:= size - (blocks * ALLOC_SPACE); + if rem > 0 then blocks:= blocks + 1; + kalloc:= nil; + for i:=0 to MAX_ENTRIES-1 do begin + miss:= false; + for j:=0 to blocks-1 do begin + if Memory_Manager[i+j].Present then begin + miss:= true; + break; + end; + end; + if not miss then begin + kalloc:= void(Memory_Start+(i * ALLOC_SPACE)); + for j:=0 to blocks-1 do begin + Memory_Manager[i+j].Present:= true; + Memory_Manager[i+j].Length:= 0; + if j = 0 then Memory_Manager[i+j].Length:= blocks; + end; + console.writestring('Allocated '); + console.writeint(blocks); + console.writestring(' Block(s). [Block: '); + console.writeint(i); + console.writestringln(']'); + break; + end; + end; +end; + +procedure kfree(area : void); +var + Block : uint32; + bLength : uint8; + i : uint32; + +begin + if uint32(area) < Memory_Start then begin + asm + INT 13 + end; + end; + Block:= (uint32(Area) - Memory_Start) div ALLOC_SPACE; + if Memory_Manager[Block].Present then begin + If Memory_Manager[Block].Length > 0 then begin + bLength:= Memory_Manager[Block].Length; + for i:=0 to bLength-1 do begin + Memory_Manager[Block+i].Present:= False; + end; + end else begin + asm + INT 13 + end; + end; + end; +end; + +end. \ No newline at end of file