将CPU切换到用户模式和内核模式的汇编指令?

标签 assembly x86 operating-system

根据我的理解,当中断被触发时,CPU将切换到内核模式,而当中断被处理时,操作系统会将CPU切换回用户模式。

现在我的问题是:

  1. 操作系统如何将CPU切换到用户模式(什么是 使用的汇编指令?)。
  2. 是否有将CPU切换到内核的汇编指令 模式,还是仅在触发中断时才切换到内核模式?

最佳答案

How did the operating system switch the CPU to user mode (what is the assembly instruction used?).

处理器有特殊的中断返回指令。指令的名称因处理器而异,但它们都执行大致相同的操作。 REI、IRET 就是例子。

Is there an assembly instruction that switches the CPU to kernel mode, or does the switch to kernel mode only happens when an interrupt is fired?

进程进入内核模式有两种方法:(1)触发异常或(2)执行特殊指令。例如,

    DIVL2 #0, R0

会让你进入内核模式

 int a = b / 0 ;

进入内核模式的指令因处理器而异,但示例包括 CHMK、INT。 i86 系列有多种方法可以实现此目的。

关于将CPU切换到用户模式和内核模式的汇编指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44569949/

相关文章:

c - 使用扩展 ASM,什么可以确保操作数的读/写在所需的时间发生?

assembly - NASM cmp 错误 : invalid combination of opcode and operands

algorithm - 在资源被使用后保持声明优势的原因是什么?

windows - 线程 ID 与线程句柄

c - GCC 内联汇编 : "g" constraint and parameter size

assembly - 8位和16位处理器如何通过两个寄存器访问更多RAM?

assembly - 为什么是 "or ah,ah"?

vb.net - Windows XP 上的错误 [IM002] [Microsoft][ODBC 驱动程序管理器]

performance - 可以使用哪些方法在现代x86上有效地扩展指令长度?

testing - Golang 有 libfaketime 替代品吗?