Page 1 of 1

Instruction unavailable error

Posted: Mon Jul 30, 2007 4:04 pm
by hanumant
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??

Posted: Mon Jul 30, 2007 4:10 pm
by jnc100
Despite your best efforts cr3 is not aligned on a page boundary...

Regards,
John.

Posted: Mon Jul 30, 2007 4:15 pm
by hanumant
I just noticed that , what should i do?????

Posted: Mon Jul 30, 2007 6:18 pm
by frank
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;

Posted: Tue Jul 31, 2007 12:08 am
by os64dev
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;"
);