MIT6.828課程JOS在macOS下的環境配置

本文將介紹如何在macOS下配置MIT6.828 JOS實驗的環境。linux

寫JOS以前,在網上搜尋JOS的開發環境,不少博客和文章都提到「不是32位linux就很差配置,會浪費大量時間在配置環境」上之類的論調。故前期開發直接使用了32位ubuntu系統,並作了共享文件系統,背景開一個ubuntu虛擬機進行編譯。
最近實在沒法忍受背景開虛擬機那恐怖的耗電量和發熱量,嘗試將開發環境移到macOS下,竟發現很是的簡單。git

Tools we need

在搭建環境以前,首先macOS上須要有如下兩個工具:shell

運行JOS

  • QEMUubuntu

    有了Homebrew,直接利用brew安裝便可安裝(自動安裝依賴庫)工具

    $brew install qemu
  • kernel.imgfs.img放在目標目錄下 (也能夠在其餘位置,爲了下面的Makefile好寫)this

    .
    ├── Makefile
    ├── fs.img
    └── kernel.img
  • 書寫Makefileurl

    QEMU=/usr/local/Cellar/qemu/2.10.0/bin/qemu-system-i386 # path to qemu
    run:
      $(QEMU) -drive file=./kernel.img,index=0,media=disk,format=raw -serial mon:stdio -vga std -smp 1 -drive file=./fs.img,index=1,media=disk,format=raw

編譯JOS

  • i386-elf-gcccode

    利用Macports來安裝i386-elf-gccorm

    $ sudo port -v selfupdate
    $ sudo port install i386-elf-gcc

    Macports會幫你下載源碼,編譯(很是漫長)blog

  • 修改Makefile中的一些內容

    diff --git a/GNUmakefile b/GNUmakefile
    index adc693e..60fe010 100644
    --- a/GNUmakefile
    +++ b/GNUmakefile
    @@ -33,15 +33,15 @@ TOP = .
    
     # try to infer the correct GCCPREFIX
     ifndef GCCPREFIX
    -GCCPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
    -       then echo 'i386-jos-elf-'; \
    +GCCPREFIX := $(shell if i386-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
    +       then echo 'i386-elf-'; \
            elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
            then echo ''; \
            else echo "***" 1>&2; \
            echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
    -       echo "*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
    +       echo "*** Is the directory with i386-elf-gcc in your PATH?" 1>&2; \
            echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
    -       echo "*** prefix other than 'i386-jos-elf-', set your GCCPREFIX" 1>&2; \
    +       echo "*** prefix other than 'i386-elf-', set your GCCPREFIX" 1>&2; \
            echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
            echo "*** To turn off this error, run 'gmake GCCPREFIX= ...'." 1>&2; \
            echo "***" 1>&2; exit 1; fi)
  • 修改.deps中一些內容

    刪除fsformat的依賴檢查

    obj/fs/: fs/fsformat.c
  • 修改配置文件中的qemu參數

    QEMU=/usr/local/Cellar/qemu/2.10.0/bin/qemu-system-i386

編譯運行JOS

相關文章
相關標籤/搜索