VMem & PMem
git-svn-id: https://spexeah.com:8443/svn/Asuro@124 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
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.
+4
-3
@@ -52,12 +52,13 @@ begin
|
||||
isr.init();
|
||||
irq.init();
|
||||
pmemorymanager.init();
|
||||
vmemorymanager.init();
|
||||
scheduler.init();
|
||||
|
||||
STI;
|
||||
isr32.hook(uint32(@bios_data_area.tick_update));
|
||||
|
||||
z:= 1;
|
||||
{z:= 1;
|
||||
while true do begin
|
||||
console.writeword(z);
|
||||
console.writestring(': ');
|
||||
@@ -65,11 +66,11 @@ begin
|
||||
console.writewordln(uint32(pint));
|
||||
if pint = nil then while true do begin end else pint^:= 1234;
|
||||
z:=z+1;
|
||||
end;
|
||||
end;}
|
||||
|
||||
//drivers
|
||||
keyboard.init(keyboard_layout);
|
||||
if PageDirectory[KERNEL_PAGE_NUMBER].Present then begin
|
||||
if PageDirectory^[KERNEL_PAGE_NUMBER].Present then begin
|
||||
console.writestringln('!');
|
||||
end else begin
|
||||
console.writestringln('?');
|
||||
|
||||
+42
-84
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@ uses
|
||||
|
||||
procedure CLI();
|
||||
procedure STI();
|
||||
procedure GPF();
|
||||
function hi(b : uint8) : uint8;
|
||||
function lo(b : uint8) : uint8;
|
||||
function switchendian(b : uint8) : uint8;
|
||||
@@ -61,6 +62,11 @@ asm
|
||||
STI
|
||||
end;
|
||||
|
||||
procedure GPF(); assembler;
|
||||
asm
|
||||
INT 13
|
||||
end;
|
||||
|
||||
function switchendian(b : uint8) : uint8; [public, alias: 'util_switchendian'];
|
||||
begin
|
||||
switchendian:= (lo(b) SHL 4) OR hi(b);
|
||||
|
||||
+87
-19
@@ -2,22 +2,12 @@ unit vmemorymanager;
|
||||
|
||||
interface
|
||||
|
||||
type
|
||||
{PPageTableEntry = ^TPageTableEntry;
|
||||
TPageTableEntry = bitpacked record
|
||||
Present,
|
||||
Writable,
|
||||
UserMode,
|
||||
WriteThrough,
|
||||
NotCacheable,
|
||||
Accessed,
|
||||
Dirty,
|
||||
AttrIndex,
|
||||
GlobalPage: Boolean;
|
||||
Available: UBit3;
|
||||
FrameAddress: UBit20;
|
||||
end;}
|
||||
uses
|
||||
util,
|
||||
pmemorymanager,
|
||||
console;
|
||||
|
||||
type
|
||||
PPageDirEntry = ^TPageDirEntry;
|
||||
TPageDirEntry = bitpacked record
|
||||
Present,
|
||||
@@ -30,15 +20,93 @@ type
|
||||
PageSize,
|
||||
GlobalPage: Boolean;
|
||||
Available: UBit3;
|
||||
TableAddress: UBit20;
|
||||
Address: UBit20;
|
||||
end;
|
||||
|
||||
TPageDirectory = Array[1..1024] of TPageDirEntry;
|
||||
TPageDirectory = Array[0..1023] of TPageDirEntry;
|
||||
PPageDirectory = ^TPageDirectory;
|
||||
|
||||
Var
|
||||
PageDirectory : TPageDirectory; external name '_PageDirectory';
|
||||
var
|
||||
PageDirectory : PPageDirectory;
|
||||
|
||||
procedure init;
|
||||
function new_page(page_number : uint16) : boolean;
|
||||
function new_page_at_address(address : uint32) : boolean;
|
||||
procedure free_page(page_number : uint16);
|
||||
|
||||
implementation
|
||||
|
||||
function load_current_page_directory : PPageDirectory;
|
||||
var
|
||||
Directory : uint32;
|
||||
|
||||
begin
|
||||
asm
|
||||
MOV EAX, CR3
|
||||
MOV Directory, EAX
|
||||
end;
|
||||
Directory:= Directory + KERNEL_VIRTUAL_BASE;
|
||||
load_current_page_directory:= PPageDirectory(Directory);
|
||||
end;
|
||||
|
||||
procedure init;
|
||||
var
|
||||
i : uint32;
|
||||
|
||||
begin
|
||||
console.writestringln('VMM: INIT BEGIN.');
|
||||
PageDirectory:= load_current_page_directory;
|
||||
console.writestringln('VMM: INIT END.');
|
||||
end;
|
||||
|
||||
function new_page(page_number : uint16) : boolean;
|
||||
var
|
||||
block : uint16;
|
||||
page : uint16;
|
||||
|
||||
begin
|
||||
new_page:= false;
|
||||
if PageDirectory^[block].Present then exit;
|
||||
if PageDirectory^[block].Reserved then exit;
|
||||
block:= pmemorymanager.newblock(uint32(PageDirectory));
|
||||
if block < 2 then begin
|
||||
GPF;
|
||||
exit;
|
||||
end else begin
|
||||
PageDirectory^[block].Present:= true;
|
||||
PageDirectory^[block].Address:= block;
|
||||
PageDirectory^[block].PageSize:= true;
|
||||
new_page:= true;
|
||||
end;
|
||||
end;
|
||||
|
||||
function new_page_at_address(address : uint32) : boolean;
|
||||
var
|
||||
page_number : uint16;
|
||||
|
||||
begin
|
||||
page_number:= address SHR 22;
|
||||
new_page_at_address:= new_page(page_number);
|
||||
end;
|
||||
|
||||
procedure free_page(page_number : uint16);
|
||||
begin
|
||||
if PageDirectory^[page_number].Present then begin
|
||||
asm
|
||||
invlpg [page_number]
|
||||
end;
|
||||
end else begin
|
||||
GPF;
|
||||
end;
|
||||
end;
|
||||
|
||||
function free_page_at_address(address : uint32);
|
||||
var
|
||||
page_number : uint16;
|
||||
|
||||
begin
|
||||
page_number:= address SHR 22;
|
||||
free_page(page_number);
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user