⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcidp.cod

📁 一个amccs5933芯片的驱动程序开发源程序和部分文档
💻 COD
📖 第 1 页 / 共 5 页
字号:
	TITLE	C:\Kernel2000\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
$$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 _DriverEntry@8
_TEXT	SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT	ENDS
;	COMDAT _PCIDPAddDevice@8
_TEXT	SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT	ENDS
;	COMDAT _PCIDPDispatchPower@8
_TEXT	SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT	ENDS
;	COMDAT _PCIDPDispatchPnp@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
;	COMDAT _GUID_PCIDP_INTERFACE
CONST	SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST	ENDS
FLAT	GROUP _DATA, CONST, _BSS
	ASSUME	CS: FLAT, DS: FLAT, SS: FLAT
endif
PUBLIC	_GUID_PCIDP_INTERFACE
;	COMDAT _GUID_PCIDP_INTERFACE
CONST	SEGMENT
_GUID_PCIDP_INTERFACE DD 0b93c517H
	DW	0dadaH
	DW	04be9H
	DB	09fH
	DB	0beH
	DB	089H
	DB	018H
	DB	08bH
	DB	039H
	DB	08eH
	DB	05H
CONST	ENDS
PUBLIC	_DriverEntry@8
PUBLIC	_PCIDPAddDevice@8
PUBLIC	_PCIDPDispatchPower@8
PUBLIC	_PCIDPDispatchPnp@8
PUBLIC	_PCIDPDeviceControl@8
PUBLIC	_PCIDPCreateClose@8
PUBLIC	_PCIDPCleanup@8
PUBLIC	_PCIDPUnload@4
;	COMDAT _DriverEntry@8
_TEXT	SEGMENT
_DriverObject$ = 8
_DriverEntry@8 PROC NEAR				; COMDAT

; 37   : 
; 38   : 	// Debug entry point
; 39   : 	//DbgPrint("[PCIDP]->Entering DriverEntry...\n");	//debug
; 40   : 	//DbgBreakPoint();	//debug
; 41   : 
; 42   : 	// Initialize the driver object with this driver's entry points.
; 43   : 	DriverObject->MajorFunction[IRP_MJ_CREATE] = PCIDPCreateClose;

  00000	8b 44 24 04	 mov	 eax, DWORD PTR _DriverObject$[esp-4]
  00004	b9 00 00 00 00	 mov	 ecx, OFFSET FLAT:_PCIDPCreateClose@8
  00009	89 48 38	 mov	 DWORD PTR [eax+56], ecx

; 44   : 	DriverObject->MajorFunction[IRP_MJ_CLOSE] = PCIDPCreateClose;

  0000c	89 48 40	 mov	 DWORD PTR [eax+64], ecx

; 45   :   DriverObject->DriverExtension->AddDevice = PCIDPAddDevice;

  0000f	8b 48 18	 mov	 ecx, DWORD PTR [eax+24]
  00012	c7 41 04 00 00
	00 00		 mov	 DWORD PTR [ecx+4], OFFSET FLAT:_PCIDPAddDevice@8

; 46   :   DriverObject->MajorFunction[IRP_MJ_PNP] = PCIDPDispatchPnp;

  00019	c7 80 a4 00 00
	00 00 00 00 00	 mov	 DWORD PTR [eax+164], OFFSET FLAT:_PCIDPDispatchPnp@8

; 47   :   DriverObject->MajorFunction[IRP_MJ_POWER] = PCIDPDispatchPower;

  00023	c7 80 90 00 00
	00 00 00 00 00	 mov	 DWORD PTR [eax+144], OFFSET FLAT:_PCIDPDispatchPower@8

; 48   : 	DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = PCIDPDeviceControl;

  0002d	c7 40 70 00 00
	00 00		 mov	 DWORD PTR [eax+112], OFFSET FLAT:_PCIDPDeviceControl@8

; 49   : 	DriverObject->MajorFunction[IRP_MJ_CLEANUP] = PCIDPCleanup;

  00034	c7 80 80 00 00
	00 00 00 00 00	 mov	 DWORD PTR [eax+128], OFFSET FLAT:_PCIDPCleanup@8

; 50   : 	DriverObject->DriverUnload = (PDRIVER_UNLOAD)PCIDPUnload;

  0003e	c7 40 34 00 00
	00 00		 mov	 DWORD PTR [eax+52], OFFSET FLAT:_PCIDPUnload@4

; 51   : 	//DriverObject->DriverStartIo = (PDRIVER_STARTIO)PCIDPStartIo; //to have OS manage queued IRPs
; 52   : 
; 53   : 	// Initialize any other driver global data.
; 54   : 
; 55   : 	// Save a copy of the registry path pointed to by RegistryPath.
; 56   : 
; 57   : 	// Register for driver reinitialization.
; 58   : 	// IoRegisterDriverReinitialization();
; 59   : 
; 60   : 	return STATUS_SUCCESS;

  00045	33 c0		 xor	 eax, eax

; 61   : }

  00047	c2 08 00	 ret	 8
_DriverEntry@8 ENDP
_TEXT	ENDS
EXTRN	__imp__MmProbeAndLockPages@12:NEAR
EXTRN	__imp__MmGetPhysicalAddress@4:NEAR
EXTRN	__imp__MmAllocateContiguousMemory@12:NEAR
EXTRN	__imp__IoRegisterDeviceInterface@16:NEAR
EXTRN	__imp__KeInitializeEvent@12:NEAR
EXTRN	__imp__IoAllocateMdl@20:NEAR
EXTRN	__imp__IoAttachDeviceToDeviceStack@8:NEAR
EXTRN	__imp__IoCreateDevice@28:NEAR
EXTRN	__imp__IoDeleteDevice@4:NEAR
;	COMDAT _PCIDPAddDevice@8
_TEXT	SEGMENT
_DriverObject$ = 8
_PhysicalDeviceObject$ = 12
_NTStatus$ = -4
_DeviceObject$ = 8
_PhysicalAddress$ = -12
_PCIDPAddDevice@8 PROC NEAR				; COMDAT

; 72   : ){

  00000	55		 push	 ebp
  00001	8b ec		 mov	 ebp, esp
  00003	83 ec 0c	 sub	 esp, 12			; 0000000cH
  00006	53		 push	 ebx
  00007	56		 push	 esi

; 73   : 	NTSTATUS NTStatus;
; 74   : 	PDEVICE_OBJECT DeviceObject;
; 75   : 	PPCIDP_EXTENSION ObjExt;
; 76   : 	PHYSICAL_ADDRESS MaxAddress;
; 77   : 	PHYSICAL_ADDRESS PhysicalAddress;
; 78   : 
; 79   : 	// Debug entry point
; 80   : 	//DbgPrint("[PCIDP]->Entering AddDevice...\n");	//debug
; 81   : 	//DbgBreakPoint();	//debug
; 82   : 
; 83   : 	// Create the device space that will be associated with this driver.
; 84   : 	//todo: how to set up security attributes so the app. can call this driver
; 85   : 	//      (because of the FILE_DEVICE_SECURE_OPEN parameter).
; 86   : 	NTStatus = IoCreateDevice(
; 87   : 		IN  DriverObject,             // The driver object
; 88   : 		IN  sizeof(PCIDP_EXTENSION),	// Size (bytes) of the device ext.
; 89   : 		IN  NULL,											// The device name; let the OS name it
; 90   : 		IN  FILE_DEVICE_PCIDP00,			// The device type
; 91   : 		IN  FILE_DEVICE_SECURE_OPEN,  // Device characteristics
; 92   : 		IN  FALSE,                    // Exclusive Device flag
; 93   : 		OUT &DeviceObject             // New created device object
; 94   : 	);

  00008	8d 45 08	 lea	 eax, DWORD PTR _DeviceObject$[ebp]
  0000b	57		 push	 edi
  0000c	33 db		 xor	 ebx, ebx
  0000e	50		 push	 eax
  0000f	53		 push	 ebx
  00010	68 00 01 00 00	 push	 256			; 00000100H
  00015	68 00 c3 00 00	 push	 49920			; 0000c300H
  0001a	53		 push	 ebx
  0001b	68 a0 00 00 00	 push	 160			; 000000a0H
  00020	ff 75 08	 push	 DWORD PTR _DriverObject$[ebp]
  00023	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__IoCreateDevice@28

; 95   : 	if(NTStatus != STATUS_SUCCESS)

  00029	3b c3		 cmp	 eax, ebx
  0002b	89 45 fc	 mov	 DWORD PTR _NTStatus$[ebp], eax
  0002e	0f 85 ce 00 00
	00		 jne	 $Exit$8436

; 96   : 		goto Exit;
; 97   : 
; 98   : 	// Initialize the driver's extended object.
; 99   : 	ObjExt = (PPCIDP_EXTENSION)DeviceObject->DeviceExtension;

  00034	8b 45 08	 mov	 eax, DWORD PTR _DeviceObject$[ebp]

; 100  : 	RtlZeroMemory(ObjExt, sizeof(PCIDP_EXTENSION));

  00037	6a 28		 push	 40			; 00000028H
  00039	59		 pop	 ecx
  0003a	8b 70 28	 mov	 esi, DWORD PTR [eax+40]
  0003d	33 c0		 xor	 eax, eax
  0003f	8b fe		 mov	 edi, esi
  00041	f3 ab		 rep stosd

; 101  : 
; 102  : 	//ObjExt->BusNumber = BusNumber; - not needed
; 103  : 	//ObjExt->SlotNumber = SlotNumber; - not needed
; 104  : 	//ObjExt->BoardNumber = BoardNumber; - not needed
; 105  : 	//ObjExt->BaseAddresses[0] = CardInfo.u.type0.BaseAddresses[0]; - not needed
; 106  : 	//ObjExt->BaseAddresses[1] = CardInfo.u.type0.BaseAddresses[1]; - not needed
; 107  : 	//ObjExt->BaseAddresses[2] = CardInfo.u.type0.BaseAddresses[2]; - not needed
; 108  : 	//ObjExt->BaseAddresses[3] = CardInfo.u.type0.BaseAddresses[3]; - not needed
; 109  : 	//ObjExt->BaseAddresses[4] = CardInfo.u.type0.BaseAddresses[4]; - not needed
; 110  : 	//ObjExt->BaseAddresses[5] = CardInfo.u.type0.BaseAddresses[5]; - not needed
; 111  : 	//ObjExt->MemoryAccess - enum resources (Start)
; 112  : 	//ObjExt->IOAccess - enum resources (Start)
; 113  : 	//ObjExt->MemoryAccessLength - enum resources (Start)
; 114  : 	//ObjExt->IOAccessLength - enum resources (Start)
; 115  : 	//ObjExt->MemoryBase - initialized by MmMapIoSpace call (Start)
; 116  : 	//ObjExt->IOBase - not needed
; 117  : 	//ObjExt->InterruptObject - initialized by IoConnectInterrupt call (Start)
; 118  : 	//ObjExt->InterruptData - used in DpcISR and ISR
; 119  : 
; 120  : 	ObjExt->LLData.IsEmpty = TRUE;
; 121  : 	ObjExt->LLData.CurrentLink = NULL;
; 122  : 	ObjExt->LLData.InsertedCount = 0;
; 123  : 	ObjExt->LLData.FreeMax = 0;
; 124  : 
; 125  : 	//ObjExt->LListSpin - initialized by KeInitializeSpinLock call (AddDevice)
; 126  : 	//ObjExt->VirtualDMAAddress - initialized by MmAllocateContiguousMemory (AddDevice)
; 127  : 	//ObjExt->PhysicalDMAAddress - initialized by MmGetPhysicalAddress (AddDevice)
; 128  : 	//ObjExt->MDL - initialized by IoAllocateMdl (AddDevice)
; 129  : 	//ObjExt->SymbolicLinkName - initialized by IoRegisterDeviceInterface (AddDevice)
; 130  : 	//ObjExt->PhysicalDeviceObject - not needed
; 131  : 	//ObjExt->NextLowerDeviceObject - initialized by IoAttachDeviceToDeviceStack (AddDevice)
; 132  : 	//ObjExt->WaitEvent - initialized by KeInitializeEvent (AddDevice)
; 133  : 
; 134  : 
; 135  : 	// Now create a symbolic link an application can use to gain access to the
; 136  : 	// driver's services for this device.
; 137  : 	NTStatus = IoRegisterDeviceInterface(
; 138  : 		IN PhysicalDeviceObject,					//The PDO
; 139  : 		IN &GUID_PCIDP_INTERFACE,					//GUID for the interface class
; 140  : 		IN NULL,													//Reference string (not used)
; 141  : 		OUT &ObjExt->SymbolicLinkName			//returned symbolic link name
; 142  : 	);

  00043	8d 86 84 00 00
	00		 lea	 eax, DWORD PTR [esi+132]
  00049	c6 46 68 01	 mov	 BYTE PTR [esi+104], 1
  0004d	50		 push	 eax
  0004e	53		 push	 ebx
  0004f	68 00 00 00 00	 push	 OFFSET FLAT:_GUID_PCIDP_INTERFACE
  00054	89 5e 70	 mov	 DWORD PTR [esi+112], ebx
  00057	ff 75 0c	 push	 DWORD PTR _PhysicalDeviceObject$[ebp]
  0005a	66 89 5e 6a	 mov	 WORD PTR [esi+106], bx
  0005e	66 89 5e 6c	 mov	 WORD PTR [esi+108], bx
  00062	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__IoRegisterDeviceInterface@16

; 143  : 	if(NTStatus != STATUS_SUCCESS)

  00068	3b c3		 cmp	 eax, ebx
  0006a	89 45 fc	 mov	 DWORD PTR _NTStatus$[ebp], eax
  0006d	74 07		 je	 SHORT $L8444

; 144  : 		if(NTStatus != STATUS_OBJECT_NAME_EXISTS)

  0006f	3d 00 00 00 40	 cmp	 eax, 1073741824		; 40000000H
  00074	75 1d		 jne	 SHORT $ExitA$8445
$L8444:

; 145  : 			goto ExitA;
; 146  : 
; 147  : 	// Attach the device object to its device stack.
; 148  : 	ObjExt->NextLowerDeviceObject = IoAttachDeviceToDeviceStack(
; 149  : 		DeviceObject,
; 150  : 		PhysicalDeviceObject
; 151  : 	);

  00076	ff 75 0c	 push	 DWORD PTR _PhysicalDeviceObject$[ebp]
  00079	ff 75 08	 push	 DWORD PTR _DeviceObject$[ebp]
  0007c	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__IoAttachDeviceToDeviceStack@8

; 152  : 	if(ObjExt->NextLowerDeviceObject == NULL){

  00082	3b c3		 cmp	 eax, ebx
  00084	89 86 8c 00 00
	00		 mov	 DWORD PTR [esi+140], eax
  0008a	75 12		 jne	 SHORT $L8447

; 153  : 		NTStatus = STATUS_UNSUCCESSFUL;		//todo: more meaningful error code or log event file

  0008c	c7 45 fc 01 00
	00 c0		 mov	 DWORD PTR _NTStatus$[ebp], -1073741823 ; c0000001H
$ExitA$8445:

; 212  : 	goto Exit;
; 213  : 
; 214  : 	ExitA:
; 215  : 		IoDeleteDevice (DeviceObject);

  00093	ff 75 08	 push	 DWORD PTR _DeviceObject$[ebp]
  00096	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__IoDeleteDevice@4
  0009c	eb 64		 jmp	 SHORT $Exit$8436
$L8447:

; 154  : 		goto ExitA;
; 155  : 	}
; 156  : 
; 157  : 	// Set up an synchro event for the start device IRP.
; 158  : 	KeInitializeEvent(&ObjExt->WaitEvent, SynchronizationEvent, FALSE);

  0009e	53		 push	 ebx
  0009f	8d 86 90 00 00
	00		 lea	 eax, DWORD PTR [esi+144]
  000a5	6a 01		 push	 1
  000a7	50		 push	 eax
  000a8	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__KeInitializeEvent@12

; 159  : 
; 160  : 	// Allocate a contiguous span of memory for DMA usage.
; 161  : 	MaxAddress.LowPart = 0xFFFFFFFF;
; 162  : 	MaxAddress.HighPart = 0;		

  000ae	33 c9		 xor	 ecx, ecx
  000b0	83 c8 ff	 or	 eax, -1

; 163  : 	ObjExt->VirtualDMAAddress = MmAllocateContiguousMemory(
; 164  : 		IN (ULONG)DMASize,	//16K
; 165  : 		IN MaxAddress				//Full 32 bit address range
; 166  : 	);

  000b3	51		 push	 ecx
  000b4	bf 00 40 00 00	 mov	 edi, 16384		; 00004000H
  000b9	50		 push	 eax
  000ba	57		 push	 edi
  000bb	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__MmAllocateContiguousMemory@12

; 167  : 
; 168  : 	//DbgPrint("[PCIDP]->AddDevice, VirtDMAAddr=0x%x...\n", ObjExt->VirtualDMAAddress);	//debug
; 169  : 
; 170  : 	if(ObjExt->VirtualDMAAddress != NULL){

  000c1	3b c3		 cmp	 eax, ebx
  000c3	89 46 78	 mov	 DWORD PTR [esi+120], eax
  000c6	74 30		 je	 SHORT $L8451

; 171  : 		PhysicalAddress = MmGetPhysicalAddress(
; 172  : 			ObjExt->VirtualDMAAddress
; 173  : 		);

  000c8	50		 push	 eax
  000c9	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__MmGetPhysicalAddress@4

; 174  : 		ObjExt->PhysicalDMAAddress = PhysicalAddress.LowPart;
; 175  : 
; 176  : 		//DbgPrint("[PCIDP]->AddDevice, PhyDMAAddr=0x%x...\n", ObjExt->PhysicalDMAAddress);	//debug
; 177  : 
; 178  : 		ObjExt->MDL = IoAllocateMdl(
; 179  : 			ObjExt->VirtualDMAAddress, 
; 180  : 			DMASize, 
; 181  : 			FALSE, 
; 182  : 			FALSE, 
; 183  : 			NULL
; 184  : 		);

  000cf	53		 push	 ebx
  000d0	53		 push	 ebx
  000d1	53		 push	 ebx
  000d2	57		 push	 edi
  000d3	ff 76 78	 push	 DWORD PTR [esi+120]
  000d6	89 55 f8	 mov	 DWORD PTR _PhysicalAddress$[ebp+4], edx
  000d9	89 46 7c	 mov	 DWORD PTR [esi+124], eax
  000dc	ff 15 00 00 00
	00		 call	 DWORD PTR __imp__IoAllocateMdl@20

; 185  : 
; 186  : 		if(ObjExt->MDL){

  000e2	3b c3		 cmp	 eax, ebx
  000e4	89 86 80 00 00
	00		 mov	 DWORD PTR [esi+128], eax
  000ea	74 0f		 je	 SHORT $L8454

; 187  : 
; 188  : 			//DbgPrint("[PCIDP]->AddDevice, MDLFlags=0x%x...\n", ObjExt->MDL->MdlFlags);	//debug
; 189  :    
; 190  : 			//MmBuildMdlForNonPagedPool(ObjExt->MDL);
; 191  : 
; 192  : 			//DbgPrint("[PCIDP]->AddDevice, MDLFlags=0x%x...\n", ObjExt->MDL->MdlFlags);	//debug
; 193  :    
; 194  : 			MmProbeAndLockPages(
; 195  : 				ObjExt->MDL,
; 196  : 				KernelMode,
; 197  : 				IoModifyAccess
; 198  : 			);

  000ec	6a 02		 push	 2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -