Virtual Memory Management fucking works!

git-svn-id: https://spexeah.com:8443/svn/Asuro@125 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
kieron 2017-05-19 23:46:20 +00:00
parent 57b6845ed4
commit 39ca6eed6f
47 changed files with 62 additions and 19 deletions

BIN
Asuro.iso

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,8 +14,8 @@ uses
bios_data_area,
keyboard,
vmemorymanager,
pmemorymanager,
scheduler;
pmemorymanager;
//scheduler;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -53,7 +53,13 @@ begin
irq.init();
pmemorymanager.init();
vmemorymanager.init();
scheduler.init();
vmemorymanager.new_page(0);
pint:= puint32(0);
console.writestringln('Writing 1234 to Logical Address $00000000');
pint^:= 1234;
if pint^ = 1234 then console.writestringln('Read 1234 back from Logical Address $00000000!!!');
//scheduler.init();
STI;
isr32.hook(uint32(@bios_data_area.tick_update));

View File

@ -14,8 +14,8 @@ type
TPhysicalMemory = array[0..1023] of TPhysicalMemoryEntry;
procedure init;
function newblock(caller : uint32) : uint16;
procedure freeblock(block : uint16; caller : uint32);
function new_block(caller : uint32) : uint16;
procedure free_block(block : uint16; caller : uint32);
implementation
@ -24,6 +24,7 @@ var
procedure init;
begin
console.writestringln('PMM: INIT BEGIN.');
with PhysicalMemory[0] do begin
Present:= True;
MappedTo:= 0;
@ -32,25 +33,33 @@ begin
Present:= True;
MappedTo:= 0;
end;
console.writestringln('PMM: INIT END.');
end;
function newblock(caller : uint32) : uint16;
function new_block(caller : uint32) : uint16;
var
i : uint16;
begin
newblock:= 0;
new_block:= 0;
for i:=2 to 1023 do begin
if not PhysicalMemory[i].Present then begin
PhysicalMemory[i].Present:= True;
PhysicalMemory[i].MappedTo:= caller;
newblock:= i;
new_block:= i;
console.writestring('4MiB Block Added @ ');
console.writeword(i);
console.writestring(' [');
console.writeword(i SHL 22);
console.writestring(' - ');
console.writeword((i+1 SHL 22)-1);
console.writestringln(']');
exit;
end;
end;
end;
procedure freeblock(block : uint16; caller : uint32);
procedure free_block(block : uint16; caller : uint32);
begin
if block > 1023 then begin
GPF;
@ -60,7 +69,7 @@ begin
GPF;
exit;
end;
if PhysicalMemory[block].caller <> caller then begin
if PhysicalMemory[block].MappedTo <> caller then begin
GPF;
exit;
end;

View File

@ -5,7 +5,7 @@ interface
uses
console,
isr32,
pmemorymanager;
lmemorymanager;
const
Quantum = 64;

View File

@ -33,6 +33,7 @@ procedure init;
function new_page(page_number : uint16) : boolean;
function new_page_at_address(address : uint32) : boolean;
procedure free_page(page_number : uint16);
procedure free_page_at_address(address : uint32);
implementation
@ -63,20 +64,42 @@ function new_page(page_number : uint16) : boolean;
var
block : uint16;
page : uint16;
rldpd : uint32;
begin
new_page:= false;
if PageDirectory^[block].Present then exit;
if PageDirectory^[block].Reserved then exit;
block:= pmemorymanager.newblock(uint32(PageDirectory));
if PageDirectory^[page_number].Present then exit;
if PageDirectory^[page_number].Reserved then exit;
block:= pmemorymanager.new_block(uint32(PageDirectory));
if block < 2 then begin
GPF;
exit;
end else begin
PageDirectory^[block].Present:= true;
PageDirectory^[block].Address:= block;
PageDirectory^[block].PageSize:= true;
PageDirectory^[page_number].Present:= true;
PageDirectory^[page_number].Address:= block;
PageDirectory^[page_number].PageSize:= true;
rldpd:= uint32(PageDirectory) - KERNEL_VIRTUAL_BASE;
asm
mov eax, rldpd
mov CR3, eax
end;
new_page:= true;
console.writestringln('New Page Added:');
console.writestring('- P:');
console.writeword(page_number);
console.writestring('-->B:');
console.writewordln(block);
console.writestring('- P:[');
console.writeword(page_number SHL 22);
console.writestring(' - ');
console.writeword((page_number+1 SHL 22) - 1);
console.writestring(']-->B:[');
console.writeword(block SHL 22);
console.writestring(' - ');
console.writeword((block+1 SHL 22) - 1);
console.writestringln(']');
end;
end;
@ -90,17 +113,22 @@ begin
end;
procedure free_page(page_number : uint16);
var
block : uint16;
begin
if PageDirectory^[page_number].Present then begin
block:= PageDirectory^[page_number].Address;
asm
invlpg [page_number]
end;
pmemorymanager.free_block(block, uint32(PageDirectory));
end else begin
GPF;
end;
end;
function free_page_at_address(address : uint32);
procedure free_page_at_address(address : uint32);
var
page_number : uint16;