How to make a 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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

I'm doing something wrong. What is it?
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

What have you done to debug it so far?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote:What have you done to debug it so far?
Nothing at the moment. I'm still trying to get GRUB to recognise the multiboot header.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

Have you examined your kernel binary in a hex editor? Your Multiboot header needs to be located within the first 8kB of your kernel. You may need to modify your linker script or your linker flags to ensure the linker doesn't insert any other sections or any padding before the Multiboot header.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote:Have you examined your kernel binary in a hex editor? Your Multiboot header needs to be located within the first 8kB of your kernel. You may need to modify your linker script or your linker flags to ensure the linker doesn't insert any other sections or any padding before the Multiboot header.
There are no sections before the multiboot header. I don't use linker flags, but there are C flags used. If correct, you're saying that the multiboot header should be at the start of the file, right? If so, then (I think) only the ELF header is there. I'm not sure.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

zap8600 wrote:If correct, you're saying that the multiboot header should be at the start of the file, right?
No, the ELF header goes at the start of the file. The Multiboot header should be somewhere after the ELF header, within the first 8kB of the file.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote:
zap8600 wrote:If correct, you're saying that the multiboot header should be at the start of the file, right?
No, the ELF header goes at the start of the file. The Multiboot header should be somewhere after the ELF header, within the first 8kB of the file.
Is there a certain value I'm looking for?
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

What value does the Multiboot header start with? Look for that value.

(Don't forget that x86 is little-endian.)
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote:What value does the Multiboot header start with? Look for that value.

(Don't forget that x86 is little-endian.)
The header starts with 0x1BADB002, the value for the magic. I'm also not sure what little-endian is.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

zap8600 wrote:I'm also not sure what little-endian is.
That's the sort of thing you should probably already know before you try to write an OS.

Type it into your favorite search engine, see if you can figure out why it matters when you're looking for your Multiboot header.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote:
zap8600 wrote:I'm also not sure what little-endian is.
That's the sort of thing you should probably already know before you try to write an OS.

Type it into your favorite search engine, see if you can figure out why it matters when you're looking for your Multiboot header.
If correct, little-endian means that the data is stored with the least significant bit first. Does that just mean reverse order?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Should I use something like NASM? Should I use EDK2 to make my kernel an EFI file? Is there an existing multiboot header I can use? What do I do?

Edit: I'm going to just continue to use the Limine boot protocol. I thought it would of been better to to set up paging myself, because I would learn from it, but I'll just use the Limine boot protocol, since I'm dumb.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to make a GDT?

Post by iansjack »

We’re all dumb until someone has taught us or we have read the appropriate documents.

I would suggest you use multiboot (it’s easy to construct the header if you read the specifications) and use grub as your boot loader. It can handle BIOS or UEFI.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

iansjack wrote:We’re all dumb until someone has taught us or we have read the appropriate documents.

I would suggest you use multiboot (it’s easy to construct the header if you read the specifications) and use grub as your boot loader. It can handle BIOS or UEFI.
Will my OS boot, even if GRUB doesn't recognize the multiboot header?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to make a GDT?

Post by iansjack »

No.
Post Reply