// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
|
|
// Matchpoint hash table: definition
|
// Matchpoint hash table: definition
|
|
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
|
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
// This file is part of the cycle accurate model of the OpenRISC 1000 based
|
// system-on-chip, ORPSoC, built using Verilator.
|
// system-on-chip, ORPSoC, built using Verilator.
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
// This program is free software: you can redistribute it and/or modify it
|
// under the terms of the GNU Lesser General Public License as published by
|
// under the terms of the GNU Lesser General Public License as published by
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
// option) any later version.
|
// option) any later version.
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
// License for more details.
|
// License for more details.
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
|
|
// $Id: MpHash.h 317 2009-02-22 19:52:12Z jeremy $
|
// $Id: MpHash.h 317 2009-02-22 19:52:12Z jeremy $
|
|
|
#ifndef MP_HASH__H
|
#ifndef MP_HASH__H
|
#define MP_HASH__H
|
#define MP_HASH__H
|
|
|
#include <stdint.h>
|
#include <stdint.h>
|
|
|
|
|
//! Default size of the matchpoint hash table. Largest prime < 2^10
|
//! Default size of the matchpoint hash table. Largest prime < 2^10
|
#define DEFAULT_MP_HASH_SIZE 1021
|
#define DEFAULT_MP_HASH_SIZE 1021
|
|
|
|
|
//! Enumeration of different types of matchpoint.
|
//! Enumeration of different types of matchpoint.
|
|
|
//! These have explicit values matching the second digit of 'z' and 'Z'
|
//! These have explicit values matching the second digit of 'z' and 'Z'
|
//! packets.
|
//! packets.
|
enum MpType {
|
enum MpType {
|
BP_MEMORY = 0,
|
BP_MEMORY = 0,
|
BP_HARDWARE = 1,
|
BP_HARDWARE = 1,
|
WP_WRITE = 2,
|
WP_WRITE = 2,
|
WP_READ = 3,
|
WP_READ = 3,
|
WP_ACCESS = 4
|
WP_ACCESS = 4
|
};
|
};
|
|
|
|
|
class MpHash;
|
class MpHash;
|
|
|
//! A structure for a matchpoint hash table entry
|
//! A structure for a matchpoint hash table entry
|
struct MpEntry
|
struct MpEntry {
|
{
|
|
public:
|
public:
|
|
|
friend class MpHash; // The only one which can get at next
|
friend class MpHash; // The only one which can get at next
|
|
|
MpType type; //!< Type of matchpoint
|
MpType type; //!< Type of matchpoint
|
uint32_t addr; //!< Address with the matchpoint
|
uint32_t addr; //!< Address with the matchpoint
|
uint32_t instr; //!< Substituted instruction
|
uint32_t instr; //!< Substituted instruction
|
|
|
|
|
private:
|
private:
|
|
|
MpEntry *next; //!< Next in this slot
|
MpEntry * next; //!< Next in this slot
|
};
|
};
|
|
|
|
|
//! A hash table for matchpoints
|
//! A hash table for matchpoints
|
|
|
//! We do this as our own open hash table. Our keys are a pair of entities
|
//! We do this as our own open hash table. Our keys are a pair of entities
|
//! (address and type), so STL map is not trivial to use.
|
//! (address and type), so STL map is not trivial to use.
|
|
|
class MpHash
|
class MpHash {
|
{
|
|
public:
|
public:
|
|
|
// Constructor and destructor
|
// Constructor and destructor
|
MpHash (int _size = DEFAULT_MP_HASH_SIZE);
|
MpHash(int _size = DEFAULT_MP_HASH_SIZE);
|
~MpHash ();
|
~MpHash();
|
|
|
// Accessor methods
|
// Accessor methods
|
void add (MpType type,
|
void add(MpType type, uint32_t addr, uint32_t instr);
|
uint32_t addr,
|
MpEntry *lookup(MpType type, uint32_t addr);
|
uint32_t instr);
|
bool remove(MpType type, uint32_t addr, uint32_t * instr = NULL);
|
MpEntry *lookup (MpType type,
|
|
uint32_t addr);
|
|
bool remove (MpType type,
|
|
uint32_t addr,
|
|
uint32_t *instr = NULL);
|
|
|
|
private:
|
private:
|
|
|
//! The hash table
|
//! The hash table
|
MpEntry **hashTab;
|
MpEntry ** hashTab;
|
|
|
//! Size of the hash table
|
//! Size of the hash table
|
int size;
|
int size;
|
|
|
};
|
};
|
|
|
#endif // MP_HASH__H
|
#endif // MP_HASH__H
|
|
|