Sign in to follow this  
Painless

Accessing device memory (win98)

Recommended Posts

Painless    126
I've been working on a program in which I need to - in a very time-critical spot - write to a certain address in the memory of a device. So far, I've been using the device's own driver DLL to do this. However, now it seems that this is too slow and I need to write the memory as directly as possible. The device's documentation tells me that I need to write to base address (0x220) + 13, however, it seems to me (if I'm wrong, just tell me - I can't test it right now) that I can't just say int address = 0x220 + 13; char *foo = *( char ** )&address; *foo = value; (I still don't know how to use code tags) So how should I go about this? A hackish solution is acceptable, but I'd prefer to keep it simple, no "ring 0" madness unless I have to do that. I'm using visual c++.NET (no managed stuff, just plain win32 code).

Share this post


Link to post
Share on other sites
S1CA    1418
An address of a memory address is simply written like this:

int* addr = (int *)0x220+13;

*addr = poke;
peek = *addr;

However - you do have a problem - all user mode (ring 3) code running under Windows uses a virtual address space. The 0x220 for your device will be a physical address not virtual.

I'm afraid ring 0 madness is likely your best option (save for a few nasty OS specific hacks). You could find the VXD the DLL is talking to and talk to that instead.

Are you certain of where the slowness is actually coming from? - from the switch to kernel mode to write the register; or from the DLL interface; from the PC hardware side; from the device side.

Windows is still able to make tons of kernel mode switches to write to display adapters, hard-disks and the like, so it's not THAT slow in the grand scheme of things. Of course Windows isn't a "realtime" OS either [smile]

Share this post


Link to post
Share on other sites
Painless    126
Thank you for the reply. I think I'll try the ring0 way - it seems to be my best bet (I have to debug and run this code on a computer that's not my development computer, which complicates things).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this