atos-tools / qemu

QEMU with instrumentation support, ref to tcg/plugins/README
https://guillon.github.io/qemu-plugins
Other
5 stars 8 forks source link

binary translation in softmmu mode #2

Closed second-reality closed 5 years ago

second-reality commented 6 years ago

From "https://github.com/atos-tools/qemu-plugins-tutorial/issues/2", by s0i37

Hello. I try to write test plugin or use icount in softmmu-mode, but I dont see anything in output. I do so:

./x86_64-softmmu/qemu-system-x86_64 -hda ~/os/images/winXP.qcow2 --tcg-plugin icount -m 1G -monitor stdio (qemu) stop (qemu) loadvm some_state (qemu) cont

May be I make something wrong?

second-reality commented 6 years ago

While plugins could work theorically in softmmu mode, we didn't work in this direction. So far, we only used it in user mode.

Indeed, it didn't work in system mode, thus I made a patch (pushed on next/master): https://github.com/atos-tools/qemu/commit/054b07ac2360489ee760f97ca80fac7e08b557ab. It allows icount plugin to work (at least).

However, any access to guest memory is failing cause we only implemented that for user mode. I'll check if it is possible easily.

second-reality commented 6 years ago

Hello,

please check branch next/master, I implemented access to memory in system mode. Tell me if you need more help!

s0i37 commented 6 years ago

Good. Its seems works. And yes, I want to ask a couple of question:

Thank you.

s0i37 commented 5 years ago

So, for obtaining registry value we need to get CPUArchState in pre_tb_helper_code handler: CPUArchState *cpu = tpi_current_cpu_arch(tpi); after that we can get registry value:

( (CPUX86State *)cpu )->regs[R_EAX];
( (CPUX86State *)cpu )->cr[3];

For reading guest memory in after_gen_opc handler: (void *)(intptr_t)tpi_guest_ptr(tpi, tpi_opcode->pc);

It seems something like that

second-reality commented 5 years ago

Thanks for update.