3 Hello TTA World!

What would a tutorial be without the traditional ``Hello World!'' example? Interestingly enough, printing out ``Hello World'' in a standalone (operating system free) platform like the TTA of TCE is not totally straightforward. That is the reason this tutorial is not the first one in this tutorial chapter.

The first question is: where should I print the string? Naturally it is easy to answer that question while working with the simulator: to the simulator console, of course. However, when implementing the final hardware of the TTA, the output is platform dependent. It can be a debugging interface, serial port output, etc.

In order to make printing data easier from TTAs designed with TCE, we have included an operation called STDOUT in the ``base operation set'' that is installed with the TCE. The simulation behavior of the operation reads its input, expects it to be a 8bit char and writes the char verbatim to the simulator host's standard output. Of course, in case the designer wants to use the operation in his final system he must provide the platform specific implementation for the function unit (FU) implementing the operation, or just remove the FU after the design is fully debugged and verified.

The default implementation of printf() in TCE uses the STDOUT operation to print out data. Therefore, implementing a ``Hello World'' application with TCE is as simple as adding an FU that implements the STDOUT to the processor design and then calling printf() in the simulated program. The simulator should print out the greeting as expected.

Here is a simple C code (hello.c) that prints the magic string:

#include <stdio.h>

int main() {
    printf("Hello TTA World!");
    return 0;
}

Next, compile it to an architecture that implements the STDOUT. TCE ships with a minimal architecture that also includes the STDOUT function unit, which you can use:

cp $(tce-config --prefix)/share/tce/data/mach/minimal_with_stdout.adf .
tcecc --swfp -O0 hello.c -a minimal_with_stdout.adf -o hello.tpef

It should compile without errors. Beware: the compilation can take a while on a slower machine. This is because printf() is actually quite a large function and the compiler is not yet optimized for speed.

Finally, simulate the program to get the greeting:

ttasim -a minimal_with_stdout.adf -p hello.tpef --no-debugmode
Hello TTA World!

That's it. Happy debugging!

Pekka Jääskeläinen 2016-11-24