UEFI Haiku boot loader for x86 (32-bit)

someone mentioned the ‘hybrid boot’ in an other topic, i.e. booting kernel_x86_64 from 32-bit EFI so I thought I give it a try.

first attempt:

  • load 64-bit kernel from the 32-bit EFI loader
  • set up initial page tables
  • switch to long mode
  • jump to kernel :sunglasses:

at least I can get some debug output:

Calling ExitBootServices. So long, EFI!
Switched to legacy serial output
long_enter_kernel(pageDirectory: 0x7bdc6000, kernelArgs: 0x8270e000, kernelEntry: 0x800644c0, sp: 0x8270e000, gBootGDTDescriptor: 0x7e6dc0e4)
ABCDEFGHWelcome to kernel debugger output!
Haiku revision: hrev56443+4+dirty, debug level: 2
CPU: no microcode provided
CPU 0: type 0 family 15 extended_family 0 model 11 extended_model 6 stepping 1, string 'GenuineIntel'
CPU 0: vendor 'Intel' model name 'QEMU Virtual CPU version 2.5+'
No CPU topology information available.
CPU 0: apic id 0, package 0, core 0, smt 0
CPU 0: features: fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clfsh mmx fxsr sse sse2 sse3 cx16 x2apic hypervisor syscall nx long 
CPU 0: patch_level 0
reserve_io_interrupt_vectors: reserved 16 vectors starting from 0
PANIC: error allocating early page!

Welcome to Kernel Debugging Land...
Thread 0 "" running on CPU 0
stack trace for thread 0 ""
    kernel stack: 0x0000000000000000 to 0x0000000000000000
frame                       caller             <image>:function + offset
 0 ffffffff8270d988 (+  24) ffffffff8014524c   
 1 ffffffff8270d9a0 (+  80) ffffffff800aeab8   
 2 ffffffff8270d9f0 (+  96) ffffffff800b00d3   
 3 ffffffff8270da50 (+  80) ffffffff800b046e   
 4 ffffffff8270daa0 (+ 240) ffffffff800b07c7   
 5 ffffffff8270db90 (+  96) ffffffff80128745   
 6 ffffffff8270dbf0 (+  96) ffffffff801172f6   
 7 ffffffff8270dc50 (+ 176) ffffffff801177ef   
 8 ffffffff8270dd00 (+ 176) ffffffff80118858   
 9 ffffffff8270ddb0 (+  48) ffffffff80114790   
10 ffffffff8270dde0 (+  96) ffffffff8011cff2   
11 ffffffff8270de40 (+  80) ffffffff8011c281   
12 ffffffff8270de90 (+ 128) ffffffff8011485c   
13 ffffffff8270df10 (+ 176) ffffffff8012a21b   
14 ffffffff8270dfc0 (+  48) ffffffff8006463c   
15 ffffffff8270dff0 (+2106531856) 000000000000a090   
kdebug> [david@fedora generated.x86]$ 

command line:

qemu-system-x86_64 -enable-kvm -m 2048 \
  -bios /usr/share/edk2/ovmf-ia32/OVMF_CODE.fd \
  -hda objects/haiku/x86_gcc2/release/efi/system/boot/esp.image \
  -hdb ../generated.x86_64/haiku-minimum.image -serial stdio -vga cirrus

my dev branch on github - not for the faint-hearted as the code is rather ugly at this point:
https://github.com/davidkaroly/haiku/tree/hybrid-boot

so as a first impression it’s probably not very difficult to get this mixed mode boot working

edit: after applying a few more hacks, I was able to get a successful boot to desktop in qemu. (no SMP, no error checking yet)
Still, it will be a good question how to integrate this mixed-mode boot in upstream Haiku sources.

18 Likes