由于使用Win10环境+Bochs,一直卡在bochs加载配置文件那里报错,于是一怒之下,在虚拟机上安装了ubuntu系统,于是环境变为了:
Ubuntu18.04(64位)、Nasm、Bochs
1 |
ubuntu$dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc |
第一步,要确保已经安装了gcc、g++:
1 2 |
ubuntu$sudo apt-get install build-essential ubuntu$sudo apt-get install g++ |
我在安装bochs时,提示需要安装x windows gui:
1 |
ubuntu$sudo apt-get install libx11-dev xserver-xorg-dev xorg-dev |
第二步,下载并安装bochs:
1 2 3 4 5 |
ubuntu$tar zxvf bochs-2.6.9.tar.gz ubuntu$cd bochs-2.6.9/ ubuntu$./configure --enable-debugger --enable-disasm ubuntu$make ubuntu$sudo make install |
第三步,建立bochs配置文件,bochsrc.bxrc:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#Configuration file for Bochs #how much memory the emulated machine will have megs: 32 #filename of ROM images romimage: file=$BXSHARE/BIOS-bochs-latest vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest #what disk images will be used floppya: 1_44=a.img, status=inserted #choose the boot disk. boot: floppy #where do we send log messages log: bochsout.txt #disable the mouse mouse: enabled=0 #enable key mapping, using US layout as default keyboard: keymap=$BXSHARE/keymaps/x11-pc-de.map |
这里有个坑,就是最后一行keyboard:的地方,网上搜到别人写的配置文件是keyboard_mapping:开头,可能大家用的bochs版本不同的原因,2.6.9版本需要改为keyboard:,以及路径改为$BXSHARE/开头。
另外,要确认romimage和vgaromimage路径,一般在/usr/local/share/doc/bochs下有示例文件,名为bochsrc-sample.txt,打开之后,可以看到romimage和vgaromimage路径,对于x11-pc-us.map的路径可以使用命令在/usr路径下查找:find -name x11-pc-us.map
第四步,将配置文件、a.img放在同一目录,然后运行bochs:
1 |
bochs -f bochsrc.bxrc |
正常运行的话,就会看到“Hello OS world!”的可爱界面了!
