A while ago, I answered a message, in the RTEMS users mailing list, about how to build raw applications for the ERC32 architecture. With raw applications I mean applications that are not dependent of RTEMS, which is the usual RTOS for this architecture. I am now writing about it just to make it easier for people to find it and to add some information to the explanation.
Before starting with the process, you need to get and build the RTEMS toolchain in order to compile your future applications (I used RTEMS 4.6.1). This is because the specific toolchain for ERC32 non-RTEMS applications is no longer maintained. Note, that you don’t need to install RTEMS itself, but you will need the source code. This video shows, step by step, how to download and build these tools for the i386 BSP, which should be almost identical for ERC32.
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 for a long time. I also think this may be useful for other architectures as well.
1. You need to get the following source files from the ERC32 BSP and copy them to your application’s directory:
cpukit/score/cpu/sparc/asm.h cpukit/score/cpu/sparc/rtems/score/sparc.h cpukit/score/cpu/sparc/rtems/score/cpu.h c/src/lib/libbsp/sparc/shared/start.S c/src/lib/libcpu/sparc/reg_win/window.S c/src/lib/libcpu/sparc/syscall/syscall.S
2. Modify start.S so it does not call any RTEMS code, that is, commenting these lines:
/* call __bsp_board_init nop 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 work_space andn %sp, 0x0f, %sp ! align stack on 16-byte boundary */
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 (e.g. test.c).
sparc-rtems4.6.1-gcc -O4 -Wall -mcpu=cypress -c -o test.o test.c
5. Link your program. It will not work right now, as you need to generate two final files, my_bsp_specs and linkcmds.
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 options to override the default switches passed to cc1, cc1plus, as, ld… By default, RTEMS uses the file bsp_specs (found in c/src/lib/libbsp/sparc/erc32). You can edit it and see that it automaticaly links with the RTEMS libraries and adds its own start.S object file. The -B flag specifies where to find the executables, libraries, include files, and data files of the compiler itself. I have used an etc directory where I have stored my_bsp_specs. If any of the needed files is not found by the compiler it will automatically search its own paths.
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.
Basically,
*endfile: crtend.o%s crtn.o%s *lib: -T linkcmds *startfile: start.o crti.o%s crtbegin.o%s *link: -dc -dp -N -e start
The %s indicates to search the file in the compiler specific directories. I have 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 option. This indicates the linker script, which describes where the code and data for the application will reside in memory, to be used by the GNU linker. Fortunately, we can use the one that comes with RTEMS (found in c/src/lib/libbsp/sparc/erc32/startup), so copy it to the etc directory.
Finally, note that when linking, we have not specified the start.o file as it is already done in the my_bsp_specs file.
You might also find more information in the RTEMS BSP and Device Driver Development Guide.
Leave a Reply