我正在尝试在实模式下编写一个将在 QEMU 中运行的示例“Hello World”。主机是运行 FreeBSD 14 的 64 位英特尔。
我尝试了以下方法:
这是boot.asm
文件:
format binary
org 0x7C00 ; Bootloader loaded at 0x7C00
start:
; Set up segment registers
mov ax, cs
mov ds, ax
mov es, ax
; Set up stack
mov ax, 0x0000
mov ss, ax
mov sp, 0x7C00
; Print message using BIOS interrupt
mov si, msg
print_loop:
lodsb ; Load next character
test al, al
jz halt ; Jump if null terminator
mov ah, 0x0E ; BIOS teletype function
int 0x10 ; Call BIOS
jmp print_loop
halt:
cli ; Disable interrupts
hlt ; Halt processor
msg db "Hello, World!", 0
times 510 - ($-$$) db 0 ; Pad to 510 bytes
dw 0xAA55 ; Boot signature
这是 makefile:
# Makefile for FreeBSD bootloader example
ASM = fasm
QEMU = qemu-system-i386
TARGET = boot.bin
SOURCE = boot.asm
all: $(TARGET)
$(TARGET): $(SOURCE)
$(ASM) $(SOURCE) $(TARGET)
run: $(TARGET)
$(QEMU) -fda boot.bin -serial stdio -display none
clean:
rm -f $(TARGET)
这是我组装文件并通过 qemu 运行后得到的结果:
$ make
fasm boot.asm boot.bin
flat assembler version 1.73.32 (16384 kilobytes memory)
2 passes, 512 bytes.
$ make run
qemu-system-i386 -fda boot.bin -serial stdio -display none
WARNING: Image format was not specified for 'boot.bin' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
一些问题:
- 我希望 -serial stdio 捕获示例引导加载程序显示的消息的输出,但没有显示任何消息。
- 如何指定 qemu 的文件格式以便不再显示警告。