| 1 |
63 |
julius |
// ----------------------------------------------------------------------------
|
| 2 |
|
|
|
| 3 |
|
|
// Debug Unit SPR cache: definition
|
| 4 |
|
|
|
| 5 |
|
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
| 6 |
|
|
|
| 7 |
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
| 8 |
|
|
|
| 9 |
|
|
// This file is part of the GDB interface to the cycle accurate model of the
|
| 10 |
|
|
// OpenRISC 1000 based system-on-chip, ORPSoC, built using Verilator.
|
| 11 |
|
|
|
| 12 |
|
|
// This program is free software: you can redistribute it and/or modify it
|
| 13 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
| 14 |
|
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
| 15 |
|
|
// option) any later version.
|
| 16 |
|
|
|
| 17 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 18 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 20 |
|
|
// License for more details.
|
| 21 |
|
|
|
| 22 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
| 23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 24 |
|
|
|
| 25 |
|
|
// ----------------------------------------------------------------------------
|
| 26 |
|
|
|
| 27 |
|
|
// $Id: SprCache.h 331 2009-03-12 17:01:48Z jeremy $
|
| 28 |
|
|
|
| 29 |
|
|
#ifndef SPR_CACHE__H
|
| 30 |
|
|
#define SPR_CACHE__H
|
| 31 |
|
|
|
| 32 |
|
|
#include <stdint.h>
|
| 33 |
|
|
|
| 34 |
|
|
//-----------------------------------------------------------------------------
|
| 35 |
|
|
//! Module for cacheing SPR accesses by the debug unit
|
| 36 |
|
|
|
| 37 |
|
|
//! SPR reads and writes through the Debug Unit via JTAG are time
|
| 38 |
|
|
//! consuming - of the order of 1000 CPU clock cycles. However when the
|
| 39 |
|
|
//! processor is stalled the values cannot change, other than through the
|
| 40 |
|
|
//! debug unit, so it makes sense to cache values.
|
| 41 |
|
|
|
| 42 |
|
|
//! @note It is not strictly true that SPRs do not change. If the NPC is
|
| 43 |
|
|
//! written, it flushes the pipeline, and subsequent reads will return
|
| 44 |
|
|
//! zero until the processor is unstalled and the pipeline has
|
| 45 |
|
|
//! refilled. However for our purposes, it is convenient to return the
|
| 46 |
|
|
//! value written into the NPC in such circumstances.
|
| 47 |
|
|
//!
|
| 48 |
|
|
//! The cache is represented as a closed hash table, which is generally
|
| 49 |
|
|
//! allowed to be no more than 70% full (however NPC is always
|
| 50 |
|
|
//! cacheable). The hash function is a simple modulo function, stepping
|
| 51 |
|
|
//! forward to the first free slot. This works because there is no function to
|
| 52 |
|
|
//! delete an entry - just to clear the whole table, so holes cannot appear.
|
| 53 |
|
|
//-----------------------------------------------------------------------------
|
| 54 |
462 |
julius |
class SprCache {
|
| 55 |
63 |
julius |
public:
|
| 56 |
|
|
|
| 57 |
462 |
julius |
// Constructor and destructor
|
| 58 |
|
|
SprCache(int _tableSize = 257);
|
| 59 |
|
|
~SprCache();
|
| 60 |
63 |
julius |
|
| 61 |
462 |
julius |
// Functions
|
| 62 |
|
|
void clear();
|
| 63 |
|
|
void write(uint16_t sprNum, uint32_t value, bool force);
|
| 64 |
|
|
bool read(uint16_t sprNum, uint32_t & value);
|
| 65 |
63 |
julius |
|
| 66 |
|
|
private:
|
| 67 |
|
|
|
| 68 |
462 |
julius |
//! The size of the hash table
|
| 69 |
|
|
int tableSize;
|
| 70 |
63 |
julius |
|
| 71 |
462 |
julius |
//! Maximum amount of cache left to use, before cacheing is rejected.
|
| 72 |
|
|
int maxToUse;
|
| 73 |
63 |
julius |
|
| 74 |
462 |
julius |
// The cache, keyed by sprNum. Done as two parallel vectors,
|
| 75 |
|
|
// allowing unambiguous clearing by use of memset for efficiency.
|
| 76 |
|
|
bool *sprIsValid;
|
| 77 |
|
|
uint16_t *sprKeyNum;
|
| 78 |
|
|
uint32_t *sprValue;
|
| 79 |
63 |
julius |
|
| 80 |
462 |
julius |
}; // SprCache ()
|
| 81 |
63 |
julius |
|
| 82 |
462 |
julius |
#endif // SPR_CACHE__H
|