我也是够无聊的...
把OS作业发出来...
英文作业...虽然英文也是够烂的...我会加点字幕的...
只是为了养成发博客的好习惯...部分内容删掉了...嫌麻烦...
set up:
I use VMware-Workstation 10.0.2 build-1744117 to set up ubuntu-14.04.1-desktop-i386, some configurations:
Memory: 2GB
Processors: 2
SCSI: 32GB
Kernel-release: 3.13.0-32-generic
// 换源
# sudo -s -H
# cp /etc/apt/sources.list /etc/apt/sources.list_backup
# gedit /etc/apt/sources.list
SJTU: 一大堆格式错掉了...嫌弃的自己去论坛里找一下吧...
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty main multiverse restricted universedeb http://ftp.sjtu.edu.cn/ubuntu/ trusty-backports main multiverse restricted universedeb http://ftp.sjtu.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universedeb http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main multiverse restricted universedeb http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main multiverse restricted universedeb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty main multiverse restricted universedeb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-backports main multiverse restricted universedeb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-proposed main multiverse restricted universedeb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main multiverse restricted universedeb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main multiverse restricted universe
# apt-get update
compiler & tools:
# apt-get install build-essential
# apt-get install libncurses5-dev
# apt-get install libqt4-dev
# apt-get install initramfs-tools
I use the linux-3.2.63 release to add my system call, first download.
# cp linux-3.2.63.tar.xz /usr/src/linux-3.2.63.tar.xz
# tar vxf linux-3.2.63.tar.xz
# cd linux-3.2.63
# make -j4 clean
By now, the kernel package contains only source files. ‘-j4’ means to run this instruction using 4 threads.
To add a system call
# cd /arch/x86/kernel
# gedit syscall_table_32.S
Add one row at the end of the file:
.long sys_helloworld /* 349 */
# cd ../include/asm
# gedit unistd_32.h
Add one row at the end of the file:
# define __NR_helloworld 349
# cd ../../../../kernel
# gedit sys.c
Include a head file:
# include <linux/linkage.h>
Add a function named sys_helloworld:
Asmlinkage int sys_helloworld(){
printk(KERN_EMERG “hello linux, from id 5120309710\n”);
Return 0;
}
Before compiling, configure the compiler.
# cd /usr/src/linux-3.2.63
#make menuconfig
Just exit and save.
And then start compiling.
# make -j4
After a period of time, source files are compiled successfully.
# make modules_install
# make install
Sometimes, this instruction will install the new kernel automatically. Otherwise, we should modify the grub.cfg by hand.
# cd /boot/grub
# gedit grub.cfg
Reboot and check if the new kernel has been applied.
# sudo -s -H
# uname -r
Build a test file to test whether this helloworld function has been added to system call.
# sudo -s -H
# cd /usr/src
# gedit test.c
#include <stdio.h>
int main(){
syscall(349);
return 0;
}
# gcc test.c
# ./a.out
# dmesg -c
看到了吧, 我当你看到了...