📄 mmush7700lib.html
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/mmuSh7700Lib.html - generated by refgen from ../sh/mmuSh7700Lib.c --> <title> mmuSh7700Lib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.htm"><i>VxWorks API Reference : OS Libraries</i></a></p></blockquote><h1>mmuSh7700Lib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>mmuSh7700Lib</strong> - Hitachi SH7700 MMU support library </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./mmuSh7700Lib.html#mmuSh7700LibInit">mmuSh7700LibInit</a>( )</b> - initialize module<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p><p><b>mmuLib.c</b> provides the architecture dependent routines that directly controlthe memory management unit. It provides 10 routines that are called by thehigher level architecture independent routines in <b>vmLib.c</b>: <p>mmuLibInit - initialize modulemmuTransTblCreate - create a new translation tablemmuTransTblDelete - delete a translation table.mmuEnable - turn mmu on or offmmuStateSet - set state of virtual memory pagemmuStateGet - get state of virtual memory pagemmuPageMap - map physical memory page to virtual memory pagemmuGlobalPageMap - map physical memory page to global virtual memory pagemmuTranslate - translate a virtual address to a physical addressmmuCurrentSet - change active translation table<p>Applications using the mmu will never call these routines directly; the visable interface is supported in <b>vmLib.c</b>.<p><b>mmuLib</b> supports the creation and maintenance of multiple translation tables,one of which is the active translation table when the mmu is enabled.Note that VxWorks does not include a translation table as part of the taskcontext; individual tasks do not reside in private virtual memory. However,we include the facilities to create multiple translation tables so thatthe user may create "private" virtual memory contexts and switch them in anapplication specific manner. Newtranslation tables are created with a call to mmuTransTblCreate, and installedas the active translation table with mmuCurrentSet. Translation tablesare modified and potentially augmented with calls to mmuPageMap and mmuStateSet.The state of portions of the translation table can be read with calls tommuStateGet and mmuTranslate.<p>The traditional VxWorks architecture and design philosophy requires that allobjects and operating systems resources be visable and accessable to all agents(tasks, isrs, watchdog timers, etc) in the system. This has traditionally beeninsured by the fact that all objects and data structures reside in physical memory; thus, a data structure created by one agent may be accessed by anyother agent using the same pointer (object identifiers in VxWorks are oftenpointers to data structures.) This creates a potentialproblem if you have multiple virtual memory contexts. For example, if asemaphore is created in one virtual memory context, you must gurantee thatthat semaphore will be visable in all virtual memory contexts if the semaphoreis to be accessed at interrupt level, when a virtual memory context other thanthe one in which it was created may be active. Another example is thatcode loaded using the incremental loader from the shell must be accessablein all virtual memory contexts, since code is shared by all agents in thesystem.<p>This problem is resolved by maintaining a global "transparent" mappingof virtual to physical memory for all the contiguous segments of physicalmemory (on board memory, i/o space, sections of vme space, etc) that is sharedby all translation tables; all available physical memory appears at the same address in virtual memory in all virtual memory contexts. This technique provides an environment that allowsresources that rely on a globally accessable physical address to run withoutmodification in a system with multiple virtual memory contexts.<p>An additional requirement is that modifications made to the state of global virtual memory in one translation table appear in all translation tables. Forexample, memory containing the text segment is made read only (to avoidaccidental corruption) by setting the appropriate writeable bits in the translation table entries corresponding to the virtual memory containing the text segment. This state information must be shared by all virtual memory contexts, so that no matter what translation table is active, the text segmentis protected from corruption. The mechanism that implements this feature isarchitecture dependent, but usually entails building a section of a translation table that corresponds to the global memory, that is shared byall other translation tables. Thus, when changes to the state of the globalmemory are made in one translation table, the changes are reflected in allother translation tables.<p><b>mmuLib</b> provides a seperate call for constructing global virtual memory -mmuGlobalPageMap - which creates translation table entries that are sharedby all translation tables. Initialization code in usrConfig makes callsto vmGlobalMap (which in turn calls mmuGlobalPageMap) to set up global transparent virtual memory for allavailable physical memory. All calls made to mmuGlobaPageMap must occur beforeany virtual memory contexts are created; changes made to global virtualmemory after virtual memory contexts are created are not guaranteed to bereflected in all virtual memory contexts.<p>Most mmu architectures will dedicate some fixed amount of virtual memory to a minimal section of the translation table (a "segment", or "block"). This creates a problem in that the user may map a small section of virtual memoryinto the global translation tables, and then attempt to use the virtual memoryafter this section as private virtual memory. The problem is that the translation table entries for this virtual memory are contained in the global translation tables, and are thus shared by all translation tables. This condition is detected by vmMap, and an error is returned, thus, the lowerlevel routines in <b>mmuLib.c</b> (mmuPageMap, mmuGlobalPageMap) need not performany error checking.<p>A global variable called mmuPageBlockSize should be defined which is equal to the minimum virtual segment size.<p>This module supports the SH7700 mmu with a two level translation table:<p><pre> root | | -------------------------------- top level | td | td | td | td | td | td | ... -------------------------------- | | | | | | | | | | | | ---------- | v v v v | ----- NULL NULL NULL NULL | | v v ------ ------l | ptel | | ptel |o ------ ------w | ptel | | ptel | e ------ ------r | ptel | | ptel |l ------ ------e | ptel | | ptel |v ------ ------e . .l . . . .</pre>where the top level consists of an array of pointers (Table Descriptors)held within a single4k page. These point to arrays of PTEL (Page Table Entry Low) arrays inthe lower level. Each of these lower level arrays is also held within a single4k page, and describes a virtual space of 4MB (each pagedescriptor is 4 bytes, so we get 1024 of these in each array, and each pagedescriptor maps a 4KB page - thus 1024 * 4096 = 4MB.) <p>To implement global virtual memory, a seperate translation table called mmuGlobalTransTbl is created when the module is initialized. Calls to mmuGlobalPageMap will augment and modify this translation table. When newtranslation tables are created, memory for the top level array of td's isallocated and initialized by duplicating the pointers in mmuGlobalTransTbl'stop level td array. Thus, the new translation table will use the globaltranslation table's state information for portions of virtual memory that aredefined as global. Here's a picture to illustrate:<p><pre> GLOBAL TRANS TBL NEW TRANS TBL root root | | | | ------------------------- ------------------------- top level | td1 | td2 | NULL| NULL| | td1 | td2 | NULL| NULL| ------------------------- ------------------------- | | | | | | | | | | | | | | | | ---------- | v v ---------- | v v | ------ NULL NULL | | NULL NULL | | | | o------------------------------------ | | | | | o----------------------------------------- | | v v ------ ------ l | ptel | | ptel |o ------ ------w | ptel | | ptel | e ------ ------r | ptel | | ptel |l ------ ------e | ptel | | ptel |v ------ ------e . .l . . . .</pre>Note that with this scheme, the global memory granularity is 4MB. Each timeyou map a section of global virtual memory, you dedicate at least 4MB of the virtual space to global virtual memory that will be shared by all virtualmemory contexts.<p>The physcial memory that holds these data structures is obtained from thesystem memory manager via memalign to insure that the memory is pagealigned. We want to protect this memory from being corrupted,so we invalidate the descriptors that we set up in the global translationthat correspond to the memory containing the translation table data structures.This creates a "chicken and the egg" paradox, in that the only way we canmodify these data structures is through virtual memory that is now invalidated,and we can't validate it because the page descriptors for that memory arein invalidated memory (confused yet?)So, you will notice that anywhere that page table descriptors (ptel's)are modified, we do so by locking out interrupts, momentarily disabling themmu, accessing the memory with its physical address, enabling the mmu, andthen re-enabling interrupts (see mmuStateSet, for example.)<p></blockquote><h4>USER MODIFIABLE OPTIONS</h4><blockquote><p><p>1) Memory fragmentation - <b>mmuLib</b> obtains memory from the system memory<br> manager via memalign to contain the mmu's translation tables. This memory<br> was allocated a page at a time on page boundries. Unfortunately, in the<br> current memory management scheme, the memory manager is not able to allocate<br> these pages contiguously. Building large translation tables (ie, when<br> mapping large portions of virtual memory) causes excessive fragmentation<br> of the system memory pool. An attempt to alleviate this has been installed<br> by providing a local buffer of page aligned memory; the user may control<br> the buffer size by manipulating the global variable mmuNumPagesInFreeList.<br> By default, mmuPagesInFreeList is set to 8.<p>2) Alternate memory source - A customer has special purpose hardware that<br> includes seperate static RAM for the mmu's translation tables. Thus, they<br> require the ability to specify an alternate source of memory other than<br> memalign. A global variable has been created that points to the memory<br> partition to be used as the source for translation table memory; by default,<br> it points to the system memory partition. The user may modify this to <br> point to another memory partition before mmuSh7700LibInit is called.<hr><a name="mmuSh7700LibInit"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>mmuSh7700LibInit( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>mmuSh7700LibInit( )</strong> - initialize module</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS mmuSh7700LibInit ( int pageSize )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>Build a dummy translation table that will hold the page table entries forthe global translation table. The mmu remains disabled uponcompletion. Note that this routine is global so that it may be referencedin <b>usrConfig.c</b> to pull in the correct <b>mmuLib</b> for the specific architecture.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK or ERROR</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./mmuSh7700Lib.html#top">mmuSh7700Lib</a></b></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -