I set up the GDT and the IDT and i successfully implemented keyboard support so far.
I now want to enable paging, so I started by getting the memory map using "INT 0x15, EAX = 0xE820" as suggested by the wiki and I wanted to store the result in a bitmap(usable/unusable RAM), so i can continue creating the page frame allocator. I have a 32768 uin32_t bitmap that is represented as a global array in kernel code. Unfortunately, when i want to go through it (using a for from 0 to 32768 for example), I noticed that it overwrites memory I didn't want to and I think it overwrites even the IDT, as shown below by BOCHS.
The kernel is loaded at 0x1000.
Code: Select all
(0) [0x000000001f70] 0008:0000000000001f70 (unk. ctxt): mov dword ptr ds:[eax*4+15776], 0x08080808 ; c70485a03d000008080808
Code: Select all
<bochs:8> info idt
Interrupt Descriptor Table (base=0x0000000000003480, limit=2047):
IDT[0x00]=32-Bit Interrupt Gate target=0x0008:0x000015ba, DPL=0
IDT[0x01]=32-Bit Interrupt Gate target=0x0008:0x000015c1, DPL=0
IDT[0x02]=32-Bit Interrupt Gate target=0x0008:0x000015c8, DPL=0
IDT[0x03]=32-Bit Interrupt Gate target=0x0008:0x000015cf, DPL=0
IDT[0x04]=32-Bit Interrupt Gate target=0x0008:0x000015d6, DPL=0
IDT[0x05]=32-Bit Interrupt Gate target=0x0008:0x000015dd, DPL=0
IDT[0x06]=32-Bit Interrupt Gate target=0x0008:0x000015e4, DPL=0
IDT[0x07]=32-Bit Interrupt Gate target=0x0008:0x000015eb, DPL=0
IDT[0x08]=32-Bit Interrupt Gate target=0x0008:0x000015f5, DPL=0
IDT[0x09]=32-Bit Interrupt Gate target=0x0008:0x000015fd, DPL=0
IDT[0x0a]=32-Bit Interrupt Gate target=0x0008:0x00001607, DPL=0
IDT[0x0b]=32-Bit Interrupt Gate target=0x0008:0x0000160f, DPL=0
IDT[0x0c]=32-Bit Interrupt Gate target=0x0008:0x00001617, DPL=0
IDT[0x0d]=32-Bit Interrupt Gate target=0x0008:0x0000161f, DPL=0
IDT[0x0e]=32-Bit Interrupt Gate target=0x0008:0x00001627, DPL=0
IDT[0x0f]=32-Bit Interrupt Gate target=0x0008:0x0000162f, DPL=0
IDT[0x10]=32-Bit Interrupt Gate target=0x0008:0x00001639, DPL=0
IDT[0x11]=32-Bit Interrupt Gate target=0x0008:0x00001643, DPL=0
IDT[0x12]=32-Bit Interrupt Gate target=0x0008:0x0000164d, DPL=0
IDT[0x13]=32-Bit Interrupt Gate target=0x0008:0x00001657, DPL=0
IDT[0x14]=32-Bit Interrupt Gate target=0x0008:0x00001661, DPL=0
IDT[0x15]=32-Bit Interrupt Gate target=0x0008:0x0000166b, DPL=0
IDT[0x16]=32-Bit Interrupt Gate target=0x0008:0x00001675, DPL=0
IDT[0x17]=32-Bit Interrupt Gate target=0x0008:0x0000167f, DPL=0
IDT[0x18]=32-Bit Interrupt Gate target=0x0008:0x00001689, DPL=0
IDT[0x19]=32-Bit Interrupt Gate target=0x0008:0x00001693, DPL=0
IDT[0x1a]=32-Bit Interrupt Gate target=0x0008:0x0000169d, DPL=0
IDT[0x1b]=32-Bit Interrupt Gate target=0x0008:0x000016a7, DPL=0
IDT[0x1c]=32-Bit Interrupt Gate target=0x0008:0x000016b1, DPL=0
IDT[0x1d]=32-Bit Interrupt Gate target=0x0008:0x000016bb, DPL=0
IDT[0x1e]=32-Bit Interrupt Gate target=0x0008:0x000016c5, DPL=0
IDT[0x1f]=32-Bit Interrupt Gate target=0x0008:0x000016cf, DPL=0
IDT[0x20]=32-Bit Interrupt Gate target=0x0008:0x000016d9, DPL=0
IDT[0x21]=32-Bit Interrupt Gate target=0x0008:0x000016e3, DPL=0
IDT[0x22]=32-Bit Interrupt Gate target=0x0008:0x000016ed, DPL=0
IDT[0x23]=32-Bit Interrupt Gate target=0x0008:0x000016f7, DPL=0
IDT[0x24]=32-Bit Interrupt Gate target=0x0008:0x00001701, DPL=0
IDT[0x25]=32-Bit Interrupt Gate target=0x0008:0x0000170b, DPL=0
IDT[0x26]=32-Bit Interrupt Gate target=0x0008:0x00001715, DPL=0
IDT[0x27]=32-Bit Interrupt Gate target=0x0008:0x0000171f, DPL=0
IDT[0x28]=32-Bit Interrupt Gate target=0x0008:0x00001729, DPL=0
IDT[0x29]=32-Bit Interrupt Gate target=0x0008:0x00001733, DPL=0
IDT[0x2a]=32-Bit Interrupt Gate target=0x0008:0x0000173d, DPL=0
IDT[0x2b]=32-Bit Interrupt Gate target=0x0008:0x00001747, DPL=0
IDT[0x2c]=32-Bit Interrupt Gate target=0x0008:0x00001751, DPL=0
IDT[0x2d]=32-Bit Interrupt Gate target=0x0008:0x0000175b, DPL=0
IDT[0x2e]=32-Bit Interrupt Gate target=0x0008:0x00001765, DPL=0
IDT[0x2f]=32-Bit Interrupt Gate target=0x0008:0x0000176f, DPL=0
Code: Select all
<bochs:9> info gdt
Global Descriptor Table (base=0x0000000000007f15, limit=23):
GDT[0x0000]=??? descriptor hi=0x00000000, lo=0x00000000
GDT[0x0008]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Non-Conforming, Accessed, 32-bit
GDT[0x0010]=Data segment, base=0x00000000, limit=0xffffffff, Read/Write, Accessed
Code: Select all
00015823627e[CPU0 ] interrupt(): not accessible or not code segment cs=0x0008
00015823627e[CPU0 ] interrupt(): not accessible or not code segment cs=0x0008
00015823627e[CPU0 ] interrupt(): not accessible or not code segment cs=0x0008
(0).[15823627] [0x000000001005] 0008:0000000000001005 (unk. ctxt): jmp .-2 (0x00001005) ; ebfe
00015823627e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
uint32_t bitmap[PAGE_NUMBER];
void init_bitmap()
{
mem_map* mmap = (mem_map*)MEM_MAP_LOCATION;
//initialize bitmap with PAGE_ALLOCATED
for (size_t i = 0; i < PAGE_NUMBER; ++i)
{
bitmap[i] = 0x08080808;
}
}
I really don't know how to solve this issue. Can you please help me?