📄 c-vm5.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Virtual Memory Interface </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-vm.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-vm4.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-config.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84478">7.5 Using the MMU Programmatically</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84480"> </a>This section describes the facilities provided for manipulating the MMU programmatically using low-level routines in <b class="library">vmLib</b>. You can make data private to a task or code segment, make portions of memory noncacheable, or write-protect portions of memory. The fundamental structure used to implement virtual memory is the <i class="term">virtual memory context</i> (VMC).</p><dd><p class="Body"><a name="84482"> </a>For a summary of the VxVMI routines, see the reference entry for <b class="library">vmLib</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84484">7.5.1 Virtual Memory Contexts</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84486"> </a>A virtual memory context (<b class="symbol_UC">VM_CONTEXT</b>, defined in <b class="file">vmLib</b>) is made up of a translation table and other information used for mapping a virtual address to a physical address. Multiple virtual memory contexts can be created and swapped in and out as desired.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84488">Global Virtual Memory</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84489"> </a>Some system objects, such as text segments and semaphores, must be accessible to all tasks in the system regardless of which virtual memory context is made current. These objects are made accessible by means of <i class="term">global virtual memory</i>. Global virtual memory is created by mapping all the physical memory in the system (the mapping is defined in <b class="symbol_lc">sysPhysMemDesc</b>) to the identical address in the virtual memory space. In the default system configuration, this initially gives a one-to-one relationship between physical memory and global virtual memory; for example, virtual address 0x5000 maps to physical address 0x5000. On some architectures, it is possible to use <b class="symbol_lc">sysPhysMemDesc</b> to set up virtual memory so that the mapping of virtual-to-physical addresses is not one-to-one; see <a href="c-vm3.html#84391"><i class="title">7.3 Virtual Memory Configuration</i></a> for additional information.</p><dd><p class="Body"><a name="84494"> </a>Global virtual memory is accessible from all virtual memory contexts. Modifications made to the global mapping in one virtual memory context appear in all virtual memory contexts. Before virtual memory contexts are created, add all global memory with <b class="routine"><i class="routine">vmGlobalMap</i></b><b>(</b> <b>)</b>. Global memory that is added after virtual memory contexts are created may not be available to existing contexts.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84497">Initialization</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84500"> </a>Global virtual memory is initialized by <b class="routine"><i class="routine">vmGlobalMapInit</i></b><b>(</b> <b>)</b> in<b class="routine"><i class="routine"> usrMmuInit</i></b><b>(</b> <b>)</b>, which is called from <b class="routine"><i class="routine">usrRoot</i></b><b>(</b> <b>)</b>. The routine <b class="routine"><i class="routine">usrMmuInit</i></b><b>(</b> <b>)</b> is in <i class="textVariable">installDir</i><b class="file">/target/src/config/usrMmuInit.c</b>, and creates global virtual memory using <b class="symbol_lc">sysPhysMemDesc</b>. It then creates a default virtual memory context and makes the default context current. Optionally, it also enables the MMU. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84502">Page States</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84504"> </a>Each virtual memory page (typically 8KB) has a state associated with it. A page can be valid/invalid, writable/nonwritable, or cacheable/noncacheable. See <a href="c-vm5.html#84511">Table 7-2</a> for the associated constants. <p class="table"><h4 class="EntityTitle"><a name="84511"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 7-2: State Flags</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84515"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Constant</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84517"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84520"> </a><b class="symbol_lc">VM_STATE_VALID</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84522"> </a>Valid translation </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84525"> </a><b class="symbol_lc">VM_STATE_VALID_NOT</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84527"> </a>Invalid translation </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84530"> </a><b class="symbol_lc">VM_STATE_WRITABLE</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84532"> </a>Writable memory </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84535"> </a><b class="symbol_lc">VM_STATE_WRITABLE_NOT</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84537"> </a>Read-only memory </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84540"> </a><b class="symbol_lc">VM_STATE_CACHEABLE</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84542"> </a>Cacheable memory </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84544"> </a><b class="symbol_lc">VM_STATE_CACHEABLE_NOT</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84546"> </a>Noncacheable memory </div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p></dl><dl class="margin"><dd><div class="Item"><a name="84547"> </a>Validity</div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="84548"> </a>A valid state indicates the virtual-to-physical translation is true. When the translation tables are initialized, global virtual memory is marked as valid. All other virtual memory is initialized as invalid. </div><br></dl></dl><dd><div class="Item"><a name="84549"> </a>Writability</div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="84550"> </a>Pages can be made read-only by setting the state to nonwritable. This is used by VxWorks to write-protect all text segments. </div><br></dl></dl><dd><div class="Item"><a name="84551"> </a>Cacheability</div><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="84552"> </a>The caching of memory pages can be prevented by setting the state flags to noncacheable. This is useful for memory that is shared between processors (including DMA devices). </div><br></dl></dl></dl><dl class="margin"><dd><p class="Body"><a name="84554"> </a>Change the state of a page with the routine <b class="routine"><i class="routine">vmStateSet</i></b><b>(</b> <b>)</b>. In addition to specifying the state flags, a state mask must describe which flags are being changed; see <a href="c-vm5.html#84561">Table 7-3</a>. Additional architecture-dependent states are specified in <b class="file">vmLib.h</b>. <p class="table"><h4 class="EntityTitle"><a name="84561"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 7-3: State Masks</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84565"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Constant</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84567"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84570"> </a><b class="symbol_lc">VM_STATE_MASK_VALID</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84572"> </a>Modify valid flag </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84575"> </a><b class="symbol_lc">VM_STATE_MASK_WRITABLE</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84577"> </a>Modify write flag </div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="84580"> </a><b class="symbol_lc">VM_STATE_MASK_CACHEABLE</b> </div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="84582"> </a>Modify cache flag </div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84584">7.5.2 Private Virtual Memory</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84587"> </a>Private virtual memory can be created by creating a new virtual memory context. This is useful for protecting data by making it inaccessible to other tasks or by limiting access to specific routines. Virtual memory contexts are not automatically created for tasks, but can be created and swapped in and out in an application-specific manner. </p><dd><p class="Body"><a name="84588"> </a>At system initialization, a default context is created. All tasks use this default context. To create private virtual memory, a task must create a new virtual memory context using <b class="routine"><i class="routine">vmContextCreate</i></b><b>(</b> <b>)</b>, and make it current. All virtual memory contexts share the global mappings that are created at system initialization; see <a href="c-vm5.html#84597">Figure 7-1</a>. Only the valid virtual memory in the current virtual memory context (including global virtual memory) is accessible. Virtual memory defined in other virtual memory contexts is not accessible. To make another memory context current, use <b class="routine"><i class="routine">vmCurrentSet</i></b><b>(</b> <b>)</b>.<div class="frame"><h4 class="EntityTitle"><a name="84597"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 7-1: Global Mappings of Virtual Memory</font></a></h4><dl class="margin"><div class="Anchor"><a name="84644"> </a><img class="figure" border="0" src="images/c-vm0.gif"></div></dl></div></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -