I'm implementing a higher-half kernel. I followed this tutorial for paging and the one before that for physical MM.
After i followed the higher-half bare bones on the wiki, it could successfully execute code in the higher half (0xC0000000).
All went well until i tried to load a new page directory,which greets me with the following error, followed by a triple fault:
Code: Select all
00084886892i[CPU0 ] CPU is in protected mode (active)
00084886892i[CPU0 ] CS.mode = 32 bit
00084886892i[CPU0 ] SS.mode = 32 bit
00084886892i[CPU0 ] EFER = 0x00000000
00084886892i[CPU0 ] | EAX=c03ff000 EBX=c0010130 ECX=00000000 EDX=c03ff000
00084886892i[CPU0 ] | ESP=c0113ce8 EBP=c0113ce8 ESI=c0010000 EDI=c0400000
00084886892i[CPU0 ] | IOPL=0 ID vip vif ac vm RF nt of df IF tf SF zf af PF cf
00084886892i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00084886892i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00084886892i[CPU0 ] | EIP=c010195c (c010195c)
00084886892i[CPU0 ] | CR0=0xe0000011 CR2=0xc0105560
00084886892i[CPU0 ] | CR3=0xc03ff000 CR4=0x00000010
bx_dbg_read_linear: physical memory read error (phy=0x01ffffd0195c, lin=0xc010195c)
00084886892e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
c0101952 <loadPageDirectory>:
c0101952: 55 push %ebp
c0101953: 89 e5 mov %esp,%ebp
c0101955: 8b 44 24 08 mov 0x8(%esp),%eax
c0101959: 0f 22 d8 mov %eax,%cr3
c010195c: 89 ec mov %ebp,%esp
c010195e: 5d pop %ebp
c010195f: c3 ret
I think the error might be from a failed instruction fetch???Or maybe i overwrote some part of my kernel???
My paging code:
Code: Select all
inline int switch_directory (pdirectory* dir) {
if (!dir)
return 1;
_cur_directory = dir;
loadPageDirectory(dir);
return 0;
}
void init_paging()
{
ptable* table = 0xC0300000;
memset(table, 0,sizeof(ptable));
ptable* table2 = 0xC03F0000;
memset(table2, 0,sizeof(ptable));
// 1st 4mb are identity mapped
for (int i=0, frame=0x0, virt=0x00000000; i<1024; i++, frame+=4096, virt+=4096) {
//! create a new page
pt_entry page=0;
pt_entry_set_bit (&page, _PTE_PRESENT);
pt_entry_set_frame (&page, frame);
//! ...and add it to the page table
table2->entries [PAGE_TABLE_INDEX (virt) ] = page;
}
for(int i=0,frame=0x000000,virt=0xC0000000;i<1024;i++,frame+=4096, virt+=4096)
{
pt_entry page=0;
pt_entry_set_bit(&page,_PTE_PRESENT);
pt_entry_set_frame(&page, frame);
table->entries [PAGE_TABLE_INDEX(virt)] = page;
}
pdirectory* dir = 0xC03FF000;
memset(dir, 0,sizeof(pdirectory));
pd_entry* entry =&dir->entries [PAGE_DIRECTORY_INDEX (0xC0000000)];
pd_entry_set_bit (entry,_PDE_PRESENT);
pd_entry_set_bit (entry,_PDE_WRITABLE);
pd_entry_set_frame(entry,(physical_addr)table);
pd_entry* entry2 = &dir->entries [PAGE_DIRECTORY_INDEX (0x00000000) ];
pd_entry_set_bit (entry2, _PDE_PRESENT);
pd_entry_set_bit (entry2, _PDE_WRITABLE);
pd_entry_set_frame (entry2, (physical_addr)table2);
switch_directory(dir);
}
Thanks for the help guys,
TheRussianFail