LogicMemoryManager working.
git-svn-id: https://spexeah.com:8443/svn/Asuro@159 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
0a26e076b9
commit
87094a7afd
BIN
lib/kernel.ppu
BIN
lib/kernel.ppu
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/libpsystem.a
BIN
lib/libpsystem.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -14,8 +14,9 @@ uses
|
|||||||
bios_data_area,
|
bios_data_area,
|
||||||
keyboard,
|
keyboard,
|
||||||
vmemorymanager,
|
vmemorymanager,
|
||||||
pmemorymanager;
|
pmemorymanager,
|
||||||
//scheduler;
|
lmemorymanager,
|
||||||
|
scheduler;
|
||||||
|
|
||||||
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
|
||||||
|
|
||||||
@ -50,32 +51,22 @@ begin
|
|||||||
isr.init();
|
isr.init();
|
||||||
irq.init();
|
irq.init();
|
||||||
pmemorymanager.init();
|
pmemorymanager.init();
|
||||||
|
|
||||||
//while true do begin end;
|
|
||||||
|
|
||||||
vmemorymanager.init();
|
vmemorymanager.init();
|
||||||
|
lmemorymanager.init();
|
||||||
|
|
||||||
vmemorymanager.new_page(0);
|
scheduler.init();
|
||||||
pint:= puint32(0);
|
|
||||||
|
|
||||||
console.writestringln('Writing 1234 to Logical Address $00000000');
|
|
||||||
pint^:= 1234;
|
|
||||||
if pint^ = 1234 then begin
|
|
||||||
console.writestringln('Read 1234 back from Logical Address $00000000!!!');
|
|
||||||
end;
|
|
||||||
|
|
||||||
//scheduler.init();
|
|
||||||
|
|
||||||
STI;
|
STI;
|
||||||
isr32.hook(uint32(@bios_data_area.tick_update));
|
isr32.hook(uint32(@bios_data_area.tick_update));
|
||||||
|
|
||||||
{z:= 1;
|
{z:= 1;
|
||||||
while true do begin
|
while true do begin
|
||||||
console.writeword(z);
|
console.writehex(z);
|
||||||
console.writestring(': ');
|
console.writestring(': ');
|
||||||
pint:= kalloc(1024*4);
|
pint:= kalloc(1024*4);
|
||||||
console.writewordln(uint32(pint));
|
console.writehexln(uint32(pint));
|
||||||
if pint = nil then while true do begin end else pint^:= 1234;
|
if pint = nil then while true do begin end else pint^:= 1234;
|
||||||
|
//kfree(pint);
|
||||||
z:=z+1;
|
z:=z+1;
|
||||||
end;}
|
end;}
|
||||||
|
|
||||||
|
@ -7,98 +7,150 @@ uses
|
|||||||
vmemorymanager,
|
vmemorymanager,
|
||||||
console;
|
console;
|
||||||
|
|
||||||
type
|
|
||||||
TBlock_Entry = packed record
|
|
||||||
Present : Boolean;
|
|
||||||
Length : uint8;
|
|
||||||
end;
|
|
||||||
|
|
||||||
const
|
const
|
||||||
ALLOC_SPACE = 8; //64-Bit Allocations
|
ALLOC_SPACE = 8; //64-Bit Allocations
|
||||||
MAX_ENTRIES = 0x60000;
|
MAX_ENTRIES = $60000;
|
||||||
|
DATA_OFFSET = $100000;
|
||||||
|
|
||||||
|
type
|
||||||
|
THeapEntry = bitpacked record
|
||||||
|
Present : Boolean;
|
||||||
|
Root : Boolean;
|
||||||
|
Last : Boolean;
|
||||||
|
Resv1 : Boolean;
|
||||||
|
Resv2 : Boolean;
|
||||||
|
Resv3 : Boolean;
|
||||||
|
Resv4 : Boolean;
|
||||||
|
Resv5 : Boolean;
|
||||||
|
end;
|
||||||
|
THeapPage = packed record
|
||||||
|
Next_Page : uint32;
|
||||||
|
Prev_Page : uint32;
|
||||||
|
Entries : Array[0..MAX_ENTRIES-1] of THeapEntry;
|
||||||
|
end;
|
||||||
|
PHeapPage = ^THeapPage;
|
||||||
|
|
||||||
var
|
var
|
||||||
Memory_Start : uint32;
|
Root_Page : PHeapPage;
|
||||||
Memory_Manager : packed array[1..MAX_ENTRIES] of TBlock_Entry;
|
|
||||||
|
|
||||||
procedure init;
|
procedure init;
|
||||||
|
function kalloc(size : uint32) : void;
|
||||||
|
procedure kfree(area : void);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function new_lmm_page() : uint32;
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
i:= KERNEL_PAGE_NUMBER + 4;
|
||||||
|
while not vmemorymanager.new_page(i) do begin
|
||||||
|
i:= i + 1;
|
||||||
|
end;
|
||||||
|
new_lmm_page:= i SHL 22;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function new_heap_page(CurrentPage : PHeapPage) : PHeapPage;
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
new_heap_page:= PHeapPage(new_lmm_page);
|
||||||
|
if CurrentPage <> nil then CurrentPage^.Next_Page:= uint32(new_heap_page);
|
||||||
|
new_heap_page^.Next_Page:= 0;
|
||||||
|
new_heap_page^.Prev_Page:= uint32(CurrentPage);
|
||||||
|
For i:=0 to MAX_ENTRIES-1 do begin
|
||||||
|
with new_heap_page^.Entries[i] do begin
|
||||||
|
Present:= False;
|
||||||
|
Root:= False;
|
||||||
|
Last:= False;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure init;
|
procedure init;
|
||||||
var
|
var
|
||||||
i : uint32;
|
i : uint32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
console.writestringln('LMM: INIT BEGIN.');
|
Root_Page:= PHeapPage(new_lmm_page);
|
||||||
|
Root_Page^.Next_Page:= 0;
|
||||||
|
Root_Page^.Prev_Page:= 0;
|
||||||
For i:=0 to MAX_ENTRIES-1 do begin
|
For i:=0 to MAX_ENTRIES-1 do begin
|
||||||
Memory_Manager[i].Present:= False;
|
Root_Page^.Entries[i].Present:= False;
|
||||||
end;
|
Root_Page^.Entries[i].Root:= False;
|
||||||
Memory_Start:= uint32(@util.endptr);
|
Root_Page^.Entries[i].Last:= False;
|
||||||
console.writestringln('LMM: INIT END.');
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function kalloc(size : uint32) : void;
|
function kalloc(size : uint32) : void;
|
||||||
var
|
var
|
||||||
blocks : uint32;
|
Heap_Entries : uint32;
|
||||||
rem : uint32;
|
i, j : uint32;
|
||||||
i,j : uint32;
|
hp : PHeapPage;
|
||||||
miss : boolean;
|
miss : boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
blocks:= size div ALLOC_SPACE;
|
Heap_Entries:= size div 8;
|
||||||
rem:= size - (blocks * ALLOC_SPACE);
|
If sint32(size-(Heap_Entries*8)) > 0 then Heap_Entries:= Heap_Entries + 1;
|
||||||
if rem > 0 then blocks:= blocks + 1;
|
hp:= Root_Page;
|
||||||
kalloc:= nil;
|
kalloc:= nil;
|
||||||
for i:=0 to MAX_ENTRIES-1 do begin
|
while kalloc = nil do begin
|
||||||
miss:= false;
|
for i:=0 to MAX_ENTRIES-1 do begin
|
||||||
for j:=0 to blocks-1 do begin
|
miss:= false;
|
||||||
if Memory_Manager[i+j].Present then begin
|
for j:=0 to Heap_Entries-1 do begin
|
||||||
miss:= true;
|
if hp^.Entries[i+j].Present then begin
|
||||||
|
miss:= true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if not miss then begin
|
||||||
|
kalloc:= void( uint32( hp ) + DATA_OFFSET + (i * 8) );
|
||||||
|
for j:=0 to Heap_Entries-1 do begin
|
||||||
|
hp^.Entries[i+j].Present:= True;
|
||||||
|
if j = (Heap_Entries-1) then begin
|
||||||
|
hp^.Entries[i+j].Last:= True;
|
||||||
|
end;
|
||||||
|
if j = 0 then begin
|
||||||
|
hp^.Entries[i+j].Root:= True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if not miss then begin
|
if kalloc = nil then begin
|
||||||
kalloc:= void(Memory_Start+(i * ALLOC_SPACE));
|
if PHeapPage(hp^.Next_Page) = nil then begin
|
||||||
for j:=0 to blocks-1 do begin
|
new_heap_page(hp);
|
||||||
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 ');
|
hp:= PHeapPage(hp^.Next_Page);
|
||||||
console.writeint(blocks);
|
|
||||||
console.writestring(' Block(s). [Block: ');
|
|
||||||
console.writeint(i);
|
|
||||||
console.writestringln(']');
|
|
||||||
break;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure kfree(area : void);
|
procedure kfree(area : void);
|
||||||
var
|
var
|
||||||
Block : uint32;
|
hp : PHeapPage;
|
||||||
bLength : uint8;
|
entry : uint32;
|
||||||
i : uint32;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if uint32(area) < Memory_Start then begin
|
hp:= PHeapPage((uint32(area) SHR 22) SHL 22);
|
||||||
asm
|
entry:= (uint32(area) - DATA_OFFSET - uint32(hp)) div 8;
|
||||||
INT 13
|
if hp^.Entries[entry].Present then begin
|
||||||
end;
|
while not hp^.Entries[entry].Root do begin
|
||||||
end;
|
entry:= entry - 1;
|
||||||
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;
|
||||||
|
While not hp^.Entries[entry].Last do begin
|
||||||
|
hp^.Entries[entry].Present:= False;
|
||||||
|
hp^.Entries[entry].Root:= False;
|
||||||
|
hp^.Entries[entry].Last:= False;
|
||||||
|
entry:= entry + 1;
|
||||||
|
end;
|
||||||
|
hp^.Entries[entry].Present:= False;
|
||||||
|
hp^.Entries[entry].Root:= False;
|
||||||
|
hp^.Entries[entry].Last:= False;
|
||||||
|
end else begin
|
||||||
|
GPF;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ begin
|
|||||||
PageDirectory:= load_current_page_directory;
|
PageDirectory:= load_current_page_directory;
|
||||||
map_page(KERNEL_PAGE_NUMBER + 1, 1);
|
map_page(KERNEL_PAGE_NUMBER + 1, 1);
|
||||||
map_page(KERNEL_PAGE_NUMBER + 2, 2);
|
map_page(KERNEL_PAGE_NUMBER + 2, 2);
|
||||||
|
map_page(KERNEL_PAGE_NUMBER + 3, 3);
|
||||||
console.writestringln('VMM: INIT END.');
|
console.writestringln('VMM: INIT END.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user