Page 1 of 1

Why do I need a GDT

Posted: Mon Feb 20, 2017 1:28 am
by beauhefley
I want to add interrupts because I want to add keyboard input without polling port 0x60. My design for my OS has the kernel parse each executable file. Why do I need a GDT and a TSS? Without one, is it possible to make a good functioning OS and/or implement interrupts?

Edit: I had GPT originally, I always thought that the wiki said GPT. Sorry for any confusion.
Edit 2: I am stupid. I meant to say "without one".

Re: Why do I need a GPT

Posted: Mon Feb 20, 2017 2:09 am
by alexfru
GPT?

Re: Why do I need a GPT

Posted: Mon Feb 20, 2017 4:11 am
by dchapiesky

Re: Why do I need a GPT

Posted: Mon Feb 20, 2017 7:33 am
by zaval
GPT - GUID partition table, you need it if your disk is GPT-formatted. :D Specified in the UEFI specification, It's actully quite easy, interesting, modern and needed to be understood by OS developers, but this is not what you were asking about.)

Re: Why do I need a GPT

Posted: Mon Feb 20, 2017 1:38 pm
by beauhefley
Presumably he meant "GDT"...
Oh. I have read that wrong.

Re: Why do I need a GDT

Posted: Mon Feb 20, 2017 7:02 pm
by zesterer
beauhefley wrote:I want to add interrupts because I want to add keyboard input without polling port 0x60. My design for my OS has the kernel parse each executable file. Why do I need a GDT and a TSS? Without one, is it possible to make a good functioning OS and/or implement interrupts?
Yes, you need a GDT. It is required in 32-bit protected mode on the x86 architecture.

You may not think you already have one. But you're probably booting your OS with GRUB. GRUB automatically creates one. When GRUB hands control over to your OS, the old GDT GRUB created still resides within the CPU's internal cache. It's a good idea to replace it with your own one ASAP in the boot process to avoid problems later.

Truth be told, the GDT has few purposes in modern systems that make use of paging. It's a dinosaur of the x86's past, but it's still required for backwards-compatibility.

My advise? Just set one up. It's not as hard as it seems, honest. Provided you know C and some simple ASM, it shouldn't take you long to figure it out from the wiki documentation. If you don't know C and simple ASM, I highly recommend that you put OS development on hold and spend a week teaching yourself C and assembly on your normal operating system before jumping into your own.

Re: Why do I need a GDT

Posted: Tue Feb 21, 2017 5:56 am
by dozniak
zesterer wrote: My advise? Just set one up. It's not as hard as it seems, honest. Provided you know C and some simple ASM, it shouldn't take you long to figure it out from the wiki documentation. If you don't know C and simple ASM, I highly recommend that you put OS development on hold and spend a week teaching yourself C and assembly on your normal operating system before jumping into your own.
You can pretty much hardcode 3 (if you have only kernel mode) or 5 entries with constants - they will always be the same anyway.

Re: Why do I need a GDT

Posted: Wed Feb 22, 2017 1:32 pm
by beauhefley
Provided you know C and some simple ASM, it shouldn't take you long to figure it out from the wiki documentation. If you don't know C and simple ASM, I highly recommend that you put OS development on hold and spend a week teaching yourself C and assembly on your normal operating system before jumping into your own.
I know C++ and a very small amount of Assembly using Linux system calls and int 0x80. I am not used to writing code in this low level, and I rely heavily on libraries such as the standard libraries, boost, and Qt.
I found a guide, I created a struct with the bytes in order. I couldn't figure out what to name each variable to get the CPU to know what to read, but according to the guide the bytes just have to be in order. Loading my GDT does triple fault, but I found out that removing my IDT headers and not linking my assembly object for my ISR does make it boot properly.

Re: Why do I need a GDT

Posted: Wed Feb 22, 2017 1:50 pm
by FusT
Welcome to osdev, where every single bit of the system matters :-P

Re: Why do I need a GDT

Posted: Wed Feb 22, 2017 2:02 pm
by beauhefley
Got my GDT and IDT to load my kernel without triple faulting! Now I just have to test and see if I can use interrupts.