【bochs启动img文件】问题解决了,给大家当教程吧

启动讨论 grub/grub2/syslinux/grub4dos/Lilo
回复
头像
NewUserFF
帖子: 413
注册时间: 2010-11-19 22:55

【bochs启动img文件】问题解决了,给大家当教程吧

#1

帖子 NewUserFF » 2012-04-24 15:42

刚才解决了,感觉网上的教程好少啊,这就当个教程吧,功能是在屏幕上显示一行文本,Hello OS,写入U盘并从U盘启动,可以看到这行字,说明程序没问题,刚才也从bochs中启动开了
首先给大家看看启动时用的system.asm文件,直接抄书本的,应该没问题

代码: 全选

	org 07c00h
	mov ax, cs
	mov ds, ax
	mov es, ax
	call DispStr
	jmp $

DispStr:
	mov ax, BootMessage
	mov bp, ax
	mov cx, 16
	mov ax, 01301h
	mov bx, 000ch
	mov dl, 0
	int 10h
	ret

BootMessage: db "Hello, OS!"
times 510-($-$$) db 0

dw 0xaa55
使用命令

代码: 全选

nasm system.asm -o system.bin
生成了system.bin文件,使用bochs带的bximage创建img映像:

代码: 全选

bximage 
========================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
          $Id: bximage.c 10933 2012-01-04 19:34:08Z vruppert $
========================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd

Choose 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.44
I will create a floppy image with
  cyl=80
  heads=2
  sectors per track=18
  total sectors=2880
  total bytes=1474560

What 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
然后用dd命令将system.bin的文件内容写入a.img:

代码: 全选

dd if=system.bin of=a.img count=1 bs=512 conv=notrunc
用ghex2查看a.img,发现文件已写入
然后将a.img放到$HOME/system/中,然后在主目录下创建.bochsrc文件,内容如下:

代码: 全选

###############################################################
# bochsrc.txt file for DLX Linux disk image.
###############################################################

# how much memory the emulated machine will have
megs: 32

# filename of ROM images
romimage: file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/bochs/VGABIOS-elpin-2.40

# what disk images will be used 
floppya: 1_44=$HOME/a.img, status=inserted

# hard disk
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
#ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4, spt=17

# choose the boot disk.
boot: floppy

# default config interface is textconfig.
#config_interface: textconfig
#config_interface: wx

#display_library: x
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga 

# where do we send log messages?
log: bochsout

# disable the mouse, since DLX is text only
mouse: enabled=0

# enable key mapping, using US layout as default.
#
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X windows.
# However, the key mapping tables are used in the paste function, so 
# in the DLX Linux example I'm enabling keyboard_mapping so that paste 
# will work. Cut&Paste is currently implemented on win32 and X windows only.

keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map
然后在$HOME/system文件夹下,执行命令bochs,启动虚拟机,按6开始模拟,弹出一个窗口,原来的窗口还带一个命令行,在命令行下输入c,开始运行,显示红色的Hello OS! 终于成功了,搞了两个下午!肯定有后人需要,给大家做个参考吧
头像
NewUserFF
帖子: 413
注册时间: 2010-11-19 22:55

Re: 【bochs启动img文件】问题解决了,给大家当教程吧

#2

帖子 NewUserFF » 2012-04-24 15:52

刚才试了一下,直接从system.bin中也能启动
月笑儿
帖子: 1
注册时间: 2013-08-26 15:33
系统: win7

Re: 【bochs启动img文件】问题解决了,给大家当教程吧

#4

帖子 月笑儿 » 2013-09-01 22:01

想问下LZ,这个bochs是安装在win上的还是linux上的啊?你也是用的于渊的那本书吗?
我的安装在win7上的,在D盘上,没有看hone/system文件夹啊.
回复