Inside my kernel-mode driver is the following code:
PHYSICAL_ADDRESS physAddr;
PVOID pvk;
unsigned int reg_addr; // physical address to write to
unsigned int* reg_val; // pointer to value to be written
// assume reg_addr and reg_val are initialized to some values
physAddr.QuadPart = (ULONGLONG)reg_addr;
pvk = MmMapIoSpace(physAddr,sizeof(reg_addr),MmNonCached);
WRITE_REGISTER_ULONG((ULONG*)pvk,(ULONG)®_val);
The address is not being written to, and I’m not sure why. Is this the correct procedure or am I missing a step? Also, could my pointer arithmetic be wrong? I’ve tried all permutations, and none have resulted in the correct result. I want the physical memory specified by reg_addr to be written with what is specified by the value pointed to by reg_val.
There are a few things that look odd/wrong with your code:-
First,
PHYSICAL_ADDRESS.QuadPartis a 64-bit value, but you’re assigning a 32-bit int to it. Are you sure that’s what you want to do?Second, I assume you want to map a 32-bit ‘ULONG’ register:
That will probably work, but what I think you mean is this
Finally, you’re writing the address of the pointer variable
reg_valto your register. Your comment implies you want to write the value pointed to byreg_val? If so, use this instead.