2001-05-09 01:59:33 +02:00
|
|
|
/*
|
2005-06-17 07:13:07 +02:00
|
|
|
* Copyright (c) 1999-2005 Stephen Williams (steve@icarus.com>
|
2001-05-09 01:59:33 +02:00
|
|
|
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
2005-06-17 07:13:07 +02:00
|
|
|
* any later version.
|
2001-05-09 01:59:33 +02:00
|
|
|
*
|
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2006-03-06 06:43:15 +01:00
|
|
|
#ident "$Id: vpi_memory.cc,v 1.33 2006/03/06 05:43:15 steve Exp $"
|
2001-05-09 01:59:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "memory.h"
|
2002-07-05 19:14:15 +02:00
|
|
|
# include "statistics.h"
|
2005-06-17 07:13:07 +02:00
|
|
|
# include <iostream>
|
2001-05-09 01:59:33 +02:00
|
|
|
# include <stdlib.h>
|
2002-07-03 04:09:38 +02:00
|
|
|
# include <string.h>
|
2001-05-09 01:59:33 +02:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
# include <stdio.h>
|
|
|
|
|
|
2002-02-06 05:48:34 +01:00
|
|
|
extern const char hex_digits[256];
|
2001-05-09 01:59:33 +02:00
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
static void memory_make_word_handles(struct __vpiMemory*rfp);
|
|
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
struct __vpiMemoryWord {
|
|
|
|
|
struct __vpiHandle base;
|
|
|
|
|
struct __vpiMemory*mem;
|
2002-05-17 06:12:19 +02:00
|
|
|
struct __vpiDecConst index;
|
2001-05-09 01:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct __vpiMemory {
|
|
|
|
|
struct __vpiHandle base;
|
2002-05-10 18:00:57 +02:00
|
|
|
struct __vpiScope* scope;
|
2002-05-17 06:12:19 +02:00
|
|
|
struct __vpiMemoryWord*words;
|
2001-05-09 01:59:33 +02:00
|
|
|
vvp_memory_t mem;
|
2005-03-03 05:33:10 +01:00
|
|
|
const char*name; /* Permanently allocated string. */
|
2002-05-17 06:12:19 +02:00
|
|
|
struct __vpiDecConst left_range;
|
|
|
|
|
struct __vpiDecConst right_range;
|
|
|
|
|
struct __vpiDecConst word_left_range;
|
|
|
|
|
struct __vpiDecConst word_right_range;
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2006-03-05 06:45:58 +01:00
|
|
|
struct __vpiCallback*value_change_cb;
|
2001-05-09 01:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
struct __vpiMemWordIterator {
|
|
|
|
|
struct __vpiHandle base;
|
|
|
|
|
struct __vpiMemory*mem;
|
|
|
|
|
unsigned next;
|
|
|
|
|
};
|
|
|
|
|
|
2002-01-31 05:28:17 +01:00
|
|
|
static vpiHandle memory_get_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*rfp = (struct __vpiMemory*)obj;
|
|
|
|
|
|
|
|
|
|
assert(obj->vpi_type->type_code==vpiMemory);
|
|
|
|
|
|
|
|
|
|
switch(code){
|
2002-05-10 18:00:57 +02:00
|
|
|
case vpiLeftRange:
|
2002-05-17 06:12:19 +02:00
|
|
|
return &(rfp->left_range.base);
|
2002-05-10 18:00:57 +02:00
|
|
|
|
|
|
|
|
case vpiRightRange:
|
2002-05-17 06:12:19 +02:00
|
|
|
return &(rfp->right_range.base);
|
2002-05-10 18:00:57 +02:00
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
return &rfp->scope->base;
|
2002-01-31 05:28:17 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
static int vpi_memory_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
|
|
|
|
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemory);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiSize:
|
2005-03-03 05:33:10 +01:00
|
|
|
return (int)memory_word_count(rfp->mem);
|
2001-05-09 01:59:33 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char* memory_get_str(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemory);
|
|
|
|
|
|
2002-07-03 04:09:38 +02:00
|
|
|
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
|
|
|
|
|
2002-09-11 18:06:57 +02:00
|
|
|
char *bn = strdup(vpi_get_str(vpiFullName, &rfp->scope->base));
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
char *rbuf = need_result_buf(strlen(bn)+strlen(rfp->name)+2, RBUF_STR);
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
switch (code) {
|
|
|
|
|
case vpiFullName:
|
2005-03-03 05:33:10 +01:00
|
|
|
sprintf(rbuf, "%s.%s", bn, rfp->name);
|
2002-09-11 18:06:57 +02:00
|
|
|
free(bn);
|
2002-07-04 01:39:57 +02:00
|
|
|
return rbuf;
|
2002-07-03 04:09:38 +02:00
|
|
|
case vpiName:
|
2005-03-03 05:33:10 +01:00
|
|
|
strcpy(rbuf, rfp->name);
|
2002-09-11 18:06:57 +02:00
|
|
|
free(bn);
|
2002-07-04 01:39:57 +02:00
|
|
|
return rbuf;
|
2001-05-09 01:59:33 +02:00
|
|
|
}
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2002-09-11 18:06:57 +02:00
|
|
|
free(bn);
|
2001-05-09 01:59:33 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle memory_scan(vpiHandle ref, int)
|
|
|
|
|
{
|
2002-05-17 06:12:19 +02:00
|
|
|
struct __vpiMemWordIterator*obj = (struct __vpiMemWordIterator*)ref;
|
2001-05-09 01:59:33 +02:00
|
|
|
assert(ref->vpi_type->type_code == vpiIterator);
|
|
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
if (obj->next >= memory_word_count(obj->mem->mem)) {
|
2001-05-09 01:59:33 +02:00
|
|
|
vpi_free_object(ref);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
return &obj->mem->words[obj->next++].base;
|
2001-05-09 01:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2002-05-03 17:44:11 +02:00
|
|
|
static int mem_iter_free_object(vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
free(ref);
|
2003-02-02 02:40:24 +01:00
|
|
|
return 1;
|
2002-05-03 17:44:11 +02:00
|
|
|
}
|
|
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
static const struct __vpirt vpip_mem_iter_rt = {
|
|
|
|
|
vpiIterator,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
memory_scan,
|
2002-05-03 17:44:11 +02:00
|
|
|
&mem_iter_free_object
|
2001-05-09 01:59:33 +02:00
|
|
|
};
|
|
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
static vpiHandle memory_iterate(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemory);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiMemoryWord: {
|
2002-05-17 06:12:19 +02:00
|
|
|
memory_make_word_handles(rfp);
|
|
|
|
|
|
|
|
|
|
struct __vpiMemWordIterator*res =
|
|
|
|
|
(struct __vpiMemWordIterator*)
|
|
|
|
|
calloc(1, sizeof(struct __vpiMemWordIterator));
|
2001-05-09 01:59:33 +02:00
|
|
|
assert(res);
|
|
|
|
|
res->base.vpi_type = &vpip_mem_iter_rt;
|
2002-05-17 06:12:19 +02:00
|
|
|
res->mem = rfp;
|
|
|
|
|
res->next = 0;
|
2001-05-09 01:59:33 +02:00
|
|
|
return &(res->base);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle memory_index(vpiHandle ref, int index)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*rfp = (struct __vpiMemory*)ref;
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemory);
|
|
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
if (index >= (int)memory_word_count(rfp->mem))
|
|
|
|
|
return 0;
|
|
|
|
|
if (index < 0)
|
|
|
|
|
return 0;
|
2002-05-17 06:12:19 +02:00
|
|
|
|
|
|
|
|
memory_make_word_handles(rfp);
|
|
|
|
|
return &(rfp->words[index].base);
|
2001-05-09 01:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
2002-01-31 05:28:17 +01:00
|
|
|
//==============================
|
|
|
|
|
|
|
|
|
|
static vpiHandle memory_word_get_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)obj;
|
|
|
|
|
assert(obj->vpi_type->type_code==vpiMemoryWord);
|
|
|
|
|
|
|
|
|
|
switch(code){
|
2002-05-17 06:12:19 +02:00
|
|
|
case vpiLeftRange:
|
|
|
|
|
return &(rfp->mem->word_left_range.base);
|
|
|
|
|
|
|
|
|
|
case vpiRightRange:
|
|
|
|
|
return &(rfp->mem->word_right_range.base);
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
case vpiIndex:
|
|
|
|
|
return &(rfp->index.base);
|
2002-01-31 05:28:17 +01:00
|
|
|
}
|
|
|
|
|
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2002-01-31 05:28:17 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
static int memory_word_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemoryWord);
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiSize:
|
2005-03-03 05:33:10 +01:00
|
|
|
return memory_word_width(rfp->mem->mem);
|
2001-05-09 01:59:33 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
static vpiHandle memory_word_put(vpiHandle ref, p_vpi_value val)
|
2001-05-09 01:59:33 +02:00
|
|
|
{
|
|
|
|
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemoryWord);
|
|
|
|
|
|
|
|
|
|
|
2001-12-08 00:23:05 +01:00
|
|
|
/* Get the width of the memory, and the byte index of the
|
|
|
|
|
first byte of the word. */
|
2005-03-03 05:33:10 +01:00
|
|
|
unsigned width = memory_word_width(rfp->mem->mem);
|
|
|
|
|
unsigned word_addr = rfp->index.value;
|
2001-05-09 01:59:33 +02:00
|
|
|
|
2005-03-05 06:43:03 +01:00
|
|
|
/* Addresses are converted to canonical form by offsetting the
|
|
|
|
|
address by the lowest index. */
|
|
|
|
|
unsigned addr_off = memory_left_range(rfp->mem->mem, 0);
|
|
|
|
|
if (memory_right_range(rfp->mem->mem, 0) < addr_off)
|
|
|
|
|
addr_off = memory_right_range(rfp->mem->mem, 0);
|
|
|
|
|
|
|
|
|
|
word_addr -= addr_off;
|
|
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
/* Build up the word value from whatever format the user
|
|
|
|
|
supplies. */
|
|
|
|
|
vvp_vector4_t put_val (width);
|
2001-12-08 00:23:05 +01:00
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
switch (val->format) {
|
2001-12-08 00:23:05 +01:00
|
|
|
case vpiVectorVal:
|
2005-03-03 05:33:10 +01:00
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
|
|
|
|
p_vpi_vecval cur = val->value.vector + (idx/32);
|
|
|
|
|
int aval = (cur->aval >> (idx%32)) & 1;
|
|
|
|
|
int bval = (cur->bval >> (idx%32)) & 1;
|
|
|
|
|
|
|
|
|
|
/* Check this bit value conversion. This is
|
|
|
|
|
specifically defined by the IEEE1364 standard. */
|
|
|
|
|
vvp_bit4_t bit;
|
|
|
|
|
if (bval) {
|
|
|
|
|
bit = aval? BIT4_Z : BIT4_X;
|
|
|
|
|
} else {
|
|
|
|
|
bit = aval? BIT4_1 : BIT4_0;
|
2001-12-08 00:23:05 +01:00
|
|
|
}
|
2005-03-03 05:33:10 +01:00
|
|
|
put_val.set_bit(idx, bit);
|
2001-12-08 00:23:05 +01:00
|
|
|
}
|
|
|
|
|
break;
|
2005-06-17 07:13:07 +02:00
|
|
|
|
|
|
|
|
case vpiIntVal: {
|
|
|
|
|
int cur = val->value.integer;
|
|
|
|
|
for (unsigned idx = 0; idx < width; idx += 1) {
|
|
|
|
|
vvp_bit4_t bit = (cur&1)? BIT4_1 : BIT4_0;
|
|
|
|
|
put_val.set_bit(idx, bit);
|
|
|
|
|
cur >>= 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-05-11 06:39:35 +02:00
|
|
|
|
2006-02-21 03:39:27 +01:00
|
|
|
case vpiBinStrVal: {
|
|
|
|
|
char*str = val->value.str;
|
2002-05-11 06:39:35 +02:00
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
2006-02-21 03:39:27 +01:00
|
|
|
switch (str[width-idx-1]) {
|
|
|
|
|
case '0':
|
|
|
|
|
put_val.set_bit(idx, BIT4_0);
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
put_val.set_bit(idx, BIT4_1);
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
case 'X':
|
|
|
|
|
put_val.set_bit(idx, BIT4_X);
|
|
|
|
|
break;
|
|
|
|
|
case 'z':
|
|
|
|
|
case 'Z':
|
|
|
|
|
put_val.set_bit(idx, BIT4_Z);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2002-05-11 06:39:35 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-21 03:39:27 +01:00
|
|
|
case vpiOctStrVal: {
|
|
|
|
|
char*str = val->value.str;
|
|
|
|
|
vpip_oct_str_to_vec4(put_val, str);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-21 03:39:27 +01:00
|
|
|
case vpiDecStrVal: {
|
|
|
|
|
char*str = val->value.str;
|
|
|
|
|
vpip_dec_str_to_vec4(put_val, str, false);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-21 03:39:27 +01:00
|
|
|
case vpiHexStrVal: {
|
|
|
|
|
char*str = val->value.str;
|
|
|
|
|
vpip_hex_str_to_vec4(put_val, str);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2006-02-21 03:39:27 +01:00
|
|
|
|
2001-12-08 00:23:05 +01:00
|
|
|
default:
|
2005-06-17 07:13:07 +02:00
|
|
|
cerr << "internal error: memory_word put_value format="
|
|
|
|
|
<< val->format << endl;
|
2001-12-08 00:23:05 +01:00
|
|
|
assert(0);
|
2001-05-09 01:59:33 +02:00
|
|
|
}
|
2001-12-08 00:23:05 +01:00
|
|
|
|
2006-02-02 03:43:57 +01:00
|
|
|
memory_set_word(rfp->mem->mem, word_addr, 0, put_val);
|
2001-05-09 01:59:33 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-03 04:09:38 +02:00
|
|
|
static char* memory_word_get_str(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code==vpiMemoryWord);
|
|
|
|
|
|
|
|
|
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
|
|
|
|
|
2002-09-12 17:13:07 +02:00
|
|
|
char *bn = strdup(vpi_get_str(vpiFullName, &rfp->mem->scope->base));
|
2005-03-03 05:33:10 +01:00
|
|
|
const char *nm = rfp->mem->name;
|
2002-07-03 04:09:38 +02:00
|
|
|
|
2002-09-12 17:13:07 +02:00
|
|
|
char *rbuf = need_result_buf(strlen(bn) + strlen(nm) + 10 + 4, RBUF_STR);
|
2002-07-03 04:09:38 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiFullName:
|
2002-07-04 01:39:57 +02:00
|
|
|
sprintf(rbuf, "%s.%s[%d]", bn, nm, rfp->index.value);
|
2002-09-12 17:13:07 +02:00
|
|
|
free(bn);
|
2002-07-04 01:39:57 +02:00
|
|
|
return rbuf;
|
2002-07-03 04:09:38 +02:00
|
|
|
break;
|
|
|
|
|
case vpiName: {
|
2002-07-04 01:39:57 +02:00
|
|
|
sprintf(rbuf, "%s[%d]", nm, rfp->index.value);
|
2002-09-12 17:13:07 +02:00
|
|
|
free(bn);
|
2002-07-04 01:39:57 +02:00
|
|
|
return rbuf;
|
2002-07-03 04:09:38 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-12 17:13:07 +02:00
|
|
|
free(bn);
|
2002-07-03 04:09:38 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 06:45:58 +01:00
|
|
|
static void memory_word_get_value(vpiHandle ref, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemoryWord*rfp = (struct __vpiMemoryWord*)ref;
|
|
|
|
|
assert(rfp->base.vpi_type->type_code==vpiMemoryWord);
|
|
|
|
|
|
|
|
|
|
unsigned width = memory_word_width(rfp->mem->mem);
|
|
|
|
|
unsigned word_address = rfp->index.value;
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t word_val = memory_get_word(rfp->mem->mem, word_address);
|
|
|
|
|
|
2006-03-06 06:43:15 +01:00
|
|
|
vpip_vec4_get_value(word_val, width, false /* never signed */, vp);
|
2006-03-05 06:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
2001-05-09 01:59:33 +02:00
|
|
|
static const struct __vpirt vpip_memory_rt = {
|
|
|
|
|
vpiMemory,
|
|
|
|
|
vpi_memory_get,
|
|
|
|
|
memory_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2002-01-31 05:28:17 +01:00
|
|
|
memory_get_handle,
|
2001-05-09 01:59:33 +02:00
|
|
|
memory_iterate,
|
|
|
|
|
memory_index,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_memory_word_rt = {
|
|
|
|
|
vpiMemoryWord,
|
|
|
|
|
memory_word_get,
|
2002-07-03 04:09:38 +02:00
|
|
|
memory_word_get_str,
|
2001-05-09 01:59:33 +02:00
|
|
|
memory_word_get_value,
|
|
|
|
|
memory_word_put,
|
2002-01-31 05:28:17 +01:00
|
|
|
memory_word_get_handle,
|
2001-05-09 01:59:33 +02:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
};
|
|
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
static void memory_make_word_handles(struct __vpiMemory*rfp)
|
|
|
|
|
{
|
|
|
|
|
if (rfp->words != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
unsigned word_count = memory_word_count(rfp->mem);
|
2002-05-17 06:12:19 +02:00
|
|
|
|
|
|
|
|
rfp->words = (struct __vpiMemoryWord*)
|
|
|
|
|
calloc(word_count, sizeof (struct __vpiMemoryWord));
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < word_count ; idx += 1) {
|
|
|
|
|
struct __vpiMemoryWord*cur = rfp->words + idx;
|
|
|
|
|
cur->base.vpi_type = &vpip_memory_word_rt;
|
|
|
|
|
cur->mem = rfp;
|
2005-03-03 05:33:10 +01:00
|
|
|
vpip_make_dec_const(&cur->index, idx);
|
2002-05-17 06:12:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 06:45:58 +01:00
|
|
|
/*
|
|
|
|
|
* Run the callbacks for a memory value change. The memory.cc methods
|
|
|
|
|
* call this method with the canonical address of the word that
|
|
|
|
|
* changed, and we here run through all the callbacks for the memory,
|
|
|
|
|
* passing the translated index through.
|
|
|
|
|
*/
|
|
|
|
|
void vpip_run_memory_value_change(vpiHandle ref, unsigned addr)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*obj = reinterpret_cast<struct __vpiMemory*>(ref);
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t word_val = memory_get_word(obj->mem, addr);
|
|
|
|
|
unsigned width = memory_word_width(obj->mem);
|
|
|
|
|
|
|
|
|
|
for (struct __vpiCallback*cur=obj->value_change_cb;
|
|
|
|
|
cur != 0 ; cur = cur->next) {
|
|
|
|
|
|
|
|
|
|
if (cur->cb_data.cb_rtn == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (cur->cb_data.value)
|
2006-03-06 06:43:15 +01:00
|
|
|
vpip_vec4_get_value(word_val, width, false, cur->cb_data.value);
|
2006-03-05 06:45:58 +01:00
|
|
|
|
|
|
|
|
cur->cb_data.index = addr;
|
|
|
|
|
vpi_mode_flag = VPI_MODE_RWSYNC;
|
|
|
|
|
(cur->cb_data.cb_rtn) (&cur->cb_data);
|
|
|
|
|
vpi_mode_flag = VPI_MODE_NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Attach the callback to the memory.
|
|
|
|
|
*/
|
|
|
|
|
void vpip_memory_value_change(struct __vpiCallback*cbh, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiMemory*obj = reinterpret_cast<struct __vpiMemory*>(ref);
|
|
|
|
|
cbh->next = obj->value_change_cb;
|
|
|
|
|
obj->value_change_cb = cbh;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-03 05:33:10 +01:00
|
|
|
vpiHandle vpip_make_memory(vvp_memory_t mem, const char*name)
|
2001-05-09 01:59:33 +02:00
|
|
|
{
|
|
|
|
|
struct __vpiMemory*obj = (struct __vpiMemory*)
|
|
|
|
|
malloc(sizeof(struct __vpiMemory));
|
2002-07-05 19:14:15 +02:00
|
|
|
count_vpi_memories += 1;
|
2001-05-09 01:59:33 +02:00
|
|
|
|
|
|
|
|
obj->base.vpi_type = &vpip_memory_rt;
|
2002-05-10 18:00:57 +02:00
|
|
|
obj->scope = vpip_peek_current_scope();
|
2001-05-09 01:59:33 +02:00
|
|
|
obj->mem = mem;
|
2005-03-03 05:33:10 +01:00
|
|
|
obj->name = vpip_name_string(name);
|
2006-03-05 06:45:58 +01:00
|
|
|
obj->value_change_cb = 0;
|
2005-03-03 05:33:10 +01:00
|
|
|
|
2006-03-05 06:45:58 +01:00
|
|
|
memory_attach_self(mem, &(obj->base));
|
2005-03-03 05:33:10 +01:00
|
|
|
vpip_make_dec_const(&obj->left_range, memory_left_range(mem, 0));
|
|
|
|
|
vpip_make_dec_const(&obj->right_range, memory_right_range(mem, 0));
|
2002-05-17 06:12:19 +02:00
|
|
|
vpip_make_dec_const(&obj->word_left_range, memory_word_left_range(mem));
|
|
|
|
|
vpip_make_dec_const(&obj->word_right_range,memory_word_right_range(mem));
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2002-05-17 06:12:19 +02:00
|
|
|
obj->words = 0;
|
2001-05-09 01:59:33 +02:00
|
|
|
|
|
|
|
|
return &(obj->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vpi_memory.cc,v $
|
2006-03-06 06:43:15 +01:00
|
|
|
* Revision 1.33 2006/03/06 05:43:15 steve
|
|
|
|
|
* Cleanup vpi_const to use vec4 values.
|
|
|
|
|
*
|
2006-03-05 06:45:58 +01:00
|
|
|
* Revision 1.32 2006/03/05 05:45:58 steve
|
|
|
|
|
* Add support for memory value change callbacks.
|
|
|
|
|
*
|
2006-02-21 04:19:03 +01:00
|
|
|
* Revision 1.31 2006/02/21 03:19:03 steve
|
|
|
|
|
* Remove dead code.
|
|
|
|
|
*
|
2006-02-21 03:56:49 +01:00
|
|
|
* Revision 1.30 2006/02/21 02:56:49 steve
|
|
|
|
|
* Get vpiVectorVal from memory words.
|
|
|
|
|
*
|
2006-02-21 03:39:27 +01:00
|
|
|
* Revision 1.29 2006/02/21 02:39:27 steve
|
|
|
|
|
* Support string values for memory words.
|
|
|
|
|
*
|
2006-02-02 03:43:57 +01:00
|
|
|
* Revision 1.28 2006/02/02 02:44:00 steve
|
|
|
|
|
* Allow part selects of memory words in l-values.
|
|
|
|
|
*
|
2005-06-17 07:13:07 +02:00
|
|
|
* Revision 1.27 2005/06/17 05:13:07 steve
|
|
|
|
|
* Support set of IntVal to memory words.
|
|
|
|
|
*
|
2005-06-13 02:54:04 +02:00
|
|
|
* Revision 1.26 2005/06/13 00:54:04 steve
|
|
|
|
|
* More unified vec4 to hex string functions.
|
|
|
|
|
*
|
2005-03-05 06:43:03 +01:00
|
|
|
* Revision 1.25 2005/03/05 05:43:03 steve
|
|
|
|
|
* Get base address from word ranges that VPI user passed.
|
|
|
|
|
*
|
2005-03-03 05:33:10 +01:00
|
|
|
* Revision 1.24 2005/03/03 04:33:10 steve
|
|
|
|
|
* Rearrange how memories are supported as vvp_vector4 arrays.
|
|
|
|
|
*
|
2004-05-19 05:26:24 +02:00
|
|
|
* Revision 1.23 2004/05/19 03:30:46 steve
|
|
|
|
|
* Support delayed/non-blocking assignment to reals and others.
|
|
|
|
|
*
|
2003-02-10 00:33:26 +01:00
|
|
|
* Revision 1.22 2003/02/09 23:33:26 steve
|
|
|
|
|
* Spelling fixes.
|
|
|
|
|
*
|
2003-02-02 02:40:24 +01:00
|
|
|
* Revision 1.21 2003/02/02 01:40:24 steve
|
|
|
|
|
* Five vpi_free_object a default behavior.
|
|
|
|
|
*
|
2002-09-12 17:13:07 +02:00
|
|
|
* Revision 1.20 2002/09/12 15:13:07 steve
|
|
|
|
|
* Account for buffer overrun in memory word names.
|
|
|
|
|
*
|
2002-09-11 18:06:57 +02:00
|
|
|
* Revision 1.19 2002/09/11 16:06:57 steve
|
|
|
|
|
* Fix wrecked rbuf in vpi_get_str of signals and memories.
|
|
|
|
|
*
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.18 2002/08/12 01:35:09 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-07-09 05:24:37 +02:00
|
|
|
* Revision 1.17 2002/07/09 03:24:37 steve
|
|
|
|
|
* Dynamic resizevpi result buf in more places.
|
|
|
|
|
*
|
2002-07-05 19:14:15 +02:00
|
|
|
* Revision 1.16 2002/07/05 17:14:15 steve
|
|
|
|
|
* Names of vpi objects allocated as vpip_strings.
|
|
|
|
|
*
|
2002-07-04 18:37:07 +02:00
|
|
|
* Revision 1.15 2002/07/04 16:37:07 steve
|
|
|
|
|
* Fix s_vpi_vecval array byte size.
|
|
|
|
|
*
|
2002-07-04 01:39:57 +02:00
|
|
|
* Revision 1.14 2002/07/03 23:39:57 steve
|
|
|
|
|
* Dynamic size result buffer for _str and _get_value functions.
|
|
|
|
|
*
|
2002-07-04 01:16:27 +02:00
|
|
|
* Revision 1.13 2002/07/03 23:16:27 steve
|
|
|
|
|
* don't pollute name space
|
|
|
|
|
* fix vecval for Z/X cases
|
|
|
|
|
*
|
2002-07-03 04:09:38 +02:00
|
|
|
* Revision 1.12 2002/07/03 02:09:38 steve
|
|
|
|
|
* vpiName, vpiFullName support in memory types,
|
|
|
|
|
* length checks for *_get_str() buffers,
|
|
|
|
|
* temporary buffers for *_get_str() data,
|
|
|
|
|
* dynamic storage for vpi_get_data() in memory types
|
|
|
|
|
* shared with signal white space
|
2001-05-09 01:59:33 +02:00
|
|
|
*/
|