1. The purpose of the experiment
1) To understand the concept and process of operating system generation;
2) To understand the concepts of two types of user interface (operation interface, system call) of the operating system;
2. Experimental content
1) Cut and compile the Linux kernel under Ubuntu or other Linux platform environments, and enable the new kernel.
2) Add 1-3 new system calls to the Linux kernel on Ubuntu or other Linux platforms, enable the new kernel, and write an application to test whether the newly added system calls work correctly.
3) In the Windows environment, write a batch program (fortune-telling master.bat). After the program runs, enter: birth date (for example, 2000-07-31). The system outputs the corresponding zodiac signs and constellations, for example: You are a rabbit, Leo. Requirement: The input is checked for legitimacy, and the user's input can be received cyclically until q or Q is input to exit.
3. Experimental process
(1) Experimental step
1) Recompile the Linux kernel
1. Resource download
Linux version: Linux 5.5.7
Environment: ubuntu-18.04.4 (virtual machine)
2. Move the folder
1. Drag the compressed package into the ubuntu main directory
2. Extract
3.sudo Music Videos /home/Linux5.5.7/ / usr / the src /
3. updates and installation of dependencies
sudo apt-get update
sudo apt-get install libncurses5-dev libssl-dev
sudo apt-get install build-essential openssl
sudo apt-get install zlibc minizip
sudo apt-get install libidn11-dev libidn11
sudo apt-get install bison
sudo apt-get install flex
4. 内核配置
#make menuconfig
5. Recompile the new kernel
#make –j4
6. Generate a new kernel
#make modules_install
#make install
2) Add system calls in Linux
1. Enter the main directory
2. Open the file that adds a custom system call number, add calls and Contents
sudo gedit arch/x86/entry/syscalls/syscall_64.tbl
sudo gedit include/linux/syscalls.h
sudo gedit kernel/sys.c
3. Compile the kernel
4. Write C language function verification
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc,int **argc)
{
printf("System call sys_first return %ld\n",syscall(335));
long temp;
temp=syscall(336,2);
printf("System call sys_second return %ld\n",temp);
temp=syscall(337,2,3);
printf("System call sys_third return %ld\n",temp);
return 0;
}
5. Run the program
sudo gcc -o test test.c
sudo ./test
6. View and call
sudo dmesg
3) Write a batch program "Fortune-telling master.bat "
1. Open the notepad, create a new document
2. Write the code, code as ANSI, save format.bat
@echo off
set /p yearmonthday=输入: 出生年月日 (例如 19990411)
set "shengxiao=猴鸡狗猪鼠牛虎兔龙蛇马羊”
set year=%yearmonthday:~0,4%
set monthday=%yearmonthday:~4,4%
set /a mod=%year%%%12
if %mod%==0 Echo 你属猴
if %mod%==1 Echo 你属鸡
if %mod%==2 Echo 你属狗
if %mod%==3 Echo 你属猪
if %mod%==4 Echo 你属鼠
if %mod%==5 Echo 你属牛
if %mod%==6 Echo 你属虎
if %mod%==7 Echo 你属兔
if %mod%==8 Echo 你属龙
if %mod%==9 Echo 你属蛇
if %mod%==10 Echo 你属马
if %mod%==11 Echo 你属羊
echo 你的星座是
if "%monthday%" LEQ "0119" echo 魔蝎座
if "%monthday%" GEQ "0120" if "%monthday%" LEQ "0218" echo 水瓶座
if "%monthday%" GEQ "0219" if "%monthday%" LEQ "0320" echo 双鱼座
if "%monthday%" GEQ "0321" if "%monthday%" LEQ "0419" echo 白羊座
if "%monthday%" GEQ "0420" if "%monthday%" LEQ "0520" echo 金牛座
if "%monthday%" GEQ "0521" if "%monthday%" LEQ "0621" echo 双子座
if "%monthday%" GEQ "0622" if "%monthday%" LEQ "0722" echo 巨蟹座
if "%monthday%" GEQ "0723" if "%monthday%" LEQ "0822" echo 狮子座
if "%monthday%" GEQ "0823" if "%monthday%" LEQ "0922" echo 处女座
if "%monthday%" GEQ "0923" if "%monthday%" LEQ "1023" echo 天秤座
if "%monthday%" GEQ "1024" if "%monthday%" LEQ "1122" echo 天蝎座
if "%monthday%" GEQ "0321" if "%monthday%" LEQ "0419" echo 白羊座
if "%monthday%" GEQ "1222" echo 魔蝎座
Pause
@echo off is because the following command statements of this statement will not be displayed on the output screen
set /p birthday= --> /p will be added when reading and assigning, and the input string will be assigned to birthday
set year=%birthday:~ 0,4% --> When starting from the 0th digit of birthday, 4 characters are intercepted and assigned to year
set /a yy=%year%%%12 When
performing calculation assignment, add /a %year% represents year The value %% refers to the remainder operation
%day% leq 19 leq means less than or equal to
3. Run
Double-click the bat file to run.
(2) Resolve errors and optimize
1. Network connection problems, environment configuration errors. It appears that the ubuntu on the virtual machine cannot access the Internet and cannot be updated. The solution is to change the network connection mode of the virtual machine from direct connection to bridge connection.
2. Some dependencies cannot be installed and the environment configuration is wrong. The solution is to re-#apt-get update, then re-install, and repeat.
3. #make menuconfig reports an error, compile error.
The solution is to maximize the terminal window.
4. Special grammatical errors. For example, when entering the command line, you often forget "." and spaces. The solution is to be familiar with Linux commands and be more careful when writing code.
4. Experimental results
1) Recompile the Linux kernel
As shown in the figure, first select the ubuntu advanced option, and then select Linux 5.5.7 to enable the new kernel.
2) Add system calls in Linux
It can be seen that the set system call can be called.
3) Write a batch program "Fortune Teller Master.bat"
After entering the year, month and day, the correct result is given.
5. Experience
1. Have a deeper understanding of the generation of operating systems
2. Have some experience in the use of Linux
3. The ability to deal with problems has been improved