Next: , Up: Example

5.1 Overview

The main source code file, hello.c defines a program to print out some strings and perform a simple calculation.

     #include "utils.h"
     void level2() {
       simexit( 42 );
     void level1() {
       simputs ("Hello World!\n");
       simputs ("The answer is ");
       simputn (6 * 7);
       simputs ("\n");

This program runs under the control of a simple bootloader, stored at the reset vector location, 0x100.

             .org    0x100           # The reset routine goes at 0x100
             .global _start
             l.addi  r1,r0,0x7f00    # Set SP to value 0x7f00
             l.addi  r2,r1,0x0       # FP and SP are the same
             l.mfspr r3,r0,17        # Get SR value
             l.ori   r3,r3,0x2       # Set TT exception enable bit
             l.jal   _main           # Jump to main routine
             l.mtspr r0,r3,17        # Enable exceptions (DELAY SLOT)

The bootloader establishes a stack (falling for the OpenRISC 1000) at location 0x7f00.

Simple utility functions provide character, string and number output to a monitor. One of these is simputs.

     void  simputs( char *str )
       int  i;
       for( i = 0; str[i] != '\0' ; i++ )
           simputc( (int)(str[i]) );
     }       /* simputs() */

The code can be compiled using the OpenRISC 1000 GNU tool chain. However for convenience a compiled image, hello, is provided with the distribution.

The code is loaded at address 0x1000. In this example, the code for main starts at 0x1338, for simputs at 0x113c and for simputc at 0x1020.