Having trouble understanding the theory behind the 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
Nucleria
Posts: 5
Joined: Sun Nov 29, 2015 6:25 pm

Having trouble understanding the theory behind the GDT.

Post 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!
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Having trouble understanding the theory behind the GDT.

Post 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!
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Having trouble understanding the theory behind the GDT.

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Nucleria
Posts: 5
Joined: Sun Nov 29, 2015 6:25 pm

Re: Having trouble understanding the theory behind the GDT.

Post 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.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Having trouble understanding the theory behind the GDT.

Post 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.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Nucleria
Posts: 5
Joined: Sun Nov 29, 2015 6:25 pm

Re: Having trouble understanding the theory behind the GDT.

Post by Nucleria »

Nevermind about the file. New question: is there a limit or specified required number of GDT entries? Is there a minimum?
Nucleria
Posts: 5
Joined: Sun Nov 29, 2015 6:25 pm

Re: Having trouble understanding the theory behind the GDT.

Post 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.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Having trouble understanding the theory behind the GDT.

Post 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
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Nucleria
Posts: 5
Joined: Sun Nov 29, 2015 6:25 pm

Re: Having trouble understanding the theory behind the GDT.

Post 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!
Post Reply