Page 1 of 1

[SOLVED] How can I test my GDT?

Posted: Tue Feb 12, 2013 2:27 pm
by BenjiWiebe
How can I check if my GDT is loaded correctly, and populated correctly?
If the following code does not cause a triple fault, can I assume that the GDT is correct?

Code: Select all

reloadSegments:
   ; Reload CS register containing code selector:
   jmp   0x08:reload_CS ; 0x08 points at the new code selector
reload_CS:
        ; Reload data segment registers:
        mov     ax, 0x10 ; 0x10 points at the new data selector
        mov     ds, ax
        mov     es, ax
        mov     fs, ax
        mov     gs, ax
        mov     ss, ax
        ret

Re: How can I test my GDT?

Posted: Tue Feb 12, 2013 4:59 pm
by Combuster
If the CPU does get past that, the chance you have a broken GDT is small - because at least you have a code selector (which at least references this part of your binary) and a data selector where you expect it. Whatever the other fields may be set to, you'll typically only notice them to be off when you actually start making memory references through those segments.

Re: How can I test my GDT?

Posted: Tue Feb 12, 2013 7:04 pm
by BenjiWiebe
Combuster wrote:If the CPU does get past that, the chance you have a broken GDT is small - because at least you have a code selector (which at least references this part of your binary) and a data selector where you expect it. Whatever the other fields may be set to, you'll typically only notice them to be off when you actually start making memory references through those segments.
Then my GDT must be working, because the CPU gets past all of this.

Thanks!!

Re: [SOLVED] How can I test my GDT?

Posted: Wed Feb 13, 2013 12:20 am
by xenos
Bochs' debugger has an info gdt command...

Re: [SOLVED] How can I test my GDT?

Posted: Wed Feb 13, 2013 7:34 am
by BenjiWiebe
XenOS wrote:Bochs' debugger has an info gdt command...
I didn't know that!! Thanks for telling me.