Page 1 of 1

General protection fault on reloading ds

Posted: Thu Sep 06, 2012 8:39 am
by richi18007
Hello , please don't get angry because of so many doubts . I have tried all day and searched forums for the answer but I couldn't .
The paging is done as
4 MB initial := identity mapped
3gb+1 (768th entry in the PDT) := mapped to 1 Mb
The kernel is loaded at 1MB using unreal mode and using GDT trick. (cs.base = 0x400000 ,ds.base=0x400000)
And kernel starts at 0xc00100000
Now , I want to reload the normal descriptors (zero base addresses)
I am trying to load the GDT (which I checked 10 times already and is correct) after enabling the paging. I keep running into a general protection fault. The info gdt in bochs says that something is wrong with the GDT .

As soon as the data segment gets loaded ,bochs generates the GPF due to wrong data segment. Please help solve this problem.

Code: Select all

        lgdt [toc]
	mov ax , 0x10
	mov ds , ax
	mov es , ax
;	mov ss , ax 
	pop ebp
;	jmp 0x08: return_cr0

Re: General protection fault on reloading ds

Posted: Thu Sep 06, 2012 11:20 am
by bluemoon
Write down a table of:
1. linear address, physical address, and logical address of GDTR (You should know the differences of 3 address types)
2. The 3 addresses of GDTR.pointer
3. The 3 addresses of CS.base & DS.base

Trace them at these checkpoint:
1. start point
2. applied GDT trick (I hate it)
3. enabled paging
4. applied normal GDT

This should pinpoint the problem.

Re: General protection fault on reloading ds

Posted: Thu Sep 06, 2012 11:58 am
by richi18007
Thank you bluemoon for the suggestion. I am trying.
EDIT : I did exactly like you said. Read the physical , virtual and logical addresses and found the error. Actually I forgot the 'h' in the last of one hexadecimal number(address in the page table) and that is why it was page faulting.

Just some experience I want to share , Operating system development is tough and it brings great joy when something works as expected after hours and days of work :). Thank you.