static void DebugPrintFuncSerial(const char *format, ...) { char buf[TEMP_BUFFER_SIZE]; NTSTATUS status; size_t len; va_list list; va_start(list, format); status = RtlStringCbVPrintfA(buf, sizeof(buf), format, list); if (status == STATUS_SUCCESS) { len = strlen(buf); } else { len = 2; buf[0] = 'O'; buf[1] = '\n'; } if (len) { WRITE_PORT_BUFFER_UCHAR(RHEL_DEBUG_PORT, (PUCHAR)buf, len); WRITE_PORT_UCHAR(RHEL_DEBUG_PORT, '\r'); } va_end(list); }
VOID ScsiPortWritePortBufferUchar( IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count ) /*++ Routine Description: Write 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 --*/ { WRITE_PORT_BUFFER_UCHAR(Port, Buffer, Count); }
VOID NTAPI ScsiPortWritePortBufferUchar( IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count) { WRITE_PORT_BUFFER_UCHAR(Port, Buffer, Count); }
VOID NTAPI VideoPortWritePortBufferUchar( PUCHAR Port, PUCHAR Buffer, ULONG Count) { WRITE_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); }