The esim Simulator
This web page contains instructions for running the ESIM simulator. It assumes
that the user has already compiled her program using the esim
compiler.
The simulator and compiler are available for download at http://www.cse.ucsc.edu/~elm/Software/Esim/download.shtml.
Starting the simulator
The simulator is started by simply typing esim at the command line.
This will start the simulator but will not load any netlists. The simulator
interface is a Tcl shell,
and can be programmed in the same way that any other Tcl shell can be programmed.
If desired, the simulator can be started with a graphical window (if you're
running under the X windowing system) by using the -tk command line
option (esim -tk).
Circuit symbols & values
The values of any circuit symbol may be examined or set during simulation.
This allows the user to interactively debug her design or provide toplevel
control by setting global signals (such as a clock). All named signals may
be examined or set. This includes symbols in components. The top level circuit
has an empty name. All other circuits are given a name consisting of their
parent's name combined with the label specified in the use statement
as follows:
define foo (a, b)
circuits
a <= b & 1;
end circuits;
end foo;
define bar (x[2], y[2])
circuits
s use foo (x[0], y[0]);
t use foo (x[1], y[1]);
end circuits;
end bar;
signal topx[4], topy[4];
circuits
hi use bar(topx[3:2], topy[3:2]);
lo use bar(topx[1:0], topy[1:0]);
end circuits;
In the above circuit, the top-level symbols are topx and topy.
Each instance of the bar component creates its own copy of the symbols
x and y. The hi use statement creates hi.x
and hi.y, and the lo use statement creates lo.x
and lo.y. Since each instance of bar itself creates two instances
of foo, the following signals are defined: lo.s.a, lo.s.b, lo.t.a,
lo.t.b, hi.s.a, hi.s.b, hi.t.a, hi.t.b. Each of these signals may have its
own value; even though there are 4 instances of the signal a in foo,
each may have its own value (and thus has its own name) because each belongs to
a different "copy" of the foo component.
Symbol values may be specified in either binary or hex (using the -hex
or -binary switch). The default for all commands is binary. Possible
symbol values include 0, 1, X, and Z.
0 and 1 are self-explanatory: high and low logic values.
Zrefers to a node that isn't currently driven by any gate. Xmeans
that the value of the node can't be determined. This can occur for several
reasons. First, the node could be driven to different values (0 and
1) by two or more different gates at the same time. Second, the node
could be driven by a single gate whose output value can't be determined for
some reason, such as indeterminate inputs (X-valued). For binary,
each bit is represented individually by one of these four symbols. For hex,
however, nodes are shown in groups of four. If all nodes in a group of four
have "real" values, a hex digit is displayed. If all are undriven,
Z is displayed. Otherwise, X is displayed. This means that
the four bits 010X would be shown as a single hex digit of X,
as would 0Z11.
Simulator commands
All simulator commands are preceded by the word esim. This is done
because the esim keyword tells Tcl to send whatever follows to the
esim simulator. Omitting esim from a simulator command can cause
errors, particularly for commands that are valid for both esim and
Tcl (such as load).
The simulator commands are as follows:
- esim load netlist
This command is used to load a netlist (the output file from ecomp)
into the simulator. It may only be used once. If you want to reload a netlist
because you've made changes, you have to exit the simulator and restart
it.
Sample command: esim load foo.net loads foo.net
into the simulator.
- esim run ?time_in_ns
Run the simulator for the time specified in the optional argument (the question
mark indicates an optional argument, and should not actually be typed).
If no time is specified, the simulator runs until there are no remaining
events (the simulation has settled) or until the maximum number of events
have been handled.
Sample command: esim run 100 runs the simulator for 100
ns or the maximum number of events, whichever comes first.
Sample command: esim run runs the simulator until there
are no events left or the maximum number of events has been reached.
- esim maxevents ?n
Set the maximum number of events to run before returning. If nis
omitted, simply return the current maximum number of events. This parameter
can be used to prevent an infinite loop in the simulator from tying up a
computer for too long. The default (1,000,000 events) is probably a good
number, and need not be changed.
Sample command: esim maxevents 5000000 sets the maximum
number of events to 5,000,000.
Sample command: esim maxevents returns the current maximum
number of events but doesn't change it.
- esim events
Returns the number of events processed by the simulator to this point.
- esim curtime
Returns the number of simulated nanoseconds since the simulator was started.
- esim show ?-hex ?-binary sym ?high ?low
Return the value of a symbol from the simulation. The default printout is
in binary, but the -hex switch can be used to force a printout
in hexadecimal. If no range is specified, the value of the entire symbol
is printed. If only the high parameter is specified, the
value returned will be that of the single bit specified. If both high
and low are specified, just that portion of the symbol will
be returned. Of course, an error occurs if the symbol isn't defined or if
the range is incorrect. Note that the value returned will have its most
significant bit on the left.
Sample command: esim show -hex a returns the current value
of the symbol ain hexdecimal.
Sample command: esim show a 10 3 returns the current value
of the expression a[10:3] in binary.
- esim set ?-hex ?-binary sym val ?high ?low
Set a symbol to a particular value. The syntax of this command is similar
to that of esim show, but a value must also be specified (using
the same formats returned by esim show). The symbol is set to the
value specified. If a range is specified, only that part of the symbol's
value is set. NOTE: The simulator will not change the symbol's
value (for any reason) until the symbol is unset using esim unset
or until a new value is specified using another esim set command.
Also, set values do not take effect until the next time the simulator is
run using esim run. Note that this command can cause unpredictable
results if there are still events waiting to be processed.
Sample command: esim set -hex a 0123 sets ato the
hex value 0x123.
Sample command: esim set a 00110101 10 3 sets a[10:3]
to 00110101.
- esim unset sym ?high ?low
Unset a variable and allow it to vary normally. This command has no effect
if the symbol wasn't already set. In other words, it can't hurt to unset
a symbol that wasn't already set.
- esim read ?-hex ?-binary memory addr nbits
Read a value nbits wide fromthe memory specified at the
address specified. The address is specified in either decimal or hexadecimal,
depending on whether there's a leading "0x". The -hex
or -binary option refers to the display format for the value read
out of memory.
Sample command: esim read -hex mem 0x123 10 reads 10 bits
starting at location 0x123 from the memory mem.
- esim write ?-hex ?-binary memory addr nbits value
Similar to esim read in its arguments, except that value
(specified in hex or binary, as per the switch) is written to the memory
rather than read. Unlike esim set, though, this value can be changed
by the normal running of the simulator; it's just a one-time write to memory.
Sample command: esim write -hex mem 0x123 12 F92 writes
12 bits starting at location 0x123 to the memory mem.
- esim list pattern
List all of the symbols matching the pattern. The only "regular
expression" allowed is a *. For example, esim list fa.* would
list fa.foo & fa.bar but not foo.foo or foo.fa.foo.
Only a single * is allowed in the pattern.
- esim trace ?-hex ?-binarysym
Update the global value Esim(sym) whenever its value changes
in the simulator. The value can be updated in either hex or binary (the
default). Note that tracing lots of symbols slows the simulator down, so
it's best to only trace those symbols in which you're interested. Also,
a node can only be traced for a single symbol. The only time this will matter
is when tracing signals that are used as parameters for components. Don't
worry, though, the simulator simply won't let you trace a symbol if any
of its nodes are already being traced. This restriction may be removed in
future versions of the simulator.
Those interested in executing a Tcl/Tk command when the variable changes
should look into the Tcl trace command.
- esim untrace sym
Remove any previous tracing on the symbol sym. If no tracing
was in place, this command has no effect. Note that this command doesn't
delete (or otherwise change) the Tcl variable Esim(sym)
except that the simulator will no longer update its value.
In addition to the commands listed above, the simulator understands all
regular Tcl & Tk commands. This means that you can write Tcl/Tk programs
to automate simulator initialization and circuit testing. For example, you
might write your startup commands to a script file and then use the source
command to read the script file when you start up the simulator. Alternatively,
you may include any startup Tcl commands you want into a file called .esimrc
located in your home directory; a sample .esimrc
file is available. This file contains commands that allow a user to set
up a small graphical window listing the current time and the current values
of any signals in the simulator. Note that you must start the simulator with
esim -tk for the graphical window to be available, and you need to
have an X display to use graphics from Tk. Students at UCSC interested in
building a graphical user interface for esim (using Tk) are invited
to talk with me about a possible independent study project.
The following short Tcl program will print a message whenever a variable
changes its value. You can type it as shown at the command line, or you can
paste it in, or you can put it into a file and read the file in using the
Tcl source command.
proc printval {n1 n2 op} {
global Esim
set t [esim curtime]
puts "$t ns: $Esim($n2) => $n2"
}
Once you've defined the printval procedure, you can tell Tcl to invoke
the procedure whenever a variable changes. For example, trace variable Esim(clk)
w printval will tell Tcl to invoke the procedure printval whenever
the variable Esim(clk) is written to (the w). Now, all you
have to do is use the command esim trace clk which will update the
variable Esim(clk) whenever the symbol clk changes. Whenever
it does, a message like this will be printed: 400 ns: 0 => clk.
You can prevent further messages for clk by using esim untrace clk.
Feedback
Feedback on this page is welcome. Please send your comments to elm@cse.ucsc.edu.
Last updated
Saturday, 10-Jun-2000 10:29:43 PDT
by Ethan Miller
(elm «at» cs·ucsc·edu)