Memory Manager.
git-svn-id: https://spexeah.com:8443/svn/Asuro@106 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
abccbb9e7f
commit
e7e5eccc9b
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/libpsystem.a
BIN
lib/libpsystem.a
Binary file not shown.
@ -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;
|
||||
|
@ -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.
|
Loading…
x
Reference in New Issue
Block a user