
Creation of execution format file (*.exf)

 <02_setup.txt> We hope that you understand the procedure by reading setup.
 In this section, we explain about the compile procedure in detail.

 We use "hello.exf" that is used in the previous section <02_setup.txt> as an example.
 Please refer to a batch file mk.bat and makefile in order to create an execution format file.

 "\" and "/" are treated as the same meaning in the following description.
  (In fact, "/" is used for makefile and etc.)

(1)Program Coding
 Create the required C resource files.  Also create assemble source files.

   *.c --- represents C source files.
   *.s --- represents assemble source files.

 In addition, other files are required.
   startup.s --- Startup routine
             (This is written in assembly and should not be changed.)

 In this example, both main.c and startup.s are required.


(2)Compile and Assemble of source files
 Create an object file (*.o) from the above mentioned C source files.
 Create an object file (*.o) from the above mentioned assemble source files.

 Compile/Assemble of C source file should be done by typing the following command (gcc).
  gcc -I C:\onHand_SDK\RupSDK\Inc -g -c -O1 main.c

  -I is an option that specifies the directory where include files are located.
  -g is an option of debug.
  -c is an option of compile -> assemble -> object file generation.
  For other compile options, refer to GCC manual and other references.

 Assemble of assemble source file should be done by typing the following command (as).
  as -I C:\onHand_SDK\RupSDK\Inc startup.s -o startup.o

  -I is an option that specifies the directory where include files are located.
  -o specifies the name of object file.


  If you find any error in this program, you need to check typing errors of the program.  For more information, refer to C language related publications.


(3)Link between object file and library
 Create elf (Executable and Linkable Format) file by linking an object file and library that are generated by the above mentioned operations.

 The address 0x110100 (PSP area = 0x110000), which is loaded to SRAM when this link is established, is setup.  You may modify this loaded address.

 Link operation should be done by typing the following command (ld).  Please note that line feeds are inserted in order to read the program easily.

  ld
     -o hello.elf
     startup.o main.o
     -Ttext 0x110100
     -Map hello.map
     -L C:\onHand_SDK\RupSDK\Lib
     -lrupmenu -lruptool -lrupsys -llcdbios -lpsdos -lwbios
     -L C:\onhand_sdk\mec-980228\H-i386-cygwin32\mn10200-elf\lib
     -lm -lc
     -L C:\onhand_sdk\mec-980228\H-i386-cygwin32\lib\gcc-lib\mn10200-elf\2.7-mec980228
     -lgcc

  -o		Output file name option
  *.o		Object file name option
  -Ttext	Memory load address setup option (usually 0x110100)
  -Map		Memory map output option
  -L		This is an option that specifies the directory where library files are located.
  -l		Library file specification  (e.g. -lrupsys -> librupsys.a is specified.)

 An object file startup.o should be linked at the first place.
      (The beginning of the startup routine should be set as _start=0x110100.)

 Please note that "mec-980228" in CYGWIN32 is different according to your downloaded versions so that you should be careful when you setup.

 In addition, "-L -\2.7-mec980228" are also different according to your downloaded versions.  You can confirm the difference by typing gcc -v in DOS prompt.


(4)Conversion to onHand/Ruputer execution format file
 Convert the elf files that are created by the above mentioned linker to onHand/Ruputer execution format file (*.exf) by using the following tools.

 Convert Elf file -> Motorola S3 format file (GNUPro tool)
 mn10200-elf-objcopy --output-target=srec hello.elf

 Then, convert S3 format to onHand/Ruputer execution format file (*.exf) (RupSDK tool)
 sf2bin hello.elf hello.exf


 When the conversion is completed, the following message is displayed.

 "Completed successfully."


This is the procedure of creating of an execution file.  Once you create a exf, transfer it to onHand/Ruputer and confirm the operation.


(5)Load to Main memory
 The transferred "hello.exf" is stored to a flash memory.

 When you execute this, display Filer screen on onHand/Ruputer, select "hello.exf" and press Enter button.

 All execution format files are loaded to the main memory (SRAM).
 In this example, the program body is loaded from the address 0x110100 that is set when a link is established.  In addition, the PSP area has 256 byte.

    0x110000 - 0x1100FF PSP:256 byte
    0x110100 -         Program body

When the loading process is completed, the instruction is executed from 0x110100.
(For more information about PSP, refer to MS-DOS system call handbook and etc.)




How the application works

 The exectution file ***.exf has the following headers.

 +00h  Load address
 +04h  Initial PC value
 +08h  File size
 +0Ch  Reserved (NULL)
 +10h  Program body
   :        :

* This header is converted from the Motorola S3 format elf file by using RupSDK tool sf2bin.exe.
* Since only one address is specified to the beginning, TEXT section cannot be separated and loaded on the main memory.



(1)When you execute a exf file within a flash memory (B drive), the contents of the exf file is copied by using dos_execute command from the load address of the header to the main memory (SRAM).

(2)Allocate PSP=256 byte from "Load address-0x100".

(3)Execute the program from the initial PC value of the header.

(4)The execution file inherits the existing stack pointer.
The stack is accumulated from the final address 0x120000 of the main memory to 0x100000 direction after the booting.


If the final address of exf file that is loaded on the main memory is overlapped with the stack, the program becomes the runaway state.  You must be careful when you develop an application.


The final address can be confirmed by the map file (*.map) that is generated when link is established.  In addition, the file size the application should be less than 50KB.  The following is an guideline of map file.


When a child process within the application is executed, you should be careful about this overlap problem.




Guideline of map file

If you specify -Map option when the link is established, you can output the memory map information to a file.

This allows you to confirm the memory consumption status of the execution file.

For example, hello.map has .text section from Line 158.

                     : 
                     : 
.text           0x00110100      0x706
 *(.text)
 .text          0x00110100       0xd4 startup.o
                0x00110100                start
 .text          0x001101d4       0x4c main.o
                0x001101d4                main
 .text          0x00110220      0x2b7 C:/onHand_SDK/RupSDK/Lib/librupsys.a(sysentry.o)
                0x0011031c                EndRupAPI
                0x0011033e                toAddrbin
                0x00110220                InitRupAPI
                     : 
                     : 

In the start address 0x110100, you can confirm that the contents of label name _start within startup.s (startup.o is its object file) is stored here.

Then, the contents of the function name main within main.c (main.o is its object file) from 0x1101d4 is stored.

As the same way, the function EndRupAPI within the rupsys library is stored.

The problem may occur.  There is a possibility that the final address conflicts with the stack accumulated from 0x120000.  Therefore, you need to confirm the final address.

                     : 
                     : 
 *(COMMON)
 COMMON         0x00110950       0x12 C:/onHand_SDK/RupSDK/Lib/librupsys.a(sysentry.o)
                0x00110950                pApiSys
                0x00110954                pApiMenu
                0x00110958                _SystemCtl_Version
                0x0011095a                pApiTool
                0x0011095e                pSystemCtl
                0x00110962                _end=.
                0x00110962                PROVIDE (end, .)
                     : 
                     : 

In this example, Line 265 0x00110962 is the final address.

It is assumed that
When an execution file size is 50KB, 0x11C800 is the final address.
When an execution file size is 60KB, 0x11F000 is the final address.
Therefore, the range between 50KB and 60KB may be the limit but it depends on how the stack is used.




Memory Over
While an application is running, in the following Filer menu operation,

 User Application
  -> FilerMenu
   -> Control Panel
    -> User Name
     -> Name(Right click)
      -> "Exit application...No,Yes" PowerOFF(LCD OFF) in the popup screen

In this condition, the usage amount of the stack becomes the maximum (abut 10KB is used)

****** Caution *****
  Please back up all data before testing.
  When you create an application, test should be done as necessary.
  You can keep the start address from 0x10F300 as an additional memory.

===============================================================================
 Copyright (c) 1998-1999.  Seiko Instruments Inc.  All rights reserved. 
===============================================================================
