System resets when PAE is enabled
Posted: Sun Dec 21, 2008 2:36 pm
Hi,
I'm trying to setup paging with PAE enabled (2MB pages). As soon as the paging is turned on, the system restarts. Any idea on what's going on? The AMD CPU has PAE support. I checked the cpuid and feature flags already. I've seen people mapping the the last page dir entry in 4KB non-PAE paging. If that is required here, how is it done?
- Thanks in advance
I'm trying to setup paging with PAE enabled (2MB pages). As soon as the paging is turned on, the system restarts. Any idea on what's going on? The AMD CPU has PAE support. I checked the cpuid and feature flags already. I've seen people mapping the the last page dir entry in 4KB non-PAE paging. If that is required here, how is it done?
- Thanks in advance
Code: Select all
#define PAGE_SHIFT 21 // for 2MB page using PAE
#define PAGE_SIZE (1 << PAGE_SHIFT)
struct pde {
uint32_t addr_lo;
uint32_t addr_hi;
} __attribute__ ((packed));
static inline void paging_on(void *pdp)
{
__asm__ __volatile__(
/* Load the page table address */
"movl %0, %%cr3\n\t"
/* Enable pae */
"movl %%cr4, %%eax\n\t"
"orl $0x00000020, %%eax\n\t"
"movl %%eax, %%cr4\n\t"
/* Enable paging */
"movl %%cr0, %%eax\n\t"
"orl $0x80000000, %%eax\n\t"
"movl %%eax, %%cr0\n\t"
:
: "r" (pdp)
: "ax"
);
}
struct pde gPageDir[2048] __attribute__ ((aligned(4096)));
struct pde gPageDirPtrTab[4] __attribute__ ((aligned(4096)));
struct pde *pd __attribute__ ((aligned(4096)));
struct pde *pdptr __attribute__ ((aligned(4096)));
void PAE_InitPaging(uint32_t maxmem)
{
uint32_t i, cr0;
uint32_t pageflags = PF_GLOBAL | PF_PRESENT | PF_KERNELPAGE | PF_READWRITE;
pd = gPageDir;
pdptr = gPageDirPtrTab;
paging_off();
// Point the page directory pointers at the page directories
pdptr[0].addr_lo = ((uint32_t)&pd[512*0])|1;
pdptr[1].addr_lo = ((uint32_t)&pd[512*1])|1;
pdptr[2].addr_lo = ((uint32_t)&pd[512*2])|1;
pdptr[3].addr_lo = ((uint32_t)&pd[512*3])|1;
//identity-map (maxmem == 512MB-1)
for(i = 0; i < maxmem; i+= PAGE_SIZE)
{
printf("%d.. ",i/PAGE_SIZE);
pd[i/PAGE_SIZE].addr_lo = i | pageflags;
pd[i].addr_hi = 0;
printf("0x%x \n",pd[i/PAGE_SIZE].addr_lo);
}
printf("..... turning on paging..\n"); // <= crashes immediately after this print
paging_on(pdptr);
printf("mapping done..\n");
return;
}