CPU 从用户模式切换到内核模式:它到底做了什么?它是如何实现这种转变的? [英] CPU Switches from User mode to Kernel Mode : What exactly does it do? How does it makes this transition?

查看:12
本文介绍了CPU 从用户模式切换到内核模式:它到底做了什么?它是如何实现这种转变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CPU 从用户模式切换到内核模式:它到底做了什么?它是如何实现这种转变的?

CPU Switches from User mode to Kernel Mode : What exactly does it do? How does it makes this transition?

即使它依赖于架构,也请给我一个答案.架构由您决定.告诉我你知道的架构.

Even if it is architecture dependent please provide me with an answer. The architecture is up to you. Tell me for the architecture you know about.

我想了解其中涉及的所有内容.

I want to get an idea about what all things will be involved in it.

推荐答案

注意:这主要与 x86 架构相关.这是一个稍微简化的解释.

Note: this is mostly relevant to x86 architecture. Here's a somewhat simplified explanation.

过渡通常由以下原因之一引起:

The transition is usually caused by one of the following:

  • 错误(例如,页面错误或由执行指令引起的其他异常)
  • 中断(例如键盘中断或 I/O 完成)
  • 陷阱(例如系统调用)

通常发生的是系统检查中断描述符表 (IDT).每个异常(中断、故障等)都有一个与之关联的数字,用于索引到该表中.

What normally happens is that system checks the Interrupt Descriptor Table (IDT). Each exception (interrupt, fault, etc.) has a number associated with it which is used to index into this table.

从这个表中,CPU 可以确定要运行的中断处理程序.

From this table the CPU can determine the interrupt handler to run.

作为过渡的一部分,以下更改(通常)生效:

As part of the transition the following changes (generally) take effect:

  • 切换到内核堆栈
  • EFLAGS 已保存
  • 保存代码段选择器和 EIP.
  • 堆栈段选择器和堆栈指针被保存
  • 开始执行中断处理程序
  • 保存通用寄存器(处理程序的工作)
  • 段选择器已更改为内核选择器(处理程序的工作)

您现在处于内核模式.

希望有帮助:)

这篇关于CPU 从用户模式切换到内核模式:它到底做了什么?它是如何实现这种转变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆