Could you give some more context on what you are working on, please?
Sorry, Nominal Animal, I'd really love to, it's a cool project but you know NDAs and stuff 
Anyways, jokes aside. Sorry for late reply I got busy with schoolwork.
Am trying to emulate a device with qemu. Actually I can already emulate the device am just polishing and stuff.
This is what happens in Qemu.
-Software reads/writes to MMIO trigger traps to which Qemu responds but calling calling an MMIO handler specific to the particular device and of course many other things happens but that's the basic overview.
-A programmer emulating a device has to implement the MMIO read/write handler - it has a general prototype.
I thought this was going to be hard to do, especially the ro/rw1c/rw1s but it proved too easy.
I just did this
Code:
/*
@ addr: address of mmio register to write to
@ s : structure representing a device (it contains a static array representing the MMIO region and others representing special masks)
@val : value to write
*/
static void mmio_write_long(struct device *s, uint64_t addr, uint32_t val)
{
uint64_t romask = s->romask[addr]; //get the read only mask
uint64_t w1cmask = s->r1cmask[addr]; //get the write 1 clear mask
s->mmio[addr] = ((val & ~ romask) | ( val & ~ w1cmask)); //store value disregarding read only bit and clearing w1c bits
}
//And of course the code's not exactly as I wrote above but that's basically how it works