VOID ScsiPortReadPortBufferUchar( IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count ) /*++ Routine Description: Read a buffer of unsigned bytes from the specified port address. Arguments: Port - Supplies a pointer to the port address. Buffer - Supplies a pointer to the data buffer area. Count - The count of items to move. Return Value: None --*/ { READ_PORT_BUFFER_UCHAR(Port, Buffer, Count); }
VOID NTAPI ScsiPortReadPortBufferUchar( IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count) { READ_PORT_BUFFER_UCHAR(Port, Buffer, Count); }
VOID NTAPI VideoPortReadPortBufferUchar( PUCHAR Port, PUCHAR Buffer, ULONG Count) { READ_PORT_BUFFER_UCHAR(Port, Buffer, Count); }
NTSTATUS DispatchControl(PDEVICE_OBJECT fdo, PIRP Irp) { // DispatchControl PAGED_CODE(); PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension; NTSTATUS status; ULONG info = 0; PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp); ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength; ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength; ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; switch (code) { // process request case IOCTL_READ_BASE_BAR0: { ULONG offset = *(ULONG*)(Irp->AssociatedIrp.SystemBuffer); PUCHAR buff = (PUCHAR)ExAllocatePool(NonPagedPool,cbout); READ_REGISTER_BUFFER_UCHAR((PUCHAR)pdx->MemBar0+offset,buff,cbout); RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, buff, cbout); ExFreePool(buff); info = cbout; break; } case IOCTL_WRITE_BASE_BAR0: { int* tempPointer = (int*)Irp->AssociatedIrp.SystemBuffer; ULONG offset = *(ULONG*)(tempPointer); tempPointer++; PUCHAR buff = *(PUCHAR*)(tempPointer); tempPointer++; ULONG nInputNumber = *(ULONG*)(tempPointer); WRITE_REGISTER_BUFFER_UCHAR((PUCHAR)pdx->MemBar0+offset,buff,nInputNumber); break; } case IOCTL_READ_BASE_BAR2: { ULONG offset = *(ULONG*)(Irp->AssociatedIrp.SystemBuffer); PUCHAR buff = (PUCHAR)ExAllocatePool(NonPagedPool,cbout); READ_PORT_BUFFER_UCHAR(pdx->portbase+offset,buff,cbout); RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, buff, cbout); ExFreePool(buff); info = cbout; break; } case IOCTL_WRITE_BASE_BAR2: { int* tempPointer = (int*)Irp->AssociatedIrp.SystemBuffer; ULONG offset = *(ULONG*)(tempPointer); tempPointer++; PUCHAR buff = *(PUCHAR*)(tempPointer); tempPointer++; ULONG nInputNumber = *(ULONG*)(tempPointer); WRITE_PORT_BUFFER_UCHAR(pdx->portbase+offset,buff,nInputNumber); break; } case IOCTL_READ_IMAGE: { PUCHAR buff = (PUCHAR)ExAllocatePool(NonPagedPool,cbout); READ_REGISTER_BUFFER_UCHAR((PUCHAR)pdx->MemForImage,buff,cbout); RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, buff, cbout); ExFreePool(buff); info = cbout; break; } case IOCTL_WRITE_IMAGE: { PUCHAR buff = (PUCHAR)ExAllocatePool(NonPagedPool,cbin); RtlCopyMemory(buff,Irp->AssociatedIrp.SystemBuffer,cbin); WRITE_REGISTER_BUFFER_UCHAR((PUCHAR)pdx->MemForImage,buff,cbin); ExFreePool(buff); info = cbin; break; } case IOCTL_ENABLE_INT: { //允许中断 UCHAR HSR = READ_PORT_UCHAR(pdx->portbase); HSR = HSR & 0xFB; WRITE_PORT_UCHAR(pdx->portbase,HSR); break; } case IOCTL_DISABLE_INT: { //关中断 UCHAR HSR = READ_PORT_UCHAR(pdx->portbase); HSR = HSR | 0x4; WRITE_PORT_UCHAR(pdx->portbase,HSR); break; } default: status = STATUS_INVALID_DEVICE_REQUEST; break; } // process request return CompleteRequest(Irp, status, info); }