I have tried sevral method but none of them worked.
here is my code i will be really thankfull to you if you can figure out what i am missing
paging.c
Code: Select all
u32int *kernel_dir;
u32int *first_table;
extern void enablePaging();
void init_paging()
{
int i,address;
kernel_dir = (u32int*)alloc_block();
first_table= (u32int*)alloc_block();
putint(kernel_dir);putchar('\n');
putint(first_table);putchar('\n');
memset((u8int*)kernel_dir,0,4096);
memset((u8int*)first_table,0,4096);
for(i=0;i<1024;i++)
{
kernel_dir[i] = 0 | 2;
}
address = 0;
for(i=0;i<1024;i++)
{
first_table[i] = address | 3;
address = address + 4096;
}
kernel_dir[0] = first_table;
kernel_dir[0] |= 3;
//switch_page_directory(kernel_dir);
enablePaging();
}
Code: Select all
global enablePaging
extern kernel_dir
enablePaging:
mov eax,[kernel_dir]
mov cr3,eax
mov eax,cr0
or eax,0x80000000
mov cr0,eax
mov eax,[kernel_dir]
nop
ret
Code: Select all
Booting from 07c0:0000
00050847509i[CPU0 ] CPU is in protected mode (active)
00050847509i[CPU0 ] CS.d_b = 32 bit
00050847509i[CPU0 ] SS.d_b = 32 bit
00050847509i[CPU0 ] EFER = 0x00000000
00050847509i[CPU0 ] | RAX=0000000000108000 RBX=0000000000002000
00050847509i[CPU0 ] | RCX=00000000003ff003 RDX=0000000000109000
00050847509i[CPU0 ] | RSP=00000000013eff94 RBP=0000000000000000
00050847509i[CPU0 ] | RSI=0000000000000000 RDI=0000000000000000
00050847509i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00050847509i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00050847509i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00050847509i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00050847509i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af pf cf
00050847509i[CPU0 ] | SEG selector base limit G D
00050847509i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00050847509i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00050847509i[CPU0 ] | MSR_FS_BASE:0000000000000000
00050847509i[CPU0 ] | MSR_GS_BASE:0000000000000000
00050847509i[CPU0 ] | RIP=0000000000101d09 (0000000000101d09)
00050847509i[CPU0 ] | CR0=0xe0000013 CR2=0x00000000013eff90
00050847509i[CPU0 ] | CR3=0x00108000 CR4=0x00000000
00050847509i[CPU0 ] 0x0000000000101d09>> ret : C3
00050847509p[CPU0 ] >>PANIC<< exception(): 3rd (14) exception with no resolution