--- title: Lab38: ARM Environment (2015q1 Week #2) toc: no ... 預期目標 ------------ - 驗證 `Introduction to ARM Architecture`_ 簡報內容 - 學習 GNU Toolchain - 使用 QEMU 作為指令集模擬器 預先準備動作 ------------------- * 在自己的電腦中,安裝 `Lubuntu`_ 14.10 作業系統 (版本太舊的話,後續操作可能會失敗) - 虛擬機器環境 (不建議): `透過 VirtualBox 安裝 LubVirtualBox 安裝 Lubuntu`_ * 安裝相關開發工具 .. code-block:: prettyprint sudo apt-get update sudo apt-get install build-essential git-core sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf sudo apt-get install qemu-user qemu-system-arm * 使用 bash 作為 shell,避免不相容的狀況 .. code-block:: prettyprint sudo apt-get install bash * 關於 GNU/Linux 指令,請參閱 `鳥哥的 Linux 私房菜`_ - 本系列課程全程使用 GNU/Linux,全世界有十幾億台裝置內建 Linux 系統,學習 Linux 是相當划算的投資! 範例程式碼操作 --------------------- * 取得 `Introduction to ARM Architecture`_ 簡報對應的程式碼 .. code-block:: prettyprint git clone https://github.com/embedded2015/arm-lecture.git * 確認 `arm-lecture`_ 目錄已正確由 git 建立,接著切換工作目錄 .. code-block:: prettyprint cd arm-lecture * 試著編譯 ARM 版本的 "Hello World" 程式 .. code-block:: prettyprint cd arm-lecture cd hello && make qemu - 預期將看到以下輸出 .. code-block:: prettyprint arm-linux-gnueabihf-as -c -o hello.o hello.s arm-linux-gnueabihf-ld -o hello hello.o qemu-arm ./hello Hello, world! * 若沒有特別指明,後續操作都在 `arm-lecture`_ 目錄之下,以下指令可以從 ``hello`` 目錄返回 .. code-block:: prettyprint cd .. 對照測試簡報中的範例程式碼 --------------------------------------- * 參閱 `Introduction to ARM Architecture`_ 簡報內容 * Example 1 (Page 31) .. code-block:: prettyprint cd example1 make default qemu - 預期輸出: ``0`` - 修改 ``example1.c``,將其中的 ``return 0`` 改為 ``return c``,之後再 ``make qemu``,即可知道 ``add(a,b)`` 的輸出結果 * Example 2 (Page 34) .. code-block:: prettyprint cd example2 make default qemu - 預期輸出: .. code-block:: prettyprint a * b is 140 a * b + c is 143 c - a * b is -137 - 對照簡報 Page 40-41,在 Makefile 的 ``CFLAGS`` 加上`` -mcpu=cortex-a15``,可發現生成的 ARM 機械碼使用了 ``sdiv`` 指令 * Example 3 (Page 45) .. code-block:: prettyprint cd example3 make default qemu - 預期輸出 .. code-block:: prettyprint a/2 / b/2 is 0 * Example 4 (Page 50) .. code-block:: prettyprint cd example4 make default qemu - 預期輸出 .. code-block:: prettyprint a * b is 664237569 * Example 5 (Page 55) .. code-block:: prettyprint cd example5 make default qemu - 預期輸出 .. code-block:: prettyprint a & b is 17 Before operation, apsr was 20030010 After operation, apsr was 60030010 * Example 6 (Page 62) .. code-block:: prettyprint cd example6 make default qemu - 預期輸出 .. code-block:: prettyprint The address of a is 0xf6fff0ac The value of b is now 10 作業要求 ------------- * 參閱 `Introduction to ARM Architecture`_ 簡報內容 - Lab-1: 實做 `Fibonacci 數列`_,使用 ARM 組合語言 - 必須實做遞迴和非遞迴的版本,分別對應 ``lab-1`` 和 ``lab-1i`` 目錄,請直接修改這兩個目錄中的程式碼,不需要建立新目錄 * 試著用最短的 ARM 組合語言程式碼來開發 - 提示:使用 Thumb2 conditional code * 嘗試評估 `Fibonacci 數列`_ 的執行效率,並比較遞迴和非遞迴實做的表現 * 繳交方式: - 在 GitHub 上 Fork `arm-lecture`_,並提交修改 * 對應於 lab-1, lab-1i 這兩個目錄 - 編輯下方「`作業區`_」,增添開發紀錄和 GitHub 連結 - 更新上述 Hackpad,將作業加入,並標注自己的 ID * 寄件到 * 標題: “[NCKU/embedded]” 開頭,後面加學號與姓名 * 內容:(回答以下問題) - GitHub 帳號, wiki 帳號 (註冊本站) - 關於 fork 出來的 repository 修改描述 - 附上一份自我介紹和對課程的期許 * 截止日期: - Mar 14, 2015 (含) 之前 - 越早在 GitHub 上有動態、越早接受 code review,評分越高 挑戰題 ---------- * 修改 Makefile 和撰寫必要的 script,讓 ``make qemu`` 可以一併自動檢驗 Fibonacci 計算的正確性 - 使用情境如同 ` Running unittests via QEMU`_ * 計算每道 ARM/Thumb 指令的 cycle count,並且提出改善實做效能的方法 * 以 `gnuplot`_ 繪製效能分析圖表,藉此得知 Fibonacci 數列對於效能的影響 - 參考資訊: `Gnuplot 純畫圖`_ * 練習 `ARM GCC Inline Assembly`_ 參考資料 ------------ * `Git / GitHub 教學`_ * `Thumb2 conditional code 以及程式開發心得`_, 竹內宏輝