MC723: ArchC tutorial on IC-3

See one SystemC and ArchC Installation Tutorial.

In this activity, as well as in several others in the discipline, we will use a MIPS processor simulator, made in the ArchC language. During the semester you will learn more about this language and the ability to implement different simulators. But in this first moment, the important thing is to understand the basic notions of the simulator, how to invoke it, how to compile programs and how to generate a correct execution result.

ArchC is a language for describing processor architectures. The main purpose is to facilitate the work of the processor and systems designer, accelerating the development of simulators and other necessary tools for the evaluation of an idea, before moving on to the hardware prototyping phase.

All the files you will need to use in this exercise are available in my IC3 homedir, at / home / staff / rodolfo / mc723. In the download folder there are versions ready to unzip and install.

For the first half of 2014, the settings required to use ArchC, SystemC and the compiler in IC-3 must be written in your .bashrc file (at the root of your homedir, eg: /home/ec2008/raXXXXXX/.bashrc). Include the two lines below at the end of the file:

export LD_LIBRARY_PATH = / home / staff / rodolfo / mc723 / systemc / lib-linux64: $ LD_LIBRARY_PATH export PATH = / home / staff / rodolfo / mc723 / archc / bin: / home / staff / rodolfo / compilers / bin: $ PATH

Compiling the Simulator and Running a Program We will use the MIPS processor model, which is an expanded version of the processor studied in the MC722 discipline, with extra instructions. The template is available in the download folder (mips-v0.7.8.tgz). Unzip this file and read the accompanying README. There are specific instructions on how to compile the processor simulator. For this, you will need the acsim simulator generator, which is already installed in / home / staff / rodolfo / mc723 / archc / bin / acsim (add to PATH to facilitate future uses). Three commands are required:

acsim mips.ac -abi make -f Makefile.archc mips.x --load = program [args]

The first command creates the simulator files, based on the description contained in mips.ac (main file for the processor's description in ArchC). The second command compiles the simulator, generating an executable called mips.x. The third command is to use the simulator to run a program compiled for MIPS. As we have no MIPS program, create a file called hello.c with the classic "Hello World" and we will compile it.

To compile a program, you need a cross-compiler (compiler that runs in one architecture and compiles the program to run in another). It is already installed on my homedir.

mips-elf-gcc -specs = archc hello.c -o hello.mips

Similar to the gcc you are used to, this is a version of gcc compiled to generate binaries for the MIPS architecture. All other development tools also exist in a version with the prefix mips-elf. A compiler that runs on one platform (x86 in this case) and generates programs to run on another (MIPS in our example) is called a cross-compiler. The -specs = archc parameter reports some ArchC-specific rules, which must be followed by the compiler. The last parameters indicate the file to be generated and we are generating the program with the architecture suffix to facilitate understanding. With the new executable in hand, now you just need to invoke the simulator and watch your program running.

mips.x --load = hello.mips

Another tool that can be useful is objdump (in the form mips-elf-objdump for MIPS). It is able to show various information about the program (see the manual for options). An example usage for listing assembly code is:

mips-elf-objdump -d hello.mips

Did you recognize any instructions? Did you understand a little of the code?

The instructions implemented by the simulator are described in two files: mips_isa.ac and mips_isa.cpp. The first describes what instructions the processor will have and their encoding. The second file contains an implementation of the statement's behavior (a C ++ code snippet that describes the statement's functionality). Open the second file and look for ac_behavior (add), does this code snippet seem intuitive?