为什么x86 CPU只使用四个“环”中的两个?

当您进一步了解操作系统和它们运行的硬件是如何工作和相互作用的时,您可能会惊讶地发现出现了一些奇怪的现象或“资源”利用不足的情况。为什么?今天的超级用户问答帖子回答了一位好奇的读者的问题。...

为什么x86 CPU只使用四个“环”中的两个?

当您进一步了解操作系统和它们运行的硬件是如何工作和相互作用的时,您可能会惊讶地发现出现了一些奇怪的现象或“资源”利用不足的情况。为什么?今天的超级用户问答帖子回答了一位好奇的读者的问题。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

图片由Lemsipmatt(Flickr)提供。

问题

超级用户读者AdHominem想知道为什么x86 CPU只使用四环中的两环:

Linux and Windows based x86 systems only use Ring 0 for kernel mode and Ring 3 for user mode. Why do processors even distinguish four different rings if they all end up just using two of them anyway? Has this changed with the AMD64 architecture?

为什么x86 CPU只使用四环中的两环?

答案

超级用户贡献者Jamie Hanrahan为我们提供了答案:

There are two primary reas***.

The first is that, although the x86 CPUs do offer four rings of memory protection, the granularity of protection offered thereby is only at the per-segment level. That is, each segment can be set to a specific ring (privilege level) along with other protecti*** like write-disabled. But there are not that many segment descriptors available. Most operating systems would like to have a much finer granularity of memory protection, like… for individual pages.

So, enter page table-based protection. Most, if not all, modern x86 operating systems more or less ignore the segmenting mechani** (as much as they can anyway) and rely on the protection available from the low-order bits in page table entries. One of these is called the “privileged” bit. This bit controls whether or not the processor has to be in one of the “privileged” levels to access the page. The “privileged” levels are PL 0, 1, and 2. But it is just one bit, so at the page-by-page protection level, the number of “modes” available as far as memory protection is concerned is just two: A page can be accessible from non-privileged mode, or not. Hence, just two rings. To have four possible rings for each page, they would have to have two protection bits in each page table entry to encode one of four possible ring numbers (just as do the segment descriptors). However, they do not.

The other reason is a desire for operating system portability. It is not just about x86; Unix taught us that an operating system could be relatively portable to multiple processor architectures, and that it was a good thing. And some processors support only two rings. By not depending on multiple rings in the architecture, the operating system implementers made the operating systems more portable.

There is a third reason that is specific to Windows NT development. NT’s designers (David Cutler and his team, whom Microsoft hired away from DEC Western Region Labs) had extensive previous experience on VMS; in fact, Cutler and a few of the others were among VMS’s original designers. And the VAX processor for which VMS was designed does have four rings (VMS uses four rings).

But the components that ran in VMS’s Rings 1 and 2 (Record Management Services and the CLI, respectively) were left out of the NT design. Ring 2 in VMS was not really about operating system security, but rather about preserving the user’s CLI environment from one program to the next, and Windows did not have that concept; the CLI runs as an ordinary process. As for VMS’s Ring 1, the RMS code in Ring 1 had to call into Ring 0 fairly often, and ring transiti*** are expensive. It turned out to be far more efficient to just go to Ring 0 and be done with it rather than have a lot of Ring 0 transiti*** within the Ring 1 code (again, not that NT has anything like RMS anyway).

As for why x86 implemented four rings while operating systems did not use them, you are talking about operating systems of far more recent design than x86. A lot of the system programming features of x86 were designed long before NT or true Unix-ish kernels were implemented on it, and they did not really know what the operating system would use. It was not until we got paging on x86 that we could implement true Unix-ish or VMS-like kernels.

Not only do modern x86 operating systems largely ignore segmenting (they just set up the C, D, and S segments with a base address of 0 and size of 4 GB; F and G segments are sometimes used to point to key operating system data structures), they also largely ignore things like “task state segments”. The TSS mechani** was clearly designed for thread context switching, but it turns out to have too many side effects, so modern x86 operating systems do it “by hand”. The only time x86 NT changes hardware tasks is for some truly exceptional conditi***, like a double fault exception.

Regarding x64 architecture, a lot of these disused features were left out. To their credit, AMD actually talked to operating system kernel teams and asked what they needed from x86, what they did not need or did not want, and what they would like added. Segments on x64 exist only in what might be called vestigial form, task state switching does not exist, etc., and operating systems continue to use just two rings.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-09 17:38
  • 阅读 ( 214 )
  • 分类:互联网

你可能感兴趣的文章

x86个(x86)和x64个(x64)的区别

...处理器,如80186、80286、80386和80486,它们都与8086处理器中使用的原始指令集向后兼容。由于所有这些处理器都以86结尾,因此指令集体系结构被命名为x86。随着80386的引入,x86指令被扩展到32位系统。这里,32位意味着所有寄存器...

  • 发布于 2020-10-29 09:01
  • 阅读 ( 144 )

有没有电脑没有受到熔毁和幽灵病毒的影响?

...果已经避开了传统的PPC处理器,转而使用英特尔。这就是为什么在MacBook上运行Windows如此简单的原因。 ...

  • 发布于 2021-03-11 21:27
  • 阅读 ( 288 )

我有32位还是64位窗口?下面是如何判断

... 下面是如何检查您的计算机是64位还是32位,以及为什么这一点很重要。 ...

  • 发布于 2021-03-20 09:57
  • 阅读 ( 212 )

32位和64位windows有什么区别?

... 如果您使用的是64位处理器,那么还需要使用64位版本的Windows来利用它。32位版本的Windows可以在64位处理器上工作,但不能使用额外的功能。 ...

  • 发布于 2021-03-22 08:49
  • 阅读 ( 240 )

为什么我的手机比我的电脑慢?智能手机vs.台式机速度

你口袋里的智能**功能强大。它的功能比大量现已失效的超级计算机,以及一些现代的超级计算机还要强大。另一个现成的事实是,“你的**比1969年美国宇航局的所有**都有更强的计算机能力,当时它把两名宇航员送上了月球。...

  • 发布于 2021-03-26 09:35
  • 阅读 ( 199 )

hackboard 2是一台运行windows10pro的单板计算机

... 这是许多旨在将嵌入式编程带入x86世界的主板之一,而使用windows10作为操作系统的类似Raspberry-Pi的开发平台将吸引许多人。 ...

  • 发布于 2021-03-29 00:44
  • 阅读 ( 187 )

似曾相识:每个mac cpu架构的简史

...尘上。这将标志着Mac系列的第三次系统架构转型,但是,为什么呢? 自2010年以来,苹果一直在稳步获得为iPhone、iPad和苹果电视硬件设计自己的基于ARM处理器的片上系统(SOC)软件包的经验。公司的进步是惊人的。它的设计在速...

  • 发布于 2021-04-02 01:53
  • 阅读 ( 225 )

我应该买哪种天气预报?

...的发电站,可以满足所有需求。 请继续阅读,了解我们为什么提出这些建议以及我们首选的四托架选项。 快速崩溃 当您快速浏览Synology的产品列表时,您会注意到它被分为不同的系列:FS&XS系列、Plus系列、Value系列和J系列。...

  • 发布于 2021-04-06 11:03
  • 阅读 ( 166 )

arm上的Windows10是什么,有什么不同?

...层,允许它在Windows商店外运行传统的桌面应用程序。 为什么微软要在arm上安装Windows10? ARM是一种不同于当今PC上使用的标准Intel x86和64位Intel体系结构的处理器体系结构。(甚至AMD也生产与英特尔体系结构兼容的芯片。)iPhone...

  • 发布于 2021-04-07 00:43
  • 阅读 ( 199 )

windows中的“program files(x86)”和“program files”文件夹有什么区别?

...2位程序存储在“C:\Program Files(x86)”文件夹中。 这就是为什么不同的程序分布在两个程序文件文件夹中,看起来是随机的。“C:\Program Files”文件夹中的是64位,而“C:\Program Files(x86)”文件夹中的是32位。 他们为什么要分开...

  • 发布于 2021-04-07 06:03
  • 阅读 ( 201 )
cy002476
cy002476

0 篇文章

相关推荐