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

📄 mmupro32lib.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef _DIAB_TOOLasm void diab_int_lock_32(unsigned int Mask){% reg Mask	pushf	popl	Mask	andl	$0x00000200, Mask	cli% mem Mask	pushf	popl	Mask	andl	$0x00000200, Mask	cli}asm void diab_int_unlock_32(unsigned int Mask){% reg Mask; lab L	testl	$0x00000200, Mask	jz	L	stiL:% mem Mask; lab L	testl	$0x00000200, Mask	jz	L	stiL:}#undef INT_LOCK#define INT_LOCK(oldLevel)	diab_int_lock_32(oldLevel)#undef INT_UNLOCK#define INT_UNLOCK(oldLevel)	diab_int_unlock_32(oldLevel)asm void MMU_ON(){%lab L! "ax"	movl	%cr0,%eax	orl	$0x80010000,%eax	movl	%eax,%cr0	jmp	LL:}asm void MMU_OFF(){%lab L! "ax"	movl	%cr0,%eax	andl	$0x7ffeffff,%eax	movl	%eax,%cr0	jmp	LL:}asm void MMU_TLB_FLUSH(){%lab L! "ax"	pushfl	cli	movl	%cr3,%eax	movl	%eax,%cr3	jmp LL:	popfl}#else /* Old GNU stuff */#define MMU_ON() \    do { int tempReg; _WRS_ASM ("movl %%cr0,%0; orl $0x80010000,%0; \    movl %0,%%cr0; jmp 0f; 0:" : "=r" (tempReg) : : "memory"); } while (0)#define MMU_OFF() \    do { int tempReg; _WRS_ASM ("movl %%cr0,%0; andl $0x7ffeffff,%0; \    movl %0,%%cr0; jmp 0f; 0:" : "=r" (tempReg) : : "memory"); } while (0)/* inline version of mmuI86TLBFlush() */#define	MMU_TLB_FLUSH() \    do { int tempReg; _WRS_ASM ("pushfl; cli; movl %%cr3,%0; \    movl %0,%%cr3; jmp 0f; 0: popfl; " : "=r" (tempReg) : : "memory"); \    } while (0)#endif /* _DIAB_TOOL  */#define MMU_UNLOCK(wasEnabled, oldLevel) \    do { if (((wasEnabled) = mmuPro32Enabled) == TRUE) \	{INT_LOCK (oldLevel); MMU_OFF (); } \    } while (0)#define MMU_LOCK(wasEnabled, oldLevel) \    do { if ((wasEnabled) == TRUE) \        {MMU_ON (); INT_UNLOCK (oldLevel);} \    } while (0)/******************************************************************************** mmuPro32LibInit - 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 mmuPro32LibInit     (    int pageSize	/* system pageSize (must be 4KB or 4MB) */    )    {    PTE *pDirectoryTable;    int ix;    /* 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;    /* we assume a 4KB or 4MB page size */    if ((pageSize != PAGE_SIZE_4KB) && (pageSize != PAGE_SIZE_4MB))	{	errno = S_mmuLib_INVALID_PAGE_SIZE;	return (ERROR);	}    mmuPro32Enabled = FALSE;    mmuPageSize = pageSize;    /* allocate the global page block array to keep track of which parts     * of virtual memory are handled by the global translation tables.     * Allocate on page boundry so we can write protect it.     */    globalPageBlock = (BOOL *) memalign (mmuPageSize, mmuPageSize);    bzero ((char *) globalPageBlock, mmuPageSize);    /* build a dummy translation table which will hold the pte's for     * global memory.  All real translation tables will point to this     * one for controling the state of the global virtual memory       */    /* allocate a page to hold the directory table */    mmuGlobalTransTbl.pDirectoryTable = pDirectoryTable = 	(PTE *) memalign (mmuPageSize, mmuPageSize);    if (pDirectoryTable == NULL)	return (ERROR);    /* invalidate all the directory table entries */    for (ix = 0; ix < (PD_SIZE / sizeof(PTE)); ix++)	{	pDirectoryTable[ix].field.present	= 0;	pDirectoryTable[ix].field.rw		= 0;	pDirectoryTable[ix].field.us		= 0;	pDirectoryTable[ix].field.pwt		= 0;	pDirectoryTable[ix].field.pcd		= 0;	pDirectoryTable[ix].field.access	= 0;	pDirectoryTable[ix].field.dirty		= 0;	if (pageSize == PAGE_SIZE_4KB)	    pDirectoryTable[ix].field.pagesize	= 0;	else	    pDirectoryTable[ix].field.pagesize	= 1;	pDirectoryTable[ix].field.global	= 0;	pDirectoryTable[ix].field.avail		= 0;	pDirectoryTable[ix].field.page		= -1;	}    /* set CR4 register: PAE=0 PSE=1 */    vxCr4Set ((vxCr4Get() & ~CR4_PAE) | CR4_PSE );    return (OK);    }/******************************************************************************** mmuPteGet - get the pte for a given page** mmuPteGet traverses a translation table and returns the (physical) address of* the pte for the given virtual address.** RETURNS: OK or ERROR if there is no virtual space for the given address **/LOCAL STATUS mmuPteGet     (    MMU_TRANS_TBL *pTransTbl, 	/* translation table */    void *virtAddr,		/* virtual address */     PTE **result		/* result is returned here */    )    {    PTE *pDte;    PTE *pPageTable;    pDte = &pTransTbl->pDirectoryTable	    [((UINT) virtAddr & DIR_BITS) >> DIR_INDEX];    if (mmuPageSize == PAGE_SIZE_4KB)	{        pPageTable = (PTE *) (pDte->bits & PTE_TO_ADDR_4KB);         if ((UINT) pPageTable == (0xffffffff & PTE_TO_ADDR_4KB))	    return (ERROR);        *result = &pPageTable [((UINT) virtAddr & TBL_BITS) >> TBL_INDEX];	}    else	{        if ((UINT) pDte == (0xffffffff & PTE_TO_ADDR_4MB))	    return (ERROR);        *result = pDte;	}    return (OK);    }/******************************************************************************** mmuTransTblCreate - create a new translation table.** create a i86 translation table.  Allocates space for the MMU_TRANS_TBL* data structure and calls mmuTransTblInit on that object.  ** RETURNS: address of new object or NULL if allocation failed,*          or NULL if initialization failed.*/LOCAL MMU_TRANS_TBL *mmuTransTblCreate     (    )    {    MMU_TRANS_TBL *newTransTbl;    newTransTbl = (MMU_TRANS_TBL *) malloc (sizeof (MMU_TRANS_TBL));    if (newTransTbl == NULL)	return (NULL);    if (mmuTransTblInit (newTransTbl) == ERROR)	{	free ((char *) newTransTbl);	return (NULL);	}    return (newTransTbl);    }/******************************************************************************** mmuTransTblInit - initialize a new translation table ** Initialize a new translation table.  The directory table is copyed from the* global translation mmuGlobalTransTbl, so that we* will share the global virtual memory with all* other translation tables.* * RETURNS: OK or ERROR if unable to allocate memory for directory table.*/LOCAL STATUS mmuTransTblInit     (    MMU_TRANS_TBL *newTransTbl		/* translation table to be inited */    )    {    FAST PTE *pDirectoryTable;    /* allocate a page to hold the directory table */    newTransTbl->pDirectoryTable = pDirectoryTable = 	(PTE *) memalign (mmuPageSize, mmuPageSize);    if (pDirectoryTable == NULL)	return (ERROR);    /* copy the directory table from mmuGlobalTransTbl,     * so we get the global virtual memory      */    bcopy ((char *) mmuGlobalTransTbl.pDirectoryTable, 	   (char *) pDirectoryTable, PD_SIZE);    /* write protect virtual memory pointing to the the directory table in      * the global translation table to insure that it can't be corrupted      */    mmuStateSet (&mmuGlobalTransTbl, (void *) pDirectoryTable, 		 MMU_STATE_MASK_WRITABLE, MMU_STATE_WRITABLE_NOT);    return (OK);    }/******************************************************************************** mmuTransTblDelete - delete a translation table.* * mmuTransTblDelete deallocates all the memory used to store the translation* table entries.  It does not deallocate physical pages mapped into the* virtual memory space.** RETURNS: OK**/LOCAL STATUS mmuTransTblDelete     (    MMU_TRANS_TBL *transTbl		/* translation table to be deleted */    )    {    FAST int ix;    FAST PTE *pDte = transTbl->pDirectoryTable;    FAST PTE *pPageTable;    /* write enable the physical page containing the directory table */    mmuStateSet (&mmuGlobalTransTbl, transTbl->pDirectoryTable, 		 MMU_STATE_MASK_WRITABLE, MMU_STATE_WRITABLE);    /* deallocate only non-global page blocks */    if (mmuPageSize == PAGE_SIZE_4KB)        for (ix = 0; ix < (PT_SIZE / sizeof(PTE)); ix++, pDte++)	    if ((pDte->field.present == 1) && !globalPageBlock[ix]) 	        {	        pPageTable = (PTE *) (pDte->bits & PTE_TO_ADDR_4KB);	        mmuStateSet (&mmuGlobalTransTbl, pPageTable,			     MMU_STATE_MASK_WRITABLE, MMU_STATE_WRITABLE);	        free (pPageTable);	        }    /* free the page holding the directory table */    free (transTbl->pDirectoryTable);    /* free the translation table data structure */    free (transTbl);        return (OK);    }/******************************************************************************** mmuVirtualPageCreate - set up translation tables for a virtual page** simply check if there's already a page table that has a* pte for the given virtual page.  If there isn't, create one.** RETURNS OK or ERROR if couldn't allocate space for a page table.*/LOCAL STATUS mmuVirtualPageCreate     (    MMU_TRANS_TBL *thisTbl, 		/* translation table */    void *virtPageAddr			/* virtual addr to create */    )    {    PTE *pDte;    FAST PTE *pPageTable;    FAST UINT ix;    PTE *dummy;    if (mmuPteGet (thisTbl, virtPageAddr, &dummy) == OK)	return (OK);

⌨️ 快捷键说明

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