fatal error: linux/compiler-gcc5.h: No such file or directory
compilation terminated.
複製內容保存爲compiler-gcc5.h,放在要編譯內核模塊的內核代碼的include/linux下。
以下編譯步驟摘自https://github.com/mengning/mykernel
Welcome to the mykernel!
It is a platform to write your own OS kernel,its based on Linux Kernel 3.9.4 source code.
Set up this platform
sudo apt-get install qemu # install QEMU
sudo ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.4.tar.xz # download Linux Kernel 3.9.4 source code
wget https://raw.github.com/mengning/mykernel/master/mykernel_for_linux3.9.4sc.patch # download mykernel_for_linux3.9.4sc.patch
xz -d linux-3.9.4.tar.xz
tar -xvf linux-3.9.4.tar
cd linux-3.9.4
patch -p1 < ../mykernel_for_linux3.9.4sc.patch
make allnoconfig
make
qemu -kernel arch/x86/boot/bzImage
從qemu窗口中您可以看到my_start_kernel在執行,同時my_timer_handler時鐘中斷處理程序週期性執行。
cd mykernel 您可以看到qemu窗口輸出的內容的代碼mymain.c和myinterrupt.c
當前有一個CPU執行C代碼的上下文環境,同時具有中斷處理程序的上下文環境,我們初始化好了系統環境。
您只要在mymain.c基礎上繼續寫進程描述PCB和進程鏈表管理等代碼,在myinterrupt.c的基礎上完成進程切換代碼,一個可運行的小OS kernel就完成了。
start to write your own OS kernel,enjoy it!
mykernel patch generated by this command:
diff -Naur linux-3.9.4 linux-3.9.4.new/ > mykernel_for_linux3.9.4sc.patch