📄 pcidp.cod
字号:
TITLE I:\PCI-DP\KERNEL\KERNELNT\pcidp.c
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT _RtlConvertLongToLargeInteger@4
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _DriverEntry@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPDeviceControl@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPCreateClose@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPCleanup@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPUnload@4
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPCancelInterrupt@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPForDpcIsr@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPISR@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPCancelMapDMARoutine@8
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _DriverEntry@8
PUBLIC _PCIDPDeviceControl@8
PUBLIC _PCIDPCreateClose@8
PUBLIC _PCIDPCleanup@8
PUBLIC _PCIDPUnload@4
PUBLIC _PCIDPForDpcIsr@16
PUBLIC _PCIDPISR@8
EXTRN __imp__RtlQueryRegistryValues@20:NEAR
EXTRN __imp__RtlInitUnicodeString@8:NEAR
EXTRN __imp__MmProbeAndLockPages@12:NEAR
EXTRN __imp__MmBuildMdlForNonPagedPool@4:NEAR
EXTRN __imp__MmMapIoSpace@16:NEAR
EXTRN __imp__MmUnmapIoSpace@8:NEAR
EXTRN __imp__MmGetPhysicalAddress@4:NEAR
EXTRN __imp__MmAllocateContiguousMemory@12:NEAR
EXTRN __imp__IoAllocateMdl@20:NEAR
EXTRN __imp__IoConnectInterrupt@44:NEAR
EXTRN __imp__IoCreateDevice@28:NEAR
EXTRN __imp__IoCreateSymbolicLink@8:NEAR
EXTRN __imp__KeInitializeDpc@12:NEAR
EXTRN __imp__IoDeleteDevice@4:NEAR
EXTRN __imp__IoDeleteSymbolicLink@4:NEAR
EXTRN __imp__KeInitializeSpinLock@4:NEAR
EXTRN __imp__HalGetInterruptVector@24:NEAR
EXTRN __imp__HalTranslateBusAddress@24:NEAR
EXTRN __imp__ExAllocatePoolWithTag@12:NEAR
EXTRN __imp__ExFreePool@4:NEAR
EXTRN __imp__HalGetBusData@20:NEAR
; COMDAT _DriverEntry@8
; File I:\PCI-DP\KERNEL\KERNELNT\pcidp.c
_TEXT SEGMENT
$SG5902 DB '\', 00H, 'P', 00H, 'a', 00H, 'r', 00H, 'a', 00H, 'm', 00H
DB 'e', 00H, 't', 00H, 'e', 00H, 'r', 00H, 's', 00H, 00H, 00H
$SG5904 DB '\', 00H, 'D', 00H, 'o', 00H, 's', 00H, 'D', 00H, 'e', 00H
DB 'v', 00H, 'i', 00H, 'c', 00H, 'e', 00H, 's', 00H, '\', 00H, 'P'
DB 00H, 'C', 00H, 'I', 00H, 'D', 00H, 'P', 00H, '0', 00H, '0', 00H
DB 00H, 00H
$SG5907 DB '\', 00H, 'D', 00H, 'e', 00H, 'v', 00H, 'i', 00H, 'c', 00H
DB 'e', 00H, '\', 00H, 'P', 00H, 'C', 00H, 'I', 00H, 'D', 00H, 'P'
DB 00H, '0', 00H, '0', 00H, '_', 00H, 'C', 00H, 'Y', 00H, '7', 00H
DB 'C', 00H, '0', 00H, '9', 00H, '4', 00H, '4', 00H, '9', 00H, 'P'
DB 00H, 'V', 00H, 00H, 00H
$SG5941 DB 'P', 00H, 'C', 00H, 'I', 00H, 'V', 00H, 'e', 00H, 'n', 00H
DB 'd', 00H, 'o', 00H, 'r', 00H, 'I', 00H, 'D', 00H, 00H, 00H
$SG5942 DB 'P', 00H, 'C', 00H, 'I', 00H, 'D', 00H, 'e', 00H, 'v', 00H
DB 'i', 00H, 'c', 00H, 'e', 00H, 'I', 00H, 'D', 00H, 00H, 00H
_DriverObject$ = 8
_RegistryPath$ = 12
_ParamPath$ = -88
_ParamSubKey$ = -204
_DeviceWin32Name$ = -244
_DeviceWin32NameUnicode$ = -72
_DeviceNTName$ = -300
_DeviceNTNameUnicode$ = -80
_DeviceObject$ = -12
_ParametersTable$ = -172
_FoundPCICard$ = 15
_BusNumber$ = -8
_PCIVendorIDDefault$ = -56
_PCIDeviceIDDefault$ = -48
_PCIVendorID$ = -40
_PCIDeviceID$ = -44
_SlotNumber$ = -4
_FunctionNumber$ = -20
_DeviceNumber$ = -28
_CardInfo$ = -556
_PCIIrql$ = -36
_PCIAffinity$ = -52
_TranslatedAddress$ = -64
_AddressSpace$ = -32
_BoardNumber$ = -24
_PhysicalAddress$ = -180
_DriverEntry@8 PROC NEAR ; COMDAT
; 35 : ){
000a8 55 push ebp
000a9 8b ec mov ebp, esp
000ab 81 ec 2c 02 00
00 sub esp, 556 ; 0000022cH
000b1 53 push ebx
000b2 56 push esi
000b3 57 push edi
; 36 :
; 37 : NTSTATUS NTStatus;
; 38 : UNICODE_STRING ParamPath;
; 39 : WCHAR ParamSubKey[] = L"\\Parameters";
000b4 6a 06 push 6
000b6 59 pop ecx
000b7 be 00 00 00 00 mov esi, OFFSET FLAT:$SG5902
000bc 8d bd 34 ff ff
ff lea edi, DWORD PTR _ParamSubKey$[ebp]
; 40 : WCHAR DeviceWin32Name[] = L"\\DosDevices\\PCIDP00";
000c2 6a 0a push 10 ; 0000000aH
000c4 f3 a5 rep movsd
000c6 59 pop ecx
000c7 be 00 00 00 00 mov esi, OFFSET FLAT:$SG5904
000cc 8d bd 0c ff ff
ff lea edi, DWORD PTR _DeviceWin32Name$[ebp]
; 41 : UNICODE_STRING DeviceWin32NameUnicode;
; 42 : WCHAR DeviceNTName[] = L"\\Device\\PCIDP00_CY7C09449PV";
000d2 6a 0e push 14 ; 0000000eH
000d4 f3 a5 rep movsd
000d6 59 pop ecx
000d7 be 00 00 00 00 mov esi, OFFSET FLAT:$SG5907
000dc 8d bd d4 fe ff
ff lea edi, DWORD PTR _DeviceNTName$[ebp]
; 43 : UNICODE_STRING DeviceNTNameUnicode;
; 44 : PDEVICE_OBJECT DeviceObject = NULL;
; 45 : pPCIDP_EXTENSION ObjExt;
; 46 : RTL_QUERY_REGISTRY_TABLE ParametersTable[3];
; 47 : BOOLEAN FoundPCICard;
; 48 : ULONG BusNumber;
; 49 : ULONG PCIVendorIDDefault = 0x12BE;
; 50 : ULONG PCIDeviceIDDefault = 0x3042;
; 51 : ULONG PCIVendorID;
; 52 : ULONG PCIDeviceID;
; 53 : PCI_SLOT_NUMBER SlotNumber;
; 54 : ULONG FunctionNumber;
; 55 : ULONG DeviceNumber;
; 56 : PCI_COMMON_CONFIG CardInfo;
; 57 : ULONG InfoSize;
; 58 : KIRQL PCIIrql;
; 59 : KAFFINITY PCIAffinity;
; 60 : PHYSICAL_ADDRESS BusAddress;
; 61 : PHYSICAL_ADDRESS TranslatedAddress;
; 62 : ULONG MappedVector;
; 63 : ULONG AddressSpace;
; 64 : ULONG IOBaseSize = 8;
; 65 : USHORT BoardNumber;
; 66 : BOOLEAN BoolStatus;
; 67 : PHYSICAL_ADDRESS MaxAddress;
; 68 : PHYSICAL_ADDRESS PhysicalAddress;
; 69 : ULONG i;
; 70 :
; 71 :
; 72 : // --------------------------------------------------------------------------
; 73 : // Block 1: Start out by obtaining the PCI Vendor and Device IDs.
; 74 : // --------------------------------------------------------------------------
; 75 : // Allocate system space for the new registry path buffer.
; 76 : ParamPath.MaximumLength = RegistryPath->Length + sizeof(ParamSubKey);
; 77 : ParamPath.Length = ParamPath.MaximumLength;
; 78 : ParamPath.Buffer = (unsigned short*)ExAllocatePool(
; 79 : PagedPool,
; 80 : ParamPath.Length
; 81 : );
000e2 68 44 64 6b 20 push 543908932 ; 206b6444H
000e7 f3 a5 rep movsd
000e9 8b 75 0c mov esi, DWORD PTR _RegistryPath$[ebp]
000ec 33 db xor ebx, ebx
000ee 89 5d f4 mov DWORD PTR _DeviceObject$[ebp], ebx
000f1 c7 45 c8 be 12
00 00 mov DWORD PTR _PCIVendorIDDefault$[ebp], 4798 ; 000012beH
000f8 66 8b 06 mov ax, WORD PTR [esi]
000fb c7 45 d0 42 30
00 00 mov DWORD PTR _PCIDeviceIDDefault$[ebp], 12354 ; 00003042H
00102 66 05 18 00 add ax, 24 ; 00000018H
00106 0f b7 c0 movzx eax, ax
00109 50 push eax
0010a 6a 01 push 1
0010c ff 15 00 00 00
00 call DWORD PTR __imp__ExAllocatePoolWithTag@12
00112 8b d0 mov edx, eax
; 82 : if (ParamPath.Buffer == NULL){
00114 3b d3 cmp edx, ebx
00116 89 55 ac mov DWORD PTR _ParamPath$[ebp+4], edx
00119 75 0a jne SHORT $L5938
; 83 : NTStatus = STATUS_NO_MEMORY;
0011b bf 17 00 00 c0 mov edi, -1073741801 ; c0000017H
; 84 : goto Exit;
00120 e9 f1 03 00 00 jmp $Exit$5940
$L5938:
; 85 : }
; 86 :
; 87 : // Copy Registry Path to ParamPath
; 88 : RtlCopyMemory(
; 89 : ParamPath.Buffer,
; 90 : RegistryPath->Buffer,
; 91 : RegistryPath->Length
; 92 : );
00125 0f b7 0e movzx ecx, WORD PTR [esi]
00128 8b 76 04 mov esi, DWORD PTR [esi+4]
0012b 8b c1 mov eax, ecx
0012d 8b fa mov edi, edx
; 93 :
; 94 : // Concatenate Sub Key to ParamPath
; 95 : RtlCopyMemory(
; 96 : &ParamPath.Buffer[RegistryPath->Length/2],
; 97 : ParamSubKey,
; 98 : sizeof(ParamSubKey)
; 99 : );
0012f 6a 06 push 6
00131 c1 e9 02 shr ecx, 2
00134 f3 a5 rep movsd
00136 8b c8 mov ecx, eax
00138 8b 45 0c mov eax, DWORD PTR _RegistryPath$[ebp]
0013b 83 e1 03 and ecx, 3
0013e f3 a4 rep movsb
00140 0f b7 00 movzx eax, WORD PTR [eax]
00143 d1 e8 shr eax, 1
00145 59 pop ecx
00146 8d b5 34 ff ff
ff lea esi, DWORD PTR _ParamSubKey$[ebp]
0014c 8d 3c 42 lea edi, DWORD PTR [edx+eax*2]
; 100 :
; 101 : //Initialize the parameters table with the vendor and device data.
; 102 : RtlZeroMemory(&ParametersTable[0], sizeof(ParametersTable));
0014f 6a 15 push 21 ; 00000015H
00151 f3 a5 rep movsd
00153 59 pop ecx
00154 33 c0 xor eax, eax
00156 8d bd 54 ff ff
ff lea edi, DWORD PTR _ParametersTable$[ebp]
; 103 :
; 104 : ParametersTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
0015c 6a 20 push 32 ; 00000020H
0015e f3 ab rep stosd
00160 58 pop eax
; 105 : ParametersTable[0].Name = L"PCIVendorID";
; 106 : ParametersTable[0].EntryContext = &PCIVendorID;
00161 8d 4d d8 lea ecx, DWORD PTR _PCIVendorID$[ebp]
00164 89 85 58 ff ff
ff mov DWORD PTR _ParametersTable$[ebp+4], eax
; 107 : ParametersTable[0].DefaultType = REG_DWORD;
; 108 : ParametersTable[0].DefaultData = &PCIVendorIDDefault;
; 109 : ParametersTable[0].DefaultLength = sizeof(PCIVendorID);
; 110 :
; 111 : ParametersTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
0016a 89 85 74 ff ff
ff mov DWORD PTR _ParametersTable$[ebp+32], eax
; 112 : ParametersTable[1].Name = L"PCIDeviceID";
; 113 : ParametersTable[1].EntryContext = &PCIDeviceID;
00170 8d 45 d4 lea eax, DWORD PTR _PCIDeviceID$[ebp]
00173 6a 04 push 4
00175 89 85 7c ff ff
ff mov DWORD PTR _ParametersTable$[ebp+40], eax
; 114 : ParametersTable[1].DefaultType = REG_DWORD;
; 115 : ParametersTable[1].DefaultData = &PCIDeviceIDDefault;
0017b 8d 45 d0 lea eax, DWORD PTR _PCIDeviceIDDefault$[ebp]
0017e 5e pop esi
0017f 89 45 84 mov DWORD PTR _ParametersTable$[ebp+48], eax
; 116 : ParametersTable[1].DefaultLength = sizeof(PCIDeviceID);
; 117 :
; 118 : // Now get the registry data.
; 119 : NTStatus = RtlQueryRegistryValues(
; 120 : IN RTL_REGISTRY_ABSOLUTE,
; 121 : IN ParamPath.Buffer,
; 122 : IN OUT &ParametersTable[0],
; 123 : IN NULL,
; 124 : IN NULL
; 125 : );
00182 53 push ebx
00183 8d 85 54 ff ff
ff lea eax, DWORD PTR _ParametersTable$[ebp]
00189 53 push ebx
0018a 89 8d 60 ff ff
ff mov DWORD PTR _ParametersTable$[ebp+12], ecx
00190 50 push eax
00191 8d 4d c8 lea ecx, DWORD PTR _PCIVendorIDDefault$[ebp]
00194 52 push edx
00195 53 push ebx
00196 c7 85 5c ff ff
ff 00 00 00 00 mov DWORD PTR _ParametersTable$[ebp+8], OFFSET FLAT:$SG5941
001a0 89 b5 64 ff ff
ff mov DWORD PTR _ParametersTable$[ebp+16], esi
001a6 89 8d 68 ff ff
ff mov DWORD PTR _ParametersTable$[ebp+20], ecx
001ac 89 b5 6c ff ff
ff mov DWORD PTR _ParametersTable$[ebp+24], esi
001b2 c7 85 78 ff ff
ff 00 00 00 00 mov DWORD PTR _ParametersTable$[ebp+36], OFFSET FLAT:$SG5942
001bc 89 75 80 mov DWORD PTR _ParametersTable$[ebp+44], esi
001bf 89 75 88 mov DWORD PTR _ParametersTable$[ebp+52], esi
001c2 ff 15 00 00 00
00 call DWORD PTR __imp__RtlQueryRegistryValues@20
001c8 8b f8 mov edi, eax
; 126 : if(NTStatus != STATUS_SUCCESS)
001ca 3b fb cmp edi, ebx
001cc 0f 85 3b 03 00
00 jne $ExitA$5947
; 127 : goto ExitA;
; 128 :
; 129 :
; 130 : // --------------------------------------------------------------------------
; 131 : // Block 2: Locate each PCI board using the PCI Vendor and DeviceType IDs.
; 132 : // Then initialize a driver device object for each board.
; 133 : // --------------------------------------------------------------------------
; 134 : BoardNumber = 0;
; 135 : FoundPCICard = FALSE;
; 136 : SlotNumber.u.bits.Reserved = 0;
001d2 81 65 fc ff 00
00 00 and DWORD PTR _SlotNumber$[ebp], 255 ; 000000ffH
001d9 89 5d e8 mov DWORD PTR _BoardNumber$[ebp], ebx
001dc 88 5d 0f mov BYTE PTR _FoundPCICard$[ebp], bl
; 137 :
; 138 : // Loop BusNumber 0 - 3.
; 139 : for(BusNumber = 0; BusNumber < 4; BusNumber++){
001df 89 5d f8 mov DWORD PTR _BusNumber$[ebp], ebx
$L5948:
; 140 :
; 141 : // Loop FunctionNumber 0 - 7.
; 142 : for(FunctionNumber = 0; FunctionNumber < 8; FunctionNumber++){
001e2 89 5d ec mov DWORD PTR _FunctionNumber$[ebp], ebx
$L5951:
; 143 : SlotNumber.u.bits.FunctionNumber = FunctionNumber;
001e5 8b 45 ec mov eax, DWORD PTR _FunctionNumber$[ebp]
001e8 8b 4d fc mov ecx, DWORD PTR _SlotNumber$[ebp]
001eb 83 e0 07 and eax, 7
001ee 80 e1 1f and cl, 31 ; 0000001fH
001f1 c1 e0 05 shl eax, 5
001f4 0b c1 or eax, ecx
; 144 :
; 145 : // Loop DeviceNumber 0 - 31.
; 146 : for(DeviceNumber = 0; DeviceNumber < 32; DeviceNumber++){
001f6 89 5d e4 mov DWORD PTR _DeviceNumber$[ebp], ebx
001f9 89 45 fc mov DWORD PTR _SlotNumber$[ebp], eax
001fc 8b 45 e8 mov eax, DWORD PTR _BoardNumber$[ebp]
001ff 83 c0 30 add eax, 48 ; 00000030H
00202 89 45 f0 mov DWORD PTR -16+[ebp], eax
$L5954:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -