实验五:分析system_call中断处理过程
来源:互联网 发布:电脑网络延迟高 编辑:程序博客网 时间:2024/05/01 21:28
将上一个系统调用函数和asm版本的实现整合进入menu的内核中:
- int
GetPid() - {
int pid = getpid(); printf("The Current Progress pid is : % d\n",pid); return 0; - }
- int
GetPidAsm() - {
int pid; asm volatile( "mov $0,%% ebx\n\t" "mov $0x14,%% eax\n\t" "int $0x80\n\t" "mov %% eax,% 0\n\t" : "=m" (pid) ); printf("The Current Progress pid asm is : % d\n",pid); return 0; - }
- int
main() - {
PrintMenuOS(); SetPrompt("MenuOS>>"); MenuConfig("version","MenuOS V1.0(Based on Linux 3.18.6)",NULL); MenuConfig("quit","Quit from MenuOS",Quit); MenuConfig("time","Show System Time",Time); MenuConfig("time-asm","Show System Time(asm)",TimeAsm); MenuConfig("getpid","Show Current Progress id",GetPid); MenuConfig("getpid-asm","Show Current Progress asm id",GetPidAsm); ExecuteMenu(); - }
上面的一段代码,MenuConfig这个函数是菜单(也就是制作出来的内核)的初始化配置函数,第一个参数是命令,第二个参数是该命令的描述,第三个参数是这个命令相对应的handler,也就是回调函数,是通过一个函数指针进行实现的。ExecuteMenu这个函数是为了启动这个menu引擎,其实是一个循环等待用户输入命令的过程。
将上周写的两个函数分别命名为int getuidc() int getuid_asm,将这两个函数写入test.c文件中:
通过make rootfs脚本命令运行一下,可以看出通过userid命令和userid_asm命令都可以获取程序的用户id:
下面,详细分析一下menu操作系统通过user命令和user_asm命令对系统内核服务的调用。在操作系统启动过程中,首先对系统调用进行初始化,系统调用实质上是一种中断,是通过\int\main.c \start_kernel文件中的trap_int()函数声明的,trap_int()函数指向\arch\x86\kernel\traps.c文件中的set_system_trap_gate(SYSCALL_VECTOR,&system_call)函数,在这一过程中,通过参数SYS_CALL传递系统调用中断向量,&system_call是汇编代码入口。在本例的menu操作系统中,中断向量int 0x80指向系统调用system_call:
在如上流程中,system_exit:是系统调用结束前的进程切换模块,其代码如下:
syscall_exit_work:
testl $_TIF_WORK_SYSCALL_EXIT, %ecxjz work_pendingTRACE_IRQS_ONENABLE_INTERRUPTS(CLBR_ANY)# could let syscall_trace_leave() call# schedule() insteadmovl %esp, %eaxcall syscall_trace_leavejmp resume_userspace END(syscall_exit_work)
系统调用完成后,通过汇编命令iret返回主程序,至此,系统调用实现任务并返回。
总之,系统调用作为一种中断处理过程,能够反映出一般的中断处理机制,对于一般的中断处理,同样是由四个主要步骤完成的,首先进入中断,保护好现场,第二步调用中断的服务程序,第三步,完成中断退出前的进程切换工作,第四步,返回主程序并恢复现场
- 实验五:分析system_call中断处理过程
- Linux内核分析 实验五:分析system_call中断处理过程
- Linux内核分析 实验五:分析system_call中断处理过程
- 通过实验分析system_call中断处理过程
- Linux内核分析实验五—分析system_call中断处理过程
- 分析system_call中断处理过程
- system_call中断处理过程分析
- system_call中断处理过程分析
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- system_call中断处理过程分析
- 分析system_call中断处理过程
- 分析system_call中断处理过程
- 12C-OCP升级1z-060-017
- 关于myeclipse里web工程访问src下servlet问题!!!急!
- 张量的展开与matlab下的工具包操作
- ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
- Cg入门19:Fragment shader - 片段级模型动态变色
- 实验五:分析system_call中断处理过程
- Android官方开发文档Training系列课程中文版:添加ActionBar之自定义ActionBar样式
- vs2012安装opencv3.0
- Eclipse安装SVN教程
- eclipse转AndroidStudio
- 广度优先搜索应用一:着色法
- 一篇很全面的freemarker教程
- Android自定义控件系列案例【一】
- 基于Spring +Apache POI 导入 ajaxSubmit提交方式导入excel