HI
I had a lot of trouble with higher half kerenl so i decided to drop that idea, though i did want to enable paging . My kernel loads at 1 MB mark
ALso prior to the paging, I setup the gdt as specified by BRAN tutorial, base 0 seg limit = 0xFFFFF(code and data descriptors)
and for paging i do this.
unsigned long pagedir[1024] __attribute__((aligned(4096)));
unsigned long *pagedir_ptr = 0;
pagedir_ptr = (char *)pagedir; /*I am guessing the pagedir address is its physical address at this point*/
int k;
for(k = 0;k < 1024;k++)
{
pagedir[k] = 0;
}
pagedir[0] = 0x00000083; /*to set size to 4MB */
pagedir[1] = 0x00000083;
/* asm volatile ( "mov %0, %%eax\n"
"mov %%eax, %%cr3\n"
"mov %%cr0, %%eax\n"
"mov %%cr4, %%eax\n"
"orl %%eax, 0x00000010\n" /* to have 4MB and 4Kb pages*/
"mov %%eax, %%cr4\n"
"mov %%cr0, %%eax\n"
"orl 0x80000000, %%eax\n"
"mov %%eax, %%cr0\n" :: "m" (pagedir_ptr));
Bochs output :
just before reset
00043383085i[CPU0 ] | SEG selector base limit G D
00043383085i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00043383085i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00043383085i[CPU0 ] | EIP=00101038 (00101038)
00043383085i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x00106080
00043383085i[CPU0 ] | CR3=0x00106850 CR4=0x00000000
00043383085i[CPU0 ] (instruction unavailable) page not present
00043383085e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status
I dont understand, I am setting the PSE bit in cr4, it shows PSE as 0. Is there something wrong with the way I am doing this??
Instruction unavailable error
You could try hard-coding the address of the page directory.
Code: Select all
unsigned long *pagedir = some address you know is free and page aligned;
or you could use something like the following (GCC):
Code: Select all
extern unsigned long pagedir[1024];
asm
( ".align 4096;"
".globl pagedir; pagedir:"
".long 0;"
".align 4096;"
);
Author of COBOS