Page 1 of 1

Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 6:35 pm
by Nucleria
Hello, I'm really new to this forum and OSDev all around. In fact, my in-progress OS was just started two days ago. I have a good handle on C and at least understand Assembly, but the idea of the Global Descriptor Table really confuses me. I'm generally quick to understand things. I've a basic knowledge of the whole interrupt thing and have read a lot of OS theory. I've also read all the way through the GDT Tutorial. It's just a slightly vague explanation. So, I'm not asking for code, I'm just looking for a basic explanation of the GDT, and possibly some hints.

Thanks, Sydney!

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:03 pm
by BASICFreak
Well, go through all of these and reply back a specific area you need help in (if you still didn't find the answer)

Global_Descriptor_Table
Protected Mode Tutorial
Protected Mode Segmentation <- Please don't use segmentation, use virtual memory.



Best regards,


B!

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:14 pm
by SpyderTL
The GDT is the table that the CPU uses to keep track of what memory is read-only, what memory is writable, and what memory is executable.

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:35 pm
by Nucleria
Thanks to both of you. I do understand it a bit better now, but now I've got a bit of a problem. I'm pretty sure that GRUB leaves me in protected mode and that it generates its own GDT. I know that it's recommended to overwrite that one. This is a somewhat stupid question compared to my first one, but how would I go about overwriting that. I can figure out the code on my own, with help from the GDT Tutorial, but where (as in what file) would I put this code. I've had problems figuring out where things go this whole time. Thanks, again.

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:55 pm
by BASICFreak
Anywhere before you need it, it requires a linear address though so after Virtual Memory / Paging if you are using it.

What file is not relevant, it could be in you main file, a file named gdt, or anywhere - as long as you link in the file.

Creating_an_Operating_System gives a very basic order of when to implement what.

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:56 pm
by Nucleria
Nevermind about the file. New question: is there a limit or specified required number of GDT entries? Is there a minimum?

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:57 pm
by Nucleria
BASICFreak wrote:Anywhere before you need it, it requires a linear address though so after Virtual Memory / Paging if you are using it.

What file is not relevant, it could be in you main file, a file named gdt, or anywhere - as long as you link in the file.

Creating_an_Operating_System gives a very basic order of when to implement what.
Thanks. That's kind of what I assumed.

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 7:58 pm
by BASICFreak
Nucleria wrote:Nevermind about the file. New question: is there a limit or specified required number of GDT entries? Is there a minimum?
The offset is the linear address of the table itself, which means that paging applies. The size is the size of the table subtracted by 1. This is because the maximum value of size is 65535, while the GDT can be up to 65536 bytes (a maximum of 8192 entries). Further no GDT can have a size of 0.
So a max of 8192.

The minimum is probably 3:
null
code
data

Re: Having trouble understanding the theory behind the GDT.

Posted: Sun Nov 29, 2015 8:00 pm
by Nucleria
BASICFreak wrote:
Nucleria wrote:Nevermind about the file. New question: is there a limit or specified required number of GDT entries? Is there a minimum?
The offset is the linear address of the table itself, which means that paging applies. The size is the size of the table subtracted by 1. This is because the maximum value of size is 65535, while the GDT can be up to 65536 bytes (a maximum of 8192 entries). Further no GDT can have a size of 0.
So a max of 8192.

The minimum is probably 3:
null
code
data
Thanks. I (somehow) completely missed that. For now, I don't have any more questions, but I'm sure I'll have more soon.

Thanks for all the help!