#include "main.h" #include "mem.h" #include "disk.h" #include "string.h" #include "tlb.h" #include #include char Disk[DISK_SIZE]; unsigned numwrites = 0; unsigned numreads = 0; /* Check that the arguments are within range */ void CheckArgs(unsigned block, unsigned paddress) { if (paddress > PHYS_MEM_SIZE) { fprintf(stderr, "Error: Attempt to access out of bounds paddress %p\n",paddress); fflush(stderr); /* dump out a core file here so that you can run gdb */ assert(0); } if (block > MAX_BLOCK) { fprintf(stderr, "Error: Attempt to access out of bounds disk block %d\n",block); fflush(stderr); /* dump out a core file here so that you can run gdb */ assert(0); } } void ReadBlock(unsigned block, unsigned long paddress) { CheckArgs(block,paddress); numreads++; memcpy(&(Phys_Memory[paddress]), &(Disk[block*BLOCK_SIZE]),BLOCK_SIZE); } void WriteBlock(unsigned block, unsigned long paddress) { CheckArgs(block,paddress); numwrites++; memcpy(&(Disk[block*BLOCK_SIZE]), &(Phys_Memory[paddress]),BLOCK_SIZE); }