How can I use Bochs to run Assembly code?

前端 未结 3 2033
滥情空心
滥情空心 2021-02-08 23:55

I want to use Bochs as an 8086 emulator. Is there an easy way to do this? What I want is something like emu8086 (http://www.emu8086.com/).

3条回答
  •  再見小時候
    2021-02-09 00:39

    sudo apt-get install bochs bochs-sdl
    
    printf 'ata0-master: type=disk, path="main.img", mode=flat, cylinders=1, heads=1, spt=1
    boot: disk
    display_library: sdl
    megs: 128
    ' > .bochsrc
    
    bochs -q
    

    worked for me on Ubuntu 14.04, Bochs 2.4.6 with a 512 byte long boot sector main.img.

    • cylinders=1, heads=1, spt=1 specifies the disk size, and must match your image! Here we set everything to 1 to mean 1 cylinder, which is 512 bytes like our image file.
    • display_library: sdl may be needed because of an Ubuntu packaging bug

    main.img was generated from main.asm:

    org 0x7c00
    bits 16
    cli
    mov ax, 0x0E61
    int 0x10
    hlt
    times 510 - ($-$$) db 0
    dw 0xaa55
    

    Then:

    nasm -f bin -o main.img main.asm
    

    This images uses the BIOS to print a single character a to the screen.

    It is possible to avoid the creation of the .bochsrc file by using the following command line:

    bochs \
        -qf /dev/null \
        'ata0-master: type=disk, path="main.img", mode=flat, cylinders=1, heads=1, spt=1' \
        'boot: disk' \
        'display_library: sdl' \
        'megs: 128'
    

    The -qf /dev/null part is ugly, but it is the only way I've managed to automatically skip the menu screen:

    • -q or -n always ask for it, and I have to hit 6 for it to run afterwards
    • -qn <(echo ...) also worked, but uses a Bash extension which would fail on my Makefile

    QEMU's interface was easier to get started with, so I recommend using it instead.

    GitHub repository with this example: https://github.com/cirosantilli/x86-bare-metal-examples/blob/cba0757990843f412b14dffad45467ad0034d286/Makefile#L33

提交回复
热议问题