Go to the first, previous, next, last section, table of contents.

Compiling programs under ARC

This section assumes that you have already gone through the section on getting started. See section Getting started using ARC if this is not the case. This section provides more detail on topics involved in compiling programs under ARC.

Specifying which libraries and kernel to use

It is important to specify which kernel to compile against before trying to compile a program under ARC. You can make this specification at several different levels:

The options in this list are looked for and used in order. For example, if you specify a command-line option to arcc, the other options are not pursued.

Choosing the kernel which is right for you

Kernels are stored in subdirectories of the main `arc' directory and have the following form:

`arc/332libs-x.xxx/motoboot.xxx'
A Motorola 68332 kernel which will run on a Motorola BCC332 board
`arc/332libs-x.xxx/vestaboot.xxx'
A Motorola 68332 kernel which will run on a Vesta SBC332 board
`arc/332libs-x.xxx/ttaleboot.xxx'
A Motorola 68332 kernel which will run on an Onset Tattletale 68332 board
`arc/386libs-x.xxx/pckernel.xxx'
An Intel 386, 468, Pentium kernel which will run on an IBM PC (not yet in distribution).

To discover which version a given board is running, look at the tag on the ROMs, or connect the board to arc, hit reset, and look at the boot line. It should have the version number in the boot message.

Anarchboot Multitasking 68332 Kernel Version 0.919
Copyright Anne Wright 1993

Compiled May  3 1995 at 13:09:12

vestaboot.919>

This example is from a Vesta SBC332 board. It is running version 0.919 of the 68332 kernel for Vesta boards, so if you were using this board, the kernel you want is `vestaboot.919'.

Specifying which kernel in a project-specific way

If you are likely to want to switch between different kernels frequently, or if certain projects use a kernel other than the default, you should include KERNEL=<kernelname> as an argument to arcc, or on a line in the .lis file for the project.

An example of using this in a Makefile is:

foo: foo.c
        arcc KERNEL=vestaboot.919 foo.c

bar: bar.c
        arcc KERNEL=ttaleboot.915 bar.c

In this case, when you execute make foo, it will use `vestaboot.919' as the kernel, but when you execute make bar, it will use `ttaleboot.919'.

You also could have used `.lis' files:

foo.lis:

KERNEL=vestaboot.919
foo.c

bar.lis:

KERNEL=ttaleboot.915
bar.c

In this case, when you execute arcc foo.lis (either by typing the command at a shell or loading it from arc), it will use `vestaboot.919' as the kernel, but when you execute arcc bar.lis, it will use `ttaleboot.919'.

Specifying your personal default kernel

If you are not likely to want to switch between different kernels frequently, or if you will be using one kernel predominantly, you can specify your default kernel in `~/.arcrc', the ARC resources file in your home directory.

Just create `~/.arcrc' and include the line KERNEL=<kernelname> on a line by itself. An example `~/.arcrc' file is as follows:

KERNEL=vestaboot.919

If you specify which kernel to use as a command line option or in a `.lis' file, this default will be overridden.

If you neither specify the kernel at the command line or in a `~/.arcrc' file, then the global default kernel (if any) will be used. See section Set up the default kernel for details.

Using arcc

The actual compiler being used to compile code under the ARC Development system is gcc, the GNU C Compiler. gcc is free, copy-lefted software. The source is freely available via anonymous ftp from `prep.ai.mit.edu' in `pub/gnu'. We distribute gcc cross-compilers with our system as a convenience, but we cannot and do not charge anything for it.

However, in order to get gcc to compile and link correctly for this specialized use requires a large number of command-line options and paths. This used to be done via complicated Makefiles and shell scripts.

To make the process of compilation easier, we wrote a front end called arcc which knows how to find the correct directories for libraries and header files, and set up the options for gcc correctly. (This does, however, require you to set up your environment properly. See section Set up your environment to use ARC for details.)

For example, if you have a file called `hello.c' and you have set up the default kernel already, you can type arcc hello.c and it will create an executable `hello'. Calling the gcc cross-compiler directly, you would have to type, for example:

332gcc -nostdinc -nostdlib -B/usr/local/arc/sparcbin/332
-I/usr/local/arc/332libs-0.9 -m68020 -mnobitfield
-freg-struct-return -g -O -L/usr/local/arc/332libs-0.9
-Wl,-R,/usr/local/arc/332libs-0.9/vestaboot.919,-N
-Wl,-Ttext,106000 -Wl,-T,/usr/local/arc/332libs-0.9/usercode.ld
/usr/local/arc/332libs-0.9/usercrt0_332.o hello.c -o hello -lgcc
-ldefaults -ltpu

arcc options

The following options can be specified at the arcc command line, placed on a line by themselves in a program's `.lis' file, specified in a person's `~/.arcrc' file, specified in the `.info' file for libraries or kernel, or (in the case of KERNEL) in the filesystem of `/usr/local/arc'. The above are listed in the order of precedence. Options specified in more than one place will take the value from the command line if specified, otherwise from the `.lis' file if specified, etc.

`KERNEL=<kernelname>'
Link against the specified kernel, and use it to determine which directory to find header files and libraries in. For more information, see section Specifying which libraries and kernel to use.
`CODE_ADDR=<address>'
Set the starting address of the program to <address>. If not specified at the command-line or in your `~/.arcrc' file, the default is to use the value of `CODE_ADDR' specified in the `<kernelname>.info' file in the same directory as the kernel itself. The default radix for the address is decimal, so be sure to specify `0x' at the beginning for hexidecimal addresses. Use the memmap console command to determine where free space is on the board (see section User console).
`LSB_FIRST'
Specify this if you are targeting an LSB first processor, for example, the Intel x86 family. Do not use this option for using the Motorola 68332.
`SHOW_ARGS'
Show the full arguments to gcc (cannot be used as a command-line option).

Changing program startup parameters

Your program can optionally specify certain parameters that affect how it is run.

`run_on_reset'
This detemines whether you want the function "main" in your program to be run when the reset button is pressed. A value of 0 for run_on_reset specifies that your program should not be run on reset, and a non-zero value specifies that it should be run on reset. The default value is 1.
`startup_stack'
This determines how much RAM will be allocated for the stack in your program's main process. The default is 2048, but if you get "stack overflow" messages from the board, you should specify a higher number.
`startup_ticks'
This determines how many ticks your program will take in the multitasking system. Usually, you won't need to change this. The default is 5. By specifying a higher number, your program's main process gets to run for a longer time before another process gets a chance.

You can override the defaults for these values by defining a global variable with the new value.

Examples:

int run_on_reset= 0;     /* don't run main() on reset */

int startup_stack= 4096;  /* give me 4K of startup stack */

Like any other global variable, you should only declare these parameters once in each program or you will get compile errors.


Go to the first, previous, next, last section, table of contents.