作業系統實驗報告-熟悉實驗環境

來源:互聯網
上載者:User

標籤:

實驗材料準備

下載實驗包hit-oslab-linux-20110823.tar.gz(包含linux-0.11源碼、bochs虛擬機器等):

https://cms.hit.edu.cn/pluginfile.php/3329/mod_folder/content/6/hit-oslab/hit-oslab-linux-20110823.tar.gz?forcedownload=1

下載gcc-3.4-ubuntu.tar.gz(編譯linux-0.11需要用到的低版本gcc):

https://cms.hit.edu.cn/pluginfile.php/3329/mod_folder/content/6/hit-oslab/gcc-3.4-ubuntu.tar.gz?forcedownload=1
實驗環境設定(ubuntu-16.04.1-desktop-amd64)實驗材料

在~(使用者Home檔案夾)下建立workspace檔案夾,將hit-oslab-linux-20110823.tar.gz解壓到workspace下:

mkdir workspacecd workspacetar xzf hit-oslab-linux-20110823.tar.gz
gcc-3.4安裝

解壓gcc-3.4-ubuntu.tar.gz到/opt下:

cd /opt tar xzf ~/Downloads/gcc-3.4-ubuntu.tar.gz

安裝gcc-3.4(因為我的是64位系統,所以安裝參數為amd64;若為32位系統,參數應為i386):

cd gcc-3.4sudo ./inst.sh amd64
as86、ld86安裝(用於編譯和連結linux-0.11/boot下的bootsect.s和setup.s,它們採用as86彙編文法;而linux-0.11下的其他組合語言檔案採用gas的文法AT&T)

搜尋包含as86、ld86的包:

apt-cache search as86 ld86

執行結果:

bin86 - 16-bit x86 assembler and loader

安裝bin86:

sudo apt-get install bin86
64位系統需要安裝32位相容庫:
sudo apt-get install libc6-dev-i386 
C語言編譯環境
sudo apt-get install build-essential
安裝IDE
sudo apt-get install vim cscope exuberant-ctags
編譯核心
1 cd ~/workspace/oslab/linux-0.112 make

編譯中斷,輸出錯誤資訊:

In file included from /usr/include/linux/fs.h:10,                 from tools/build.c:28:/usr/include/linux/ioctl.h:4:23: asm/ioctl.h: No such file or directoryIn file included from /usr/include/linux/fs.h:11,                 from tools/build.c:28:/usr/include/linux/types.h:4:23: asm/types.h: No such file or directoryIn file included from /usr/include/linux/types.h:8,                 from /usr/include/linux/fs.h:11,                 from tools/build.c:28:/usr/include/linux/posix_types.h:35:29: asm/posix_types.h: No such file or directoryIn file included from /usr/include/linux/fs.h:11,                 from tools/build.c:28:/usr/include/linux/types.h:27: error: syntax error before "__le16"/usr/include/linux/types.h:28: error: syntax error before "__be16"/usr/include/linux/types.h:29: error: syntax error before "__le32"/usr/include/linux/types.h:30: error: syntax error before "__be32"/usr/include/linux/types.h:31: error: syntax error before "__le64"/usr/include/linux/types.h:32: error: syntax error before "__be64"/usr/include/linux/types.h:34: error: syntax error before "__sum16"/usr/include/linux/types.h:35: error: syntax error before "__wsum"In file included from tools/build.c:28:/usr/include/linux/fs.h:43: error: syntax error before "__u64"/usr/include/linux/fs.h:45: error: syntax error before "minlen"make: *** [tools/build] Error 1

google搜尋得知是因為64位linux的asm目錄為:

/usr/include/x86_64-linux-gnu/asm

make找不到檔案從而導致編譯中斷

解決方案(建立連結):

sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
運行和調試運行

運行編譯好的核心,在oslab目錄下:

./run

出現錯誤:

./bochs/bochs-gdb: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory

列印動態連結配置:

ldconfig -p | grep libSM.so.6

libSM.so.6的連結資訊:

libSM.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libSM.so.6

我們需要的是32位的。搜尋庫對應的包名稱:

apt-file search libSM.so.6

列印結果:

libsm6: /usr/lib/x86_64-linux-gnu/libSM.so.6libsm6: /usr/lib/x86_64-linux-gnu/libSM.so.6.0.1

得到其對應的包名為libsm6,安裝對應的32位庫:

sudo apt-get install libsm6:i386

再次嘗試,出現錯誤:

./bochs/bochs-gdb: error while loading shared libraries: libXpm.so.4: cannot open shared object file: No such file or directory

也可按以上方法解決,不過這裡用了另一個工具:

dpkg-query -S libXpm.so.4

同理解決之,再次嘗試:

./run

成功運行!

調試彙編級調試
./dbg-asm

操作參考Bochs使用手冊

C語言級調試
./dbg-c

Ctrl+Alt+T開啟另一個終端視窗,進到~/workspace/oslab下執行:

./rungdb

出現兩次庫不存在錯誤,按照上面的方法安裝對應32位庫解決後運行成功:

操作參考GDB的Manuel:

man gdb
Ubuntu與Linux-0.11之間的檔案交換掛載Linux-0.11
./mount-hdc

mount-hdc是一個shell指令碼:

1 #!/bin/sh2 export OSLAB_PATH=$(dirname `which $0`)3 mount -t minix -o loop,offset=1024 $OSLAB_PATH/hdc-0.11.img $OSLAB_PATH/hdc 

第1行 指明指令碼使用的shell

第2行 將調用本指令碼的目錄設定為oslab的目錄

第3行 根據mount的manual手冊,

    -t minix 表示要掛載的檔案系統類型為minix

    -o[ption] 可以有3個參數(參考losetup的manual):

      loop 可以指定檔案所映射的迴環裝置;若不指定,則由mount自動搜尋

      offset 指定檔案或裝置中資料起始位置在該檔案或裝置中的位移

      sizelimit 從offset開始算起檔案或裝置的最大大小

   故此行將$OSLAB_PATH/hdc-0.11.img映射到mount搜尋到的裝置中,檔案系統為minix,資料起始位移為1024byte,再掛載到$OSLAB_PATH/hdc目錄下。

這樣Ubuntu就可以在$OSLAB_PATH/hdc下訪問Linux-0.11的檔案了。

卸載Linux-0.11

在oslab目錄下:

umount hdc

注意

1:不要在0.11核心啟動並執行時候mount鏡像檔案,否則可能會損壞檔案系統。同理,也不要在已經mount的時候運行0.11核心;

2:在關閉Bochs之前,需要先在Linux-0.11的命令列運行“sync”,確保所有快取資料都存檔後,再關閉Bochs。

參考

as86、ld86安裝

核心編譯asm不存在錯誤

loop device迴環裝置

 

作業系統實驗報告-熟悉實驗環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.