您的位置:首页 > 运维架构 > Linux

自己动手搭建 Linux 0.12 编译环境 — Bochs

2013-03-26 19:39 591 查看
从一篇开始,我们慢慢会展开主题。

Linux 0.12已经是一个可以运行起来的OS,它需要一个Intel 386的硬件环境来支撑,选择Bochs作为虚拟环境完全是因为当初学习Oldlinux的缘故,慢慢地也就懒得去尝试其他的虚拟机了,这部分我会在闲下来后或者觉得有必要尝试更优秀的软件的时候去做它。因此此刻此景,我们还是将就一下吧,如果你在使用qemu虚拟机,完全可以直接跳过~

[Bochs].

我使用的是Windows版本的,大家最好去下载Bochs-2.6最新版本,最新版模拟的更好。如果你直接去Bochs的Home Page下载,可能进不去,貌似被墙了~,不过在Oldlinux论坛里已经下载好了,可以去这里把它down下来。如果在Linux下可以使用wget工具直接下载。

[配置].

在安装目录下面有个“bochsrc-sample.txt”文件,将它稍加改动就可以用了。

#=======================================================================

# ROMIMAGE:

# The ROM BIOS controls what the PC does when it first powers on.

# Normally, you can use a precompiled BIOS in the source or binary

# distribution called BIOS-bochs-latest. The ROM BIOS is usually loaded

# starting at address 0xf0000, and it is exactly 64k long. Another option

# is 128k BIOS which is loaded at address 0xe0000.

# You can also use the environment variable $BXSHARE to specify the

# location of the BIOS.

# The usage of external large BIOS images (up to 512k) at memory top is

# now supported, but we still recommend to use the BIOS distributed with

# Bochs. The start address optional, since it can be calculated from image size.

#=======================================================================

romimage: file=$BXSHARE/BIOS-bochs-latest

从描述中可以看到一些信息,比如0xF0000, 0xE0000,这些是什么,待会给幅图片就清楚了。这个ROM BIOS是可以自己compile in the source的。

#=======================================================================

# VGAROMIMAGE

# You now need to load a VGA ROM BIOS into C0000.

#=======================================================================

vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest

这个ROM用于VGA,被放于0xC0000处,在我的网易博客里面有一个系列的文章简单的介绍了如何客制化一个自己的VGA ROM。

下面截取来自《剖析》里面的一幅图片来说明BIOS ROM在内存的位置:



#=======================================================================

# ATA0, ATA1, ATA2, ATA3

# ATA controller for hard disks and cdroms

#

# ata[0-3]: enabled=[0|1], ioaddr1=addr, ioaddr2=addr, irq=number

#

# These options enables up to 4 ata channels. For each channel

# the two base io addresses and the irq must be specified.

#

# ata0 and ata1 are enabled by default with the values shown below

#=======================================================================

ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14

IDE控制器设定,I/O地址0x1F0~0x1F7 & 0x3F6,14号中断。





#=======================================================================

# ATA[0-3]-MASTER, ATA[0-3]-SL***E

#

# This defines the type and characteristics of all attached ata devices:

# type= type of attached device [disk|cdrom]

# mode= only valid for disks [flat|concat|external|dll|sparse|vmware3]

# [vmware4|undoable|growing|volatile|vpc|vvfat]

# path= path of the image / directory

# cylinders= only valid for disks

# heads= only valid for disks

# spt= only valid for disks

# status= only valid for cdroms [inserted|ejected]

# biosdetect= type of biosdetection [none|auto], only for disks on ata0 [cmos]

# translation=type of translation of the bios, only for disks [none|lba|large|rechs|auto]

# model= string returned by identify device command

# journal= optional filename of the redolog for undoable, volatile and vvfat disks

#

# Point this at a hard disk image file, cdrom iso file, or physical cdrom

# device. To create a hard disk image, try running bximage. It will help you

# choose the size and then suggest a line that works with it.

#

# In UNIX it may be possible to use a raw device as a Bochs hard disk,

# but WE DON'T RECOMMEND IT. In Windows there is no easy way.

#

# In windows, the drive letter + colon notation should be used for cdroms.

# Depending on versions of windows and drivers, you may only be able to

# access the "first" cdrom in the system. On MacOSX, use path="drive"

# to access the physical drive.

#

# The path is mandatory for hard disks. Disk geometry autodetection works with

# images created by bximage if CHS is set to 0/0/0 (cylinders are calculated

# using heads=16 and spt=63). For other hard disk images and modes the

# cylinders, heads, and spt are mandatory. In all cases the disk size reported

# from the image must be exactly C*H*S*512.

#

# Default values are:

# mode=flat, biosdetect=auto, translation=auto, model="Generic 1234"

#

# The biosdetect option has currently no effect on the bios

#=======================================================================

ata0-master: type=disk, path="hd64-0.1x.img", mode=flat, cylinders=130, heads=16, spt=63

挂载的第一块硬盘位置,对于mode, cylinders, heads, spt 这些值我们可以用Bochs自带工具“bximage.exe”来产生,它用来***出一个“硬盘”文件。注意,它其实就是一个空空如也的有大小的文件而已,还不能叫做硬盘,因为它还没有经过分区。一个IDE控制器可以控制两块硬盘,一块硬盘最多只能分出4个分区,因此你还可以为ata0增加一块硬盘,用ata0-slave来设定它的硬盘参数,设定方法和第一块硬盘一致。

#=======================================================================

# BOOT:

# This defines the boot sequence. Now you can specify up to 3 boot drives,

# which can be 'floppy', 'disk', 'cdrom' or 'network' (boot ROM).

# Legacy 'a' and 'c' are also supported.

# Examples:

# boot: floppy

# boot: cdrom, disk

# boot: network, disk

# boot: cdrom, floppy, disk

#=======================================================================

boot: disk

启动位置,这个默认是从硬盘启动的,也是我们想要的设定,因为搭建Linux 0.12的编译环境对于软盘可太小了。后面我们在陆续写***出Linux 0.12启动硬盘的方法。

说白了,整个“bochsrc-sample.txt”文件我们只需,改一处硬盘设定就可以完全使用它来启动我们的Bochs!

[调试].

Bochs自带了调试功能,当然,它是调试内核的,非常方便且简单易用上手快。

它的调试工具是“bochsdbg.exe”,在安装目录下面,通常可以写一个.dat脚本即可双击即可启动:

"[工具路径]\bochsdbg.exe" -q -f [Bochs配置文件全称(包括路径)]。

比如“break”命令,可以设定断点地址,是物理地址喔~亲!比如“c”命令,就是继续执行的意思,“n/s”就是单步执行,“x/xp”可以查看内存内容等等,好多的。如果你经常工作在Linux环境下,那么你会不由自主的用“h/help”查看一下帮助,是的,这里也可以喔。

<bochs:1> h

h|help - show list of debugger commands

h|help command - show short command description

-*- Debugger control -*-

help, q|quit|exit, set, instrument, show, trace, trace-reg,

trace-mem, u|disasm, ldsym, slist

-*- Execution control -*-

c|cont|continue, s|step, p|n|next, modebp, vmexitbp

-*- Breakpoint management -*-

vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,

bpe, bpd, d|del|delete, watch, unwatch

-*- CPU and memory contents -*-

x, xp, setpmem, writemem, crc, info,

r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,

page, set, ptime, print-stack, ?|calc

-*- Working with bochs param tree -*-

show "param", restore

若想进一步了解每个命令的用法,我们只需“h [命令]”即可。

<bochs:2> h xp

x /nuf <addr> - examine memory at linear address

xp /nuf <addr> - examine memory at physical address

nuf is a sequence of numbers (how much values to display)

and one or more of the [mxduotcsibhwg] format specificators:

x,d,u,o,t,c,s,i select the format of the output (they stand for

hex, decimal, unsigned, octal, binary, char, asciiz, instr)

b,h,w,g select the size of a data element (for byte, half-word,

word and giant word)

m selects an alternative output format (memory dump)

如果你觉得这样了解用法比较不适应,都是英文,哎~~,那你就google咯!记得要用google喔~

[问题].

在文章的最后,有个问题顺便提一下,网上也可以搜到答案,就是“Bochs CPU占用率过高”的问题,我自己也测试过几组参数,确认到网上的答案应该是最佳的了。



还OK,delay的程度可以接受,这里指的是键盘输入的延迟,我也试过调节“keyboard: serial_delay”参数,没用,一样有delay,可能是受到clock的限制了。如果有网友知道更佳的参数配置,可记得更贴分享一下喔^_^
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: