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