Example of printing a string on the serial with a custom 32bits BIOS - P1kachu/qemu-hvf GitHub Wiki
p1kachu@GreyLabOfSteel:custom-32bits-bios$ cat Makefile
all:
$(CC) -m32 -nostartfiles bios.S
objcopy a.out custom_bios -O binary --only-section=.text
rm a.out
objdump -D -b binary -mi386 -Maddr32,data32 custom_bios
p1kachu@GreyLabOfSteel:custom-32bits-bios$ cat bios.S
.intel_syntax noprefix
#define ROM_SIZE (1 << 16)
fw_start:
main:
xor eax, eax
mov dx, 0x3f8
xor ecx, ecx
not ecx
mov edi, string - fw_start
cld
repne scasb
mov edi, string - fw_start
not ecx
dec ecx
.Lprint_loop:
mov al, [edi]
out dx, al
inc edi
dec ecx
jnz .Lprint_loop
.Lwait:
hlt
jmp .Lwait
string:
.string "Custom BIOS succesfully launched\n"
.space ROM_SIZE - (. - fw_start + fw_end - _start)
.global _start
// fw_end - 16
_start:
jmp main
.space 16 - (. - _start)
fw_end:
p1kachu@GreyLabOfSteel:qemu-hvf$ ./configure --extra-cflags="-D CONFIG_HVF" --extra-ldflags="-framework Hypervisor" --target-list=x86_64-softmmu
p1kachu@GreyLabOfSteel:qemu-hvf$ make -j8
p1kachu@GreyLabOfSteel:qemu-hvf$ ./x86_64-softmmu/qemu-system-x86_64 --machine accel=hvf -bios ../custom_bios