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, bios_data_area,
keyboard, keyboard,
vmemorymanager, vmemorymanager,
pmemorymanager, pmemorymanager;
scheduler; //scheduler;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -53,7 +53,13 @@ begin
irq.init(); irq.init();
pmemorymanager.init(); pmemorymanager.init();
vmemorymanager.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; STI;
isr32.hook(uint32(@bios_data_area.tick_update)); isr32.hook(uint32(@bios_data_area.tick_update));

View File

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

View File

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

View File

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