On Wed, Aug 22, 2012 at 09:38:17PM -0700, Xin Tong wrote: > On Wed, Aug 22, 2012 at 8:14 PM, 陳韋任 (Wei-Ren Chen) > <che...@iis.sinica.edu.tw> wrote: > >> In tcg_gen_qemu_ld8s(tmp, addr, index); a TCGv addr is passed to the > >> INDEX_op_qemu_ld8s as param and the loaded value is passed back in > >> tmp. i want to get the translated value as well. how can i do that ? > > > > IIUC, qemu_ld takes addr as guest virtual address, then loads the > > value in that address into tmp. So, what "translated value" you mean > > here? The guest physical address, host virtual address, or the value > > of the guest virtual address? > > either the guest physical or the host virtual is fine with me. but > better to be guest physical. i think guest physical can be obtained by > subtracting host virtual with a fixed offset for ram. but the thing i > do not know how to do is how to pass the guest physical back, can i > store the guest physical in the TCGv from the guest virtual.
qemu_ld will go through software tlb first, you will get host virtual address there. It will go ld{b,w,l,q}_mmu if software tlb miss, call tlb_fill -> cpu_x86_handle_mmu_fault, you can get guest physical address there (target_phys_addr_t paddr). If you want to get guest physical address for each guest memory access, I guess you need to disable software tlb lookup, you can refer to Max's patch [1]. Or as you said, maybe you can get guest physical addr from host virtual addr. You can refer to cpu_physical_memory_map (exec.c) which map guest physical addr to host virtual addr, then see how you can do the reverse. HTH, chenwj [1] http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg03226.html -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj