简体   繁体   中英

Print range of memory addresses in qemu

I am new to qemu development. I wanted to print the corresponding addresses involved when a memory has been assigned to a virtual machine.

For example, when i invoke the following command

qemu-system-i386 ubuntu.img -m 1G

I need to be able to print the virtual addresses and physical addresses involved. Like above 1G memory involved:

Guest Virtual Addr = 0x12345678..to 0x87654321..

Guest Physical Addr = 0x23456781..to 0x74536733..(This is the one that gets mapped to host virtual memory if my understanding is right).

Note: Above numbers are just for explanation.

When I looked into the source code of qemu, I see that this size whatever we are mentioning in the command here is assigned as a part of |ram_addr_t| block. But I am not able to find as how to proceed to find the offset for this size.Kindly help me in this regard at the earliest.

Based on the above, I think what you want to do is not map guest virtual address to guest physical address (per the post), but guest physical address to host virtual address.

The mapping between guest physical and guest virtual is (mostly) controlled by the guest OS. If you are really are trying to look at guest physical to guest virtual, that will be target specific. Some qemu targets do not even have such a mapping (flat address space).

I would start by looking at the source for memory.c and memory_mapping.c .

Below is an excerpt from exec.c which converts a target a target (guest) virtual address into a target physical address, and manipulates memory there. Is that what you needed?

int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
                        uint8_t *buf, int len, int is_write)
{
    int l;
    hwaddr phys_addr;
    target_ulong page;

    while (len > 0) {
        page = addr & TARGET_PAGE_MASK;
        phys_addr = cpu_get_phys_page_debug(cpu, page);
        /* if no physical page mapped, return an error */
        if (phys_addr == -1)
            return -1;
        l = (page + TARGET_PAGE_SIZE) - addr;
        if (l > len)
            l = len;
        phys_addr += (addr & ~TARGET_PAGE_MASK);
        if (is_write) {
            cpu_physical_memory_write_rom(cpu->as, phys_addr, buf, l);
        } else {
            address_space_rw(cpu->as, phys_addr, buf, l, 0);
        }
        len -= l;
        buf += l;
        addr += l;
    }
    return 0;

Finally, I think you might get more help on the qemu IRC channel than here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM