--- trunk/src/memory.c 2007/10/08 16:19:37 22 +++ trunk/src/memory.c 2007/10/08 16:19:56 24 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: memory.c,v 1.187 2006/01/14 12:51:59 debug Exp $ + * $Id: memory.c,v 1.190 2006/06/16 18:31:25 debug Exp $ * * Functions for handling the memory of an emulated machine. */ @@ -270,9 +270,8 @@ void memory_device_dyntrans_access(struct cpu *cpu, struct memory *mem, void *extra, uint64_t *low, uint64_t *high) { - int i, j; size_t s; - int need_inval = 0; + int i, need_inval = 0; /* TODO: This is O(n), so it might be good to rewrite it some day. For now, it will be enough, as long as this function is not @@ -307,26 +306,6 @@ | INVALIDATE_PADDR); } - if (cpu->machine->arch == ARCH_MIPS) { - /* - * ... and invalidate the "fast_vaddr_to_ - * hostaddr" cache entries that contain - * pointers to this device: (NOTE: Device i, - * cache entry j) - */ - for (j=0; jcd. - mips.bintrans_data_hostpage[j] >= - mem->dev_dyntrans_data[i] && - cpu->cd.mips. - bintrans_data_hostpage[j] < - mem->dev_dyntrans_data[i] + - mem->dev_length[i]) - cpu->cd.mips. - bintrans_data_hostpage[j] - = NULL; - } - } return; } } @@ -387,13 +366,13 @@ if (verbose >= 2) { /* (40 bits of physical address is displayed) */ - debug("device at 0x%010llx: %s", (long long)baseaddr, + debug("device at 0x%010"PRIx64": %s", (uint64_t) baseaddr, device_name); if (flags & (DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK) && (baseaddr & mem->dev_dyntrans_alignment) != 0) { fatal("\nWARNING: Device dyntrans access, but unaligned" - " baseaddr 0x%llx.\n", (long long)baseaddr); + " baseaddr 0x%"PRIx64".\n", (uint64_t) baseaddr); } if (flags & (DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK)) { @@ -555,8 +534,8 @@ table = mem->pagetable; entry = (paddr >> shrcount) & mask; - /* printf("memory_paddr_to_hostaddr(): p=%16llx w=%i => entry=0x%x\n", - (long long)paddr, writeflag, entry); */ + /* printf("memory_paddr_to_hostaddr(): p=%16"PRIx64 + " w=%i => entry=0x%x\n", (uint64_t) paddr, writeflag, entry); */ if (table[entry] == NULL) { size_t alloclen; @@ -593,3 +572,44 @@ return (unsigned char *) table[entry]; } + +#define UPDATE_CHECKSUM(value) { \ + internal_state -= 0x118c7771c0c0a77fULL; \ + internal_state = ((internal_state + (value)) << 7) ^ \ + (checksum >> 11) ^ ((checksum - (value)) << 3) ^ \ + (internal_state - checksum) ^ ((value) - internal_state); \ + checksum ^= internal_state; \ + } + + +/* + * memory_checksum(): + * + * Calculate a 64-bit checksum of everything in a struct memory. This is + * useful for tracking down bugs; an old (presumably working) version of + * the emulator can be compared to a newer (buggy) version. + */ +uint64_t memory_checksum(struct memory *mem) +{ + uint64_t internal_state = 0x80624185376feff2ULL; + uint64_t checksum = 0xcb9a87d5c010072cULL; + const int n_entries = (1 << BITS_PER_PAGETABLE) - 1; + const size_t len = (1 << BITS_PER_MEMBLOCK) / sizeof(uint64_t); + size_t entry, i; + + for (entry=0; entry<=n_entries; entry++) { + uint64_t **table = mem->pagetable; + uint64_t *memblock = table[entry]; + + if (memblock == NULL) { + UPDATE_CHECKSUM(0x1198ab7c8174a76fULL); + continue; + } + + for (i=0; i