Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Hi.
I'm trying to setup GDT in my C kernel, but there's something wrong.
The bootloader sets up a GDT for me to use, but I want to set one up in my kernel.
Someone said I can get the address of the GDT with LGDT, how?
And, when will I have to access the GDT in my kernel, do I have to access it when I create a process?
1. did you made sure the gdtr struct was 6 bytes and the descriptor strcut was 8 ?
2. are you aware that changes performed on GDTR will have no effect until segment registers are re-loaded ?
3. why do you declare the limit as 256*sizeof(descriptor) if you allocate only 20 of them ??
4. what the **** does the PG bit comes here ?
00005196106i[CMOS ] read of index port 0x70. returning 0xff
00005196131e[CPU ] seg = DS
00005196131e[CPU ] seg->selector.value = 0000
00005196131e[CPU ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
1. Make sure you "__attribute__ ((packed))" your x86_gdt structure.
2. If you know that you must reload the segment registers after you load the GDTR register, why isn't that in your code?
3. Is there a reason you must temporarily disable NMI before loading the GDTR?
4. What is the purpose of the XOR and MOV instructions you put just prior to the LGDT instruction?
5. The following:
well, if you can afford it, i suggest you run your code in a debug-enabled version of BOCHS. Using the dump_cpu and the trace-on commands accurately, you should be able to better aim your bug ...
btw, the message code you showed tends to convince me the problem comes from the fact you're not reloading segment registers after you're done ... i don't know what exactly you try to do by reloading the GDT, but one thing is certain: if you don't do that
"mov ax,ds; mov ds,ax" thing together with a "jmp CODE_SELECTOR:here; here:", the CPU will keep the old base, options and limit in its internal shadow registers.
src/bootp/gdt.c, lines 40-45 reload DS, ES, FS, GS, and SS. Lines 56-58 would reload CS via LJMP. (I'm not quite sure why lines 56-58 are commented out, however. They are necessary.)