📄 pcidp.cod
字号:
; 147 : SlotNumber.u.bits.DeviceNumber = DeviceNumber;
00205 8b 45 e4 mov eax, DWORD PTR _DeviceNumber$[ebp]
; 148 :
; 149 : // Try to get the PCI Configuration space.
; 150 : InfoSize = HalGetBusData(
; 151 : IN PCIConfiguration,
; 152 : IN BusNumber,
; 153 : IN SlotNumber.u.AsULONG,
; 154 : OUT (PVOID)&CardInfo,
; 155 : IN (ULONG)(sizeof(CardInfo))
; 156 : ); // ID only
00208 68 00 01 00 00 push 256 ; 00000100H
0020d 33 45 fc xor eax, DWORD PTR _SlotNumber$[ebp]
00210 83 e0 1f and eax, 31 ; 0000001fH
00213 31 45 fc xor DWORD PTR _SlotNumber$[ebp], eax
00216 8d 85 d4 fd ff
ff lea eax, DWORD PTR _CardInfo$[ebp]
0021c 50 push eax
0021d ff 75 fc push DWORD PTR _SlotNumber$[ebp]
00220 ff 75 f8 push DWORD PTR _BusNumber$[ebp]
00223 56 push esi
00224 ff 15 00 00 00
00 call DWORD PTR __imp__HalGetBusData@20
; 157 :
; 158 : // Did we get any data?
; 159 : if(InfoSize > 2){
0022a 83 f8 02 cmp eax, 2
0022d 0f 86 56 02 00
00 jbe $L5955
; 160 :
; 161 : // Check for valid device and vendor IDs.
; 162 : if(CardInfo.VendorID == PCIVendorID &&
; 163 : CardInfo.DeviceID == PCIDeviceID){
00233 0f b7 85 d4 fd
ff ff movzx eax, WORD PTR _CardInfo$[ebp]
0023a 3b 45 d8 cmp eax, DWORD PTR _PCIVendorID$[ebp]
0023d 0f 85 46 02 00
00 jne $L5955
00243 0f b7 85 d6 fd
ff ff movzx eax, WORD PTR _CardInfo$[ebp+2]
0024a 3b 45 d4 cmp eax, DWORD PTR _PCIDeviceID$[ebp]
0024d 0f 85 36 02 00
00 jne $L5955
; 164 :
; 165 : // We found a valid card. Create a device object for it.
; 166 : DeviceNTName[14] = (USHORT) (0x30 + BoardNumber);
00253 66 8b 45 f0 mov ax, WORD PTR -16+[ebp]
00257 66 89 85 f0 fe
ff ff mov WORD PTR _DeviceNTName$[ebp+28], ax
; 167 : RtlInitUnicodeString(&DeviceNTNameUnicode, DeviceNTName);
0025e 8d 85 d4 fe ff
ff lea eax, DWORD PTR _DeviceNTName$[ebp]
00264 50 push eax
00265 8d 45 b0 lea eax, DWORD PTR _DeviceNTNameUnicode$[ebp]
00268 50 push eax
00269 ff 15 00 00 00
00 call DWORD PTR __imp__RtlInitUnicodeString@8
; 168 :
; 169 : NTStatus = IoCreateDevice(
; 170 : IN DriverObject, // The driver object
; 171 : IN sizeof(PCIDP_EXTENSION), // Size (bytes) of the device ext.
; 172 : IN &DeviceNTNameUnicode, // The device name
; 173 : IN FILE_DEVICE_PCIDP00, // The device type
; 174 : IN 0, // Ignored by this device
; 175 : IN FALSE, // Exclusive Device flag
; 176 : OUT &DeviceObject // New created device object
; 177 : );
0026f 8d 45 f4 lea eax, DWORD PTR _DeviceObject$[ebp]
00272 50 push eax
00273 53 push ebx
00274 53 push ebx
00275 8d 45 b0 lea eax, DWORD PTR _DeviceNTNameUnicode$[ebp]
00278 68 00 c3 00 00 push 49920 ; 0000c300H
0027d 50 push eax
0027e 68 90 00 00 00 push 144 ; 00000090H
00283 ff 75 08 push DWORD PTR _DriverObject$[ebp]
00286 ff 15 00 00 00
00 call DWORD PTR __imp__IoCreateDevice@28
0028c 8b f8 mov edi, eax
; 178 : if(NTStatus != STATUS_SUCCESS)
0028e 3b fb cmp edi, ebx
00290 0f 85 77 02 00
00 jne $ExitA$5947
; 179 : goto ExitA;
; 180 :
; 181 : // Initialize the driver's extended object.
; 182 : ObjExt = (pPCIDP_EXTENSION)DeviceObject->DeviceExtension;
00296 8b 45 f4 mov eax, DWORD PTR _DeviceObject$[ebp]
; 183 : RtlZeroMemory(ObjExt, sizeof(PCIDP_EXTENSION));
00299 6a 24 push 36 ; 00000024H
0029b 59 pop ecx
; 184 : ObjExt->LLData.IsEmpty = TRUE;
; 185 : ObjExt->LLData.CurrentLink = NULL;
; 186 : ObjExt->LLData.InsertedCount = 0;
; 187 : ObjExt->LLData.FreeMax = 0;
; 188 : ObjExt->BusNumber = BusNumber;
; 189 : ObjExt->SlotNumber = SlotNumber;
; 190 : ObjExt->BoardNumber = BoardNumber;
; 191 : ObjExt->BaseAddresses[0] = CardInfo.u.type0.BaseAddresses[0];
; 192 : ObjExt->BaseAddresses[1] = CardInfo.u.type0.BaseAddresses[1];
; 193 : ObjExt->BaseAddresses[2] = CardInfo.u.type0.BaseAddresses[2];
; 194 : ObjExt->BaseAddresses[3] = CardInfo.u.type0.BaseAddresses[3];
; 195 : ObjExt->BaseAddresses[4] = CardInfo.u.type0.BaseAddresses[4];
; 196 : ObjExt->BaseAddresses[5] = CardInfo.u.type0.BaseAddresses[5];
; 197 : //ObjExt->MemoryBase - initialized by MmMapIoSpace call
; 198 : //ObjExt->IOBase - initialized by MmMapIoSpace call
; 199 : //ObjExt->InterruptObject - initialized by IoConnectInterrupt call
; 200 : //ObjExt->LListSpin - initialized by KeInitializeSpinLock call
; 201 :
; 202 : // Translate the bus address for the memory space base address
; 203 : // to the system logical address. Then map it into nonpaged
; 204 : // system space. Save the result in device extended space for
; 205 : // use with other services.
; 206 : BusAddress.HighPart = 0;
; 207 : BusAddress.LowPart = CardInfo.u.type0.BaseAddresses[0];
; 208 : AddressSpace = 0; //address space is memory
; 209 : BoolStatus = HalTranslateBusAddress(
; 210 : IN PCIBus, //bus type
; 211 : IN BusNumber, //bus number
; 212 : IN BusAddress, //bus address
; 213 : IN OUT &AddressSpace, //address space is Memory
; 214 : OUT &TranslatedAddress //translated address
; 215 : );
0029c 8d 55 c0 lea edx, DWORD PTR _TranslatedAddress$[ebp]
0029f 8b 70 28 mov esi, DWORD PTR [eax+40]
002a2 33 c0 xor eax, eax
002a4 8b fe mov edi, esi
002a6 52 push edx
002a7 f3 ab rep stosd
002a9 8b 45 fc mov eax, DWORD PTR _SlotNumber$[ebp]
002ac 8b 4d f8 mov ecx, DWORD PTR _BusNumber$[ebp]
002af 89 46 04 mov DWORD PTR [esi+4], eax
002b2 c6 46 74 01 mov BYTE PTR [esi+116], 1
002b6 0f b7 45 e8 movzx eax, WORD PTR _BoardNumber$[ebp]
002ba 89 5e 7c mov DWORD PTR [esi+124], ebx
002bd 66 89 5e 76 mov WORD PTR [esi+118], bx
002c1 66 89 5e 78 mov WORD PTR [esi+120], bx
002c5 89 0e mov DWORD PTR [esi], ecx
002c7 89 46 08 mov DWORD PTR [esi+8], eax
002ca 8b 85 e4 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+16]
002d0 89 46 0c mov DWORD PTR [esi+12], eax
002d3 8b 85 e8 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+20]
002d9 89 46 10 mov DWORD PTR [esi+16], eax
002dc 8b 85 ec fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+24]
002e2 89 46 14 mov DWORD PTR [esi+20], eax
002e5 8b 85 f0 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+28]
002eb 89 46 18 mov DWORD PTR [esi+24], eax
002ee 8b 85 f4 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+32]
002f4 89 46 1c mov DWORD PTR [esi+28], eax
002f7 8b 85 f8 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+36]
002fd 8d 55 e0 lea edx, DWORD PTR _AddressSpace$[ebp]
00300 89 46 20 mov DWORD PTR [esi+32], eax
00303 8b 85 e4 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+16]
00309 52 push edx
0030a 53 push ebx
0030b 50 push eax
0030c 51 push ecx
0030d 6a 05 push 5
0030f 89 5d e0 mov DWORD PTR _AddressSpace$[ebp], ebx
00312 ff 15 00 00 00
00 call DWORD PTR __imp__HalTranslateBusAddress@24
; 216 : if(BoolStatus == FALSE){
00318 84 c0 test al, al
0031a 0f 84 9b 01 00
00 je $L6232
; 219 : }
; 220 :
; 221 : if(AddressSpace == 0) //address space of 0 means map it
00320 39 5d e0 cmp DWORD PTR _AddressSpace$[ebp], ebx
00323 75 14 jne SHORT $L5971
; 222 : ObjExt->MemoryBase = (ULONG*)MmMapIoSpace(
; 223 : IN TranslatedAddress, //address to map
; 224 : IN MemoryBaseSize, //length in bytes
; 225 : IN FALSE //memory cache
; 226 : );
00325 53 push ebx
00326 68 00 80 00 00 push 32768 ; 00008000H
0032b ff 75 c4 push DWORD PTR _TranslatedAddress$[ebp+4]
0032e ff 75 c0 push DWORD PTR _TranslatedAddress$[ebp]
00331 ff 15 00 00 00
00 call DWORD PTR __imp__MmMapIoSpace@16
; 227 : else
00337 eb 03 jmp SHORT $L6243
$L5971:
; 228 : ObjExt->MemoryBase = (ULONG*)TranslatedAddress.LowPart;
00339 8b 45 c0 mov eax, DWORD PTR _TranslatedAddress$[ebp]
$L6243:
0033c 89 46 24 mov DWORD PTR [esi+36], eax
; 229 :
; 230 : // Save the I/O space base address for use with other services.
; 231 : ObjExt->IOBase = (CardInfo.u.type0.BaseAddresses[1] & 0xFFFFFFFE);
0033f 8b 85 e8 fd ff
ff mov eax, DWORD PTR _CardInfo$[ebp+20]
00345 24 fe and al, -2 ; fffffffeH
00347 89 46 28 mov DWORD PTR [esi+40], eax
; 232 :
; 233 : // Create a symbolic link, i.e. a name that a Win32 app
; 234 : // can specify to open the device.
; 235 : DeviceWin32Name[18] = (USHORT) (0x30 + BoardNumber);
0034a 66 8b 45 f0 mov ax, WORD PTR -16+[ebp]
0034e 66 89 85 30 ff
ff ff mov WORD PTR _DeviceWin32Name$[ebp+36], ax
; 236 : RtlInitUnicodeString(
; 237 : IN &DeviceWin32NameUnicode,
; 238 : IN DeviceWin32Name
; 239 : );
00355 8d 85 0c ff ff
ff lea eax, DWORD PTR _DeviceWin32Name$[ebp]
0035b 50 push eax
0035c 8d 45 b8 lea eax, DWORD PTR _DeviceWin32NameUnicode$[ebp]
0035f 50 push eax
00360 ff 15 00 00 00
00 call DWORD PTR __imp__RtlInitUnicodeString@8
; 240 : NTStatus = IoCreateSymbolicLink(
; 241 : IN &DeviceWin32NameUnicode,
; 242 : IN &DeviceNTNameUnicode
; 243 : );
00366 8d 45 b0 lea eax, DWORD PTR _DeviceNTNameUnicode$[ebp]
00369 50 push eax
0036a 8d 45 b8 lea eax, DWORD PTR _DeviceWin32NameUnicode$[ebp]
0036d 50 push eax
0036e ff 15 00 00 00
00 call DWORD PTR __imp__IoCreateSymbolicLink@8
00374 8b f8 mov edi, eax
; 244 : if(NTStatus != STATUS_SUCCESS)
00376 3b fb cmp edi, ebx
00378 0f 85 4e 01 00
00 jne $ExitB$5970
; 245 : goto ExitB;
; 246 :
; 247 : // Map the PCI board's IRQ to a system vector.
; 248 : if((ULONG)CardInfo.u.type0.InterruptPin != 0){
0037e 38 9d 11 fe ff
ff cmp BYTE PTR _CardInfo$[ebp+61], bl
00384 74 69 je SHORT $L5979
; 249 : MappedVector = HalGetInterruptVector(
; 250 : IN PCIBus,
; 251 : IN BusNumber,
; 252 : IN (ULONG)CardInfo.u.type0.InterruptLine, //interrupt level
; 253 : IN 0, //interrupt vector
; 254 : OUT &PCIIrql,
; 255 : OUT &PCIAffinity
; 256 : );
00386 8d 45 cc lea eax, DWORD PTR _PCIAffinity$[ebp]
00389 50 push eax
0038a 8d 45 dc lea eax, DWORD PTR _PCIIrql$[ebp]
0038d 50 push eax
0038e 53 push ebx
0038f 0f b6 85 10 fe
ff ff movzx eax, BYTE PTR _CardInfo$[ebp+60]
00396 50 push eax
00397 ff 75 f8 push DWORD PTR _BusNumber$[ebp]
0039a 6a 05 push 5
0039c ff 15 00 00 00
00 call DWORD PTR __imp__HalGetInterruptVector@24
; 257 :
; 258 : // Connect the driver to the IRQ.
; 259 : NTStatus = IoConnectInterrupt(
; 260 : OUT &ObjExt->InterruptObject,
; 261 : IN PCIDPISR, //pointer to ISR
; 262 : IN DeviceObject, //context to send to ISR
; 263 : IN NULL, //optional spinlock
; 264 : IN MappedVector, //mapped interrupt vector
; 265 : IN PCIIrql, //DIRQL
; 266 : IN PCIIrql, //DIRQL
; 267 : //IN Latched, //latched/level interrupt
; 268 : IN LevelSensitive, //latched/level interrupt
; 269 : IN TRUE, //shareable interrupt
; 270 : IN PCIAffinity, //processor enable mask
; 271 : IN FALSE //floating save (false for X86)
; 272 : );
003a2 53 push ebx
003a3 ff 75 cc push DWORD PTR _PCIAffinity$[ebp]
003a6 6a 01 push 1
003a8 53 push ebx
003a9 ff 75 dc push DWORD PTR _PCIIrql$[ebp]
003ac ff 75 dc push DWORD PTR _PCIIrql$[ebp]
003af 50 push eax
003b0 53 push ebx
003b1 ff 75 f4 push DWORD PTR _DeviceObject$[ebp]
003b4 8d 46 2c lea eax, DWORD PTR [esi+44]
003b7 68 00 00 00 00 push OFFSET FLAT:_PCIDPISR@8
003bc 50 push eax
003bd ff 15 00 00 00
00 call DWORD PTR __imp__IoConnectInterrupt@44
003c3 8b f8 mov edi, eax
; 273 : if(NTStatus != STATUS_SUCCESS)
003c5 3b fb cmp edi, ebx
003c7 0f 85 f5 00 00
00 jne $ExitC$5984
; 274 : goto ExitC;
; 275 :
; 276 : // Register the PCIDPForDpcIsr routine with this device
; 277 : // driver.
; 278 : IoInitializeDpcRequest(
; 279 : IN DeviceObject,
; 280 : IN PCIDPForDpcIsr
; 281 : );
003cd 8b 45 f4 mov eax, DWORD PTR _DeviceObject$[ebp]
003d0 50 push eax
003d1 83 c0 74 add eax, 116 ; 00000074H
003d4 68 00 00 00 00 push OFFSET FLAT:_PCIDPForDpcIsr@16
003d9 50 push eax
003da ff 15 00 00 00
00 call DWORD PTR __imp__KeInitializeDpc@12
; 282 :
; 283 : // Set up the spin lock for the linked list holding pending IRPs.
; 284 : KeInitializeSpinLock(&ObjExt->LListSpin);
003e0 8d 86 80 00 00
00 lea eax, DWORD PTR [esi+128]
003e6 50 push eax
003e7 ff 15 00 00 00
00 call DWORD PTR __imp__KeInitializeSpinLock@4
; 285 : }
; 286 :
; 287 : // Otherwise, interrupts are not enabled on the board.
; 288 : else
003ed eb 03 jmp SHORT $L5986
$L5979:
; 289 : ObjExt->InterruptObject = 0;
003ef 89 5e 2c mov DWORD PTR [esi+44], ebx
$L5986:
; 290 :
; 291 : // Allocate a contiguous span of memory for DMA usage.
; 292 : MaxAddress.LowPart = 0xFFFFFFFF;
003f2 83 c8 ff or eax, -1
; 293 : MaxAddress.HighPart = 0;
; 294 : ObjExt->VirtualDMAAddress = MmAllocateContiguousMemory(
; 295 : IN (ULONG)DMASize, //16K
; 296 : IN MaxAddress //Full 32 bit address range
; 297 : );
003f5 53 push ebx
003f6 bf 00 40 00 00 mov edi, 16384 ; 00004000H
003fb 50 push eax
003fc 57 push edi
003fd ff 15 00 00 00
00 call DWORD PTR __imp__MmAllocateContiguousMemory@12
; 298 :
; 299 : if(ObjExt->VirtualDMAAddress != NULL){
00403 3b c3 cmp eax, ebx
00405 89 86 84 00 00
00 mov DWORD PTR [esi+132], eax
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -