Kek
git-svn-id: https://spexeah.com:8443/svn/Asuro@126 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
39ca6eed6f
commit
2788d81f7c
Binary file not shown.
Binary file not shown.
BIN
lib/libpsystem.a
BIN
lib/libpsystem.a
Binary file not shown.
105
src/lmemorymanager.pas
Normal file
105
src/lmemorymanager.pas
Normal file
@ -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.
|
Loading…
x
Reference in New Issue
Block a user