Page 1 of 1

64-bit Multiboot Header issues

Posted: Wed Mar 16, 2016 3:16 pm
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

Re: 64-bit Multiboot Header issues

Posted: Wed Mar 16, 2016 4:34 pm
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?

Re: 64-bit Multiboot Header issues

Posted: Thu Mar 17, 2016 3:53 pm
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

Re: 64-bit Multiboot Header issues

Posted: Thu Mar 17, 2016 4:07 pm
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.

Re: 64-bit Multiboot Header issues

Posted: Thu Mar 17, 2016 4:11 pm
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