Page 1 of 1

GDT and IDT problems

Posted: Fri Apr 11, 2014 2:34 am
by hometue
Hi guys, I am doing GDT and IDT, just wondering, what is the best way to check I have correctly make a GDT and IDT.(Will bochs debugger mention that they have been made?) Thanks

Re: GDT and IDT problems

Posted: Fri Apr 11, 2014 3:24 am
by alexfru
hometue wrote:Hi guys, I am doing GDT and IDT, just wondering, what is the best way to check I have correctly make a GDT and IDT.(Will bochs debugger mention that they have been made?) Thanks
Yeah, when scientist finally invent working AI, Bochs will probably be able to tell the right GDT/IDT from the wrong. No, really, Bochs can't know whether or not what you've got is what you want and if it's somehow right. There's no single right here. You may have reasons for setting up unusable segment descriptors. Bochs wouldn't know that. But it will surely tell you of triple faults emanating from #GP's, #SS' and so on.

You could probably use some Bochs functionality to dump CPU registers and system tables (I've never done that). You could also use some sort of debug prints or things as simple as "jmp $" to see how far you get without a crash. Be inventive.

Re: GDT and IDT problems

Posted: Fri Apr 11, 2014 8:12 am
by hometue
Thanks for the info. By the way, how do I tell if there is a faulty gdt/idt (as in there is a faulty gdt/idt what will happen?)

EDIT: I know the qns is very similar to the one I had but what I mean this time is like if I have a faulty gdt/idt, what are the known problems I will face (fault? registers not having the right value?)

Re: GDT and IDT problems

Posted: Fri Apr 11, 2014 8:16 am
by Bender
(as in there is a faulty gdt/idt what will happen?)
Triple Fault it is then. (for most cases like you'll maybe switch to an invalid segment (faulty GDT), CPU relaxes and says "Why should I bother?" searches for handler, faulty IDT, can't find the appropriate handler, then asks "Why should I bother?", goes finds the DF handler, faulty IDT, then asks "Why should I bother?", and reboots.) or it can be something beyond our imagination.
EDIT:
Registers will have the correct values btw, but it may be that the segments will be so badly messed up that you'll think you're writing to some memory location and you'll be writing to some other memory address. Has happened to me before.

Re: GDT and IDT problems

Posted: Fri Apr 11, 2014 8:26 am
by hometue
Thanks Bender for the info.

Re: GDT and IDT problems

Posted: Fri Apr 11, 2014 11:07 am
by jnc100
hometue wrote:Hi guys, I am doing GDT and IDT, just wondering, what is the best way to check I have correctly make a GDT and IDT.(Will bochs debugger mention that they have been made?) Thanks
Yes, it can do just this. Typically you'd want to set a breakpoint after the lidt and lgdt instructions, and then use the 'info gdt' and 'info idt' commands. The bochs debugger is a powerful tool if you learn to use it properly.

Regards,
John.

Re: GDT and IDT problems

Posted: Sat Apr 12, 2014 9:30 am
by hometue
Would that be the same as displaying the gdt and idt in the gui debugger. How would I tell a faulty gdt with a proper one then?

Btw, I came across this question which confuses me, when making a gdt and must i fill it for it to work(I see when switching to proteted mode they don't but in some gdt tutorial you actually have to)? And what do I fill it with (I am a visual learner, so if someone can provide me with a good diagram of the gdt and idt I will appreciate it as it would make it much simpler to understand, can't find a good visualization of the gdt and idt anywhere), while there is code provided to fill it I rather understand the structure of the gdt and not rely on other's code to do things for me. Thank you very much.

Re: GDT and IDT problems

Posted: Sat Apr 12, 2014 10:40 am
by Bender
hometue wrote:Would that be the same as displaying the gdt and idt in the gui debugger. How would I tell a faulty gdt with a proper one then?

Btw, I came across this question which confuses me, when making a gdt and must i fill it for it to work(I see when switching to proteted mode they don't but in some gdt tutorial you actually have to)? And what do I fill it with (I am a visual learner, so if someone can provide me with a good diagram of the gdt and idt I will appreciate it as it would make it much simpler to understand, can't find a good visualization of the gdt and idt anywhere), while there is code provided to fill it I rather understand the structure of the gdt and not rely on other's code to do things for me. Thank you very much.
Rule #1 : Tutorials deal with a specific-implementation, You shouldn't rely much on them, basically it's like a ready made answer, from what I've learnt from my mistakes tutorials help you get started and that's it. What happens after is on your hands. Teachers will know the best about what I'm talking about.
Rule #2 : Never forget Rule #1
Rule #3 : If you do, well, "triple fault here we come" (or something of that sort perhaps) is going to happen.
Visual Representation? The wiki has a good one. http://wiki.osdev.org/Global_Descriptor_Table
The structure of the GDT and IDT are quite similar, so if you understand the GDT you shouldn't have much problems with the IDT.
I don't know what is meant by "filling" a GDT. Since I have little knowledge about tutorials, I can't really say anything. In my OS the GDT is never touched. The values are hardcoded, by filling a GDT what I can "guess" is setting the GDT entries at runtime, rather than hard coding. (Mind the word "guess")