-------------------------------------
Running DV Code on the real CPU model
-------------------------------------

This directory contains the boot code and an example of how to write
a DV test that runs on the version of the Verilog simulator that includes
the real ARM7TDMI cycle accurate model.

What you need to do
-------------------

Your test code can be written in c and needs to supply two procedures
typed as follows:

extern int cpu0main(void);
extern int cpu1main(void);

The completion status of your test can be communicated to the host-side
program by calling "exit(status)" or as the return value from your
cpu?main routine.

To build and link your code, copy the Makefile lines from the Makefile
in this directory for the program example.c, which produces example.elf
and example.bin as its output files.

Note that the boot code is a library, but it must appear before the
main program on the link line so that the ARM exception vectors end
up at address 0.  The $(LD) line needs to look like:

$(LD) -T linker.dat -u _start -o $@ $(ROOT)/usr/lib/sc/libdvboot.a yourmain.o

The linker.dat locates the code at address 0 and the "-u _start" creates
an undefined reference to pull in the boots.o module that contains
the definition of the ARM exception vector table.

The boot code does the following:

1) Sets RX bits on the code segment.
2) Sets RW bits on stack, data and BSS.
3) Clears BSS.
4) Creates a stack for cpu0 of size 1KB and then jumps to the user-supplied
cpu0main().
5)  If your test needs to run code on cpu1, then your cpu0main should take
cpu1 out of reset (see the sample code in example.c).  The boot code
will create a 1KB stack for cpu1 and then call the cpu1main() routine
that you supply.  Any synchronization between the actions of the code
running on the two cpus is the responsibility of the programmer.

Running your test code
----------------------

To run a Verilog simulation, make sure you update the hw/ tree
(especially hw/chip/lib/arm, hw/chip/sim, and hw/chip/v), then execute
the following commands:

% cd hw/chip/sim
% make cpu.ipc

To load your test routine, you need to create a host-side program
to get your code loaded and then feed cycles to the simulator.  A
sample of such a program can be found in

sw/dv/iosim/example/cpu.c

Depending on how long your test runs, you may need to add some
additional "IO_STALL" calls to provide enough cycles to finish
your test.  Other than that, the cpu.c as written should suffice
for now.  Invoke it as follows:

cpu -ccpu0 -En -q -r../tests/cpu/flip.bin -D../tests/cpu/example.bin

The "-En" is required because cpu.c as written generates some intentional
errors.

The "-r" argument gives the pathname of the initial boot code that
does the flipping of ROM and DA space.  The -D option specifies the
.bin file that should be loaded in DA space (your test program).
Note that the file is in ".bin" format and was produced
as described above.  The common rules include a default rule for
translated .elf files to .bin using strip.

The "-q" will cause the simulator to exit when the host-side program
is finished.  The "example/cpu" program will collect the exit status
from the test running on the ARM cpus and will exit with the same
exit status value supplied by the ARM test program.

Other notes
-----------

You can coordinate activity between the code running on the simulated
CPUs and the host-side C program by defining a communication protocol
through system memory on the simulator.  We may provide library routines
to do something useful (printf?) at some point in the near future.

If you have problems or suggestions, please contact Paul, Phil or Haishan.

