【发布时间】:2017-04-11 17:45:36
【问题描述】:
我知道以前有人问过这个问题,但其他答案似乎都没有解决我的问题。也许我错过了什么?
我知道 .iso 有效,因为我在 QEMU 中运行它并且它成功运行。那我做错了什么?
bits 16
xor ax, ax
start:
cld ; Set direction flag to forward
; Set up registers
mov ax, 07c0h ; Segment location which BIOS loads
add ax, 288 ; (4096 + 512) / 16 bytes
mov ss, ax ; Sets stack segment register
mov sp, 4096 ; Sets stack pointer register (offset of stack)
mov ax, 07c0h
mov ds, ax ; Sets data segment to where we're loaded
mov si, text ; Puts string into source index
call print_string ; Calls print string
jmp $ ; Infinite loop to prevent shutdown
print_string:
mov ah, 0eh ; System call for printing
xor bh, bh ; Sets BH register to 0
.repeat:
lodsb ; Loads byte into AL
cmp al, 0 ; Sees if AL is 0
je .done ; Jumps to done if AL is zero
int 10h ; Otherwise, print
jmp .repeat ; Repeat
.done:
ret
text db 'Test', 0
times 510 - ($ - $$) db 0 ; Pads 510 - (current location - start location) zeros
dw 0xAA55 ; Standard PC boot signature (takes up 2 bytes)
编辑:我在代码中添加了以下内容:
xor ax, ax
cld
xor bh, bh
为了创建 iso,我运行以下命令:
dd if=/dev/zero of=floppy.img bs=1024 count=1440
dd if=bootloader.bin of=floppy.img seek=0 count=1 conv=notrunc
mkdir iso
cp floppy.img iso/
mkisofs -o file.iso -b floppy.img iso
为了将 iso 刻录到我的 USB,我运行以下命令:
umount /dev/sdX
dd if=/home/mint/Downloads/file.iso of=/dev/sdX bs=4M && sync
【问题讨论】:
-
您在实际计算机上启动“.iso”的具体操作是什么?
-
您可能希望使用 CLD 将方向标志设置为向前,因为您依赖于 LODSB 的向前方向。您无法保证 BIOS 在到达您的 coe 之前设置了哪个方向。
-
对于Int 10h/ah=0eh,您可能希望将 BH 寄存器设置为 0,因为它用作要写入的页码。
-
开机时是否使用了CD-ROM? (我问是因为您提到您制作了 ISO,但不清楚您是否在真实 PC 上刻录了物理 CD)。我很好奇你启动 QEMU 的命令行是什么样子的。
-
真实硬件,特别是 EFI CSM,做额外检查:maybe this question will help?
标签: assembly x86 nasm bootloader bare-metal