Can use Multiboot1 for x86_64 kernel?

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.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

Hi,
I have one question? Can I use Multiboot1 with x86_64 kernel? If so, can it use with ELF64? I want to writing debug utilities with stack trace, but Multiboot2 is too complicated for me :D
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Re: Can use Multiboot1 for x86_64 kernel?

Post by kotovalexarian »

Multiboot 2 is not complicated. I strongly recommend it over Multiboot 1. I've also tried to start with Multiboot 1, but I met a lot of problems. I don't remember what kind of problems (this was more than a year ago), but at least with Multiboot 2 everything works great. Multiboot 1 & 2 are very similar for the most basic tasks. The main difference is how data is organized in memory. Multiboot 2 uses tags, which are placed in memory after the header. The common pitfall is that tags are aligned, so they may have some gaps between them. However it is not hard to parse them.

Also you can try my auxiliary library for kernel development (https://github.com/tailix/libkernaux). It includes Multiboot 2 parser. Unfortunatelly it's not well documented, examples are missing, and the API for Multiboot 2 parser will change soon.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

kotovalexarian wrote:Multiboot 2 is not complicated. I strongly recommend it over Multiboot 1. I've also tried to start with Multiboot 1, but I met a lot of problems. I don't remember what kind of problems (this was more than a year ago), but at least with Multiboot 2 everything works great. Multiboot 1 & 2 are very similar for the most basic tasks. The main difference is how data is organized in memory. Multiboot 2 uses tags, which are placed in memory after the header. The common pitfall is that tags are aligned, so they may have some gaps between them. However it is not hard to parse them.

Also you can try my auxiliary library for kernel development (https://github.com/tailix/libkernaux). It includes Multiboot 2 parser. Unfortunatelly it's not well documented, examples are missing, and the API for Multiboot 2 parser will change soon.
Thank you.
User avatar
mid
Member
Member
Posts: 31
Joined: Thu Mar 04, 2021 7:25 am

Re: Can use Multiboot1 for x86_64 kernel?

Post by mid »

Yes, you can use Multiboot1 for a x86_64 kernel.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

mid wrote:Yes, you can use Multiboot1 for a x86_64 kernel.
Oh, thank you.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

NeonLightions wrote:
mid wrote:Yes, you can use Multiboot1 for a x86_64 kernel.
Oh, thank you.
Wait, there's still one question: Can I use it with ELF64?
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Can use Multiboot1 for x86_64 kernel?

Post by nexos »

Ye, GRUB works with ELF64. I'm not sure if that's actually in the multiboot spec, however.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

By the way, I have post my code on stack tracing to my repo. It just catch 1 function name and stop. Can anyone help me solve this?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Can use Multiboot1 for x86_64 kernel?

Post by nullplan »

Multiboot1 will always drop you off in a 32-bit environment. If you can write a 32-bit entry point in assembler that manages to prepare all the paging structures you require and switches to 64-bit mode before running any C function, then yes, you can use multiboot1. I personally have chosen to implement multiboot1 for my 64-bit kernel by using the module mechanism: I have written a small 32-bit "kernel" that takes the actual 64-bit kernel as a module (and requests page alignment of all modules). And then just creates the paging structures the main kernel requires, and formats the multiboot information in a kernel-specific way, and then it just launches the 64-bit kernel.

This is done so that I can also have a UEFI bootloader independent of the multiboot loader, and run my kernel on both UEFI and legacy machines. However, if you are creating a 64-bit kernel, then the number of machines not able to run a UEFI application is minuscule compared the number of those that are, so the UEFI application is almost certainly more important than the multiboot application. I would therefore suggest you look into creating one of those and find an emulator that allows you to run UEFI applications, or a way to configure your emulator to do so.
Carpe diem!
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Re: Can use Multiboot1 for x86_64 kernel?

Post by kotovalexarian »

NeonLightions wrote:Can anyone help me solve this?
Please, make your question more specific and give a link to your code.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

kotovalexarian wrote:
NeonLightions wrote:Can anyone help me solve this?
Please, make your question more specific and give a link to your code.
I'm sorry, I forgot to give you my repo, here is it: https://github.com/NeonLightions/Amore-OS-x64
Also, I want to have a back trace mechanism like Python. It will take return address in stack frames, look for symbol name in ELF symbol table and print it into screen.
JustVic
Posts: 17
Joined: Tue Jul 07, 2020 3:18 pm

Re: Can use Multiboot1 for x86_64 kernel?

Post by JustVic »

As I understand right even multiboot2 leaves you in protected mode(32bit). And you need to switch to long mode(64bit) by yourself.
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Re: Can use Multiboot1 for x86_64 kernel?

Post by kotovalexarian »

NeonLightions wrote:Also, I want to have a back trace mechanism like Python. It will take return address in stack frames, look for symbol name in ELF symbol table and print it into screen.
That's a nice idea. I also feel the need in such mechanism. I have not idea how to achieve this, but I'll take a look.
NeonLightions
Member
Member
Posts: 102
Joined: Wed Oct 20, 2021 6:00 pm
Location: Paraguay

Re: Can use Multiboot1 for x86_64 kernel?

Post by NeonLightions »

kotovalexarian wrote:
NeonLightions wrote:Also, I want to have a back trace mechanism like Python. It will take return address in stack frames, look for symbol name in ELF symbol table and print it into screen.
That's a nice idea. I also feel the need in such mechanism. I have not idea how to achieve this, but I'll take a look.
Thanks, I'm looking forward to it.
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Re: Can use Multiboot1 for x86_64 kernel?

Post by kotovalexarian »

Here is some stack tracing example: https://github.com/josehu07/hux-kernel/ ... -&-Testing
Post Reply