Page 2 of 2

Re: PAE How to map the specific address?

Posted: Wed Oct 27, 2021 11:49 am
by nifanfa
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?

Re: PAE How to map the specific address?

Posted: Wed Oct 27, 2021 11:50 am
by nifanfa

Code: Select all

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: Select all

[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

Re: PAE How to map the specific address?

Posted: Wed Oct 27, 2021 11:51 am
by nifanfa
my code caused triple fault

Re: PAE How to map the specific address?

Posted: Wed Oct 27, 2021 12:22 pm
by deadmutex
nifanfa wrote:

Code: Select all

            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.