First of all, I'm not sure how QEMU handles this, but I'll explain my thoughts.
So, I'm using unicorn engine to implement an entire machine (iPod Classic, in this case). I've been developing the qemu port side-by-side with the unicorn port (because compiling QEMU for android is a pain in the ass).
In QEMU, when I want to add a peripheral that is memory-mapped I just make calls to memory_region_init_io and to sysbus_init_mmio, and then all accesses to those memory regions get redirected to the hook functions, where I can read and write my internal structure. When doing this, I don't think QEMU allocates a memory region for the peripheral size (for example 0x10000), but only calls the function when it needs the data and uses a single variable for it (this is all my thoughts, as I haven't been able to find something that contradicts this).
However, in unicorn it looks like you 100% need to allocate system memory for that peripheral, and then the callbacks get executed but the data is still read from the allocated system memory. Of course, in case of a read hook, i can use uc_mem_write to fix this issue.
In case QEMU does in fact allocate system memory, the issue can be closed :) In case it doesn't, can unicorn be modified so that we don't have to allocate huge amounts of useless memory for peripherals?
I hope I made it clear enough. Feel free to ask for any details!
Hi!
First of all, I'm not sure how QEMU handles this, but I'll explain my thoughts.
So, I'm using unicorn engine to implement an entire machine (iPod Classic, in this case). I've been developing the qemu port side-by-side with the unicorn port (because compiling QEMU for android is a pain in the ass).
In QEMU, when I want to add a peripheral that is memory-mapped I just make calls to
memory_region_init_io
and tosysbus_init_mmio
, and then all accesses to those memory regions get redirected to the hook functions, where I can read and write my internal structure. When doing this, I don't think QEMU allocates a memory region for the peripheral size (for example 0x10000), but only calls the function when it needs the data and uses a single variable for it (this is all my thoughts, as I haven't been able to find something that contradicts this).However, in unicorn it looks like you 100% need to allocate system memory for that peripheral, and then the callbacks get executed but the data is still read from the allocated system memory. Of course, in case of a read hook, i can use
uc_mem_write
to fix this issue.In case QEMU does in fact allocate system memory, the issue can be closed :) In case it doesn't, can unicorn be modified so that we don't have to allocate huge amounts of useless memory for peripherals?
I hope I made it clear enough. Feel free to ask for any details!
Regards, Iscle