Memory Manager.

git-svn-id: https://spexeah.com:8443/svn/Asuro@106 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron committed 2017-05-18 15:20:37 +00:00
1 parent abccbb9e7f
commit e7e5eccc9b
7 files changed
+51 -8

No files matched your search

BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+4 -1
View File
@@ -27,6 +27,7 @@ var
z : uint32; z : uint32;
dds : uint32; dds : uint32;
pint : puint32; pint : puint32;
pint2 : puint32;
begin begin
mbi:= mbinfo; mbi:= mbinfo;
@@ -48,11 +49,13 @@ begin
irq.init(); irq.init();
memorymanager.init(); memorymanager.init();
pint2:= kalloc(18);
pint:= kalloc(sizeof(uint32)); pint:= kalloc(sizeof(uint32));
if pint = nil then console.writestringln('!'); if pint = nil then console.writestringln('!');
pint^:= 1234; pint^:= 1234;
kfree(pint2);
console.writeintln(pint^); console.writeintln(pint^);
pint:= kalloc(18); kfree(pint);
util.halt_and_catch_fire; util.halt_and_catch_fire;
STI; STI;
+47 -7
View File
@@ -14,11 +14,17 @@ procedure init;
function kalloc(size : uint32) : void; function kalloc(size : uint32) : void;
procedure kfree(area : void); procedure kfree(area : void);
type
TBlock_Entry = packed record
Present : Boolean;
Length : uint8;
end;
implementation implementation
var var
Memory_Start : uint32; Memory_Start : uint32;
Memory_Manager : packed array[1..MAX_ENTRIES] of Boolean; Memory_Manager : packed array[1..MAX_ENTRIES] of TBlock_Entry;
procedure init; procedure init;
var var
@@ -26,14 +32,14 @@ var
begin begin
For i:=0 to MAX_ENTRIES-1 do begin For i:=0 to MAX_ENTRIES-1 do begin
Memory_Manager[i]:= false; Memory_Manager[i].Present:= False;
end; end;
Memory_Start:= uint32(@util.endptr); Memory_Start:= uint32(@util.endptr);
end; end;
function kalloc(size : uint32) : void; function kalloc(size : uint32) : void;
var var
blocks : uint32; blocks : uint8;
rem : uint32; rem : uint32;
i,j : uint32; i,j : uint32;
miss : boolean; miss : boolean;
@@ -46,24 +52,58 @@ begin
for i:=0 to MAX_ENTRIES-1 do begin for i:=0 to MAX_ENTRIES-1 do begin
miss:= false; miss:= false;
for j:=0 to blocks-1 do begin 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; end;
if not miss then begin if not miss then begin
kalloc:= void(Memory_Start+(i * 8)); kalloc:= void(Memory_Start+(i * 8));
for j:=0 to blocks-1 do begin 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; end;
console.writestring('Allocated '); console.writestring('Allocated ');
console.writeint(blocks); console.writeint(blocks);
console.writestringln(' Block(s).'); console.writestring(' Block(s). [Block: ');
console.writeint(i);
console.writestringln(']');
break; break;
end; end;
end; end;
end; end;
procedure kfree(area : void); 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;
end. end.