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

相关文章
相关标签/搜索