close

其實4G的記憶體不會消失,也不會被Windows拿給底層用,應該是說有 200MB 的 "定址空間" 被硬體作為 記體體映射(Memory Map IO)用走了,所以 RAM 的 2XXMB 沒有定址空間可用,也就是說這段記憶體位址是被保留來當專用的Memory Mapped IO的位置,所以這一段的記憶體位址並不會拿來當作一般的記憶體存取,所以而是浪費了這兩百多MB的記憶體空間。

名詞解釋...

蝦米是Memory Map IO


Memory Mapped IO (MMIO) 使用的是實體記憶體位址 (Physical Address)
並不是使用虛擬記憶體

基本上只有虛擬記憶體位址(Virtual Address) 和 實體記憶體位址 (Physical Address)
這兩者間使用 分頁(page) 或 分段(segment) 達成映射關係

MMIO 大致上佔據高位址 0xF0000000 ~ 0xFFFFFFFF 這段位址區大部分都是周邊硬體
和CPU溝通的介面 並不是佔用到磁碟上的虛擬記憶體空間

簡單的講MMIO 就是CPU和周邊溝通的介面之一,就是直接去找週邊要的方式
如果週邊還有其他的溝通方式如 Port IO 就可以不用 MMIO
如果只有MMIO, 那 Disable MMIO 就好像關掉大門 就沒得溝通了

 

有人一定會想那如果我只用1~2GB or Disable MMIO in BIOS,這時週邊硬體如何跟CPU溝通阿?

因為MMIO 將周邊硬體的暫存器(Register) 映射到 CPU 的定址空間上
所以CPU並不需要也不能夠將MMIO位址映射到記憶體(DRAM)

舉例來說 我的電腦 網路卡的暫存器映射到 CPU 的定址空間 0xF7FFFC00 ~ 0xF7FFFFFF (1KB)
就表示 CPU 存取 0xF7FFFC00 ~ 0xF7FFFFFF 就是存取網路卡的暫存器
這1KB不能在DRAM位址上,所以如果有4GB DRAM (0x00000000~0xFFFFFFFF)
那這1KB會和DRAM位址重疊,所以這1KB不能給DRAM

網路卡規格書會說明暫存器用途
假設暫存器1可以回傳網路卡的IP位址,那CPU可以使用下面這一段程式碼來抓到

{
...
unsigned int IPAddress;

IPAddress = *(unsigned int *)(0xF7FFFC00);
...
}

通常這種程式碼可以在驅動程式碼中找到,而驅動程式必須以核心模式(Kernel Mode)執行
一般的應用程式是沒有權利執行這類的程式碼

64-bit OS (0x0000000000000000 ~ 0xFFFFFFFFFFFFFFFF)就不會有重疊的問題了
像以上的例子,可以將 MMIO 定址到 (0xF.F7FFC00 ~ 0xF.F7FFFFFF)
就不會和 4GB DRAM 位址重疊 了



以下來自 http://en.wikipedia.org/wiki/Memory-mapped_IO
Memory-mapped I/O (MMIO) and port I/O (also called port-mapped I/O or PMIO) are two complementary methods of performing input/output between the CPU and I/O devices in a computer. Another method is using dedicated I/O processors (channels, used in IBM mainframe computers).

Memory-mapped I/O (not to be confused with memory-mapped file I/O) uses the same bus to address both memory and I/O devices, and the CPU instructions used to read and write to memory are also used in accessing I/O devices. In order to accommodate the I/O devices, areas of CPU addressable space must be reserved for I/O rather than memory. This does not have to be permanent, for example the Commodore 64 could bank switch between its I/O devices and regular memory. The I/O devices monitor the CPU's address bus and respond to any CPU access of their assigned address space, mapping the address to their hardware registers.

Port-mapped I/O uses a special class of CPU instructions specifically for performing I/O. This is generally found on Intel microprocessors, specifically the IN and OUT instructions which can read and write a single byte to an I/O device. I/O devices have a separate address space from general memory, either accomplished by an extra "I/O" pin on the CPU's physical interface, or an entire bus dedicated to I/O.

知秋和尚 / Xuite日誌 / 回應(0) / 引用(0)
電腦小常識-CPU進階技術講解...|日誌首頁|電腦小常識-AMD與INTEL...上一篇電腦小常識-CPU進階技術講解,XD、VT、SSE...下一篇電腦小常識-AMD與INTEL的戰爭...
回應