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.
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:
arcc
, either directly
or by putting it on a line in a `.lis' file.
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.
Kernels are stored in subdirectories of the main `arc' directory and have the following form:
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'.
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'.
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.
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
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.
memmap
console command to determine where free space is on the
board (see section User console).
Your program can optionally specify certain parameters that affect how it is run.
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.