Test native x86 programs, building bootable images/drives

不羁的心 提交于 2019-12-21 23:24:08

问题


I have the next problem: I'm working with NASM and building some native and compiling it on this way:

nasm -f bin source -o out

I'm getting my native program for x86.

And now the most interesting, how can I make it bootable and then test it?

As I think there are 3 ways to make bootable ( but for me, all they has failed :( )

  • using mkbt utility ( or another soft which is similar ) to write it to floppy disk
  • building ISO image, with editing bootable sector in it
  • manually write memory sector to usb/sd-card or another driver

As for testing, all times rebooting PC is very bad, so it's better to use some Virtual OS soft like Vbox, VMWare etc..

So I used VBox for this. For building ISO - I used CDBurnerXP.

With cdburner I have optioned bootable sector for my native program, then choose new ISO in Vbox as disk from which will my program boot.

The result is always empty screen, no errors are showed, just nothing...

I think, that I have many errors...

Using mkbt, I can't write it to usb driver.... I don't have flooppy now, so I'm not able to write image to floppy, mkbt can't write to usb... :(

What do I wrong?

How can I solve my problem?


回答1:


Just do this:
nasm -f bin -o boot.bin boot.asm
qemu -boot order=a -fda boot.bin

And you should see the message. For other emulators you'll want to pad the image to 1474560 bytes.

boot.asm:

        BITS 16
        ORG 0
        jmp 0x07c0:start

start:
        mov ax, cs
        mov ds, ax

        mov si, msg
        call print_string

hang:
        jmp hang

print_string:
        cld
        lodsb
        or al, al
        jz .done
        mov ah, 0x0E
        int 0x10
        jmp print_string
.done:
        ret

msg:    db 'Hello World!', 13, 10, 0

        times 510-($-$$) db 0
        dw 0xAA55


来源:https://stackoverflow.com/questions/9320423/test-native-x86-programs-building-bootable-images-drives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!