Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode
来源:互联网 发布:nvidia怎么读 知乎 编辑:程序博客网 时间:2024/05/21 21:38
本文分析基于Linux 0.11内核,转载请标明出处,http://blog.csdn.net/yming0221/archive/2011/06/01/6459119.aspx
在main.c的程序中,当设备初始化完毕后,程序将从内核模式切换到用户模式,也就是所说的任务0,执行fork()函数(该函数使用内嵌的汇
编,防止函数调用弄乱堆栈,造成写时复制COPY_ON_WRITE)切换到用户堆栈并执行任务0使用iret指令,首先将有关的值压入堆栈,然后执
行iret指令。将刚刚压入对堆栈的数据根据标志位弹入相应的寄存器。
执行iret前的堆栈如下:
一下这段话引用自http://faydoc.tripod.com/cpu/iret.htm
In Protected Mode, the action of the IRET instruction depends on the settings of the NT (nested task) and VM flags in the EFLAGS register and the VM flag in the EFLAGS image stored on the current stack. Depending on the setting of these flags, the processor performs the following types of interrupt returns:
- Return from virtual-8086 mode.
- Return to virtual-8086 mode.
- Intra-privilege level return.
- Inter-privilege level return.
- Return from nested task (task switch).
If the NT flag (EFLAGS register) is cleared, the IRET instruction performs a far return from the interrupt procedure, without a task switch. The code segment being returned to must be equally or less privileged than the interrupt handler routine (as indicated by the RPL field of the code segment selector popped from the stack). As with a real-address mode interrupt return, the IRET instruction pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack to the EIP, CS, and EFLAGS registers, respectively, and then resumes execution of the interrupted program or procedure. If the return is to another privilege level, the IRET instruction also pops the stack pointer and SS from the stack, before resuming program execution. If the return is to virtual-8086 mode, the processor also pops the data segment registers from the stack.
-----------------------------------
由于在sched_init()中已经设置了标志寄存器中的vm标志为0,所以iret掉用后不会发生任务切换,而是继续执行EIP指向的指令故继续执行
1标号的代码,开始执行任务0,任务0的堆栈段选择符为0x17,在sched_init()中已设置了任务0 的任务描述符和局部描述符为INIT_TASK
- Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode
- Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode
- Linux 内核--任务0的调度切换
- Linux 内核--任务0的调度切换
- Linux 内核--任务0的调度切换
- linux用户态到内核态的切换
- 内核模式和用户模式的切换
- linux 的任务堆栈,以及用户态和内核态的切换
- 《重要》从用户模式切换到内核模式的完整过程分析
- 《重要》从用户模式切换到内核模式的完整过程分析
- Linux内核分析(二) 任务切换
- 在从用户态到内核态的切换过程中,Linux主要做的事情
- linux的用户模式和内核模式
- Linux用户切换到root后运行图形程序报错(*GLib-GIO-CRITICAL **)
- 用户态切换到内核态的3种方式
- 用户态切换到内核态的3种方式
- linux-0.11内核中任务的堆栈切换
- uclinux内核的任务切换
- Android逐条加载ListView,实现动画更新
- OUTLOOK- group outline
- sIEve中文使用手册
- FLASH相关工具
- 如何在 Windows XP 的事件查看器中查看和管理事件日志
- Linux 内核--任务0的运行(切换到用户模式)move_to_user_mode
- 自动化测试
- 向Android模拟器发短信和打电话
- hdu--2561(第二小数,时间复杂度为0(n))
- 关于Linux的几幅图
- 通过php的curl获取msn邮箱联系人(经测试2011-6-1)
- 函数指针,指向成员函数的指针与指向成员变量的指针
- 学几个bash快捷键
- OpenMP编程的数据竞争问题