使用Bochs运行程序
来源:互联网 发布:c语言24关键字 编辑:程序博客网 时间:2024/06/04 17:44
1. 概述
看《一个操作系统的实现》的时候,书中的第一个列子就是写了一个简单的代码,然后用bochs去仿真。然后觉得很有必要自己亲自动手去实现体验一下,以便加深理解。
2.安装 bochs
在linux中安装bochs十分简单,我自己用的是ubuntu-14.04,直接使用命令:
$ sudo apt-get install vgabios boots bximage
用apt-get命令安装的bochs只能运行程序,不能调试程序。需要调试程序的话就要用源码安装。
安装汇编NASM编译器:
$sudo apt-get install nasm
3.编译程序
书中的第一个程序就是一个现实字符串的程序boot.asm:
org 07c00hmov ax, csmov ds, axmov es, axcall DispStrjmp $DispStr:mov ax, BootMessagemov bp, axmov cx, 16mov ax, 01301hmov bx, 000chmov dl, 0int 10hretBootMessage: db "Hello, OS"times 510 - ($-$$) db 0dw 0xaa55
nasm boot.asm -o boot.bin
$ hexdump boot.bin 0000000 c88c d88e c08e 02e8 eb00 b8fe 7c1e c5890000010 10b9 b800 1301 0cbb b200 cd00 c310 65480000020 6c6c 2c6f 4f20 0053 0000 0000 0000 00000000030 0000 0000 0000 0000 0000 0000 0000 0000*00001f0 0000 0000 0000 0000 0000 0000 0000 aa550000200
$ bximage======================================================================== bximage Disk Image Creation Tool for Bochs $Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts Exp $========================================================================Do you want to create a floppy disk image or a hard disk image?Please type hd or fd. [hd] fdChoose the size of floppy disk image to create, in megabytes.Please type 0.16, 0.18, 0.32, 0.36, 0.72, 1.2, 1.44, 1.68, 1.72, or 2.88. [1.44] 1.44I will create a floppy image with cyl=80 heads=2 sectors per track=18 total sectors=2880 total bytes=1474560What should I name the image?[a.img] Writing: [] Done.I wrote 1474560 bytes to a.img.The following line should appear in your bochsrc: floppya: image="a.img", status=inserted
使用hexdump查看生成的映象文件格式,其实映象文件是一个空文件,内容被填充为0:
将boot.bin写入映象文件中(dd命令的用法参考:https://www.lifewire.com/dd-linux-command-4095971):
$ hexdump a.img 0000000 0000 0000 0000 0000 0000 0000 0000 0000*0168000zhaxia@zhaxia:~/zhaxia/linux/test$ ls -l-rw-rw-r-- 1 zhaxia zhaxia 1474560 May 13 22:40 a.img
$ dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc1+0 records in1+0 records out512 bytes (512 B) copied, 0.000273614 s, 1.9 MB/s
再此查看a.img文件的格式,发现boot.bin已经被写入a.img的开始处:
$ hexdump a.img 0000000 c88c d88e c08e 02e8 eb00 b8fe 7c1e c5890000010 10b9 b800 1301 0cbb b200 cd00 c310 65480000020 6c6c 2c6f 4f20 0053 0000 0000 0000 00000000030 0000 0000 0000 0000 0000 0000 0000 0000*00001f0 0000 0000 0000 0000 0000 0000 0000 aa550000200 0000 0000 0000 0000 0000 0000 0000 0000*0168000
bochs配置文件:
$ cat bochsrc ################################################################ Configuration file for Bochs################################################################ how much memory the emulated machine will havemegs: 32# filename of ROM imagesromimage: file=/usr/share/bochs/BIOS-bochs-latestvgaromimage: file=/usr/share/vgabios/vgabios.bin# what disk images will be usedfloppya: 1_44=a.img, status=inserted# choose the boot disk.boot: floppy# where do we send log messages?# log: bochsout.txtdisplay_library: sdl# disable the mousemouse: enabled=0# enable key mapping, using US layout as default.#keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map
运行bochs:
$ bochs -f bochsrc
运行成果,出现画面:
0 0
- 使用Bochs运行程序
- Ubuntu下使用bochs运行Linux 0.12
- 使用bochs运行Linux Kernel-2.4.0
- BOCHS 使用
- BOCHS 使用
- bochs 使用
- Bochs使用
- bochs运行a.img
- Bochs运行bootsect步骤
- bochs和gdb联合使用调试程序_开始
- bochs运行linux0.11系统
- Ubuntu下Bochs运行Xv6
- Ubuntu14.04安装运行bochs
- windows7 下 Bochs 运行 helloworld
- bochs的使用
- bochs安装以及使用
- 使用bochs调试MBR
- bochs的使用心得
- Android之error: 'const struct JNINativeInterface' has no member named 'callVoidMethod'
- C/C++中的计时函数
- SVM中的Dual
- 用一个数组实现两个堆栈,最大地使用数组的空间,只要有空间就能入栈成功
- 简易扁平旅游网H5开源项目
- 使用Bochs运行程序
- hiho一下 第150周 Demo Day
- C++普通函数,普通成员函数、静态成员函数的区别
- 抛硬币第一次出现连续两个正面的期望次数
- Sicily--1471. No Left Turns(BFS)
- Android RecyclerView 使用完全解析 体验艺术般的控件
- 函数指针数组
- 如何自学Android(强烈推荐)
- Java日期操作工具类