Does memset_dw take number of dwords to clear?
Yes it does. I was coding late last night and this morning when I woke up I realized the problem you point out. Then I just now realized that I'm retarded and apparently I forgot how pointers work for about an hour last night. Thank you, and I fixed that. No longer using dwords.
I would recommend Bochs in this case. First off, uninstall the 'Page Fault' handler and see if your code still fires the 'General Protection Fault'.
If it is again the same GPF, then, you may want to examine the contents of CR0 and CR3 register to figure out if paging is actually enabled and if page directory is where you want it to be.
The paging bit is enabled and the page directory is where I told it to be.
Edit: Can we have the code for interrupt handlers?
Ask and ye shall recieve.
I will admit I'm lost in all the Intel assembly code. I learned assembly for MIPS once, so I know *basically* whats happening, but I'm don't know very much about the specifics of the x86 processor. I really just want to get into portable C code since I intend on running this on ARM someday (I like RISC).
My interrupt handlers are pretty basic.
; this exception already pushes an error code
push byte 13
mov ax, ds
mov ax, 0x10 ; Load the Kernel Data Segment Descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
add esp, 4
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
iret ; Pop 5 things at once: CS, EIP, EFLAGS, SS, and ESP
and then finally
void fault_handler(struct regs *r)
void (*handler)(struct regs *r);
handler = isrs[r->int_no];
/* Is this a fault whose number is from 0 to 31? */
if (r->int_no < 32)
/* Display the description for the exception that occurred */
/* For now, deal with the exception by entering an infinite loop */
puts (" System Halted!\n");
Thank you for responding!
I've noticed that when I try to write to the ptr to force a page fault, bochs says "write_virtual_dword_32() segment limit violation".
I set the limit in my GDT to 0xFFFFFFFF which is 4 GB and way higher than 0xC0000000...
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
// The null descriptor
gdt_set_gate(0, 0, 0, 0, 0);
// The second entry is the Code Segment. The base address is 0, the limit is 4 GB, it uses 4 KB granularity, uses 32 bit opcodes
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
// The third entry is the Data Segment. Its the same as the Code Segment, but the descriptor type is that of a Data Segment
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
and yes, the GDT is properly installed.