📄 pcidppublic.cod
字号:
TITLE C:\Kernel2000\pcidppublic.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
$$SYMBOLS SEGMENT BYTE USE32 'DEBSYM'
$$SYMBOLS ENDS
$$TYPES SEGMENT BYTE USE32 'DEBTYP'
$$TYPES ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT _RtlConvertLongToLargeInteger@4
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPGetDriverVersion@12
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPMapBaseRegs@20
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPUnMap@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPMapDMAMem@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPCancelMapDMA@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPUnMapDMA@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPGetPCIRegs@20
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPSetPCIRegs@20
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPRegisterInterrupt@20
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT _PCIDPUnregisterInterrupt@16
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC _PCIDPGetDriverVersion@12
; COMDAT _PCIDPGetDriverVersion@12
_TEXT SEGMENT
_Irp$ = 8
_IoBuffer$ = 12
_OutputBufferLength$ = 16
_PCIDPGetDriverVersion@12 PROC NEAR ; COMDAT
; 28 :
; 29 : // Define variables.
; 30 : NTSTATUS NTStatus;
; 31 : PPCIDP00_GET_VERSION_RECV IoOutput;
; 32 :
; 33 : // Initialize variables.
; 34 : IoOutput = (PPCIDP00_GET_VERSION_RECV)IoBuffer;
; 35 :
; 36 : // Check for adequate output buffer space.
; 37 : if(OutputBufferLength >= sizeof(PCIDP00_GET_VERSION_RECV)){
00000 8b 44 24 04 mov eax, DWORD PTR _Irp$[esp-4]
00004 6a 04 push 4
00006 59 pop ecx
00007 39 4c 24 0c cmp DWORD PTR _OutputBufferLength$[esp-4], ecx
0000b 72 13 jb SHORT $L8423
0000d 56 push esi
; 38 : NTStatus = STATUS_SUCCESS;
; 39 : IoOutput->Version = 0x20020822;
0000e 8b 74 24 0c mov esi, DWORD PTR _IoBuffer$[esp]
00012 33 d2 xor edx, edx
00014 c7 06 22 08 02
20 mov DWORD PTR [esi], 537004066 ; 20020822H
; 40 : Irp->IoStatus.Information = sizeof(PCIDP00_GET_VERSION_RECV);
0001a 89 48 1c mov DWORD PTR [eax+28], ecx
0001d 5e pop esi
; 41 : }
; 42 :
; 43 : else
0001e eb 05 jmp SHORT $L8426
$L8423:
; 44 : NTStatus = STATUS_INVALID_BUFFER_SIZE;
00020 ba 06 02 00 c0 mov edx, -1073741306 ; c0000206H
$L8426:
; 45 :
; 46 : Irp->IoStatus.Status = NTStatus;
00025 89 50 18 mov DWORD PTR [eax+24], edx
; 47 : }
00028 c2 0c 00 ret 12 ; 0000000cH
_PCIDPGetDriverVersion@12 ENDP
_TEXT ENDS
PUBLIC _PCIDPMapBaseRegs@20
EXTRN __imp__RtlInitUnicodeString@8:NEAR
EXTRN __imp__ObReferenceObjectByHandle@24:NEAR
EXTRN __imp__ZwClose@4:NEAR
EXTRN __imp__ZwOpenSection@12:NEAR
EXTRN __imp__ZwMapViewOfSection@40:NEAR
; COMDAT _PCIDPMapBaseRegs@20
; File c:\kernel2000\pcidppublic.c
_TEXT SEGMENT
$SG8470 DB '\', 00H, 'D', 00H, 'e', 00H, 'v', 00H, 'i', 00H, 'c', 00H
DB 'e', 00H, '\', 00H, 'P', 00H, 'h', 00H, 'y', 00H, 's', 00H, 'i'
DB 00H, 'c', 00H, 'a', 00H, 'l', 00H, 'M', 00H, 'e', 00H, 'm', 00H
DB 'o', 00H, 'r', 00H, 'y', 00H, 00H, 00H
_DeviceObject$ = 8
_Irp$ = 12
_IoBuffer$ = 16
_InputBufferLength$ = 20
_OutputBufferLength$ = 24
_LengthOut$ = 20
_VirtualAddress$ = 8
_PhysicalMemoryUnicodeString$ = -28
_ObjectAttributes$ = -52
_SectionOffset$ = -20
_NTStatus$ = -4
_PhysicalMemoryHandle$ = -8
_PhysicalMemorySection$ = -12
_PCIDPMapBaseRegs@20 PROC NEAR ; COMDAT
; 59 : ){
0002e 55 push ebp
0002f 8b ec mov ebp, esp
00031 83 ec 34 sub esp, 52 ; 00000034H
; 60 :
; 61 : // Define variables.
; 62 : //ULONG PCIAddress;
; 63 : ULONG Length;
; 64 : ULONG LengthOut;
; 65 : //ULONG BusNumber;
; 66 : ULONG VirtualAddress;
; 67 : //ULONG MappedLength;
; 68 : //ULONG MapIndex;
; 69 : UNICODE_STRING PhysicalMemoryUnicodeString;
; 70 : OBJECT_ATTRIBUTES ObjectAttributes;
; 71 : //BOOLEAN HALStatus;
; 72 : //PHYSICAL_ADDRESS LongLength;
; 73 : //PHYSICAL_ADDRESS FullPCIAddress;
; 74 : //PHYSICAL_ADDRESS FullPCIAddressEnd;
; 75 : //PHYSICAL_ADDRESS FullLogicalAddress;
; 76 : //PHYSICAL_ADDRESS FullLogicalAddressEnd;
; 77 : PHYSICAL_ADDRESS SectionOffset;
; 78 : NTSTATUS NTStatus;
; 79 : HANDLE PhysicalMemoryHandle;
; 80 : PVOID PhysicalMemorySection;
; 81 : ULONG MemorySpace;
; 82 : ULONG MemorySpaceEnd;
; 83 : PPCIDP00_MAP_BASE_REGS_SEND IoInput;
; 84 : PPCIDP00_MAP_BASE_REGS_RECV IoOutput;
; 85 : PPCIDP_EXTENSION ObjExt;
; 86 :
; 87 : // Initialize variables.
; 88 : NTStatus = STATUS_SUCCESS;
; 89 : PhysicalMemoryHandle = NULL;
; 90 : PhysicalMemorySection = NULL;
; 91 : MemorySpace = 0;
; 92 : MemorySpaceEnd = 0;
; 93 : IoInput = (PPCIDP00_MAP_BASE_REGS_SEND)IoBuffer;
; 94 : IoOutput = (PPCIDP00_MAP_BASE_REGS_RECV)IoBuffer;
; 95 : ObjExt = (PPCIDP_EXTENSION)DeviceObject->DeviceExtension;
00034 8b 45 08 mov eax, DWORD PTR _DeviceObject$[ebp]
00037 53 push ebx
00038 33 db xor ebx, ebx
; 96 :
; 97 : // Make sure the buffer lengths are of sufficient size to handle
; 98 : // the transactions.
; 99 : if((InputBufferLength < sizeof(PCIDP00_MAP_BASE_REGS_SEND)) ||
; 100 : (OutputBufferLength < sizeof(PCIDP00_MAP_BASE_REGS_RECV))){
0003a 83 7d 14 08 cmp DWORD PTR _InputBufferLength$[ebp], 8
0003e 56 push esi
0003f 8b 70 28 mov esi, DWORD PTR [eax+40]
00042 57 push edi
00043 89 5d fc mov DWORD PTR _NTStatus$[ebp], ebx
00046 89 5d f8 mov DWORD PTR _PhysicalMemoryHandle$[ebp], ebx
00049 89 5d f4 mov DWORD PTR _PhysicalMemorySection$[ebp], ebx
0004c 0f 82 0d 01 00
00 jb $L8462
00052 6a 0c push 12 ; 0000000cH
00054 5a pop edx
00055 39 55 18 cmp DWORD PTR _OutputBufferLength$[ebp], edx
00058 0f 82 01 01 00
00 jb $L8462
; 102 : goto ExitA;
; 103 : }
; 104 :
; 105 : // Check for a valid Base Address Register index and that its value
; 106 : // is zero or one, currently, the only supported registers.
; 107 : if(IoInput->RegNumber > 1){
0005e 8b 7d 10 mov edi, DWORD PTR _IoBuffer$[ebp]
00061 6a 01 push 1
00063 58 pop eax
00064 8b 0f mov ecx, DWORD PTR [edi]
00066 3b c8 cmp ecx, eax
00068 76 0c jbe SHORT $L8806
; 108 : NTStatus = STATUS_INVALID_PARAMETER;
0006a c7 45 fc 0d 00
00 c0 mov DWORD PTR _NTStatus$[ebp], -1073741811 ; c000000dH
; 109 : goto ExitA;
00071 e9 f0 00 00 00 jmp $ExitA$8464
$L8806:
; 110 : }
; 111 :
; 112 : // First check to see if the address is for I/O space. If it is, we
; 113 : // can't map it. Just return the I/O Address so the application can
; 114 : // use an I/O access driver to read and write from this space.
; 115 : if(IoInput->RegNumber == 1){
00076 75 19 jne SHORT $L8467
; 116 : IoOutput->IOSpace = 1;
00078 89 47 08 mov DWORD PTR [edi+8], eax
; 117 : IoOutput->Length = ObjExt->IOAccessLength;
0007b 8b 46 14 mov eax, DWORD PTR [esi+20]
0007e 89 47 04 mov DWORD PTR [edi+4], eax
; 118 : IoOutput->Address = (ULONG)ObjExt->IOAccess.LowPart;
00081 8b 46 08 mov eax, DWORD PTR [esi+8]
00084 89 07 mov DWORD PTR [edi], eax
; 119 : Irp->IoStatus.Information = sizeof(PCIDP00_MAP_BASE_REGS_RECV);
00086 8b 45 0c mov eax, DWORD PTR _Irp$[ebp]
00089 89 50 1c mov DWORD PTR [eax+28], edx
; 120 : goto ExitA;
0008c e9 d5 00 00 00 jmp $ExitA$8464
$L8467:
; 121 : }
; 122 :
; 123 : // Create the full path name for the physical memory object.
; 124 : RtlInitUnicodeString(
; 125 : IN &PhysicalMemoryUnicodeString,
; 126 : IN L"\\Device\\PhysicalMemory"
; 127 : );
00091 8d 45 e4 lea eax, DWORD PTR _PhysicalMemoryUnicodeString$[ebp]
00094 68 00 00 00 00 push OFFSET FLAT:$SG8470
00099 50 push eax
0009a ff 15 00 00 00
00 call DWORD PTR __imp__RtlInitUnicodeString@8
; 128 :
; 129 : // Initialize the physical memory object attributes.
; 130 : InitializeObjectAttributes(
; 131 : OUT &ObjectAttributes, // Object attributes structure
; 132 : IN &PhysicalMemoryUnicodeString, // Full path name of the object
; 133 : IN OBJ_CASE_INSENSITIVE, // Object attribute
; 134 : IN (HANDLE) NULL, // Root directory is N/A
; 135 : IN (PSECURITY_DESCRIPTOR) NULL // Security descriptor is N/A
; 136 : );
000a0 8d 45 e4 lea eax, DWORD PTR _PhysicalMemoryUnicodeString$[ebp]
000a3 c7 45 cc 18 00
00 00 mov DWORD PTR _ObjectAttributes$[ebp], 24 ; 00000018H
000aa 89 45 d4 mov DWORD PTR _ObjectAttributes$[ebp+8], eax
; 137 :
; 138 : // Get a handle to the physical memory object.
; 139 : NTStatus = ZwOpenSection(
; 140 : OUT &PhysicalMemoryHandle, // Handle to the physical memory object
; 141 : IN SECTION_ALL_ACCESS, // Allow full access to the memory
; 142 : IN &ObjectAttributes // Object attributes structure
; 143 : );
000ad 8d 45 cc lea eax, DWORD PTR _ObjectAttributes$[ebp]
000b0 50 push eax
000b1 8d 45 f8 lea eax, DWORD PTR _PhysicalMemoryHandle$[ebp]
000b4 68 1f 00 0f 00 push 983071 ; 000f001fH
000b9 50 push eax
000ba 89 5d d0 mov DWORD PTR _ObjectAttributes$[ebp+4], ebx
000bd c7 45 d8 40 00
00 00 mov DWORD PTR _ObjectAttributes$[ebp+12], 64 ; 00000040H
000c4 89 5d dc mov DWORD PTR _ObjectAttributes$[ebp+16], ebx
000c7 89 5d e0 mov DWORD PTR _ObjectAttributes$[ebp+20], ebx
000ca ff 15 00 00 00
00 call DWORD PTR __imp__ZwOpenSection@12
; 144 : if(NTStatus != STATUS_SUCCESS) goto ExitA;
000d0 3b c3 cmp eax, ebx
000d2 89 45 fc mov DWORD PTR _NTStatus$[ebp], eax
000d5 0f 85 8b 00 00
00 jne $ExitA$8464
; 145 :
; 146 : // Validate access on the object's handle and get a pointer to the object's
; 147 : // body.
; 148 : NTStatus = ObReferenceObjectByHandle(
; 149 : IN PhysicalMemoryHandle,
; 150 : IN SECTION_ALL_ACCESS,
; 151 : IN (POBJECT_TYPE) NULL,
; 152 : IN KernelMode,
; 153 : OUT &PhysicalMemorySection,
; 154 : OUT (POBJECT_HANDLE_INFORMATION) NULL
; 155 : );
000db 8d 45 f4 lea eax, DWORD PTR _PhysicalMemorySection$[ebp]
000de 53 push ebx
000df 50 push eax
000e0 53 push ebx
000e1 53 push ebx
000e2 68 1f 00 0f 00 push 983071 ; 000f001fH
000e7 ff 75 f8 push DWORD PTR _PhysicalMemoryHandle$[ebp]
000ea ff 15 00 00 00
00 call DWORD PTR __imp__ObReferenceObjectByHandle@24
; 156 : if(NTStatus != STATUS_SUCCESS) goto ExitB;
000f0 3b c3 cmp eax, ebx
000f2 89 45 fc mov DWORD PTR _NTStatus$[ebp], eax
000f5 75 5d jne SHORT $ExitB$8485
; 157 :
; 158 : // Translate the address from a PCI address to a system logical address.
; 159 : // Initialize the PCI full physical addresses that will be translated.
; 160 : //FullPCIAddress.HighPart = 0;
; 161 : //FullPCIAddress.LowPart = ObjExt->BaseAddresses[IoInput->RegNumber];
; 162 : //FullPCIAddressEnd = RtlLargeIntegerAdd (
; 163 : // IN FullPCIAddress,
; 164 : // IN RtlConvertUlongToLargeInteger(IoInput->Length)
; 165 : //);
; 166 :
; 167 : // Translate the full PCI physical addresses into corresponding full system
; 168 : // logical addresses.
; 169 : //NTStatus = STATUS_ACCESS_DENIED;
; 170 : //HALStatus = HalTranslateBusAddress(
; 171 : // IN PCIBus, // bus type
; 172 : // IN ObjExt->BusNumber, // bus number
; 173 : // IN FullPCIAddress, // bus address
; 174 : // IN &MemorySpace, // I/O or memory space
; 175 : // OUT &FullLogicalAddress // system logical address
; 176 : //);
; 177 : //if(HALStatus == FALSE) goto ExitB;
; 178 :
; 179 : //HALStatus = HalTranslateBusAddress(
; 180 : // IN PCIBus, // bus type
; 181 : // IN ObjExt->BusNumber, // bus number
; 182 : // IN FullPCIAddressEnd, // bus address
; 183 : // IN &MemorySpaceEnd, // I/O or memory space
; 184 : // OUT &FullLogicalAddressEnd // system logical address
; 185 : //);
; 186 : // if(HALStatus == FALSE) goto ExitB;
; 187 :
; 188 : // Calculate the length of the memory to be mapped.
; 189 : //LongLength = RtlLargeIntegerSubtract(
; 190 : // IN FullLogicalAddressEnd,
; 191 : // IN FullLogicalAddress
; 192 : //);
; 193 : //Length = LongLength.LowPart;
; 194 : //LengthOut = LongLength.LowPart;
; 195 : Length = ObjExt->MemoryAccessLength;
000f7 8b 46 10 mov eax, DWORD PTR [esi+16]
; 196 : LengthOut = ObjExt->MemoryAccessLength;
; 197 :
; 198 : // Now map the system logical address in this process' virtual address
; 199 : // space.
; 200 : VirtualAddress = 0;
000fa 89 5d 08 mov DWORD PTR _VirtualAddress$[ebp], ebx
000fd 89 45 14 mov DWORD PTR _LengthOut$[ebp], eax
; 201 : //SectionOffset = FullLogicalAddress;
; 202 : SectionOffset = ObjExt->MemoryAccess;
00100 8b 0e mov ecx, DWORD PTR [esi]
00102 89 4d ec mov DWORD PTR _SectionOffset$[ebp], ecx
00105 8b 4e 04 mov ecx, DWORD PTR [esi+4]
00108 89 4d f0 mov DWORD PTR _SectionOffset$[ebp+4], ecx
; 203 :
; 204 : NTStatus = ZwMapViewOfSection(
; 205 : IN PhysicalMemoryHandle, //section handle
; 206 : IN (HANDLE) -1, //process handle
; 207 : IN OUT (PVOID*)&VirtualAddress, //base address (virtual address)
; 208 : IN 0L, //zero bits
; 209 : IN Length, //commit size
; 210 : IN OUT &SectionOffset, //section offset
; 211 : IN OUT &LengthOut, //view size
; 212 : IN ViewShare, //inherit disposition (0)
; 213 : IN 0, //allocation type
; 214 : IN PAGE_READWRITE | PAGE_NOCACHE //protect
; 215 : );
0010b 68 04 02 00 00 push 516 ; 00000204H
00110 53 push ebx
00111 8d 4d 14 lea ecx, DWORD PTR _LengthOut$[ebp]
00114 6a 01 push 1
00116 51 push ecx
00117 8d 4d ec lea ecx, DWORD PTR _SectionOffset$[ebp]
0011a 51 push ecx
0011b 50 push eax
0011c 8d 45 08 lea eax, DWORD PTR _VirtualAddress$[ebp]
0011f 53 push ebx
00120 50 push eax
00121 6a ff push -1
00123 ff 75 f8 push DWORD PTR _PhysicalMemoryHandle$[ebp]
00126 ff 15 00 00 00
00 call DWORD PTR __imp__ZwMapViewOfSection@40
; 216 :
; 217 : // Mapping the section above rounded the logical address down to
; 218 : // the nearest 64 K boundary. Now return a virtual address pointing
; 219 : // to our request area by adding in the offset from the beginning
; 220 : // of the section.
; 221 : if(NTStatus == STATUS_SUCCESS){
0012c 3b c3 cmp eax, ebx
0012e 89 45 fc mov DWORD PTR _NTStatus$[ebp], eax
00131 75 21 jne SHORT $ExitB$8485
; 222 : IoOutput->IOSpace = 0;
; 223 : //IoOutput->Address = VirtualAddress +
; 224 : // ((ULONG)FullLogicalAddress.LowPart - (ULONG)SectionOffset.LowPart);
; 225 : //IoOutput->Length = LengthOut -
; 226 : // ((ULONG)FullLogicalAddress.LowPart - (ULONG)SectionOffset.LowPart);
; 227 : IoOutput->Address = VirtualAddress +
; 228 : ((ULONG)ObjExt->MemoryAccess.LowPart - (ULONG)SectionOffset.LowPart);
00133 8b 45 ec mov eax, DWORD PTR _SectionOffset$[ebp]
00136 89 5f 08 mov DWORD PTR [edi+8], ebx
00139 8b 0e mov ecx, DWORD PTR [esi]
0013b 2b c8 sub ecx, eax
0013d 03 4d 08 add ecx, DWORD PTR _VirtualAddress$[ebp]
00140 89 0f mov DWORD PTR [edi], ecx
; 229 : IoOutput->Length = LengthOut -
; 230 : ((ULONG)ObjExt->MemoryAccess.LowPart - (ULONG)SectionOffset.LowPart);
00142 2b 06 sub eax, DWORD PTR [esi]
00144 03 45 14 add eax, DWORD PTR _LengthOut$[ebp]
00147 89 47 04 mov DWORD PTR [edi+4], eax
; 231 : Irp->IoStatus.Information = sizeof(PCIDP00_MAP_BASE_REGS_RECV);
0014a 8b 45 0c mov eax, DWORD PTR _Irp$[ebp]
0014d c7 40 1c 0c 00
00 00 mov DWORD PTR [eax+28], 12 ; 0000000cH
$ExitB$8485:
; 232 : }
; 233 :
; 234 :
; 235 : ExitB:
; 236 : ZwClose(PhysicalMemoryHandle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -