64-bit Multiboot Header issues

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
Dennisbonke
Posts: 15
Joined: Sun Aug 09, 2015 7:23 pm
Libera.chat IRC: Dennisbonke

64-bit Multiboot Header issues

Post by Dennisbonke »

Hello everyone,

A while ago i started to move my OS into the 64-bit era. Now that the code is complete, and except for the main loop, which I will do when this problem is fixed, the code compiles and links. When i first tried it in QEMU, it crashed with a stacktrace and actually lock up the host OS once. I managed to fix this problem, but now grub refuses to load my kernel file. I managed to find an copy of mbchk.c, and it reports that there is no multiboot header. I have been trying to work this out for 2 days now, but I can't figure it out, so I ask you guys here if you can help me. The link to the source code for my OS can be found in my signature, and the readme includes the versions of binutils and gcc used.

If you need any more information, please let me know.

Thanks in advance!
Dennis
Hi, I'm Dennis, the resident port maintainer of Managarm!
Happy to help or answer questions, porting software is my speciality but I'll try everything.
Please correct my English as I'm not a native speaker of it.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 64-bit Multiboot Header issues

Post by iansjack »

How are you booting your kernel? Directly using qemu or as a disk image booted by GRUB? Is your multiboot header right at the start of your kernel file?
Dennisbonke
Posts: 15
Joined: Sun Aug 09, 2015 7:23 pm
Libera.chat IRC: Dennisbonke

Re: 64-bit Multiboot Header issues

Post by Dennisbonke »

Currently I'm booting my kernel directly with the -kernel option in qemu (but I am planning on booting by iso), and that gave the following results.
With qemu-system-x86-64 (and the i386 one) and the 64-bit kernel file, it errors about wanting an 32 bit image,
When I objcopy it to an 32-bit ELF file, the i386 resets like a triple fault, and the x86-64 hangs on loading from rom.
And yes, the multiboot header is the first thing in the file, as can be found here
Hi, I'm Dennis, the resident port maintainer of Managarm!
Happy to help or answer questions, porting software is my speciality but I'll try everything.
Please correct my English as I'm not a native speaker of it.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: 64-bit Multiboot Header issues

Post by iansjack »

As you have found out, qemu can't directly load a 64-bit kernel. I'm not sure what you mean by objcopying it to a 32-bit Elf file, but if it's 64-bit code you can't pretend it is 32-bit.

I think you are going to have to use GRUB, or else write your own boot loader. I have GRUB loading a 32-bit initial kernel and a 64-bit module which is the real kernel. The 32-bit code sets up an initial page table and then jumps to the 64-bit code.

I suspect that part of your problem is the fact that 64-bit code requires paging to be set up. I'm pretty sure that qemu doesn't do this for you; I'm not sure if GRUB can set up a basic paging system. Someone more knowledgeable than me about GRUB can probably answer that one.
Dennisbonke
Posts: 15
Joined: Sun Aug 09, 2015 7:23 pm
Libera.chat IRC: Dennisbonke

Re: 64-bit Multiboot Header issues

Post by Dennisbonke »

I have done that, the linker entry point is set to the 32-bit bootstrap, which prepares the cpu for 64-bit, and then jumps to the 64-bit kernel

EDIT: You load it as an module, i have a 32-bit stub inside the 64-bit kernel
Hi, I'm Dennis, the resident port maintainer of Managarm!
Happy to help or answer questions, porting software is my speciality but I'll try everything.
Please correct my English as I'm not a native speaker of it.
Post Reply