分析 system_call 中断处理过程
一、打开QEMU模拟虚拟机
cd ~/LinuxKernel/
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img
二、在test.c文件中增加Helloworld函数,删除一行多余的MenuConfig和在main函数中增加MenuConfig语句,编译并执行
int helloworld(int argc,char* argv[])
{
char message[] = {"helloworld,20222804\n"};
int length = 21;
write(1,message,length);
return 0;
}
MenuConfig("helloworld","show helloworld",helloworld);
MenuConfig:指令,说明,调用函数
三、再次运行Menu可以发现命令中添加了helloworld,可运行显示:![在这里插入图片描述](https://img-blog.csdnimg.cn/baa325aa9b174c32b7d5b4da2994db6f.png)
四、使用 gdb 跟踪调试Linux内核的启动过程。在start_kernel、sys_time处设置断点,启动MenuOS后执行time命令。![在这里插入图片描述](https://img-blog.csdnimg.cn/4d9446ea66134866b232c1ddf9deeb2a.png)
五、实验总结
system call涉及syscall exit_work内部处理的一些关键点,大致的过程是syscall_exit_work需要跳转到work_pending,里面有 work notifysig 处理信号。系统调用时如同函数调用栈,在中断前需要保存系统调用的上下文,用于恢复后能够在原有的运行环境下继续正确执行。目的:在中断处理完之后,可以返回到原来被中断的地方,在原有的运行环境下继续正确的执行下去。