Three-tier mechanism (under) system call
Add a command to MenuOS
1. At the experimental requirements, before the first menu to delete a directory, and then download the updated version of the menu directory after
-rm -rf menu
-git clone http://github.com/mengning/menu.git
2. After entering the menu directory, generate the root system, using make rootf enter MenuOS, and use the help command to view the existing command
-make rootfs
-MenuOS>>help
3. Add the fifth week in a job test.c file getpid () function
-sudo gedit test.c
4. Re-use make rootfs command, the root of the system to re-compile the command added to it, you can see, add commands success
-rootfs
-MenuOS>>help
-MenuOS>>Gpid
Using gdb tracking system calls the kernel function sys_time
1. Go to LinuxKernel directory, start the kernel, and freeze
-cd LinuxKernel
-qemu -kernel linux-3.18.6/arch/x86/boot/bzImge -initrd rootfs.img -s -S
2. The horizontal split open a shell window, use gdb debugger, open the vmlinux, connection port 1234, and set a breakpoint at the start_kernel
-(gdb)file linux-3.18.6/vmlinux
-(gdb)target remote:1234
-(gdb)b start_kernel
3. Set a breakpoint in sys_time place, and c continue debugging, you can be seen in QEMU program to stop the time function
-(gdb)b sys_time
-(gdb)c
4. Use the list command to view the details of the function, and the use of single-step debugging command s
-(gdb)list
-(gdb)s
Analysis of the work process corresponding to the code system_call
Set a breakpoint at the system_call view system_call shows that it is actually a process of system calls, there is no strict compliance with internal function call stack base address, does not support the gdb debugger, so MenuOS still stuck in sys_time
The following is the call flow system
to sum up
本实验中,我掌握如何实现MenuOS功能的扩展,并知道了如何去增加系统的调用。我还了解到当我们执行int x80时,CPU会自动跳转到system_call函数,所以实验中我们可以直接把断点设置到system_call,system_call的实现是在linux-3.18.6/arch/x86/kernel/entry_32S,是汇编代码。当我们从系统调用处理过程的入口开始,就可以看到SAVE_ALL保存现场,然后找到system_call和sys_call_table,函数调用后通过restore_all和最后一个INTERRUPT_RETURN(iret)恢复现场并返回系统调用到用户态结束。(不同于之前的博客,我再一次学习了Markdown编辑方法,对照片格式进行调整)