Line 28... |
Line 28... |
|
|
#include <cstdlib>
|
#include <cstdlib>
|
|
|
#include "MpHash.h"
|
#include "MpHash.h"
|
|
|
|
|
//! Constructor
|
//! Constructor
|
|
|
//! Allocate the hash table
|
//! Allocate the hash table
|
//! @param[in] size Number of slots in the hash table. Defaults to
|
//! @param[in] size Number of slots in the hash table. Defaults to
|
//! DEFAULT_MP_HASH_SIZE.
|
//! DEFAULT_MP_HASH_SIZE.
|
Line 40... |
Line 39... |
size (_size)
|
size (_size)
|
{
|
{
|
// Allocate and clear the hash table
|
// Allocate and clear the hash table
|
hashTab = new MpEntry *[size];
|
hashTab = new MpEntry *[size];
|
|
|
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++) {
|
{
|
|
hashTab[i] = NULL;
|
hashTab[i] = NULL;
|
}
|
}
|
} // MpHash ()
|
} // MpHash ()
|
|
|
|
|
//! Destructor
|
//! Destructor
|
|
|
//! Free the hash table
|
//! Free the hash table
|
MpHash::~MpHash ()
|
MpHash::~MpHash ()
|
{
|
{
|
delete [] hashTab;
|
delete [] hashTab;
|
|
|
} // ~MpHash ()
|
} // ~MpHash ()
|
|
|
|
|
//! Add an entry to the hash table
|
//! Add an entry to the hash table
|
|
|
//! Add the entry if it wasn't already there. If it was there do nothing. The
|
//! Add the entry if it wasn't already there. If it was there do nothing. The
|
//! match just be on type and addr. The instr need not match, since if this is
|
//! match just be on type and addr. The instr need not match, since if this is
|
//! a duplicate insertion (perhaps due to a lost packet) they will be
|
//! a duplicate insertion (perhaps due to a lost packet) they will be
|
Line 71... |
Line 67... |
|
|
//! @param[in] type The type of matchpoint
|
//! @param[in] type The type of matchpoint
|
//! @param[in] addr The address of the matchpoint
|
//! @param[in] addr The address of the matchpoint
|
//! @para[in] instr The instruction to associate with the address
|
//! @para[in] instr The instruction to associate with the address
|
void
|
void
|
MpHash::add (MpType type,
|
MpHash::add(MpType type, uint32_t addr, uint32_t instr)
|
uint32_t addr,
|
|
uint32_t instr)
|
|
{
|
{
|
int hv = addr % size;
|
int hv = addr % size;
|
MpEntry *curr;
|
MpEntry *curr;
|
|
|
// See if we already have the entry
|
// See if we already have the entry
|
for(curr = hashTab[hv]; NULL != curr; curr = curr->next)
|
for (curr = hashTab[hv]; NULL != curr; curr = curr->next) {
|
{
|
if ((type == curr->type) && (addr == curr->addr)) {
|
if ((type == curr->type) && (addr == curr->addr))
|
|
{
|
|
return; // We already have the entry
|
return; // We already have the entry
|
}
|
}
|
}
|
}
|
|
|
// Insert the new entry at the head of the chain
|
// Insert the new entry at the head of the chain
|
Line 99... |
Line 91... |
|
|
hashTab[hv] = curr;
|
hashTab[hv] = curr;
|
|
|
} // add ()
|
} // add ()
|
|
|
|
|
//!Look up an entry in the matchpoint hash table
|
//!Look up an entry in the matchpoint hash table
|
|
|
//! The match must be on type AND addr.
|
//! The match must be on type AND addr.
|
|
|
//! @param[in] type The type of matchpoint
|
//! @param[in] type The type of matchpoint
|
//! @param[in] addr The address of the matchpoint
|
//! @param[in] addr The address of the matchpoint
|
|
|
//! @return The entry found, or NULL if the entry was not found
|
//! @return The entry found, or NULL if the entry was not found
|
MpEntry *
|
MpEntry *MpHash::lookup(MpType type, uint32_t addr)
|
MpHash::lookup (MpType type,
|
|
uint32_t addr)
|
|
{
|
{
|
int hv = addr % size;
|
int hv = addr % size;
|
|
|
// Search
|
// Search
|
for (MpEntry *curr = hashTab[hv]; NULL != curr; curr = curr->next)
|
for (MpEntry * curr = hashTab[hv]; NULL != curr; curr = curr->next) {
|
{
|
if ((type == curr->type) && (addr == curr->addr)) {
|
if ((type == curr->type) && (addr == curr->addr))
|
|
{
|
|
return curr; // The entry found
|
return curr; // The entry found
|
}
|
}
|
}
|
}
|
|
|
return NULL; // Not found
|
return NULL; // Not found
|
|
|
} // lookup ()
|
} // lookup ()
|
|
|
|
|
//! Delete an entry from the matchpoint hash table
|
//! Delete an entry from the matchpoint hash table
|
|
|
//! If it is there the entry is deleted from the hash table. If it is not
|
//! If it is there the entry is deleted from the hash table. If it is not
|
//! there, no action is taken. The match must be on type AND addr. The entry
|
//! there, no action is taken. The match must be on type AND addr. The entry
|
//! (MpEntry::) is itself deleted
|
//! (MpEntry::) is itself deleted
|
Line 143... |
Line 129... |
//! @param[in] addr The address of the matchpoint
|
//! @param[in] addr The address of the matchpoint
|
//! @param[out] instr Location to place the instruction found. If NULL (the
|
//! @param[out] instr Location to place the instruction found. If NULL (the
|
//! default) then the instruction is not written back.
|
//! default) then the instruction is not written back.
|
|
|
//! @return TRUE if an entry was found and deleted
|
//! @return TRUE if an entry was found and deleted
|
bool
|
bool MpHash::remove(MpType type, uint32_t addr, uint32_t * instr)
|
MpHash::remove (MpType type,
|
|
uint32_t addr,
|
|
uint32_t *instr)
|
|
{
|
{
|
int hv = addr % size;
|
int hv = addr % size;
|
MpEntry *prev = NULL;
|
MpEntry *prev = NULL;
|
MpEntry *curr;
|
MpEntry *curr;
|
|
|
// Search
|
// Search
|
for (curr = hashTab[hv]; NULL != curr; curr = curr->next)
|
for (curr = hashTab[hv]; NULL != curr; curr = curr->next) {
|
{
|
if ((type == curr->type) && (addr == curr->addr)) {
|
if ((type == curr->type) && (addr == curr->addr))
|
|
{
|
|
// Found - delete. Method depends on whether we are the head of
|
// Found - delete. Method depends on whether we are the head of
|
// chain.
|
// chain.
|
if (NULL == prev)
|
if (NULL == prev) {
|
{
|
|
hashTab[hv] = curr->next;
|
hashTab[hv] = curr->next;
|
}
|
} else {
|
else
|
|
{
|
|
prev->next = curr->next;
|
prev->next = curr->next;
|
}
|
}
|
|
|
if (NULL != instr)
|
if (NULL != instr) {
|
{
|
|
*instr = curr->instr; // Return the found instruction
|
*instr = curr->instr; // Return the found instruction
|
}
|
}
|
|
|
delete curr;
|
delete curr;
|
return true; // Success
|
return true; // Success
|