📄 hdwsim.c
字号:
// Hardware Simulator driver
/*****************************************************************************
* Change Log
* Date | Change
*-----------+-----------------------------------------------------------------
* 3-23-99 END - Added missing DBG_MSG_HDR to print statement
* 18-Mar-98 | Added new codes for get/set of debug mask.
* | Debug mask stored in device extension
* | Debug mask controls printout
* 10-06-97 | END - Created
*****************************************************************************/
/*****************************************************************************
* To Do
*-----------------------------------------------------------------------------
*****************************************************************************/
#include "ntddk.h"
#include "HdwSim.h"
#include "HdwSimIoctl.h"
#include "mapMemory.h"
#include "readReg.h"
#define DBG_MSG_HDR "HdwSim: "
NTSTATUS HdwSimOpen(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp );
NTSTATUS HdwSimClose(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp );
NTSTATUS HdwSimDeviceControl (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp );
VOID HdwSimUnload(
IN PDRIVER_OBJECT DriverObject );
BOOLEAN HdwSimInterruptServiceRoutine(
IN PKINTERRUPT Interrupt,
IN OUT PVOID Context
);
VOID HdwSimDpcRoutine(
IN PKDPC Dpc,
IN PVOID DeferredContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2
);
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath )
{
PDEVICE_OBJECT deviceObject = NULL;
NTSTATUS status;
UNICODE_STRING uniNtNameString;
UNICODE_STRING uniDosNameString;
NTSTATUS retReg;
//
// registry values
//
ULONG debugMask;
ULONG eventLog;
ULONG shouldBreak;
ULONG interrupt_Line;
// unsigned int busNumber;
PHDW_SIM_DEVICE_EXTENSION extension;
unsigned int vgaBaseReg;
unsigned int baseReg = 0;
ULONG baseAddressReg1;
PHYSICAL_ADDRESS physicalAddressBase1;
ULONG lengthToMap;
unsigned int i;
UNICODE_STRING ephemeralRegistryPath;
UNICODE_STRING parameterRegistryPath;
UNICODE_STRING registryPathName;
#define HDW_SIM_MAX_NAMELENGTH 200
KdPrint( ("%s Entered the HdwSim driver!\n", DBG_MSG_HDR) );
status = initDevicePath( DriverObject, RegistryPath , &ephemeralRegistryPath, ¶meterRegistryPath, ®istryPathName);
retReg = readRegistry(DriverObject, ¶meterRegistryPath, &debugMask, &eventLog, &shouldBreak, &interrupt_Line);
KdPrint( ("%s returned from readRegistry!\n", DBG_MSG_HDR) );
if (shouldBreak)
DbgBreakPoint();
//
// Create counted string version of our device name.
//
RtlInitUnicodeString( &uniNtNameString, NT_DEVICE_NAME );
//
// Create the device object
//
status = IoCreateDevice(
DriverObject,
sizeof(HDW_SIM_DEVICE_EXTENSION), // device extension
&uniNtNameString,
FILE_DEVICE_UNKNOWN,
0, // No standard device characteristics
FALSE, // This isn't an exclusive device
&deviceObject
);
if ( !NT_SUCCESS(status) )
{
KdPrint(("%s could not create device\n", DBG_MSG_HDR));
status = STATUS_NO_SUCH_DEVICE;
return status;
}
extension = deviceObject->DeviceExtension;
extension->DeviceObject = deviceObject;
extension->ephemeralRegistryPath = ephemeralRegistryPath ;
extension->parameterRegistryPath = parameterRegistryPath;
extension->registryPathName = registryPathName;
extension->debugMask = debugMask;
extension->pSimulatedRegisterLogicalAddress = &extension->simulatedRegister[0];
// (PUCHAR)ExAllocatePool(NonPagedPool, sizeof(HDW_SIM_REGS));
//
// if NULL returned error
//
extension->pSimulatedRegisterPhysicalAddress = MmGetPhysicalAddress(extension->pSimulatedRegisterLogicalAddress);
KeInitializeSpinLock(&extension->registerLock);
//
// Create dispatch points for create/open, close, unload.
//
DriverObject->MajorFunction[IRP_MJ_CREATE] = HdwSimOpen;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = HdwSimClose;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HdwSimDeviceControl;
DriverObject->DriverUnload = HdwSimUnload;
KdPrint( ("%s just about ready!\n", DBG_MSG_HDR) );
//
// Do Buffered I/O. A nop Read and write are not supported by this driver
//
deviceObject->Flags |= DO_BUFFERED_IO;
//
// Create counted string version of our Win32 device name.
//
RtlInitUnicodeString( &uniDosNameString, DOS_DEVICE_NAME );
//
// Create a link from our device name to a name in the Win32 namespace.
//
status = IoCreateSymbolicLink( &uniDosNameString, &uniNtNameString );
if (!NT_SUCCESS(status))
{
KdPrint( ("%s Couldn't create the symbolic link\n", DBG_MSG_HDR) );
IoDeleteDevice( DriverObject->DeviceObject );
return status;
}
//
// save the address in the device extension;
//
extension->interrupt_Line = interrupt_Line;
extension->Level = extension->interrupt_Line;
extension->Vector = extension->interrupt_Line;
extension->interrupt_IDT = HalGetInterruptVector(Isa,
(ULONG)0, // BusNumber,
extension->Level, // Level
extension->Vector, // Vector,
&extension->irql, // IRQL
&extension->Affinity); // Affinity mask
status = saveConfig( extension->ephemeralRegistryPath.Buffer,
extension->interrupt_Line,
extension->interrupt_IDT,
(VOID *)extension->pSimulatedRegisterLogicalAddress,
extension->pSimulatedRegisterPhysicalAddress
);
KdPrint(("%s TargetReadRegistry - interruptLine = 0x%08x\n", DBG_MSG_HDR, extension->interrupt_Line ));
KdPrint(("%s TargetReadRegistry - interruptIDT = 0x%08x\n", DBG_MSG_HDR, extension->interrupt_IDT ));
KdPrint(("%s TargetReadRegistry - registerAddress = 0x%08x\n", DBG_MSG_HDR,
(ULONG)extension->pSimulatedRegisterLogicalAddress));
KdPrint(("%s TargetReadRegistry - PhysicalAddress= 0x%08x 0x%08x\n", DBG_MSG_HDR,
extension->pSimulatedRegisterPhysicalAddress.HighPart,
extension->pSimulatedRegisterPhysicalAddress.LowPart));
KdPrint( ("%s All initialized\n", DBG_MSG_HDR) );
return status;
}
NTSTATUS HdwSimOpen(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp )
{
KdPrint( ("%s Opened!!\n", DBG_MSG_HDR) );
//
// No need to do anything.
//
//
// Fill these in before calling IoCompleteRequest.
//
// DON'T get cute and try to use the status field of
// the irp in the return status. That IRP IS GONE as
// soon as you call IoCompleteRequest.
//
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_SUCCESS;
}
NTSTATUS HdwSimClose(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp )
{
KdPrint( ("%s Closed!!\n", DBG_MSG_HDR) );
//
// No need to do anything.
//
//
// Fill these in before calling IoCompleteRequest.
//
// DON'T get cute and try to use the status field of
// the irp in the return status. That IRP IS GONE as
// soon as you call IoCompleteRequest.
//
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_SUCCESS;
}
/****************************************************************************
Function:
generateInterrupt
Arguments:
Description:
Returns:
*****************************************************************************/
void generateInterrupt(UCHAR interrupt_IDT)
{
switch ( interrupt_IDT )
{
case 0x00: _asm { int 0x00 }
break;
case 0x01: _asm { int 0x01 }
break;
case 0x02: _asm { int 0x02 }
break;
case 0x03: _asm { int 0x03 }
break;
case 0x04: _asm { int 0x04 }
break;
case 0x05: _asm { int 0x05 }
break;
case 0x06: _asm { int 0x06 }
break;
case 0x07: _asm { int 0x07 }
break;
case 0x08: _asm { int 0x08 }
break;
case 0x09: _asm { int 0x09 }
break;
case 0x0a: _asm { int 0x0a }
break;
case 0x0b: _asm { int 0x0b }
break;
case 0x0c: _asm { int 0x0c }
break;
case 0x0d: _asm { int 0x0d }
break;
case 0x0e: _asm { int 0x0e }
break;
case 0x0f: _asm { int 0x0f }
break;
case 0x10: _asm { int 0x10 }
break;
case 0x11: _asm { int 0x11 }
break;
case 0x12: _asm { int 0x12 }
break;
case 0x13: _asm { int 0x13 }
break;
case 0x14: _asm { int 0x14 }
break;
case 0x15: _asm { int 0x15 }
break;
case 0x16: _asm { int 0x16 }
break;
case 0x17: _asm { int 0x17 }
break;
case 0x18: _asm { int 0x18 }
break;
case 0x19: _asm { int 0x19 }
break;
case 0x1a: _asm { int 0x1a }
break;
case 0x1b: _asm { int 0x1b }
break;
case 0x1c: _asm { int 0x1c }
break;
case 0x1d: _asm { int 0x1d }
break;
case 0x1e: _asm { int 0x1e }
break;
case 0x1f: _asm { int 0x1f }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -