Page 2 of 2
Re:IDT and GDT
Posted: Sun May 12, 2002 6:46 am
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
Re:IDT and GDT
Posted: Sun May 12, 2002 7:35 am
by f2
But how do you edit the GDT after you already have set it up? Can you tell me that? Thanks!
Re:IDT and GDT
Posted: Mon May 13, 2002 2:32 am
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.
Re:IDT and GDT
Posted: Mon May 13, 2002 5:03 am
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.
Re:IDT and GDT
Posted: Mon May 13, 2002 6:53 am
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?
Re:IDT and GDT
Posted: Mon May 13, 2002 7:18 am
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.
Re:IDT and GDT
Posted: Mon May 13, 2002 1:30 pm
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!
Re:IDT and GDT
Posted: Mon May 13, 2002 2:23 pm
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...