--- trunk/src/memory.c 2007/10/08 16:20:18 27 +++ trunk/src/memory.c 2007/10/08 16:20:26 28 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: memory.c,v 1.190 2006/06/16 18:31:25 debug Exp $ + * $Id: memory.c,v 1.192 2006/07/14 16:33:27 debug Exp $ * * Functions for handling the memory of an emulated machine. */ @@ -313,6 +313,31 @@ /* + * memory_device_update_data(): + * + * Update a device' dyntrans data pointer. + * + * SUPER-IMPORTANT NOTE: Anyone who changes a dyntrans data pointer while + * things are running also needs to invalidate all CPUs' address translation + * caches! Otherwise, these may contain old pointers to the old data. + */ +void memory_device_update_data(struct memory *mem, void *extra, + unsigned char *data) +{ + int i; + + for (i=0; in_mmapped_devices; i++) { + if (mem->dev_extra[i] != extra) + continue; + + mem->dev_dyntrans_data[i] = data; + mem->dev_dyntrans_write_low[i] = (uint64_t)-1; + mem->dev_dyntrans_write_high[i] = 0; + } +} + + +/* * memory_device_register(): * * Register a (memory mapped) device by adding it to the dev_* fields of a @@ -518,9 +543,11 @@ /* * memory_paddr_to_hostaddr(): * - * Translate a physical address into a host address. + * Translate a physical address into a host address. The usual way to call + * this function is to make sure that paddr is page aligned, which will result + * in the host _page_ corresponding to that address. * - * Return value is a pointer to a host memblock, or NULL on failure. + * Return value is a pointer to the address in the host, or NULL on failure. * On reads, a NULL return value should be interpreted as reading all zeroes. */ unsigned char *memory_paddr_to_hostaddr(struct memory *mem, @@ -530,6 +557,7 @@ int entry; const int mask = (1 << BITS_PER_PAGETABLE) - 1; const int shrcount = MAX_BITS - BITS_PER_PAGETABLE; + unsigned char *hostptr; table = mem->pagetable; entry = (paddr >> shrcount) & mask; @@ -569,7 +597,12 @@ } } - return (unsigned char *) table[entry]; + hostptr = (unsigned char *) table[entry]; + + if (hostptr != NULL) + hostptr += (paddr & ((1 << BITS_PER_MEMBLOCK) - 1)); + + return hostptr; }