CMU 18-447: Introduction to Computer Architecture

ModelSim Introduction

www.ece.cmu.edu/~ece447

 

ModelSim will serve as the main Verilog compiler, simulator, and debugger for 18-447. This file will guide you through using ModelSim for the first time.  ModelSim also comes with a number of official documents (/afs/ece/class/ece447/docs/modelsim). The ModelSim Tutorial (se_tutor.pdf) is a must read after reading this document.

 

Environment Setup

 

ModelSim requires a large number of environment variables to be configured before it will run properly on the 447 Lab Linux machines (alpha, aphrodite, apollo, ares, artemis, athena, beta, chi, delta, demeter, dionysys, epsilon, eta, gamma, hephaestus, hera, hermes, iota, kappa, lambda, mu, nu, phi, pi, poseidon, psi, rho, sigma, tau, theta, xi, zeta). We have supplied configuration scripts which will aid in this process.

 

First, determine which shell you are using by typing this at your Unix command prompt:

 

echo $SHELL

 

If the command returns tcsh, add the following line to your ~/.login file:

 

source /afs/ece/class/ece447/bin/setup

 

If the command returns bash, add the following line to your ~/.bashrc file:

 

. /afs/ece/class/ece447/bin/setup_bash

 

(Note in the above, there is a space between the . and the filename.)

 

If you are using something other than tcsh or bash, we assume you are familiar enough with Unix to get the setup script to work on your own.

 

After making the above edits, you should log out from your account and log back in again. If all went well, when you type this command at the Unix command prompt

 

echo $LM_LICENSE_FILE

 

you should see a string that includes

 

/afs/ece/support/mgc/share/image/usr/local/mgc//license.dat:/afs/ece/support/synopsys//license.dat

 

Also check

 

            echo $PATH

 

you should see a string that includes

 

/afs/ece/support/mgc/share/image/usr/local/mgc//bin:/afs/ece/support/mgc/share/image/usr/local/mgc//modelsim/modeltech/bin:/afs/ece/support/synopsys//2004.06/share/image/usr/local/synopsys/2004.06/linux/syn/bin

 

If you have an 18-240 setup script, you'll have to either disable or override it. Either comment out any references to the script (by putting a '#' in front of the command line) or putting the 18-447 script after the 240 script. If you don't do this, you'll probably get an ugly license server error and ModelSim won't start. The reason that we do this is because the 240 script has a nasty habit of overwriting our environment variables!

 

Creating a library directory

 

ModelSim requires a "library directory" to store configuration information specific to your project (separate from your .v Verilog files). In your working directory (for example, ~/447/checkpoint0/), you will need to run the following command once before running ModelSim:

 

vlib work

 

This creates a directory called ~/447/checkpoint0/work (in our example). If you either delete the library directory or create it by hand, ModelSim will not be amused.

 

Compiling Verilog files

 

ModelSim's Verilog compiler must be invoked on Verilog files, like gcc is used to compile C files. Fortunately, the command-line syntax is very simple:

 

vlog lab0.v

 

where lab0.v is the Verilog file you want to compile. If all goes well, the compiler should list the modules that it compiled, as well as potential Top level modules in the project.

 

Running ModelSim

 

To run ModelSim, enter your working directory and type:

 

vsim top

 

where top is the Top level module name in your design (this argument is optional, but it makes things easier).

 

This will bring up the simulator main window. If you feel lucky, you can run your whole test suite by typing the command:

 

run -all

 

The simulation will run until it encounters a $stop or $finish command in your Verilog file. If you use only display and print for debugging, this is all the ModelSim you need know. In fact, if this is all you do, you can just type

 

vsim -c -do "run -all" top

 

at the Unix command prompt to run vsim in text mode (without X).

 

Most likely, you'll get a few bad test vectors and you'll need to muck around with the waveform viewer and debugger. ModelSim has a great GUI with which to debug the design. Most of this you will have to discover for yourself. Here's a quick tutorial.

 

·       To bring up an object window: ViewàDebug WindowsàObject

·       To bring up a waveform window: ViewàDebug WindowsàWaves. You can add signals to the waveform window by dragging and dropping things from the object window into the waveform window (left panel).

·       To run the simulation (from the SimulateàRun pull-down menu):

o      Run - All: Run until the next breakpoint or until a $finish or $stop, or forever.

o      Run - Continue: Continue running after a breakpoint.

o      Run - 100ns: Run for 100ns of simulation time.

·       If you find a bug, you can edit, recompile and restart the simulation, without quitting the ModelSim executable. Just type the same vlog compilation command you'd use at the shell prompt and then type restart. This will save a lot of time.

·       For power users, virtually all click-able things can be accessed with keyboard commands. For power users with too much time on their hands, ModelSim can be scripted using TCL.

 

This should give you the most minimum of functionalities to get through the labs. Reading the documentations will help you access the more powerful debugging and simulation features. (Start with se_tutor.pdf in the docs AFS directory. This little investment up front will greatly simplify your work for the whole semester. Good luck.)

 

Acknowledgements: Portions of this document were first created by Profs. Rutenbar and Marculescu