From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mn7Px-0005Wf-7G for qemu-devel@nongnu.org; Mon, 14 Sep 2009 05:00:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mn7Ps-0005W9-JS for qemu-devel@nongnu.org; Mon, 14 Sep 2009 05:00:12 -0400 Received: from [199.232.76.173] (port=51959 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mn7Ps-0005W6-Fg for qemu-devel@nongnu.org; Mon, 14 Sep 2009 05:00:08 -0400 Received: from mail.gmx.net ([213.165.64.20]:44089) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1Mn7Pr-0003yU-PG for qemu-devel@nongnu.org; Mon, 14 Sep 2009 05:00:08 -0400 Content-Type: text/plain; charset="iso-8859-1" Date: Mon, 14 Sep 2009 11:00:01 +0200 From: "Johannes Luber" Message-ID: <20090914090001.99230@gmx.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] tlb_update_dirty() question List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, Before I state my question I describe my assumptions how Qemu works internally. If I'm wrong there you'll notice it sooner. The pointers of the emulation layer are transformed into physical addresses is a two-steps process. The emulated machine itself uses virtual addresses which are represented by the type ram_addr_t. These virtual addresses are different from the one the host OS, in fact they are a completely internal representation. To actually work with ram_addr_t pointers, these have to be transformed into host virtual addresses. These are represented by target_phys_addr_t pointers. To access with the host virtual memory the physical memory, the host OS does its own magic which is no functionality of Qemu itself. Taking all assumptions into account it is certainly possibly that ram_addr_t can be smaller than target_phys_addr_t. E.g., a 32-bit target system can access only 4 GB of memory while its 64-bit host put that memory anywhere in the whole address range. But then I stumbled over these snippets: static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry) { ram_addr_t ram_addr; void *p; if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == IO_MEM_RAM) { p = (void *)(unsigned long)((tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend); ram_addr = qemu_ram_addr_from_host(p); if (!cpu_physical_memory_is_dirty(ram_addr)) { tlb_entry->addr_write |= TLB_NOTDIRTY; } } } /* Some of the softmmu routines need to translate from a host pointer (typically a TLB entry) back to a ram offset. */ ram_addr_t qemu_ram_addr_from_host(void *ptr) { ... } The comment is particularly insightful. p is supposed to be a host pointer yet the initialization code uses "(unsigned long)" in a cast for an expression which has the type target_phys_addr_t because the struct variable "addend" has this type. This cast assumes that unsigned long is at least as big as target_phys_addr_t. Under Unix this may be true, but Windows C compilers treat long == int and int remains a 32-bit type. Why isn't simply target_phys_addr_t used as cast? target_phys_addr_t does support max(target pointer size, host pointer size), doesn't it? Or is there another option? Best regards, Johannes -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01