Dive into Intel iret instruction
本文将深入解析Intel iret
instruction。
1. Prerequisite
2. Materials
最权威的资料,值得读者细品。
- Intel SDM Vol1 CHAPTER 6 PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
- Intel SDM Vol2 INSTRUCTION SET REFERENCE
3. Theory
4. Example in kvm unit test
1 | asm volatile ( |
为了能进入user mode,在内核态,进行了如下操作:1
2
3
4
5
6
7
8
9
10
11/* Load user_ds to DS and ES */
"mov %[user_ds], %%ax\n\t"
"mov %%ax, %%ds\n\t"
"mov %%ax, %%es\n\t"
/* IRET into user mode */
"pushq %[user_ds]\n\t"
"pushq %[user_stack_top]\n\t"
"pushfq\n\t"
"pushq %[user_cs]\n\t"
"pushq $user_mode\n\t"
"iretq\n"
5. 总结
掌握住iret
instruction的Operation即可!
详情当然是参考Intel SDM Vol2 INSTRUCTION SET REFERENCE!
建议详细阅读下Switching to User-mode using iret!
参考资料: