diff --git a/Asuro.iso b/Asuro.iso index d32d4b1f..2ab4db1c 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index 0193c546..cd207ccf 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index d1a26206..6489aee4 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index 3a6b7319..e2fe869e 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 98af4db3..3486d37d 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/src/kernel.pas b/src/kernel.pas index 46e9f3e9..02280c46 100644 --- a/src/kernel.pas +++ b/src/kernel.pas @@ -27,6 +27,7 @@ var z : uint32; dds : uint32; pint : puint32; + pint2 : puint32; begin mbi:= mbinfo; @@ -48,11 +49,13 @@ begin irq.init(); memorymanager.init(); + pint2:= kalloc(18); pint:= kalloc(sizeof(uint32)); if pint = nil then console.writestringln('!'); pint^:= 1234; + kfree(pint2); console.writeintln(pint^); - pint:= kalloc(18); + kfree(pint); util.halt_and_catch_fire; STI; diff --git a/src/memorymanager.pas b/src/memorymanager.pas index e397d37f..d7136712 100644 --- a/src/memorymanager.pas +++ b/src/memorymanager.pas @@ -14,11 +14,17 @@ procedure init; function kalloc(size : uint32) : void; procedure kfree(area : void); +type + TBlock_Entry = packed record + Present : Boolean; + Length : uint8; + end; + implementation var Memory_Start : uint32; - Memory_Manager : packed array[1..MAX_ENTRIES] of Boolean; + Memory_Manager : packed array[1..MAX_ENTRIES] of TBlock_Entry; procedure init; var @@ -26,14 +32,14 @@ var begin For i:=0 to MAX_ENTRIES-1 do begin - Memory_Manager[i]:= false; + Memory_Manager[i].Present:= False; end; Memory_Start:= uint32(@util.endptr); end; function kalloc(size : uint32) : void; var - blocks : uint32; + blocks : uint8; rem : uint32; i,j : uint32; miss : boolean; @@ -46,24 +52,58 @@ begin for i:=0 to MAX_ENTRIES-1 do begin miss:= false; for j:=0 to blocks-1 do begin - if Memory_Manager[i+j] then miss:= true; + if Memory_Manager[i+j].Present then begin + miss:= true; + break; + end; end; if not miss then begin kalloc:= void(Memory_Start+(i * 8)); for j:=0 to blocks-1 do begin - Memory_Manager[i+j]:= true; + 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.writestringln(' Block(s).'); + console.writestring(' Block(s). [Block: '); + console.writeint(i); + console.writestringln(']'); break; end; end; end; procedure kfree(area : void); -begin +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 8; + 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; + console.writestring('Freed '); + console.writeint(bLength); + console.writestring(' Block(s). [Block: '); + console.writeint(Block); + console.writestringln(']'); + end else begin + asm + INT 13 + end; + end; + end; end; end. \ No newline at end of file