本文将介绍如何在macOS下配置MIT6.828 JOS实验的环境。
写JOS之前,在网上搜寻JOS的开发环境,很多博客和文章都提到“不是32位linux就不好配置,会浪费大量时间在配置环境”上之类的论调。故前期开发直接使用了32位ubuntu系统,并做了共享文件系统,背景开一个ubuntu虚拟机进行编译。
最近实在无法忍受背景开虚拟机那恐怖的耗电量和发热量,尝试将开发环境移到macOS下,竟发现非常的简单。
Tools we need
在搭建环境之前,首先macOS上需要有以下两个工具:
Homebrew
Homebrew — The missing package manager for macOS
MacPorts
The MacPorts Project -- Home
运行JOS
QEMU
有了Homebrew
,直接利用brew
安装即可安装(自动安装依赖库)
$brew install qemu
将kernel.img
与fs.img
放在目标目录下 (也可以在其他位置,为了下面的Makefile
好写)
.
├── Makefile
├── fs.img
└── kernel.img
书写Makefile
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-gcc
利用Macports
来安装i386-elf-gcc
$ sudo port -v selfupdate
$ sudo port install i386-elf-gcc
Macports
会帮你下载源码,编译(非常漫长)
修改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