MIT操作系统课程CS6.828实验(1) —— 工具链安装

6.828中使用两类工具:

x86模拟器 - Qemu, 用于运行内核

编译工具链 - 汇编器,链接器,C编译器和调试器, 用于编译和测试内核

本节内容讲述下载和安装这些工具(假设已经熟悉常用Unix命令用法)

若是在Windows下搭建开发环境,需要安装Cygwin(确保安装flex和bison包,开发头文件需要)

以下介绍在Ubuntu下安装Qemu和编译器工具链

1. Qemu emulator安装

Qemu是现代的和快速的PC模拟器,6.828基于Qemu 1.7.0版本
但是,QEMU调试功能,尽管强大,但是有些不成熟,因此,强烈推荐使用MIT的补丁版本,

1) 下载MIT 6.828 QEMU补丁版本

$ git clone https://github.com/geofft/qemu.git -b 6.828-1.7.0

2) 在Linux上,可能需要安装SDL开发库以便获得图形VGA窗口,在Ubuntu下使用如下命令安装

$ sudo apt-get install libsdl1.2-dev

3)配置qemu代码

Linux: 
$ ./configure --disable-kvm [--prefix=PFX] [--target-list="i386-softmmu x86_64-softmmu"]
OS X: 
$ ./configure --disable-kvm --disable-sdl [--prefix=PFX] [--target-list="i386-softmmu x86_64-softmmu"] 

prefix参数指定QEMU安装目录; 若没有该参数,默认安装到 /usr/local
The target-list参数指定QEMU模拟的CPU架构

4) 编译

$ make

5) 安装

$ sudo make install

2. 编译工具链

编译工具链是是一些工具程序的集合,包括C编译器,汇编器,链接器,用于把代码转换为可执行二进制文件,在本课程中需要一个编译工具链,产生ELF二进制格式的32-bit Intel架构指令

Ubuntu下可以使用默认安装的编译器工具链,不过要做如下的检测即可,也可以自己安装编译器工具链,以下分别介绍

2.1 测试工具链

在Linux下已经一套适合6.828课程的工具链, 输入如下命令进行测试

$ objdump -i

该命令输出的第二行应该是elf32-i386
$ gcc -m32 -print-libgcc-file-name
该命令应该输出/usr/lib/gcc/i486-linux-gnu/version/libgcc.a或/usr/lib/gcc/x86_64-linux-gnu/version/32/libgcc.a

若这些命令的测试输出如上所述,那么就不用安装自己的编译工具链

若gcc命令失败,需要安装开发环境, 在Ubunu下,用如下命令

$ sudo apt-get install -y build-essential gdb


在64-bit机器上,需要安装32-bit的支持库,但出现如下错误时,

"__udivdi3 not found"和"————muldi3 not found"时,

在Ubuntu下,通过如下命令安装库文件即可

$ sudo apt-get install gcc-multilib

2.2 编译自己的工具链

下载如下工具包

ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2

http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
http://www.multiprecision.org/mpC/download/mpc-0.9.tar.gz
http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2
http://ftpmirror.gnu.org/gcc/gcc-4.6.1/gcc-core-4.6.1.tar.bz2
http://ftpmirror.gnu.org/gdb/gdb-7.3.1.tar.bz2
也可以使用这些包的最新版本, 

按如下流程安装这些工具包

tar xjf gmp-5.0.2.tar.bz2
cd gmp-5.0.2
./configure --prefix=/usr/local
make
make install             # This step may require privilege (sudo make install)
cd ..

tar xjf mpfr-3.0.1.tar.bz2
cd mpfr-3.0.1
./configure --prefix=/usr/local
make
make install             # This step may require privilege (sudo make install)
cd ..

tar xzf mpc-0.9.tar.gz
cd mpc-0.9
./configure --prefix=/usr/local
make
make install             # This step may require privilege (sudo make install)
cd ..


tar xjf binutils-2.21.1.tar.bz2
cd binutils-2.21.1
./configure --prefix=/usr/local --target=i386-jos-elf --disable-werror
make
make install             # This step may require privilege (sudo make install)
cd ..

i386-jos-elf-objdump -i
# Should produce output like:
# BFD header file version (GNU Binutils) 2.21.1
# elf32-i386
#  (header little endian, data little endian)
#   i386...


tar xjf gcc-core-4.6.1.tar.bz2
cd gcc-4.6.1
mkdir build              # GCC will not compile correctly unless you build in a separate directory
cd build
../configure --prefix=/usr/local \
    --target=i386-jos-elf --disable-werror \
    --disable-libssp --disable-libmudflap --with-newlib \
    --without-headers --enable-languages=c

  
  
MAC OS X 10.7 "LION" NOTE: The default clang compiler on Mac OS X 10.7 cannot build a working version of GCC. Use the following configure line to work around the problem (this has reported to work with OS X 10.9.4 withXCode 5.1.1 and its Command Line Tools package (for gcc): ../configure --prefix=/usr/local \ --target=i386-jos-elf --disable-werror \ --disable-libssp --disable-libmudflap --with-newlib \ --without-headers --enable-languages=c \ CC=/usr/bin/gcc-4.2 \ make all-gcc make install-gcc # This step may require privilege ( sudo make install-gcc) make all-target-libgcc make install-target-libgcc # This step may require privilege ( sudo make install-target-libgcc) cd ../.. i386-jos-elf-gcc -v # Should produce output like: # Using built-in specs. # COLLECT_GCC=i386-jos-elf-gcc # COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i386-jos-elf/4.6.1/lto-wrapper # Target: i386-jos-elf tar xjf gdb-7.3.1.tar.bz2 cd gdb-7.3.1 ./configure --prefix=/usr/local --target=i386-jos-elf --program-prefix=i386-jos-elf- \ --disable-werror make all make install # This step may require privilege ( sudo make install) cd ..

3. 参考


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值