Exemplo n.º 1
0
/* An actual memory access based on the vaddr from the trace file.
 *
 * The find_physpage() function is called to translate the virtual address
 * to a (simulated) physical address -- that is, a pointer to the right
 * location in physmem array. The find_physpage() function is responsible for
 * everything to do with memory management - including translation using the
 * pagetable, allocating a frame of (simulated) physical memory (if needed),
 * evicting an existing page from the frame (if needed) and reading the page
 * in from swap (if needed).
 *
 * We then check that the memory has the expected content (just a copy of the
 * virtual address) and, in case of a write reference, increment the version
 * counter. 
 */
void access_mem(char type, addr_t vaddr) {
	char *memptr = find_physpage(vaddr, type);
	int *versionptr = (int *)memptr;
	addr_t *checkaddr = (addr_t *)(memptr + sizeof(int));

	if (*checkaddr != vaddr) {
		fprintf(stderr,"Error, simulated page returned by pagetable lookup does "
			"not have expected value.\n");
	}
	
	if (type == 'S' || type == 'M') {
		// write access to page, increment version number
		(*versionptr)++;
	}

}
Exemplo n.º 2
0
/* An actual memory access based on the vaddr from the trace file.
 *
 * The find_physpage() function is called to translate the virtual address
 * to a (simulated) physical address -- that is, a pointer to the right
 * location in physmem array. The find_physpage() function is responsible for
 * everything to do with memory management - including translation using the
 * pagetable, allocating a frame of (simulated) physical memory (if needed),
 * evicting an existing page from the frame (if needed) and reading the page
 * in from swap (if needed).
 *
 * We then check that the memory has the expected content (just a copy of the
 * virtual address) and, in case of a write reference, increment the version
 * counter. 
 */
void access_mem(char type, addr_t vaddr) {
	//printf("DEBUG: from access_mem");
	char *memptr = find_physpage(vaddr, type);
	int *versionptr = (int *)memptr;
	addr_t *checkaddr = (addr_t *)(memptr + sizeof(int));
	
	line++;
	printf("line: %d , *checkaddr: %lx , vaddr: %lx\n",line, *checkaddr, vaddr );
	if (*checkaddr != vaddr) {
		fprintf(stderr,"Error, simulated page returned by pagetable lookup doese not have expected value.\n");
	}
	else printf("MATCH! simulated page has expected value!\n");
	
	if (type == 'S' || type == 'M') {
		// write access to page, increment version number
		(*versionptr)++;
	}

}