How to generate a raw C program with xxx-rtems-gcc?

Aleix Conchillo Flaqué aconchillo at
Mon Jan 9 17:43:36 UTC 2006


yes, it is possible, but you'll have to change some things.

I'm not sure if what I'm going to explain is the best way to do it,
but it has worked for me, and I have ran programs generated this way
in a real board.

1. You will need to get the sparc ERC32 asm.h, sparc.h, cpu.h,
start.S, window.S and syscall.S.

2. Modify start.S, so it does not call any RTEMS code, that is,
commenting this lines:

          call    __bsp_board_init

          set     (SYM(rdb_start)), %g6   ! End of work-space area
          st      %sp, [%g6]

          set     (SYM(Configuration)), %l1
          ld      [%l1+4], %l3            ! work_space_size
          sub     %sp, %l3, %sp           ! set %sp to area below
          andn    %sp, 0x0f, %sp          ! align stack on 16-byte

3. Compile start.S, window.S and syscall.S. You can remove many
things from the header files, but that's up to you.

sparc-rtems4.6.1-gcc -DASM -c -o start.o start.S

4. Compile your C files.

sparc-rtems4.6.1-gcc -O4 -Wall -mcpu=cypress -c -o test.o test.c

5. And the last thing is to link your program:

sparc-rtems4.6.1-gcc -mcpu=cypress -Betc -specs my_bsp_specs -o test
window.o syscall.o test.o

Note the arguments -B and -specs. -specs is used to specify a file
with extra information for the compiler. By default RTEMS uses the
file bsp_specs, it is in erc32/lib directory. Edit it an you will see
that it automaticaly links with the RTEMS libraries and adds its own
start.S object file. The -B flag is used to specify the directory to
find this file (I have used an etc/ directory).

So, what we need to do is to create our own file (my_bsp_specs) which
will not use any RTEMS library and which will point to our compiled
start.S object file.


crtend.o%s crtn.o%s

-T linkcmds

start.o crti.o%s crtbegin.o%s

-dc -dp -N -e start

The %s indicates to search the file in the compiler specific
directories. I removed the %s from start.o so It will search for it
in the current directory.

Another important thing to note in this file is the -T linkcmds. This
indicates the linker script to be used by GNU LD. You better check
the GNU LD manual to understand it, I was a bit confused the first
time I saw it. Anyway, you can use the one that comes with RTEMS (in

Note that when linking, we have not specified the start.o file as it
is already done in the my_bsp_specs file.

Also, many of this things are explained in the RTEMS BSP and Device
Driver Development Guide.

Of course you will need to investigate to make it work but I hope
this information helps you.

Best regards,


On 22 Dec 2005, at 19:44, Fabrício de Novaes Kucinskis wrote:

> Hi all,
> First of all, I'm sorry for asking so many questions in the last  
> few days.
> It's because I was just setting up my development environment in  
> the free
> time (or better said, my "idle" time), and now I'm starting to work  
> with
> RTEMS in full-time.
> I hope I'll soon stop to ask, and start to answer here in the list ;)
> Well, let's go: Is it still possible to compile raw C applications  
> (without
> RTEMS libs) using xxxx-rtems-gcc?
> I have some applications which I created to test my development  
> board (an
> ERC32 from Tharsys) and compiled under sparc-rtems-gcc from  
> RTEMS-4.0.0.
> I updated to RTEMS-4.6.4, created some RTEMS applications with  
> success, and
> tried to run these raw C ERC32 apps, but when loading them with gdb  
> I got
> the error "memory access error while loading".
> I tried to recompile the source code and got the message "cannot  
> find symbol
> _start". Then I pointed to the "linkcmds" file using the -T switch  
> and the
> program was compiled with no warnings or errors.
> But when I load and run the application nothing happens; the  
> program I'm
> using is just a HelloWorld, and it just finishes doing nothing. I  
> inserted
> breakpoints in main() and in the ERC32 initial address (0x2000000),  
> but none
> of then is reached.
> Am I doing something - or everything - wrong? How can I compile a  
> "raw C"
> app with sparc-rtems-gcc from RTEMS 4.6.4?
> Thanks in advance,
> Fabrício de Novaes Kucinskis - DEA / INPE
> -----------------------------------------
> Divisão de Eletrônica Aeroespacial
> Instituto Nacional de Pesquisas Espaciais

More information about the users mailing list