I wanted to play a bit with how EFI apps works and tried with this simple code successfully running on my PC:
Code: Select all
int main() {
int a = 0x10;
asm volatile ( "pxor %%xmm0, %%xmm0\n\t"
"vmovd %0, %%xmm0\n\t"
:: "m" (a)
);
return 0;
}
Code: Select all
#include <efi.h>
#include <efilib.h>
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
InitializeLib(ImageHandle, SystemTable);
Print(L"Hello, world!\r\n");
UINT32 a = 0x10;
asm volatile ( "pxor %%xmm0, %%xmm0\n\t"
"vmovd %0, %%xmm0\n\t" :: "m" (a));
return EFI_SUCCESS;
}
However, when trying to run as an EFI app I only get a crash (I'm under UEFI ver 2.2). After setting up a qemu/gdb environment, here's the error I get:
Code: Select all
BdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,BdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,0x0)
BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,0x0)
Hello, world!
!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!!
RIP - 000000000627C06B, CS - 0000000000000038, RFLAGS - 0000000000010202
RAX - 0000000000000010, RCX - 00000000070EF340, RDX - 0000000000000000
RBX - 0000000000000000, RSP - 0000000007E8F700, RBP - 0000000007E8F720
RSI - 0000000000000000, RDI - 0000000007E8F540
R8 - 00000000000000AF, R9 - 0000000000002000, R10 - 0000000006296D58
R11 - 0000000000000000, R12 - 000000000700B218, R13 - 00000000079EC018
R14 - 0000000000000000, R15 - 0000000006B85818
DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030
GS - 0000000000000030, SS - 0000000000000030
CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000
CR4 - 0000000000000668, CR8 - 0000000000000000
DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 00000000079DC000 0000000000000047, LDTR - 0000000000000000
IDTR - 000000000751B018 0000000000000FFF, TR - 0000000000000000
FXSAVE_STATE - 0000000007E8F360
!!!! Find image based on IP(0x627C06B) (No PDB) (ImageBase=0000000006279000, EntryPoint=000000000627C000) !!!!
Code: Select all
vmod
Code: Select all
movd
The control registers indicates that I'm in protected mode so I don't understand why this would fail.
The Intel Software Developer’s Manual specifies errors that may arise depending of the prefix used but I don't know how to check that (nor did I find how to :/).
I'm starting qemu with
Code: Select all
qemu-system-x86_64 -drive if=pflash,format=raw,file=OVMF.4m.fd -cdrom boot.img -cpu host,+avx2 -enable-kvm -serial tcp::6666,server -s
Nathan