mit6.828-lab0:環(huán)境配置
文章是markdown源碼,為了閱讀體驗(yàn),請(qǐng)全文復(fù)制到任意markdown編輯器
在線閱讀地址:https://www.kinvy.cn/posts/tech/os/mit6.828-lab0/
操作系統(tǒng):Ubuntu-18.04.5-64bit(VM虛擬機(jī))/ Ubuntu20.04(WSL2)
課程主頁:[mit6.828(2018)](https://pdos.csail.mit.edu/6.828/2018/schedule.html)
環(huán)境配置 [參考](https://pdos.csail.mit.edu/6.828/2018/tools.html)
注:mit6.828 課程從2019年開始使用 RISC_V 處理器,不再使用x86(IA-32)架構(gòu)。
## 編譯工具鏈
### 1.測(cè)試編譯工具
```shell
$objdump -i
```
<img src="https://kinvy-images.oss-cn-beijing.aliyuncs.com/Images/image-20210727123132004.png" title="" alt="image-20210727123132004" data-align="center">
```shell
$gcc -m32 -print-libgcc-file-name ? ? ? ? #測(cè)試gcc
```
上面這條命令是測(cè)試gcc的,一般系統(tǒng)是沒有g(shù)cc的,需要安裝
安裝gcc , gdb, git, vim
```shell
$sudo apt-get install -y build-essential gdb git vim
```
安裝32位的支持庫
```shell
$sudo apt-get install gcc-multilib
```
### 2. 編譯安裝工具鏈
#### 2.1下載以下工具包
- [ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2](ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2)
- https://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.bz2
- http://www.multiprecision.org/downloads/mpc-0.9.tar.gz
- http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2
- http://ftpmirror.gnu.org/gcc/gcc-4.6.4/gcc-core-4.6.4.tar.bz2
- http://ftpmirror.gnu.org/gdb/gdb-7.3.1.tar.bz2
以上鏈接課程官網(wǎng)給出的,部分鏈接已失效,可復(fù)制鏈接前面部分網(wǎng)址,下載相應(yīng)版本的軟件包。
所有工具包也可在網(wǎng)盤下載:
https://pan.baidu.com/s/13vcPrmgT8p0zF-GD-d-cJQ
提取碼:yr1r
#### 2.2 編譯安裝
為了方便,將以上6個(gè)壓縮包放在一個(gè)文件夾下 ,`~/download/mit6.828`
文件夾結(jié)構(gòu)

> 以下的操作都是在 `~/download/mit6.828` 目錄下
1. 安裝gmp-5.0.2
? ?```shell
? ?$tar xjf gmp-5.0.2.tar.bz2
? ?$cd gmp-5.0.2
? ?$./configure --prefix=/usr/local ? # 可能的錯(cuò)誤:No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
? ?$make
? ?$sudo make install ? ? ? ? ? ?
? ?$cd ..
? ?```
? ?逐條執(zhí)行命令,每執(zhí)行一條后,輸出無 `error` 就可往下執(zhí)行,后面幾個(gè)安裝包也是一樣的
? ?> 可能的錯(cuò)誤是第3個(gè)命令,如果報(bào)錯(cuò),執(zhí)行以下命令,然后再次執(zhí)行第3行命令
? ?```shell
? ?$sudo apt install m4
? ?```
2. 安裝mpfr-3.1.2
? ?```shell
? ?$tar xjf mpfr-3.1.2.tar.bz2
? ?$cd mpfr-3.1.2
? ?$./configure --prefix=/usr/local
? ?$make
? ?$sudo make install ? ? ? ? ?
? ?$cd ..
? ?```
3. 安裝mpc-0.9
? ?```shell
? ?$tar xzf mpc-0.9.tar.gz
? ?$cd mpc-0.9
? ?$./configure --prefix=/usr/local
? ?$make
? ?$sudo make install ? ? ? ? ? ?
? ?$cd ..
? ?```
4. 安裝binutils-2.21.1
? ?```shell
? ?$tar xjf binutils-2.21.1.tar.bz2
? ?$cd binutils-2.21.1
? ?$./configure --prefix=/usr/local --target=i386-jos-elf --disable-werror
? ?$make
? ?$sudo make install ? ? ? ? ? ? # This step may require privilege (sudo make install)
? ?$cd ..
? ?
? ?#測(cè)試
? ?$i386-jos-elf-objdump -i
? ?# 成功安裝會(huì)輸出類似下面的信息
? ?# BFD header file version (GNU Binutils) 2.21.1
? ?# elf32-i386
? ?# ?(header little endian, data little endian)
? ?# ? i386...
? ?```
5. 安裝gcc-core-4.6.4
? ?```shell
? ?$tar xjf gcc-core-4.6.4.tar.bz2
? ?$cd gcc-4.6.4
? ?$mkdir build ? ? ? ? ?
? ?$cd build
? ?$../configure --prefix=/usr/local \
? ? ? ?--target=i386-jos-elf --disable-werror \
? ? ? ?--disable-libssp --disable-libmudflap --with-newlib \
? ? ? ?--without-headers --enable-languages=c MAKEINFO=missing
? ?$make all-gcc
? ?$sudo make install-gcc ? ? ? ?
? ?$make all-target-libgcc ? ? ? ?#可能會(huì)報(bào)錯(cuò) [configure-target-libgcc] Error 1
? ?$sudo make install-target-libgcc ?
? ?$cd ../..
? ?
? ?#測(cè)試
? ?$i386-jos-elf-gcc -v
? ?# 成功安裝會(huì)輸出類似下面的信息
? ?# Using built-in specs.
? ?# COLLECT_GCC=i386-jos-elf-gcc
? ?# COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i386-jos-elf/4.6.4/lto-wrapper
? ?# Target: i386-jos-elf
? ?```
? ?> 執(zhí)行11行命令可能會(huì)報(bào)錯(cuò),如果報(bào)錯(cuò),執(zhí)行以下命令,然后再次執(zhí)行第11行命令
? ?```shell
? ?$export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
? ?```
6. 安裝gdb-7.3.1
? ?```shell
? ?$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 ? ? ? ? ? ?#可能的錯(cuò)誤 no termcap library found
? ?$sudo make install ? ? ? ?
? ?$cd ..
? ?```
? ?> 可能報(bào)錯(cuò)的命令第5個(gè),如果出現(xiàn)錯(cuò)誤,執(zhí)行以下命令,然后再執(zhí)行該命令
? ?```shell
? ?$wget http://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
? ?$tar -zxv -f termcap-1.3.1.tar.gz
? ?$cd termcap-1.3.1
? ?$ ./configure
? ?$make
? ?$sudo make install
? ?$cd ..
? ?```
## 安裝 QEMU
### 1. 安裝工具包
```shell
$sudo apt install libsdl1.2-dev libtool-bin libglib2.0-dev ?libz-dev ?libpixman-1-dev
$sudo apt install python2
```
安裝python2可能會(huì)出錯(cuò),參考https://blog.csdn.net/u010879745/article/details/125115600 解決
```bash
$ cd /usr/local/lib
$ sudo rm libgmp*
$ sudo apt --fix-broken install
$ sudo apt update
```
完成以上步驟回到之前的工作目錄繼續(xù)
### 2. 下載qemu
qemu需要用6.828定制的
```shell
$git clone https://github.com/mit-pdos/6.828-qemu.git qemu
```
### 3. 編譯安裝
```shell
$./configure --disable-kvm --disable-werror --prefix=/usr/local ?\
? ? --target-list="i386-softmmu x86_64-softmmu" --python=python2
$make
$sudo make install
```
可能的錯(cuò)誤:
1. 缺少一個(gè)頭文件,錯(cuò)誤如下
? ?```shell
? ?qga/commands-posix.c: In function ‘dev_major_minor’:
? ?qga/commands-posix.c:633:13: error: In the GNU C Library, "major" is defined
? ? by <sys/sysmacros.h>. For historical compatibility, it is
? ? currently defined by <sys/types.h> as well, but we plan to
? ? remove this soon. To use "major", include <sys/sysmacros.h>
? ? directly. If you did not intend to use a system-defined macro
? ? "major", you should undefine it after including <sys/types.h>. [-Werror]
? ? ? ? ? ? *devmajor = major(st.st_rdev);
? ? ? ? ? ? ? ? ^~~~~~~~~~~~~~~~~~~~~~~~~~ ?
? ?```
? ?> 解決:在 qga/commands-posix.c文件中的 #include <sys/types.h> 下面增加#include <sys/sysmacros.h>即可
? ?
### 4.測(cè)試
```shell
#下載實(shí)驗(yàn)源碼
$git clone https://pdos.csail.mit.edu/6.828/2018/jos.git lab
$cd lab
$make
$make qemu-noxl
```
make 可能報(bào)錯(cuò)
```bash
/usr/local/libexec/gcc/i386-jos-elf/4.6.4/cc1: error while loading shared libraries: libmpc.so.2:
```
解決方法參考:https://stackoverflow.com/questions/19625451/cc1-error-while-loading-shared-libraries-libmpc-so-2-cannot-open-shared-objec
測(cè)試成功
