OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:40 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: PAE How to map the specific address?
PostPosted: Wed Oct 27, 2021 11:49 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
deadmutex wrote:
>and how i do i map the address like 0xFFFF_FFFF_FF00_0000 to 0xFFFF_FF00 ?

You'd translate the virtual address into its pml4e number, pdpte number, etc., and then set the entries appropriately.


does
page_dir[0] = 0b10000011; means map the 0-2mb?
and
page_dir[1] = 0b10000011; means map the 2-4mb?

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: PAE How to map the specific address?
PostPosted: Wed Oct 27, 2021 11:50 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
Code:
using Mosa.Kernel.x86;
using Mosa.Runtime;
using System.Runtime.InteropServices;

namespace MOSA1
{
    unsafe class PAE
    {
        [DllImport("PAE.o")]
        public static extern void PAE_ASM(uint ptr);

        public static void Initialize()
        {
            ulong* page_dir_ptr_tab = (ulong*)((uint)GC.AllocateObject((sizeof(ulong) * 4) + 0x20) & 0x20);

            ulong* page_dir0 = (ulong*)((uint)GC.AllocateObject((sizeof(ulong) * 512) + 0x1000) & 0x1000);
            ulong* page_dir1 = (ulong*)((uint)GC.AllocateObject((sizeof(ulong) * 512) + 0x1000) & 0x1000);
            ulong* page_dir2 = (ulong*)((uint)GC.AllocateObject((sizeof(ulong) * 512) + 0x1000) & 0x1000);
            ulong* page_dir3 = (ulong*)((uint)GC.AllocateObject((sizeof(ulong) * 512) + 0x1000) & 0x1000);

            page_dir_ptr_tab[0] = (ulong)page_dir0 | 1; // set the page directory into the PDPT and mark it present
            page_dir_ptr_tab[1] = (ulong)page_dir1 | 1; // set the page directory into the PDPT and mark it present
            page_dir_ptr_tab[2] = (ulong)page_dir2 | 1; // set the page directory into the PDPT and mark it present
            page_dir_ptr_tab[3] = (ulong)page_dir3 | 1; // set the page directory into the PDPT and mark it present

            for (ulong i = 1; i < 512; i++)
            {
                page_dir0[i] = 0b10000011;
                //page_dir1[i] = 0b10000011;
                //page_dir2[i] = 0b10000011;
                //page_dir3[i] = 0b10000011;
            }

            PAE_ASM((uint)page_dir_ptr_tab);

            Console.WriteLine("PAE(Physical Address Extension) Configuration Done");

            //Native.SetCR0(Native.GetCR0() | 0x80000000);
        }
    }
}


Code:
[bits 32]
   mov eax, cr4
   or eax, 1 << 5
   mov cr4, eax
   mov eax, [esp + 4]
   mov cr3, eax
   mov eax, cr0
   or eax, 0x80000000
   mov cr0, eax
   ret

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: PAE How to map the specific address?
PostPosted: Wed Oct 27, 2021 11:51 am 
Offline
Member
Member

Joined: Tue Aug 17, 2021 10:40 am
Posts: 104
Location: CN
my code caused triple fault

_________________
My github: https://github.com/nifanfa


Top
 Profile  
 
 Post subject: Re: PAE How to map the specific address?
PostPosted: Wed Oct 27, 2021 12:22 pm 
Offline
Member
Member
User avatar

Joined: Wed Sep 28, 2005 11:00 pm
Posts: 85
nifanfa wrote:
Code:
            for (ulong i = 1; i < 512; i++)
            {
                page_dir0[i] = 0b10000011;
                //page_dir1[i] = 0b10000011;
                //page_dir2[i] = 0b10000011;
                //page_dir3[i] = 0b10000011;
            }



You're only setting the present, read-write, and page size flags for each entry of page_dir0, so only the first 2-MiB of physical memory is being mapped. You also have to set the base address for each 2 MiB page. See the wiki.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 48 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group