[LLVMdev] Targeting low level embedded

Pekka Jääskeläinen pekka.jaaskelainen at tut.fi
Sat Mar 13 04:41:49 PST 2010


Hi,

Tom Hawkins kirjoitti:
> I'm new to LLVM and I'm trying to set it up to target a low level
> embedded device with no OS.  Therefore the final program needs to
 > perform variable initialization and be located at a certain address
 > location.  Here is my basic flow:

We also have an embedded osless target (see http://tce.cs.tut.fi) using
LLVM very successfully. However, our target is not "pure and clean" LLVM
backend as we generate backends on the fly to allow easy and fast target
customization.

LLVM code generation framework is used in our toolchain for instruction
selection and register allocation but we do our own instruction
scheduling and "bundling" + the final assembly phase that generates the
bit images to be uploaded to the instruction memory and data memory.
Also the data memory layout is generated in our own code, that's where
the start address of data memory is fixed.

> 2. Does llvm-gcc insert initialization code?  It doesn't look like it,
> but I may be missing something.

How those images are to be uploaded/loaded/initialized in the final
device is not the problem of the compiler but a runtime loader of some
kind, thus target platform (and memory system) dependent.

You can generate an initializer code for the data memory which
in effect is then a simple "program loader" that copies the initial
values from a non-volatile memory (or some other source, from where
ever you want to initialize the program) to the RAM before starting the
actual main program. This can be a simple (assembly written) loop
in crt0 before calling main, for example. In a multiprocess operating
system env this would be the responsibility of the process
initialization routines (the exec() syscall?).

Or you can have the data memory initialized by a host processor before
it starts your slave processor. As you see, it all depends on your
embedded platform, thus it's clearly not the compiler's responsibility.

-- 
Pekka Jääskeläinen




More information about the llvm-dev mailing list