[SOLVED] How can I test my GDT?

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.
Post Reply
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

[SOLVED] How can I test my GDT?

Post 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
Last edited by BenjiWiebe on Tue Feb 12, 2013 7:05 pm, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How can I test my GDT?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

Re: How can I test my GDT?

Post 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!!
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

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

Post by xenos »

Bochs' debugger has an info gdt command...
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

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

Post by BenjiWiebe »

XenOS wrote:Bochs' debugger has an info gdt command...
I didn't know that!! Thanks for telling me.
Post Reply