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的文件格式,因此不再显示警告。
-display curses
-drive format=raw,file=boot.bin,if=floppy