I am working on a hobbyist OS and I am having trouble with identity mapping and enabling paging. I am working with Bochs emulator, and I have the following error message :=
00691299602e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0e)
00691299602e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00691299602i[CPU0 ] CPU is in protected mode (active)
00691299602i[CPU0 ] CS.d_b = 32 bit
00691299602i[CPU0 ] SS.d_b = 32 bit
00691299602i[CPU0 ] | EAX=e0000011 EBX=00000209 ECX=00000f9f EDX=00000f9f
00691299602i[CPU0 ] | ESP=0000ff5c EBP=00000001 ESI=00000209 EDI=0001d000
00691299602i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00691299602i[CPU0 ] | SEG selector base limit G D
00691299602i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00691299602i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | DS:0018( 0003| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | SS:0018( 0003| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | ES:0018( 0003| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | FS:0018( 0003| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | GS:0018( 0003| 0| 0) 00000000 ffffffff 1 1
00691299602i[CPU0 ] | EIP=00102764 (00102764)
00691299602i[CPU0 ] | CR0=0xe0000011 CR2=0xe0000011
00691299602i[CPU0 ] | CR3=0x00014000 CR4=0x00000000
00691299602i[CPU0 ] 0x00102764>> add byte ptr ds:[eax], al : 0000
00691299602e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
What I am trying to do is identity map the entire available ram, and the code I am using to do this is :=
printk(" page_limit [%d]\n",page_limit);
for(i=0,virt=0; i < NR_PAGES; ++i,virt += PAGE_SIZE) {
frame = (PAGE_SIZE * (i % 1024));
if(i < page_limit) {
page = 0;
PT_SET_ATTRIB(page, PTE_PRESENT);
PT_SET_ATTRIB(page, PTE_READ_WRITE);
PT_SET_FRAME(page, frame);
KERNEL_PAGE_TABLE[i] = page;
} else {
page = 0;
PT_SET_ATTRIB(page, PTE_PRESENT);
PT_SET_ATTRIB(page, PTE_READ_WRITE);
PT_SET_ATTRIB(page, PTE_USER);
PT_SET_FRAME(page, frame);
KERNEL_PAGE_TABLE[i] = page;
}
}
printk(" page_limit [%d]\n",page_limit);
for(i = 0, frame = (unsigned)KERNEL_PAGE_TABLE;
i < NR_PAGE_TABLES; ++i, frame += PAGE_SIZE) {
if(i < page_limit) {
page = 0;
PD_SET_ATTRIB(page, PDE_PRESENT);
PD_SET_ATTRIB(page, PDE_READ_WRITE);
PD_SET_FRAME(page, frame);
KERNEL_PAGE_DIR[i] = page;
} else {
page = 0;
PD_SET_ATTRIB(page, PDE_PRESENT);
PD_SET_ATTRIB(page, PDE_READ_WRITE);
PD_SET_ATTRIB(page, PDE_USER);
PD_SET_FRAME(page, frame);
KERNEL_PAGE_DIR[i] = page;
}
}
Where the following macros are defined :=
#define PD_SET_ATTRIB(entry, attrib) \
(entry) |= (attrib);
#define PD_SET_FRAME(entry, addr) \
(entry) = ((entry) & ~0xFFFFF000) | (addr << 12);
And similar for PT_SET_ATTRIB and PT_SET_FRAME. I think the mapping is wrong, the actual line Bochs stops on looks like its referencing a null pointer :=
add byte ptr ds:[eax], al : 0000
but it also looks like the CPU tried to load the page fault and double fault handlers and eventually triple faulted causing a CPU reset. I am hoping someone could help point out the error.
Thanks