阅读:1287回复:5
请各位高手指教:地址映射,急!!!送分。
用driver works 3.0 开发wdm驱动,怎样实现虚拟地址到物理地址的映射。类似ddk中mmGetPhysicalAddress函数的功能,但该函数在wdm中无法使用。
我需要在应用程序中通过directX在显存中申请缓冲,然后设法将该地址转换成物理地址,传给我们的PCI板卡,然后由板卡直接向显卡传图像! 哪位高手有其他方法,请多多指教!! |
|
最新喜欢:![]() |
沙发#
发布于:2003-11-10 14:40
z通过查表,直接将线性地址转换为物理地址
ULONG LinearAddressToPhysicalAddress(ULONG lAddress) { unsigned int *pAddr; unsigned int *PageDirectoryEntry=(unsigned int *)0xC0300000; unsigned int *PageTableEntry=(unsigned int *)0xC0000000; //判断页目录是否有效,第0位(P)为存在位, if((!(PageDirectoryEntry[lAddress>>22]&0xFFFFF000)) &&(!(PageDirectoryEntry[lAddress>>22]&0x00000001))) return 0; //@(C0000000h+(LA&0xFFFFF000)>>10d)&0fffff000h+PO pAddr=(int *)((int)PageTableEntry+((lAddress&0xFFFFF000)>>10)); if((*pAddr)&1) return ((*pAddr) &0xFFFFF000) |(lAddress&0x00000FFF); return 0; } |
|
|
板凳#
发布于:2003-11-10 15:17
老兄:多谢,多谢!
刚才试了一下,我在驱动里申请了一段空间,然后用你的算法测试是可以的。但还不知道这个算法是否在任何情况下都成立。在DirectX里申请显存Overlay缓冲,虽然现在还没法测试,但还是先行谢过! |
|
地板#
发布于:2003-11-10 16:09
是不是在任何情况下都可以,可很难说,保险点用下面这个,基本是对NTOSKRNL的MmGetPhysicalAddress,反汇编代码写的,可以支持
支持高达64GB寻址的PSE 36寻址,用EDX:EAX双字返回换算结果。 MmGetPhysicalAddress proc VirtualAddress:dword mov ecx,[VirtualAddress] mov eax,ecx shr eax,20 and eax,0FFCH push esi lea esi,[eax+0C0300000H] mov edx,[esi] test dl,BIT0 ;P Flag jz .NotPresent test dl,BIT7 ;PS Flag jnz .Page4M mov eax,ecx and eax,NOT 0FFFH shr eax,10 add eax,0C0000000H mov eax,[eax] test al,BIT0 ;P Flag jz .NotPresent and eax,NOT 0FFFH and ecx,0FFFH add eax,ecx xor edx,edx pop esi jmp .L2PQuit Page4M: mov eax,ecx and eax,NOT 0FFC00000H ;Clear 31-22 Bits and edx,NOT 01FFFH ;0-12 Bits add eax,edx push eax ;Save 0-31 Bits mov eax,1 cpuid test edx,BIT17 ;PSE feature Flag jnz @f pop eax xor edx,edx pop esi jmp .L2PQuit @@: pop eax mov edx,[esi] shr edx,12 and edx,0FH ;Get 32-35 Bits pop esi jmp .L2PQuit NotPresent: pop esi xor eax,eax xor edx,edx L2PQuit: ret MmGetPhysicalAddress endp |
|
|
地下室#
发布于:2003-11-12 16:55
我也遇到过这个问题,后来我采用强行连接ntoskrnl.lib的方法解决的。
因为MmGetPhysicalAddress实际就在ntoskrnl.lib中,因此你在程序中,人为的添加 extern \"C\" PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vAddr); 然后在链接库中添加ntoskrnl.lib。(如果没有发现,就写上全路经名)。 编译,连接正常。 |
|
5楼#
发布于:2003-11-13 09:11
多谢
|
|