OpenRisc Architectural Simulator Patches

or1ksim is the architectural simulator of the OpenRisc core, that is a powerful open source hardware processor.

Reentrance/Multiple Instances Patch

Unfortunately the library of the or1ksim is not reentrant and thus does not allow multiple instances of the core simulator to be executed in one address space. Historically all data is stored in global variables.
In a first step I hence performed this straight-forward actions: Apparently that is not the nicest way to transform the code, but may be a starting point for future development. Maybe a (C++-)rewrite comes to focus.

Status

In the current status the patch works for the standard configuration as checked out from the repository. I am also able to boot linux and also the parallel execution of two simulation instances did at least not crash.
Further functional verification and testing/modification using all possible configurations and #defines is still missing, but here I hope you can help me out, so that I make a first patch available. Please send me your feedback.

Files

or1ksim patch: or1ksim_patch_reentrant_0.3.0_20090326.bz2

Embecosm ESP1 patch: embecosm-esp1_patch_reentrant_20090326.bz2

Installation

First check out a repository version of the simulator:
> svn co http://opencores.org/ocsvn/or1k/or1k/tags/rel-0-3-0/or1ksim
Enter the directory and apply the patch:
> cd or1ksim
> bzcat -dc ../or1ksim_patch_reentrant_0.3.0_20090326.bz2 | patch -p1
From the main directory build the simulator as described here.
> mkdir builddir_or1ksim
> cd builddir_or1ksim
> ../or1ksim/configure --target=or32-uclinux --prefix=/opt/or1ksim
> make all
You may install it globally, but that is not necessary for testing. The building process was tested with Ubuntu 8.10 and gcc 4.3.

Usage

To use the simulator from the library in your files use the type or1ksim for every instance. You can create a new instance with the default configuration using or1ksim_instance().
#include "or1ksim.h"
..
or1ksim *sim = or1ksim_instance()
Your instance is automatically registered globally during or1ksim_init()(for book-keeping, might be used in future).

Finally I tested the library patch with the vmlinux binary, that I created as described here. I applied these changes to the sim.cfg. Create the directory under the main directory:

> mkdir or1ksim_simpletest
> cd or1ksim_simpletest
Add the example file main.c:
#include "or1ksim.h"

#include 

int main()
{
	or1ksim* sim1 = or1ksim_instance();
	or1ksim* sim2 = or1ksim_instance();
	or1ksim_init( sim1, "sim.cfg", "vmlinux", NULL, NULL, NULL );
	or1ksim_init( sim2, "sim.cfg", "vmlinux", NULL, NULL, NULL );

	double dt = 1.0 / (double) or1ksim_clock_rate( sim1 );;

	while ( 1 )
	{
		or1ksim_run( sim1, dt );
		or1ksim_run( sim2, dt );
	}

	return 0;
}
Finally compile this simple test:
> gcc -o simple_test -I../or1ksim/ -lsim -L../builddir_or1ksim/.libs main.c
Execute it:
> LD_LIBRARY_PATH=../builddir_or1ksim/.libs ./simple_test
If vmlinux is present and everything worked out fine until now, two xterm windows will open booting linux on two simulator instances.

The fact, that no segmentation faults appear and both linux boot seems good, but since both instances now run synchronously it is thinkable that they do not interfere negatively. To put more stress on the check whether I missed a global variable (that is pretty unlikely thanks to objdump and eclipse) I also put the code in threads and ran five threads in parallel. Also here, all instances booted.

Apparently this is very trivial, further testing is required. I hope, you can contribute to this, since I am still at the start of the understanding of or1ksim.

SystemC Integration

The SystemC models described by EAN1 and implemented in ESP1 of embecosm have also been patched. Simply apply the patch from above to the software package.

Future work involves the setup of MPSoC environments.

Last update: March 26, 2009, Stefan Wallentowitz