OSDev.org
https://forum.osdev.org/

[Solved] QEMU: Booting x86_64 kernel via PVH
https://forum.osdev.org/viewtopic.php?f=1&t=47479
Page 1 of 1

Author:  lukecreator [ Tue Jul 27, 2021 5:29 pm ]
Post subject:  [Solved] QEMU: Booting x86_64 kernel via PVH

After getting a basic 32-bit i386 kernel emulating through QEMU, I figured I would go ahead and get one fired up on x86_64. I am still completely in the "Let's make sure this actually works before doing anything else" phase. Running "qemu-system-x86_64 -kernel out.bin" results in QEMU spitting out "Error loading uncompressed kernel without PVH ELF Note." The binary file has been verified with grub-file as well.

I've read around that QEMU does not support multiboot2 so I figured I would just give it what it wants and include the elf note. My only issue here is figuring out how to do this correctly. As of now I have
Code:
section .note
align 4
   dd 3 ; name size
   dd 4 ; data size
   dd 18 ; type (0x12)
align 4
   db 'Xen' ; name
align 4
   dd _start ; data

and my linker puts the section at the right spot in the file.
Code:
   .note :
   {
      *(.note)
   }


Running readelf does show that the elfnote is present and contains what I thought was the correct information (see below). QEMU still tells me that it wants its PVH elfnote despite this. I have exhausted every resource trying to get it to work over the past week and I'm about at the end of my ropes; Thinking I misunderstood something big-time. Would love if someone could point me in the right direction here on where I went wrong.

Note data:
Code:
Displaying notes found in: .note
  Owner                Data size        Description
  Xen                  0x00000004       Unknown note type: (0x00000012)
   description data: 00 20 00 00


https://xenbits.xen.org/docs/unstable/misc/pvh.html

Author:  Octocontrabass [ Wed Jul 28, 2021 9:03 am ]
Post subject:  Re: QEMU: Booting x86_64 kernel via PVH

I'm no PVH expert, but I think you might run into trouble if you tell QEMU your kernel supports paravirtualization when it actually doesn't.

Code:
section .note

I'm not sure if it makes a difference, but Xen uses the section name ".note.Xen" in the ELFNOTE macro.

Code:
   dd 3 ; name size

This should be 4.

Code:
   db 'Xen' ; name

The missing 4th byte is a null terminator.

Author:  lukecreator [ Wed Jul 28, 2021 10:52 am ]
Post subject:  Re: QEMU: Booting x86_64 kernel via PVH

Octocontrabass wrote:
I'm no PVH expert, but I think you might run into trouble if you tell QEMU your kernel supports paravirtualization when it actually doesn't.

Code:
section .note

I'm not sure if it makes a difference, but Xen uses the section name ".note.Xen" in the ELFNOTE macro.

Code:
   dd 3 ; name size

This should be 4.

Code:
   db 'Xen' ; name

The missing 4th byte is a null terminator.


Thank you! You're probably right on the first part but I'm going to give it a shot anyway and see if everything doesn't blow up. Good to know that the name field absolutely requires null termination at the end; I have tried that already but I haven't tried putting the labeled note section so I'll give it a go and let you know what comes out of it.

EDIT: The section naming was it! Words cannot explain how ecstatic I am to see something so mediocre working right now haha

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/