[Bug 268418] UEFI boot; i386 VM ; crash before jump to kernel

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 16 Dec 2022 19:36:08 UTC

            Bug ID: 268418
           Summary: UEFI boot; i386 VM ; crash before jump to kernel
           Product: Base System
           Version: 13.1-RELEASE
          Hardware: i386
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: martin@bxlr.sk

Failure to uefi boot i386 VM on various hypervisors: qemu, VMware, VirtualBox.
Crash happens when jump to kernel is done.
I've created test qemu VM, used the bios from sysutils/edk2.

qemu-system-i386 -s -m 2048 -bios QEMU_UEFI-i386.fd -debugcon file:debug.log
-global isa-debugcon.iobase=0x402 \
-serial file:serial.log \
-hda FreeBSD-13.1-RELEASE-i386.qcow2


Loading kernel...
/boot/kernel/kernel text=0xfc084 text=0xb39210 text=0x5b5100 data=0xb0
data=0x109290+0x2d5540 syms=[0x4+0xe91c0+0x4+0x17caac]
Loading configured modules...
/boot/entropy size=0x1000
/etc/hostid size=0x25
Start @ 0x8fd000 ...
!!!! IA32 Exception Type - 06(#UD - Invalid Opcode)  CPU Apic ID - 00000000
EIP  - 000B0000, CS  - 00000010, EFLAGS - 00000082
EAX  - 7FED4E40, ECX - 0000000C, EDX - 7FEBF2D4, EBX - 7FEBF2D4
ESP  - 7FEBF25C, EBP - 7FEBF298, ESI - 80000007, EDI - 7F347010
DS   - 00000008, ES  - 00000008, FS  - 00000008, GS  - 00000008, SS - 00000008
CR0  - 40000033, CR2 - 00000000, CR3 - 00000000, CR4 - 00000640
DR0  - 00000000, DR1 - 00000000, DR2 - 00000000, DR3 - 00000000
DR6  - FFFF0FF0, DR7 - 00000400
GDTR - 7FC7F000 00000047, IDTR - 7F88D010 000007FF
LDTR - 00000000, TR - 00000000
!!!! Can't find image information. !!!!

With gdb I found the location where jump to kernel it being done:

   0x7f463a55:  mov    eax,ds:0x7f464734
   0x7f463a5a:  mov    ebx,edx
   0x7f463a5c:  push   0x10
   0x7f463a5e:  mov    esi,0x80000007
=> 0x7f463a63:  call   DWORD PTR [eax+0x18]

(gdb) x/16xw $eax
0x7fed4ea0:     0x00000000      0x00000000      0x00000000      0x00000000
0x7fed4eb0:     0x00000000      0x00000000      0x00000000      0x00000000
0x7fed4ec0:     0x00000000      0x00000000      0x00000000      0x00000000
0x7fed4ed0:     0x00000000      0x00000000      0x00000000      0x00000000

That explains the #UD exception. Problem is that kernel is not loaded at all:

(gdb) x/2xw 0x8fd000
0x8fd000:       0xffffffff      0xffffffff

I don't have i386 HW capable of UEFI boot, I can test this only in VM.

I'm not familiar with the UEFI, debugging this is a bit of challenge for me. If
I understand it correctly at this stage (after
I can't call printf any more.
I'm trying to get familiar with this but I thought opening PR would be worth

You are receiving this mail because:
You are the assignee for the bug.