Thursday, July 21, 2011

Doing Memory mapped I/O from windows driver

Here is the example of how to perform Memory Mapped I/O using windows driver.



#include <wdm.h>

VOID DriverUnload(PDRIVER_OBJECT pDriverObject)
{
    DbgPrint("Driver unloading\n");
    {
        PVOID p;
        PHYSICAL_ADDRESS physAddr;
        physAddr.QuadPart = 0xFED01000;
        p = MmMapIoSpace(physAddr, 4, 1);
        *(unsigned int*)p = 0xF9;
    }
}

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    DbgPrint("Hello, World\n");
    DriverObject->DriverUnload = DriverUnload;

    return STATUS_SUCCESS;
}

No comments: