為什麼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
  • 閱讀 ( 47 )
  • 分類:網際網路

你可能感興趣的文章

你電腦的終極指南:你想知道的一切——等等

...持不變。在本指南中,我們將詳細說明每個元件的作用,為什麼要這樣做,以及為什麼這一點很重要。 ...

  • 發佈於 2021-03-13 07:48
  • 閲讀 ( 50 )

應該在虛擬機器中嘗試的7大linux作業系統

... 如果Lubuntu本身對你來說不夠輕,為什麼不試試LXLE,Lubuntu額外的壽命延長?LXLE甚至比Lubuntu更輕,非常適合在低規格但支援虛擬化的硬體上作為虛擬機器執行。 ...

  • 發佈於 2021-03-16 11:49
  • 閲讀 ( 52 )

WindowsSystem32目錄:它是什麼以及為什麼不能刪除它

...indowsSystem32資料夾。但是這個神祕的Windows資料夾是什麼,為什麼有人要你刪除它呢? ...

  • 發佈於 2021-03-20 03:47
  • 閲讀 ( 50 )

我有32位還是64位視窗?下面是如何判斷

... 下面是如何檢查您的計算機是64位還是32位,以及為什麼這一點很重要。 ...

  • 發佈於 2021-03-20 09:57
  • 閲讀 ( 45 )

cpu插槽型別說明:插槽5到bga

... 那麼,您為什麼要關心CPU插槽呢?嗯,如果你想升級你的CPU,你需要知道插座的型別。主機板插座型別決定了您可以使用哪種型別的CPU,CPU升級是否值得,或者您是否應該考慮升級...

  • 發佈於 2021-03-20 10:13
  • 閲讀 ( 46 )

32位和64位windows有什麼區別?

...看看這些名稱來自何處,以及它們對您的計算體驗意味著什麼。 ...

  • 發佈於 2021-03-22 08:49
  • 閲讀 ( 44 )

什麼是預兆?此intel cpu漏洞如何影響您

... 什麼是脆弱性的預兆(the foreshadow vulnerability)? ...

  • 發佈於 2021-03-24 00:49
  • 閲讀 ( 59 )

為什麼我的手機比我的電腦慢?智慧手機vs.桌上型電腦速度

你口袋裡的智慧**功能強大。它的功能比大量現已失效的超級計算機,以及一些現代的超級計算機還要強大。另一個現成的事實是,“你的**比1969年美國宇航局的所有**都有更強的計算機能力,當時它把兩名宇航員送上了月球。...

  • 發佈於 2021-03-26 09:35
  • 閲讀 ( 50 )

mac os x之前:下一步是什麼?人們為什麼喜歡它?

...體的後代。但這是怎麼發生的? 相關報道:什麼是BeOS,為什麼人們喜歡它? 下一步的起源 20世紀80年代中期對史蒂夫·喬布斯來說很艱難。在蘋果的一場權力鬥爭之後,他離開了他在1985年共同創立的公司。同年,他與其他幾位...

  • 發佈於 2021-04-01 09:35
  • 閲讀 ( 51 )

似曾相識:每個mac cpu架構的簡史

...塵上。這將標誌著Mac系列的第三次系統架構轉型,但是,為什麼呢? 自2010年以來,蘋果一直在穩步獲得為iPhone、iPad和蘋果電視硬體設計自己的基於ARM處理器的片上系統(SOC)軟體包的經驗。公司的進步是驚人的。它的設計在速...

  • 發佈於 2021-04-02 01:53
  • 閲讀 ( 55 )
cy002476
cy002476

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦