1998-11-10 00:44:10 +01:00
|
|
|
#ifndef __vvm_H
|
|
|
|
|
#define __vvm_H
|
|
|
|
|
/*
|
2000-02-23 03:56:53 +01:00
|
|
|
* Copyright (c) 1998-2000 Stephen Williams (steve@icarus.com)
|
1998-11-10 00:44:10 +01:00
|
|
|
*
|
|
|
|
|
* 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)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2000-02-23 03:56:53 +01:00
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2000-03-13 01:02:34 +01:00
|
|
|
#ident "$Id: vvm.h,v 1.32 2000/03/13 00:02:34 steve Exp $"
|
1998-11-10 00:44:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
1999-02-08 04:55:55 +01:00
|
|
|
# include <cassert>
|
1999-10-28 02:47:24 +02:00
|
|
|
# include "vpi_priv.h"
|
1998-11-10 00:44:10 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The Verilog Virtual Machine are definitions for the virtual machine
|
|
|
|
|
* that executes models that the simulation generator makes.
|
|
|
|
|
*/
|
|
|
|
|
|
1998-12-18 00:54:58 +01:00
|
|
|
typedef unsigned vvm_u32;
|
|
|
|
|
|
1998-11-10 00:44:10 +01:00
|
|
|
class vvm_event;
|
|
|
|
|
class vvm_thread;
|
1999-11-22 01:30:52 +01:00
|
|
|
class ostream;
|
1998-11-10 00:44:10 +01:00
|
|
|
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
inline vpip_bit_t operator & (vpip_bit_t l, vpip_bit_t r)
|
1998-11-10 00:44:10 +01:00
|
|
|
{
|
|
|
|
|
if (l == V0) return V0;
|
|
|
|
|
if (r == V0) return V0;
|
|
|
|
|
if ((l == V1) && (r == V1)) return V1;
|
|
|
|
|
return Vx;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
inline vpip_bit_t operator | (vpip_bit_t l, vpip_bit_t r)
|
1999-03-16 05:43:46 +01:00
|
|
|
{
|
|
|
|
|
if (l == V1) return V1;
|
|
|
|
|
if (r == V1) return V1;
|
|
|
|
|
if ((l == V0) && (r == V0)) return V0;
|
|
|
|
|
return Vx;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
inline vpip_bit_t operator ^ (vpip_bit_t l, vpip_bit_t r)
|
1998-11-10 00:44:10 +01:00
|
|
|
{
|
|
|
|
|
if (l == Vx) return Vx;
|
|
|
|
|
if (l == Vz) return Vx;
|
|
|
|
|
if (r == Vx) return Vx;
|
|
|
|
|
if (r == Vz) return Vx;
|
|
|
|
|
if (l == V0) return r;
|
|
|
|
|
return (r == V0)? V1 : V0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
inline vpip_bit_t less_with_cascade(vpip_bit_t l, vpip_bit_t r, vpip_bit_t c)
|
1999-06-07 05:40:22 +02:00
|
|
|
{
|
|
|
|
|
if (l == Vx) return Vx;
|
|
|
|
|
if (r == Vx) return Vx;
|
|
|
|
|
if (l > r) return V0;
|
|
|
|
|
if (l < r) return V1;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
inline vpip_bit_t greater_with_cascade(vpip_bit_t l, vpip_bit_t r, vpip_bit_t c)
|
1999-09-28 03:13:15 +02:00
|
|
|
{
|
|
|
|
|
if (l == Vx) return Vx;
|
|
|
|
|
if (r == Vx) return Vx;
|
|
|
|
|
if (l > r) return V1;
|
|
|
|
|
if (l < r) return V0;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
extern vpip_bit_t add_with_carry(vpip_bit_t l, vpip_bit_t r, vpip_bit_t&carry);
|
1998-11-10 00:44:10 +01:00
|
|
|
|
2000-02-23 05:43:43 +01:00
|
|
|
inline vpip_bit_t v_not(vpip_bit_t l)
|
1998-11-10 00:44:10 +01:00
|
|
|
{
|
|
|
|
|
switch (l) {
|
|
|
|
|
case V0:
|
|
|
|
|
return V1;
|
|
|
|
|
case V1:
|
|
|
|
|
return V0;
|
|
|
|
|
default:
|
|
|
|
|
return Vx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-01 03:07:40 +01:00
|
|
|
extern bool posedge(vpip_bit_t from, vpip_bit_t to);
|
|
|
|
|
|
|
|
|
|
|
1998-11-10 00:44:10 +01:00
|
|
|
class vvm_bits_t {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~vvm_bits_t() =0;
|
|
|
|
|
virtual unsigned get_width() const =0;
|
1999-10-28 02:47:24 +02:00
|
|
|
virtual vpip_bit_t get_bit(unsigned idx) const =0;
|
1999-11-22 01:30:52 +01:00
|
|
|
|
1999-12-02 04:36:01 +01:00
|
|
|
unsigned as_unsigned() const;
|
1998-11-10 00:44:10 +01:00
|
|
|
};
|
|
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
extern ostream& operator << (ostream&os, vpip_bit_t);
|
1998-11-10 00:44:10 +01:00
|
|
|
extern ostream& operator << (ostream&os, const vvm_bits_t&str);
|
|
|
|
|
|
|
|
|
|
/*
|
1999-10-28 02:47:24 +02:00
|
|
|
* The vvm_bitset_t is a fixed width array-like set of vpip_bit_t
|
1998-11-10 00:44:10 +01:00
|
|
|
* items. A number is often times made up of bit sets instead of
|
|
|
|
|
* single bits. The fixed array is used when possible because of the
|
|
|
|
|
* more thorough type checking and (hopefully) better optimization.
|
|
|
|
|
*/
|
|
|
|
|
template <unsigned WIDTH> class vvm_bitset_t : public vvm_bits_t {
|
|
|
|
|
|
|
|
|
|
public:
|
1999-05-03 03:51:29 +02:00
|
|
|
vvm_bitset_t()
|
|
|
|
|
{ for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
|
1999-10-28 02:47:24 +02:00
|
|
|
bits[idx] = Vz;
|
1999-05-03 03:51:29 +02:00
|
|
|
}
|
1999-10-28 02:47:24 +02:00
|
|
|
|
1999-10-05 06:02:10 +02:00
|
|
|
vvm_bitset_t(const vvm_bits_t&that)
|
|
|
|
|
{ unsigned wid = WIDTH;
|
|
|
|
|
if (that.get_width() < WIDTH)
|
|
|
|
|
wid = that.get_width();
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1)
|
1999-10-28 02:47:24 +02:00
|
|
|
bits[idx] = that.get_bit(idx);
|
1999-10-05 06:02:10 +02:00
|
|
|
for (unsigned idx = wid ; idx < WIDTH ; idx += 1)
|
1999-10-28 02:47:24 +02:00
|
|
|
bits[idx] = V0;
|
1999-10-05 06:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
1999-05-03 03:51:29 +02:00
|
|
|
|
1999-11-22 01:30:52 +01:00
|
|
|
vvm_bitset_t(const vvm_bitset_t<WIDTH>&that)
|
1999-12-09 07:00:00 +01:00
|
|
|
{ for (unsigned idx = 0; idx < WIDTH; idx += 1)
|
|
|
|
|
bits[idx] = that.bits[idx];
|
|
|
|
|
}
|
1999-11-22 01:30:52 +01:00
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
vpip_bit_t operator[] (unsigned idx) const { return bits[idx]; }
|
|
|
|
|
vpip_bit_t&operator[] (unsigned idx) { return bits[idx]; }
|
1998-11-10 00:44:10 +01:00
|
|
|
|
|
|
|
|
unsigned get_width() const { return WIDTH; }
|
1999-10-28 02:47:24 +02:00
|
|
|
vpip_bit_t get_bit(unsigned idx) const { return bits[idx]; }
|
1998-11-10 00:44:10 +01:00
|
|
|
|
1999-10-28 02:47:24 +02:00
|
|
|
public:
|
|
|
|
|
vpip_bit_t bits[WIDTH];
|
1998-11-10 00:44:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Verilog events (update events and nonblocking assign) are derived
|
|
|
|
|
* from this abstract class so that the simulation engine can treat
|
|
|
|
|
* all of them identically.
|
|
|
|
|
*/
|
|
|
|
|
class vvm_event {
|
|
|
|
|
|
|
|
|
|
public:
|
1999-10-28 02:47:24 +02:00
|
|
|
vvm_event();
|
1998-11-10 00:44:10 +01:00
|
|
|
virtual ~vvm_event() =0;
|
|
|
|
|
virtual void event_function() =0;
|
|
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
void schedule(unsigned long delay =0);
|
1999-10-28 02:47:24 +02:00
|
|
|
|
1998-11-10 00:44:10 +01:00
|
|
|
private:
|
1999-10-28 02:47:24 +02:00
|
|
|
struct vpip_event*event_;
|
1998-11-10 00:44:10 +01:00
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
static void callback_(void*);
|
|
|
|
|
|
1998-11-10 00:44:10 +01:00
|
|
|
private: // not implemented
|
|
|
|
|
vvm_event(const vvm_event&);
|
|
|
|
|
vvm_event& operator= (const vvm_event&);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-10-28 02:47:24 +02:00
|
|
|
* The vvm_signal_t template is the real object that handles the
|
1999-10-28 23:36:00 +02:00
|
|
|
* receiving of assignments and doing whatever is done. It also
|
|
|
|
|
* connects VPI to the C++/vvm design.
|
1998-11-10 00:44:10 +01:00
|
|
|
*/
|
1999-10-28 23:36:00 +02:00
|
|
|
template <unsigned WIDTH> class vvm_signal_t : public __vpiSignal {
|
1999-02-08 04:55:55 +01:00
|
|
|
|
|
|
|
|
public:
|
1999-10-28 23:36:00 +02:00
|
|
|
vvm_signal_t(vvm_bitset_t<WIDTH>*b)
|
|
|
|
|
{ bits = b->bits;
|
|
|
|
|
nbits = WIDTH;
|
|
|
|
|
}
|
1999-10-28 02:47:24 +02:00
|
|
|
~vvm_signal_t() { }
|
|
|
|
|
|
1999-10-31 05:11:27 +01:00
|
|
|
void init_P(unsigned idx, vpip_bit_t val)
|
1999-10-28 23:36:00 +02:00
|
|
|
{ bits[idx] = val; }
|
1999-06-21 03:02:34 +02:00
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
void set_P(unsigned idx, vpip_bit_t val)
|
1999-10-28 23:36:00 +02:00
|
|
|
{ bits[idx] = val;
|
1999-10-29 05:37:22 +02:00
|
|
|
vpip_run_value_changes(this);
|
1999-02-08 04:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
void set_P(const vvm_bitset_t<WIDTH>&val)
|
1999-04-22 06:56:58 +02:00
|
|
|
{ for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
|
|
|
|
|
set(sim, idx, val[idx]);
|
|
|
|
|
}
|
1999-02-08 04:55:55 +01:00
|
|
|
};
|
|
|
|
|
|
1999-11-21 01:13:08 +01:00
|
|
|
struct vvm_ram_callback {
|
|
|
|
|
vvm_ram_callback();
|
|
|
|
|
virtual ~vvm_ram_callback();
|
1999-12-12 20:47:54 +01:00
|
|
|
virtual void handle_write(unsigned idx) =0;
|
1999-11-21 01:13:08 +01:00
|
|
|
vvm_ram_callback*next_;
|
|
|
|
|
};
|
|
|
|
|
|
1999-11-10 03:52:24 +01:00
|
|
|
template <unsigned WIDTH, unsigned SIZE>
|
|
|
|
|
class vvm_memory_t : public __vpiMemory {
|
|
|
|
|
|
|
|
|
|
public:
|
1999-11-21 01:13:08 +01:00
|
|
|
vvm_memory_t()
|
|
|
|
|
{ cb_list_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
void set_word(unsigned addr,
|
1999-11-21 01:13:08 +01:00
|
|
|
const vvm_bitset_t<WIDTH>&val)
|
1999-11-10 03:52:24 +01:00
|
|
|
{ unsigned base = WIDTH * addr;
|
2000-01-06 06:56:02 +01:00
|
|
|
assert(addr < size);
|
1999-11-10 03:52:24 +01:00
|
|
|
for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
|
|
|
|
|
bits[base+idx] = val[idx];
|
1999-12-12 20:47:54 +01:00
|
|
|
call_list_(addr);
|
1999-11-10 03:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
1999-12-12 20:47:54 +01:00
|
|
|
void set_word(unsigned addr,
|
1999-12-05 03:24:08 +01:00
|
|
|
const vpip_bit_t val[WIDTH])
|
|
|
|
|
{ unsigned base = WIDTH * addr;
|
2000-01-06 06:56:02 +01:00
|
|
|
assert(addr < size);
|
1999-12-05 03:24:08 +01:00
|
|
|
for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
|
|
|
|
|
bits[base+idx] = val[idx];
|
1999-12-12 20:47:54 +01:00
|
|
|
call_list_(addr);
|
1999-12-05 03:24:08 +01:00
|
|
|
}
|
|
|
|
|
|
1999-11-10 03:52:24 +01:00
|
|
|
vvm_bitset_t<WIDTH> get_word(unsigned addr) const
|
|
|
|
|
{ vvm_bitset_t<WIDTH> val;
|
|
|
|
|
unsigned base = WIDTH * addr;
|
2000-01-06 06:56:02 +01:00
|
|
|
assert(addr < size);
|
1999-11-10 03:52:24 +01:00
|
|
|
for (unsigned idx = 0 ; idx < WIDTH ; idx += 1)
|
|
|
|
|
val[idx] = bits[base+idx];
|
|
|
|
|
return val;
|
|
|
|
|
}
|
1999-11-21 01:13:08 +01:00
|
|
|
|
|
|
|
|
void set_callback(vvm_ram_callback*ram)
|
|
|
|
|
{ ram->next_ = cb_list_;
|
|
|
|
|
cb_list_ = ram;
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 04:09:14 +01:00
|
|
|
class assign_nb : public vvm_event {
|
|
|
|
|
public:
|
|
|
|
|
assign_nb(vvm_memory_t<WIDTH,SIZE>&m, unsigned i,
|
|
|
|
|
const vvm_bitset_t<WIDTH>&v)
|
|
|
|
|
: mem_(m), index_(i), val_(v) { }
|
|
|
|
|
|
|
|
|
|
void event_function() { mem_.set_word(index_, val_); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvm_memory_t<WIDTH,SIZE>&mem_;
|
|
|
|
|
unsigned index_;
|
|
|
|
|
vvm_bitset_t<WIDTH> val_;
|
|
|
|
|
};
|
|
|
|
|
|
1999-11-21 01:13:08 +01:00
|
|
|
private:
|
|
|
|
|
vvm_ram_callback*cb_list_;
|
1999-12-12 20:47:54 +01:00
|
|
|
void call_list_(unsigned idx)
|
1999-11-21 01:13:08 +01:00
|
|
|
{ for (vvm_ram_callback*cur = cb_list_; cur; cur = cur->next_)
|
1999-12-12 20:47:54 +01:00
|
|
|
cur->handle_write(idx);
|
1999-11-21 01:13:08 +01:00
|
|
|
}
|
1999-11-10 03:52:24 +01:00
|
|
|
};
|
|
|
|
|
|
2000-01-08 04:09:14 +01:00
|
|
|
|
1998-11-10 00:44:10 +01:00
|
|
|
/*
|
|
|
|
|
* $Log: vvm.h,v $
|
2000-03-13 01:02:34 +01:00
|
|
|
* Revision 1.32 2000/03/13 00:02:34 steve
|
|
|
|
|
* Remove unneeded templates.
|
|
|
|
|
*
|
2000-02-23 05:43:43 +01:00
|
|
|
* Revision 1.31 2000/02/23 04:43:43 steve
|
|
|
|
|
* Some compilers do not accept the not symbol.
|
|
|
|
|
*
|
2000-02-23 03:56:53 +01:00
|
|
|
* Revision 1.30 2000/02/23 02:56:56 steve
|
|
|
|
|
* Macintosh compilers do not support ident.
|
|
|
|
|
*
|
2000-01-08 04:09:14 +01:00
|
|
|
* Revision 1.29 2000/01/08 03:09:14 steve
|
|
|
|
|
* Non-blocking memory writes.
|
1998-11-10 00:44:10 +01:00
|
|
|
*/
|
|
|
|
|
#endif
|