Page 1 of 1

paging, the last;

Posted: Wed Jun 25, 2008 4:57 am
by kmtdk
HI again.`Realy sry for beeig so stupid about "PAGING" .....and all the posters..... :oops: :cry:
well this time, i have tryed to setup paging, but as soon as i have enablede paging, a page fault opurcere. Well that is not the problem. The problem is, that it is still the samm address. EVen if i change the address in cr3 to 0xffffff.. or 0x0001, it only changes when: cr3:0x00000000 or when i write at the address (0x11d1).
I have tryed all, followed that geppy said, looked at a exapmle code, and so on.... but no changes.
the code is here:
paging.start:




mov eax,0x00000000 ; where we shall the page start in phy mem
mov esi,0x0006000+(10*4) ; where are the table located in mem

call paging.table.prepare ;setup the first 4 mb, for the kernel


call paging.dir.prepare ; setup the dir
mov eax,0x04000008 ; kernel area. tables beginns at 0x04000 and ends at 40000 + 4mb
mov cr3,eax ; prepare.
jmp paging.enable ; this shuld be the last "thing" before going into paging, because the code will then run smoothy then.



paging.dir.prepare:
mov cx,0x0001 ; how maney dir entrys to setup
mov eax,0x00060000 ; table address
mov al,0x3 ;attributes for the kernels map
mov esi,0x40000 ; the dir start

paging.dir.prepare.loop:
mov [esi],eax
add esi,0x4 ; 32 bits incresse
add eax,0x2000 ; only the new address of a page table.
loop paging.dir.prepare.loop ; countinue undtil we are finish
ret




paging.table.prepare:
mov cx,0x0400-0xa ; how maney dir entrys to setup (1014)
mov al,0x3 ;attributes for the kernels map

paging.table.prepare.loop:
add eax,0x1000
mov [esi],eax
add eax,0x1000; we need to incres the page's frame, so we map more than the same page!
add esi,0x4 ; next entry

loop paging.table.prepare.loop

ret ; now we have map the first 4 mb memory, this is the interface between the dir and table.




paging.enable:

mov eax, cr0
or eax, 0x80000000
mov cr0, eax
jmp $+2
cli
hlt


KMTDK

Re: paging, the last;

Posted: Wed Jun 25, 2008 5:25 am
by JamesM
Firstly, use [ code ] tags.

Secondly, don't base your page directory at 0x00000000. You'll overwrite BIOS stuff and a load of memory-mapped device registers (like CMOS and the VGA framebuffer), and that is a Bad Thing.

Re: paging, the last;

Posted: Wed Jun 25, 2008 7:52 am
by kmtdk
Well, i am not mapping the dir table at 0x000000, but i "was" trying to map the first page to 0x000 .. but never mind

can you solve what the "problem" is, with the code (sry for not putting it in a [ code ])


Kmtdk

Re: paging, the last;

Posted: Wed Jun 25, 2008 8:15 am
by JamesM
Well, all of it seems incorrect. There are hardcoded constants in there that seem to change in value as you progress!

Code: Select all

mov esi,0x0006000+(10*4) ; where are the table located in mem
So that makes me assume that the first page table is located at 0x00006028 (which is 0x6000 + 40decimal).

Code: Select all

mov eax,0x00060000 ; table address
But this line makes me assume that the first page table is located at 0x00060000 (which is about a factor of 16 different...)

Code: Select all

paging.table.prepare.loop:
add eax,0x1000
mov [esi],eax
add eax,0x1000; we need to incres the page's frame, so we map more than the same page!
add esi,0x4 ; next entry

loop paging.table.prepare.loop
Here you increment eax by 0x1000 twice in each loop iteration...

Code: Select all

mov eax,0x04000008 ; kernel area. tables beginns at 0x04000 and ends at 40000 + 4mb
Why the 8? and if the table begins at 0x4000 why are you putting 0x4000000 in cr3?

All in all there are too many hardcoded constants and it appears you're mixing them up nastily, missing out or adding extra '0's in places.

Needs neatening up. Then maybe you'll find your solution (if it's not one of the above problems!)

Re: paging, the last;

Posted: Wed Jun 25, 2008 10:47 am
by kmtdk
Well
after trying to changes, most of the code, the only changes is the log:
it only outputs this:

Code: Select all

00038566750i[CPU0 ] | CR0=0x80000011 CR1=0x0 CR2=0x00000000000011d1
00038566750i[CPU0 ] | CR3=0x00004000 CR4=0x00000000
00038566750i[CPU0 ] (instruction unavailable) page not present
The reason why i placede the "8" was for the options in the cr3. (look at intels manual)
You say that iam mixing the address, and the adding to maney, or having too few "0"'s

What i know, the addresses is all 20 bit. This means that the last 12 are for options.
With that in "my" head, i cant see any errors with the "0"'s.
but i might haved missed something...
the code after currenting is:

Code: Select all

;this file is for all the kernel activity. (starting paging)






paging.start:
                cli 
                 mov eax,0x00000000            ; where we shall the page start in phy mem 
                 mov esi,0x0006000           ; where are the table located in mem 

                 call paging.table.prepare ;setup the first 4 mb, for the kernel


                 call paging.dir.prepare   ; setup the dir
                 mov eax,0x00004000     ; kernel area.  tables beginns at 0x04000 and ends at 40000 + 4mb
                 mov cr3,eax          ; prepare.
                 jmp paging.enable ; this shuld be the last "thing" before going into paging, because the code will then run smoothy then.

paging.dir.prepare:
                 mov cx,0x0001 ; how maney dir entrys to setup
                 mov eax,0x00006000 ; table address
                 mov al,0x3 ;attributes for the kernels map
                 mov esi,0x40000 ; the dir start

paging.dir.prepare.loop:
                 mov [esi],eax
                 add esi,0x4  ; 32 bits incresse
                 add eax,0x2000 ;  4kb alligned in hex.
                 loop paging.dir.prepare.loop  ; countinue undtil we are finish
                 ret

paging.table.prepare:
                 mov cx,0x0400 ; how maney dir entrys to setup (1014)
                 mov al,0x3 ;attributes for the kernels map

paging.table.prepare.loop:
                        ; we need to incres the page's frame, so we map more than the same page!
                 mov [esi],eax
                 add eax,0x1000
                 add esi,0x4    ; next entry

                 loop paging.table.prepare.loop

                 ret    ; now we have map the first 4 mb memory, this is the interface between the dir and table.


paging.enable:
                        mov eax, cr0
                        or eax, 0x80000000
                        mov cr0, eax
                        jmp $+2
                        cli
                        hlt
Hoping that iam not beeing too stupid

Still Thanks
KMT dk

Re: paging, the last;

Posted: Wed Jun 25, 2008 11:49 am
by JamesM
Hi,
With that in "my" head, i cant see any errors with the "0"'s.
Well, that could be because you changed the code since you last posted. However, I still spot one (glaringly obvious):

Code: Select all

mov eax,0x00004000     ; kernel area.  tables beginns at 0x04000 and ends at 40000 + 4mb
mov cr3,eax          ; prepare
Page directory is at 0x4000, right?

Code: Select all

mov esi,0x40000 ; the dir start
Wrong! It's at 0x40000! Come on man, proofread your code a little.

Cheers,

James

Re: paging, the last;

Posted: Wed Jun 25, 2008 1:43 pm
by kmtdk
.. I might have to start code from the start......
THis time i have to say: DOH


I apologeyes for this poster,,, as it work now....

:( :? #-o #-o :oops: 0xDead KMT

Re: paging, the last;

Posted: Thu Jun 26, 2008 4:49 am
by kmtdk
Well, it normaly dónt happens, and i had told it to my self loud..
but i agree with you(not about asm though, since i love asm), but the secound did not helped-- i acturely slept insted...

KMT dk