IDT and 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.
jedld

Re:IDT and GDT

Post by jedld »

okay, I'll answer my own question, I accidentally
set my my stack segment to code which prevents
the cpu from writing data to it. That's why it reboots :)
f2

Re:IDT and GDT

Post by f2 »

But how do you edit the GDT after you already have set it up? Can you tell me that? Thanks! :D
jedld

Re:IDT and GDT

Post by jedld »

You could just modify the contents of the GDT...BUT
you can not modify an entry which is beyond the limit specified in your GDTR, for example, you've set up your limit to be at 63, which is around 8 GDT entries, you cannot add an entry to make int a total of 9. I have not tried modifying an entry in which its corresponding selector is being used (CS for example) though.
Tim

Re:IDT and GDT

Post by Tim »

If you add entries to the GDT, and therefore change the limits, you will need to reload it using LGDT. If you change entries, you don't need to reload the GDT, but you will have to reload any segment registers that refer to the changed descriptors. This is because you need to refresh the descriptor caches that the CPU keeps.
f2

Re:IDT and GDT

Post by f2 »

How exactly would you "modify" the GDT? Could you supply some code?

Also, could you please look at the thread here:
http://www.mega-tokyo.com/forum/index.p ... readid=699

I'm having problems setting up the initial GDT because when I get to that part on the boot, my computer restarts. I can't figure out what is causing this. Can you? :(
Tim

Re:IDT and GDT

Post by Tim »

The GDT is just a normal variable in memory. Think of it as an array of 8-byte structures. To modify it in C, I'd recommend that you set up a structure definition as per the Intel documentation. To modify it from assembler, obtain the address of a descriptor by multiplying the index of your descriptor by 8. Then modify the various fields relative to that. The layout is all documented in the Intel manual; other than that, it's just basic assembly.

If you're having problems switching to protected mode, I'd advise you to start debugging under Bochs. It won't stop your code triple-faulting, but it will tell you why and where your code failed.
f2

Re:IDT and GDT

Post by f2 »

Can you point me to this "Bochs" tool? It might come in handy and I'll try the debug thing. Although, I may need some guidance on how to debug with this "Bochs". Thanks!
ChronoZ

Re:IDT and GDT

Post by ChronoZ »

You can get Bochs from http://bochs.sourceforge.net.

I haven't used the debugger that much myself, but the documentation available at the above url should be enough to atleast get you started...
Post Reply