技术开发 频道

Windows Embedded CE 6.0 Internals下

 【IT168技术文档】5.内存构架

 内存的种类

 1.Random Access Memory (RAM)

 Random access memory can be read or written directly at any address. There are various types of RAM that are differentiated by the underlying hardware technology used to implement them. However they all share the ability to be read or written directly at any random address. RAM memory is volatile, the contents are only maintained as long as power is not lost.

 2.Read Only Memory (ROM)

 Read Only Memory typically refers to memory that can be read just like RAM, but not written directly. Most ROM used today can be rewritten using a software algorithm, and is often called Flash ROM. Data stored in ROM is nonvolatile, and remains valid even after power is removed. ROM is sometimes used to refer to any kind of memory that is nonvolatile, even if it is not randomly accessible (e.g. paged memory).

 3.Paged Memory

 Some memory technologies are not randomly accessible. These memory technologies must be read and written in blocks. A CPU typically requires memory that it executes code from to be randomly accessible, so Paged memory can’t be used as a medium to execute code. This type of memory is often used for bulk nonvolatile storage, and includes NAND technology.(存储在NAND Flash中的镜像在执行时被拷贝到RAM中。而NOR Flash是支持XIP的,这也是NAND和NOR的主要区别。)

 虚拟内存架构

 1.虚拟内存

 Windows Embedded CE 6.0使用单一的32位(4G)平坦模式虚拟内存寻址空间。

 这样可以高效的、保护的使用物理内存。

 2.虚拟寻址

 有几个概率需要澄清,首先是▲物理内存是被内存管理单元(MMU)拥有的,当然处理器得有MMU,不然没法跑起来CE 6.0。

 ▲把虚拟内存转换为物理内存是MMU的工作。

 ▲一个有效的虚拟内存必须是已经映射到物理内存的。

 ▲操作系统中近乎所有地址都是虚拟地址,进程不允许直接访问物理地址,物理地址必须首先映射到虚拟地址上,不管是静态映射还是动态映射。

 下图是静态映射的例子,CE 5.0版本和6.0版本映射图是相同的。那么有个问题:为什么要静态映射?仅仅动态映射不是很好嘛?

 因为动态映射需要时间,当一个页错误异常发生时,MMU需要时间把这个虚拟内存映射到真正的物理内存上,这可能导致系统崩溃,因为在实时中断时页错误是不允许的。静态映射就是解决这些问题。

 3.物理寻址

 在什么情况下需要物理寻址?跟Windows桌面系统一样:在系统上电之后、MMU启动之前。另外Bus Mastering组件(比如DMA控制器)也会用到物理寻址。

 虚拟内存总览

 下图是Windows CE 5.0的4GB虚拟内存分布图,每个进程单独的内存是32MB,当前系统最多只允许存在32个进程。

 下图是5.0各个进程的内存发布以及具体一个进程内部的内存发布,从右边的图可以看出,DLL存放的位置从高地址向下扩展,而EXE的位置从低地址向高地址扩展,当相遇时就会报地址不足错误。这也是5.0不足的地方。另外nk.exe比较特殊,总是运行在Slot 97位置。

 下图是Windows Embedded CE 6.0的4GB虚拟内存分布图,每个进程现在都有2GB的虚拟地址,抛弃了原来的按Slot分配的方式,而是只要你需要你就可以创建内存。关于更详细的请见下面的内核态和用户态地址空间。

0
相关文章