/* SmArc VMachine - Simplified SPARC emulator Copyright (C) 2002 Michal Stochmialek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * $Id: cache.cc,v 1.1 2002/12/29 23:45:23 misto Exp $ */ #include "cache.h" void cache::process( mode m = rd, size s = word ) { unsigned long addr = (get_in(0)).b(); unsigned long caddr = (addr/4); if (( s == word && addr%4 != 0) || ((s == half || s == uhalf) && addr%2 != 0 ) ) throw ex("cache::process: " "Memory address not aligned."); else if ( caddr >= mem_size ) throw ex("cache::process: " "Memory address too high. "); if (m == rd){ unsigned long offset = (addr%4)*8; bit_word w = mem[ caddr ]; bit_word value; if ( s == word ) value = w; else if ( s == half || s == uhalf ) { value = w.b(offset, 15 + offset ); if (s == half && value.b(15)) value.bset(16,31); } else if ( s == byte || s == ubyte ) { value = w.b(offset, 7 + offset ); if (s == byte && value.b(7)) value.bset(8,31); } else throw ex("cache::process: " "Unknown cache output size-mode."); set_out(0 , value ); } else if ( m == wr ) { unsigned long offset = (addr%4)*8; bit_word value = get_in(1); if ( s == word ) mem[ caddr ] = value; else if ( s == half ) mem[ caddr ] = (mem[caddr] & ~(0xffffUL<("cache::process: " "Unknown cache input size mode."); } else throw ex("cache::process: " "Unknown cache I/O mode."); }