flat assembler
Message board for the users of flat assembler.

Index > OS Construction > paging ?

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 31 Dec 2009, 20:46
I have been looking over the net for good tutorials on paging...

Some are okay.. but its leading to some confusion between segments and the paging virtual address ...

and some confusion with seting up the page tables...
most examples are in C.. Evil or Very Mad

I am looking for help, examples,good websites ...ect..

Later I will convert some of the C examples... and post on here.. for help / sugestions.. ect..

I am just learning more on this.. and have enabled paging in my os..
but I would like a better understanding before I contin...

Thanks for any help!!! Very Happy
Post 31 Dec 2009, 20:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20358
Location: In your JS exploiting you and your system
revolution 31 Dec 2009, 21:27
First thing to do is to eliminate the effects of segments and make them all 4GB. That way you can use paging in its pure form without the abomination of segments to confuse things.
Post 31 Dec 2009, 21:27
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 31 Dec 2009, 22:00
I have been looking over this:

http://wiki.osdev.org/Paging

and looking for more tuts.. to post..

will have some code posted soon..

Should paging be enabled before entering PM..

or can it be done in pm ?
From these examples looks like there in PM..

The 1st one I have was based off menuette.. and enables it before pm..

Quote:

First thing to do is to eliminate the effects of segments and make them all 4GB. That way you can use paging in its pure form without the abomination of segments to confuse things.


are your refering to making the segments all 4GB?
Post 31 Dec 2009, 22:00
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 31 Dec 2009, 22:40
Yes, that's what he's referring to. For a flat 4GB memory with all segments overlapping, simply set all your PM segments' bases to 0 and limits to the maximum, in the segment descriptors, in the GDT.

For paging, first enable PM, initialize your page hierarchy (directory, tables, etc.), load the PD in cr3 and finally enable paging.
The OSDev wiki page you linked shows that quite well.
Post 31 Dec 2009, 22:40
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 31 Dec 2009, 23:05
Thanks for explaining..

Yes - I have set all my base to 0 and 0xFFFF for the limit..

I was just making sure I understood what rev was saying..
and thanks for the link!


example:
Is this what the layout of the page dir and table would look like?
Code:
Table Dir starts at 0x4000 cleared and set to not present: 
[0x00000002] 
[0x00000002] 
[0x00000002] 
[0x00000002] 
cont..

table starting 0x5000: should look like this 
[0x00000003] 
[0x00001003] 
[0x00002003] 
[0x00003003]
cont... 

When I move this table address to the table dir 
[0x00005003] 
[0x00000002] 
[0x00000002] 
[0x00000002] 
[0x00000002] 

    


This is what I am seeing with the C code.. would this be correct?


Last edited by dosin on 18 Jan 2010, 04:37; edited 1 time in total
Post 31 Dec 2009, 23:05
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 06 Jan 2010, 07:19
Wath strange flag values are you using? Read-only global pages, not-present "global pages", valid page dir entry with active global flag...
Post 06 Jan 2010, 07:19
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 06 Jan 2010, 21:09


Last edited by Dex4u on 07 Jan 2010, 02:23; edited 1 time in total
Post 06 Jan 2010, 21:09
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 07 Jan 2010, 01:35
Yes, recursive page dir mapping...
I wrote:
is professional solution. But one should remember that this technology requires a kernel protection on PDE level. Else user space will be invalid.

In this case page dir entry with active global flag could be useful, if it describes page tab for total 4 mb global region (all valid page tab entries have active global flag too).
Post 07 Jan 2010, 01:35
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 07 Jan 2010, 22:25
Code:
Wath strange flag values are you using? Read-only global pages, not-present "global pages", valid page dir entry with active global flag...     


yes in that C++ example.. it sets to not present page dir...

when the table is added to the dir.. it set the bits to R/W present to the dir..
setting the bits to 11.. according to the example..

The point of drawing it out like that was.. trying to visualize what the code is doing..

Its basicly causing confusion for me- between looking at the manual and what bits need to be set and what was in the example..

Dex - Thanks - I have been reading that article...
Post 07 Jan 2010, 22:25
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 08 Jan 2010, 18:45
What would this be in Fasm?

Code:
addr &= ~0xFFF;
    


would it = this?
Code:
;eax = addr

mov ebx,0xFFF
not ebx
and eax,ebx

    
Post 08 Jan 2010, 18:45
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Jan 2010, 19:00
Or just:
Code:
and eax, not 0xFFF ; Is assembled as AND EAX, 0xFFFFF000    


The C compiler is very likely to generate the same code as above.
Post 08 Jan 2010, 19:00
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 08 Jan 2010, 19:16
cool Thanks.. That is easier.. Very Happy

Code:
//align address to 4k (highest 20-bits of address)  
addr &= ~0xFFF;  
pginf.pagetable = addr / 0x400000; // each page table covers 0x400000 bytes in memory  
pginf.page = (addr % 0x400000) / 0x1000; //0x1000 = page size  
return pginf;  
 } 
    


converted to:
Code:
;*******************
;eax = Virtual Addres
;returns:
;eax = page table 
;ebx = page 
;*******************
 
mm_virtaddrtopageindex:
and eax, not 0xFFF
mov ebx,eax
shr eax,22
shl ebx,10
shr ebx,22
ret
    
Post 08 Jan 2010, 19:16
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Jan 2010, 20:11
Perhaps this is equivalent too?
Code:
mm_virtaddrtopageindex:
shr eax, 12
mov ebx,eax
shr eax,10
and ebx, 3FF
ret     
(Perhaps I messed up with the constants, but the first line of the C code seems useless, both divisions will hide the first 12 bits anyway)
Post 08 Jan 2010, 20:11
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 09 Jan 2010, 01:18
I am going to attempt to convert the tutorial to asm code...
Though some funcions memset and mm_allocphyspage() are not in this code.. but I do have my own memset and allocate_mem.. but this is the next peice to convert... will post asm code prob sometime on monday...
if anyone is interested...

Thought it may help me and possible people new to paging..

once done I will remove the c++ versions - with asm only...

from: http://www.rohitab.com/discuss/index.php?showtopic=31139
Code:
set  

if(page_directory[890] & 1){  

 // page table exists, continue as we did earlier  

unsigned long *page_table = (unsigned long *) page_directory[890] & 0xFFFFF000;   

page_table[727] = 0x00012000 | 3;   

}else{  

 // page table doesn’t exist, so create one  

unsigned long *page_table = (unsigned long *) mm_allocphyspage();  

memsetl(page_table, 2, 1024); // set 1024 dwords to 2 (r/w, not present)   

page_table[727] = 0x00012000 | 3;   

 } 
   
    


Last edited by dosin on 09 Jan 2010, 13:39; edited 1 time in total
Post 09 Jan 2010, 01:18
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 09 Jan 2010, 11:24
Where is in else-block the command for putting page tab address and flags into page dir? And use recursive page dir mapping structures (total 4 mb page tab and page dir as its part) else our discussion will be abstract.
Post 09 Jan 2010, 11:24
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 11 Jan 2010, 19:27
I am starting to convert: now for the 1st if statement:
This one I am not sure on the conversion.. but I post for sugestions..

Code:
;This is conversion of the last post of C code above
;page_directory  = 0x10000   ;set asside an address for the page dir
;page_table dw  0

ckforpage:
mov eax,dword[page_directory+890*4] 
cmp  al,00 
jne page_exist 
;esle does not exist create it 
call malloc_page  ; returns addres in eax 
mov dword[eax],page_table 
mov esi,page_table 
mov eax,2  ;set bits  
mov ecx,1024 ;1024 dwords to set 
call mem_set 
mov dword[page_table*727+4], 0x00012000 or 3;  
jmp if_fin  
page_exist: 
;page exists  
and eax,0xFFFFF000 
mov dword[eax],page_table 
mov dword[page_table+727*4],0x00012000 or 3 
if_fin : 


ret
    


Last edited by dosin on 12 Jan 2010, 01:53; edited 4 times in total
Post 11 Jan 2010, 19:27
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 11 Jan 2010, 21:42
No comments...
Post 11 Jan 2010, 21:42
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 12 Jan 2010, 02:03
Then why post Question .. Evil or Very Mad

At least be constuctive or offer some advise...
Post 12 Jan 2010, 02:03
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 12 Jan 2010, 07:42
C code in the article is an algorithm, not a program. You need the function for page mapping.
Post 12 Jan 2010, 07:42
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 12 Jan 2010, 09:55
Code:
; eax = virt. addr. for mapped page; PDir = virt. addr. of page dir; PTab = virt. addr. of total 4 mb page tabMapPage:push eaxmov edi,eaxshr edi,22 ; index in PDirmov esi,eaxshr esi,12 ; index in PTabtest byte [PDir+edi*4],1jnz @fcall GetZeroedPageadd eax,PDE_FLAGSmov [PDir+edi*4],eax@@:test byte [PTab+esi*4],1jnz @fcall GetPageadd eax,PTE_FLAGSmov [PTab+esi*4],eaxinc [PTabCounters+edi*2] ; can be useful for unmapping@@:pop eaxret    
Post 12 Jan 2010, 09:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.