可能有个误区:VxWorks可以直接访问Memory的物理地址。个人愚见:程序使用的就叫虚拟地址,只不过Vx5和Vx6里虚拟地址与物理地址的值通常相等
用相应的Show命令看一下地址转换表
为什么是这样的?在Vx5和Vx6的BSP里都会有个sysLib.c文件,里面都会有一个全局数组sysPhysMemDesc,看一下它的值
就是这个表来映射地址的,虚拟地址和物理地址使用的都是同一个值
扒一下它在Vx55的加载顺序
代码语言:javascript复制void usrRoot(char *pMemPoolStart, unsigned memPoolSize)
{
...
usrMmuInit();
...
}
void usrMmuInit()
{
...
if((vmLibInit(VM_PAGE_SIZE) != OK) ||
(vmGlobalMapInit(&sysPhysMemDesc[0], sysPhysMemDescNumEnt, TRUE) == NULL))
...
...
return;
}
VM_CONTEXT_ID vmGlobalMapInit(PHYS_MEM_DESC *pMemDescArray, int numDescArrayElements, BOOL enable)
{
int i;
PHYS_MEM_DESC *thisDesc;
for (i = 0; i < numDescArrayElements; i )
{
thisDesc = &pMemDescArray[i];
/* map physical directly to virtual and set initial state */
if (vmGlobalMap ((void *)thisDesc->virtualAddr,
(void *)thisDesc->physicalAddr, thisDesc->len) == ERROR)
{
...
}
}
...
}
#define MMU_GLOBAL_PAGE_MAP (*(mmuLibFuncs.mmuGlobalPageMap))
STATUS vmGlobalMap(void *virtualAddr, void *physicalAddr, UINT len)
{
char *thisVirtPage = (char *)virtualAddr;
char *thisPhysPage = (char *)physicalAddr;
if(MMU_GLOBAL_PAGE_MAP (thisVirtPage, thisPhysPage) == ERROR)
{
...
}
...
}
Vx69的大同小异
代码语言:javascript复制void usrRoot(char *pMemPoolStart, unsigned memPoolSize)
{
...
usrMmuInit((VIRT_ADDR)pMemPoolStart, memPoolSize); /* MMU global map support */
...
}
#define MEM_DESC sysPhysMemDesc
#define MEM_DESC_NUM_ENT sysPhysMemDescNumEnt
void usrMmuInit(VIRT_ADDR memPoolStartAdrs, unsigned memPoolSize)
{
...
if(vmGlobalMapInit(MEM_DESC, MEM_DESC_NUM_ENT, TRUE, MMU_DEFAULT_CACHE_MODE) == NULL)
...
...
}
#define MMU_GLOBAL_PAGE_MAP (*(mmuLibFuncs.mmuGlobalPageMap))
VM_CONTEXT_ID vmGlobalMapInit(PHYS_MEM_DESC * pMemDescArray, int numDescArrayElements, BOOL enable, UINT cacheDefault)
{
...
MMU_GLOBAL_PAGE_MAP(thisDesc->virtualAddr, thisDesc->physicalAddr,...);
...
}
如果物理地址很难静态指定呢?例如PCI或USB设备。那就使用sysMmuMapAdd()
从源码至少可以得到两个信息
- 虚拟地址与物理地址的值相等
- 数组的长度要足够
扒一下Vx55下Intel PRO1000网卡驱动的地址映射过程
代码语言:javascript复制void usrInit(int startType)
{
...
sysHwInit();
...
}
void sysHwInit()
{
...
/* initialize PCI network controllers starting from Bus 0 */
pciConfigForeachFunc(0, TRUE, (PCI_FOREACH_FUNC)sysNetPciInit, NULL);
...
}
VEND_ID_DESC vendorIdEnet[] =
{
...
#if defined(INCLUDE_GEI8254X_END)
{INTEL_PCI_VENDOR_ID, sys543PciInit},
#endif
{0xffffffff, NULL} /* last entry */
};
STATUS sysNetPciInit(UINT32 pciBus, UINT32 pciDevice, UINT32 pciFunc, void *pArg)
{
...
/* find & exec. a PCI initialization routine for the device */
for(i = 0; (vendorIdEnet[i].pPciInitRtn) != NULL; i)
{
if((vendorId == vendorIdEnet[i].vendorId) &&
(*(vendorIdEnet[i].pPciInitRtn))(...) == OK)
{
/* initialized the device - move on */
return OK;
}
}
...
}
STATUS sys543PciInit(...)
{
...
/* map the memory-mapped IO (CSR) space into host CPU address space */
if(sysMmuMapAdd(...) == ERROR)
{
...
}
...
}