⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmu30lib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/* mmu30Lib.c - mmu library for 68030 *//* Copyright 1984-1992 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01n,10feb99,wsl  Add comment documenting ERRNO value01m,11jul96,jmb  Make comments consistent with 8K pagesize, not 4K (SPR #5846)01l,05jul94,rdc  mods to decrease fragmentation and provide alternate memory 		 source.  Fixed bug that caused pages containing page 		 descriptors to be write enabled.01k,12feb93,rdc  changed scheme for sharing data structures with vmLib.01j,09feb93,rdc  fixed bug in mmuMemPagesWriteDisable.01i,09oct92,rdc  added prototype for mmuPtest.01h,01oct92,jcf  changed cache* interface.01f,22sep92,rdc  doc.01e,13jul92,rdc  write protected pages used for global trans tbl.01d,28jul92,jmm  added forward function references01c,15jul92,jwt  converted cacheClearEntry() to cacheMc68kClearEntry().01b,13jul92,rdc  changed reference to vmLib.h to vmLibP.h.01a,08jul92,rdc  written.*//*DESCRIPTION:mmuLib.c 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 vmLib.c: 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 tableApplications using the mmu will never call these routines directly; the visable interface is supported in vmLib.c.mmuLib 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 to mmuStateGet and mmuTranslate.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 potential problem 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.This problem is resolved by maintaining a global "transparent" mappingof virtual to physical memory for all the contiguous segments of physical memory (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.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.mmuLib 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 be reflected in all virtual memory contexts.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 mmuLib.c (mmuPageMap, mmuGlobalPageMap) need not performany error checking.A global variable called mmuPageBlockSize should be defined which is equal to the minimum virtual segment size.  mmuLib must provide a routine mmuGlobalInfoGet, which returns a pointer to the globalPageBlock array.This provides the user with enough information to be able to allocate virtual memory space that does not conflict with the global memory space.This module supports the 68030 mmu with a two level translation table:			    root			     |			     |            ------------------------------------- top level  |sftd |sftd |sftd |sftd |sftd |sftd | ...             -------------------------------------	       |     |     |     |     |     |    	       |     |     |     |     |     |          ----------     |     v     v     v     v      |         ------    NULL  NULL  NULL  NULL      |         |      v         v     ----     ----   l   |sfpd|   |sfpd|o    ----     ----w   |sfpd|   |sfpd|     e    ----     ----r   |sfpd|   |sfpd|l    ----     ----e   |sfpd|   |sfpd|v    ----     ----e     .         .l     .         .      .         .where the top level consists of an array of pointers (Short Format Table Descriptors) held within a single8k page.  These point to arrays of Short Format Page Descriptor arrays in the lower level.  Each of these lower level arrays is also held within a single8k page, and describes a virtual space of 16 MB (each short format pagedescriptor is 4 bytes, so we get 2048 of these in each array, and each pagedescriptor maps a 8KB page - thus 2048 * 8192 = 16MB.)  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 sftd's isallocated and initialized by duplicating the pointers in mmuGlobalTransTbl'stop level sftd 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:	         GLOBAL TRANS TBL		      NEW TRANS TBL 		       root				   root		        |				    |		        |				    |            -------------------------           ------------------------- top level  |sftd1|sftd2| NULL| NULL|           |sftd1|sftd2| NULL| NULL|            -------------------------           -------------------------	       |     |     |     |                 |     |     |     |   	       |     |     |     |                 |     |     |     |        ----------     |     v     v        ----------     |     v     v      |         ------    NULL  NULL      |		 |    NULL  NULL      |         |			  |		 |      o------------------------------------		 |      |		|					 |      |		o-----------------------------------------      |		|      v         v     ----     ----   l   |sfpd|   |sfpd|o    ----     ----w   |sfpd|   |sfpd|     e    ----     ----r   |sfpd|   |sfpd|l    ----     ----e   |sfpd|   |sfpd|v    ----     ----e     .         .l     .         .      .         .Note that with this scheme, the global memory granularity is 16MB.  Each timeyou map a section of global virtual memory, you dedicate at least 16MB of the virtual space to global virtual memory that will be shared by all virtualmemory contexts.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 (pte's)are modified, we do so by locking out interrupts, momentarily disabling the mmu, accessing the memory with its physical address, enabling the mmu, andthen re-enabling interrupts (see mmuStateSet, for example.)USER MODIFIABLE OPTIONS:1) Memory fragmentation - mmuLib obtains memory from the system memory   manager via memalign to contain the mmu's translation tables.  This memory   was allocated a page at a time on page boundries.  Unfortunately, in the   current memory management scheme, the memory manager is not able to allocate   these pages contiguously.  Building large translation tables (ie, when   mapping large portions of virtual memory) causes excessive fragmentation   of the system memory pool.  An attempt to alleviate this has been installed   by providing a local buffer of page aligned memory;  the user may control   the buffer size by manipulating the global variable mmuNumPagesInFreeList.   By default, mmuPagesInFreeList is set to 4.2) Alternate memory source - A customer has special purpose hardware that   includes seperate static RAM for the mmu's translation tables.  Thus, they   require the ability to specify an alternate source of memory other than   memalign.  A global variable has been created that points to the memory   partition to be used as the source for translation table memory; by default,   it points to the system memory partition.  The user may modify this to    point to another memory partition before mmu30LibInit is called.*/#include "vxWorks.h"#include "string.h"#include "intLib.h"#include "stdlib.h"#include "memLib.h"#include "private/memPartLibP.h"#include "private/vmLibP.h"#include "arch/mc68k/mmu30Lib.h"#include "mmuLib.h"#include "errno.h"#include "cacheLib.h"/* forward declarations */ LOCAL void mmuMemPagesWriteDisable (MMU_TRANS_TBL *transTbl);LOCAL STATUS mmuPteGet (MMU_TRANS_TBL *pTransTbl, void *virtAddr, PTE **result);LOCAL MMU_TRANS_TBL *mmuTransTblCreate ();LOCAL STATUS mmuTransTblInit (MMU_TRANS_TBL *newTransTbl);LOCAL STATUS mmuTransTblDelete (MMU_TRANS_TBL *transTbl);LOCAL STATUS mmuVirtualPageCreate (MMU_TRANS_TBL *thisTbl, void *virtPageAddr);LOCAL STATUS mmuEnable (BOOL enable);LOCAL void mmuOn ();LOCAL void mmuOff ();LOCAL STATUS mmuStateSet (MMU_TRANS_TBL *transTbl, void *pageAddr, UINT stateMask, UINT state);LOCAL STATUS mmuStateGet (MMU_TRANS_TBL *transTbl, void *pageAddr, UINT *state);LOCAL STATUS mmuPageMap (MMU_TRANS_TBL *transTbl, void *virtualAddress, void *physPage);LOCAL STATUS mmuGlobalPageMap (void *virtualAddress, void *physPage);LOCAL STATUS mmuTranslate (MMU_TRANS_TBL *transTbl, void *virtAddress, void **physAddress);LOCAL void mmuCurrentSet (MMU_TRANS_TBL *transTbl);LOCAL void mmuATCFlush (void *addr);/* XXX for debugging:  LOCAL void mmuPtest (char *addr, int level); */LOCAL char *mmuPageAlloc (MMU_TRANS_TBL *transTbl);/* kludgey static data structure for parameters in __asm__ directives. */LOCAL TC_REG localTc;LOCAL CRP_REG localCrp;int mmuPageSize;int mmuNumPagesInFreeList = 4;PART_ID mmuPageSource = NULL;/* a translation table to hold the descriptors for the global transparent * translation of physical to virtual memory  */LOCAL MMU_TRANS_TBL mmuGlobalTransTbl;/* initially, the current trans table is a dummy table with mmu disabled */LOCAL MMU_TRANS_TBL *mmuCurrentTransTbl = &mmuGlobalTransTbl;/* array of booleans used to keep track of sections of virtual memory defined * as global. */LOCAL BOOL *globalPageBlock;LOCAL STATE_TRANS_TUPLE mmuStateTransArrayLocal [] =    {    {VM_STATE_MASK_VALID, MMU_STATE_MASK_VALID,      VM_STATE_VALID, MMU_STATE_VALID},    {VM_STATE_MASK_VALID, MMU_STATE_MASK_VALID,      VM_STATE_VALID_NOT, MMU_STATE_VALID_NOT},    {VM_STATE_MASK_WRITABLE, MMU_STATE_MASK_WRITABLE,     VM_STATE_WRITABLE, MMU_STATE_WRITABLE},    {VM_STATE_MASK_WRITABLE, MMU_STATE_MASK_WRITABLE,     VM_STATE_WRITABLE_NOT, MMU_STATE_WRITABLE_NOT},    {VM_STATE_MASK_CACHEABLE, MMU_STATE_MASK_CACHEABLE,     VM_STATE_CACHEABLE, MMU_STATE_CACHEABLE},    {VM_STATE_MASK_CACHEABLE, MMU_STATE_MASK_CACHEABLE,     VM_STATE_CACHEABLE_NOT, MMU_STATE_CACHEABLE_NOT}    };LOCAL MMU_LIB_FUNCS mmuLibFuncsLocal =    {    mmu30LibInit,    mmuTransTblCreate,    mmuTransTblDelete,    mmuEnable,       mmuStateSet,    mmuStateGet,    mmuPageMap,    mmuGlobalPageMap,    mmuTranslate,    mmuCurrentSet    };IMPORT STATE_TRANS_TUPLE *mmuStateTransArray;IMPORT int mmuStateTransArraySize;IMPORT MMU_LIB_FUNCS mmuLibFuncs;IMPORT int mmuPageBlockSize;LOCAL BOOL mmuEnabled = FALSE;/* MMU_UNLOCK and MMU_LOCK are used to access page table entries that are in * virtual memory that has been invalidated to protect it from being corrupted */#define MMU_UNLOCK(wasEnabled, oldLevel) \(((wasEnabled) = mmuEnabled)  ? (((oldLevel) = intLock ()), mmuOff (), 0) : 0)#define MMU_LOCK(wasEnabled, oldLevel) ((wasEnabled) ? (mmuOn (), intUnlock (oldLevel)) : 0)/******************************************************************************** mmu30LibInit - initialize module** Build a dummy translation table that will hold the page table entries* for the global translation table.  The mmu remains disabled upon* completion.** RETURNS: OK if no error, ERROR otherwise.** ERRNO: S_mmuLib_INVALID_PAGE_SIZE*/STATUS mmu30LibInit     (    int pageSize	/* system pageSize (must be 8192 for 68k) */    )    {    PTE *pUpperLevelTable;    int i;    /* if the user has not specified a memory partition to obtain pages        from (by initializing mmuPageSource), then initialize mmuPageSource       to the system memory partition.    */    if (mmuPageSource == NULL)	mmuPageSource = memSysPartId;    /* initialize the data objects that are shared with vmLib.c */    mmuStateTransArray = &mmuStateTransArrayLocal [0];    mmuStateTransArraySize =          sizeof (mmuStateTransArrayLocal) / sizeof (STATE_TRANS_TUPLE);    mmuLibFuncs = mmuLibFuncsLocal;    mmuPageBlockSize = PAGE_BLOCK_SIZE;    /* initialize the static data structure that mmuEnable uses to do the     * pmove instruction     */    localTc.zero = 0;    localTc.sre = 0;    localTc.fcl = 0;    localTc.pageSize = NUM_PAGE_OFFSET_BITS;    localTc.initialShift = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -