flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > [x86-64] Is it possible to mix 1GB pages and 4KB pages?

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 285
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
Question about the paging.
I map first (64+8)GB memory 1:1
Whether it is possible to mix 1GB pages and 4KB pages?
How to map video memory from 0xA0000-0xAFFFF at 0x1101000000 (68G+16M)?
Code:
MaxMemV =       64+8                    ;72GB

        mov     ebx,512*8*(1+1)

        push    ebx

        mov     ebx,1024*1024           ;CR3=1M
        mov     [PML4],ebx
        lea     eax,[ebx+4096]
        mov     [PDP],eax

        pxor    mm0,mm0
        pop     ecx
        shr     ecx,3
      @@:
        dec     ecx
        movq    [fs:ebx+ecx*8],mm0
        jnz     @B

        mov     eax,[PML4]
        mov     ebx,[PDP]
        mov     edx,ebx
        or      bl,7
        mov     [fs:eax+8*000],ebx

        mov     eax,1024*1024*1024
        movd    mm1,eax
        mov     eax,1187h
        movd    mm0,eax
       ;Fill page tables
        xor     ecx,ecx
      .1:
        movq    [fs:edx+8*ecx],mm0
        paddq   mm0,mm1
        inc     ecx
        cmp     ecx,MaxMemV
        jb      .1    

_________________
smaller is better
Post 23 Apr 2018, 13:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16054
Location: 112 Ocean Avenue, Amityville
CandyMan wrote:
Whether it is possible to mix 1GB pages and 4KB pages?
I don't see any reason why not. But different CPUs may exhibit different behaviour.
Post 23 Apr 2018, 14:32
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 285
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
how could a code look?
Post 23 Apr 2018, 14:36
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 444
Location: Czech republic, Slovak republic
For that purpose just create 4-level 4KB paging and mix it together with already existing 2-level 1GB paging. For video memory 0xA0000-0xAFFFF it requires 1 PML4E, 1 PDPE, 1 PDE, 1 PTE. You already have PML4. Create 1 PDP, 1 PD, 1 PT. Add 1 entry into your PML4 pointing to the newly created PDP, add 1 entry into PDP pointing to the newly created PD, add 1 entry into PD pointing to the newly created PT, add 1 entry into PT pointing to the video memory. Also take care about page attributes as it is video memory (it may impact performance).
Post 01 May 2018, 04:39
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 285
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
I did as this way as below. It is working with qemu and withut emulator, but bochs generating #PF at the attempt of the reading of the 0xFC000000 address. where is the bug?
Code:
PT_P            = bit 0         ;present (else not)
PT_W            = bit 1         ;writable (else read-only)
PT_U            = bit 2         ;user mode (else kernel mode)
PT_WT           = bit 3         ;write through
PT_CD           = bit 4         ;page caching disabled (else enabled)
PT_A            = bit 5         ;accessed (else not)
PT_D            = bit 6         ;dirty (else clean)
PT_PS           = bit 7         ;page size = 4MB
PT_AVL          = bit 8         ;available
PT_PAT          = bit 12        ;1GB page
PT_XD           = bit 63        ;no execute

MaxMemV =       69      ;69 GB

long_PML4       = (1M+4k*0)
long_PDPT       = (1M+4k*1)
long_PDT        = (1M+4k*2)
long_PT0        = (1M+4k*2+1G/2M*8)

        mov     eax,1G
        movd    mm1,eax
        mov     eax,PT_PS+PT_P+PT_W+PT_U+PT_PAT
        movd    mm0,eax
        xor     ecx,ecx
      @@:
        movq    [fs:long_PDPT+8*ecx],mm0
        paddq   mm0,mm1
        inc     ecx
        cmp     ecx,MaxMemV
        jb      @B

        mov     [fs:long_PML4+000*8+0],dword long_PDPT+PT_P+PT_W+PT_U
        and     [fs:long_PML4+000*8+4],dword 0
        mov     [fs:long_PDPT+000*8+0],dword long_PDT+PT_P+PT_W+PT_U
        and     [fs:long_PDPT+000*8+4],dword 0
        mov     [fs:long_PDPT+068*8+0],dword long_68G+PT_P+PT_W+PT_U
        and     [fs:long_PDPT+068*8+4],dword 0

;2MB pages, map 1st 1GB
Map1st  =       (1G/2M)
        mov     ecx,Map1st
        mov     eax,long_PDT
        mov     edx,PT_PS+PT_P+PT_W+PT_U
      @@:
        mov     [fs:eax],edx
        add     edx,2M
        add     eax,8
        loopd   @B

long_68G = (long_PT0)

        mov     ecx,16M/2M
        mov     eax,long_68G
        mov     edx,[AddrLFB]
        or      edx,PT_PS+PT_P+PT_W+PT_U

        cmp     [AddrLFB],0
        jnz     @F
        and     dl,not PT_P
      @@:

      @@:
        mov     [fs:eax],edx
        add     edx,2M
        add     eax,8
        loopd   @B

        mov     [fs:eax],dword long_PTX+PT_P+PT_W+PT_U  ;16M

long_PTX = (long_68G+4K)

        mov     edi,long_PTX
        mov     ebx,0xA0000+PT_P+PT_W+PT_U
        mov     ecx,(0xC0000-0xA0000)/4k
      @@:
        mov     [fs:edi],ebx
        add     ebx,4K
        add     edi,8
        loopd   @B
        ...    
Post 01 May 2018, 17:16
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 444
Location: Czech republic, Slovak republic
On #PF, error code is pushed into the stack with additional info. Did bochs report some info or not (in the second case you need to setup IDT and #PF handler which reports the error code).
Post 11 May 2018, 07:38
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 285
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
I already advised myself (I incorrectly accepted that bochs support 1GB paging while was turned off).
thanks all
Post 11 May 2018, 21:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2018, Tomasz Grysztar.

Powered by rwasa.