Linking with Linker

If you are using the Linker ( SmartLinker) build tool utility for a relocatable assembly project, you will use a PRM file for the Linker to allocate ROM and RAM memory areas.

  1. Using a text editor, create the project's linker parameter file. You can modify a *.prm file from another project and rename it as <project_name>.prm.
  2. Store the PRM file in a convenient location, such as the project directory.
  3. In the <project_name>.prm file, change the name of the executable ( *.elf) file to whatever you choose, for example, <project_name>.elf. In addition, you can also modify the start and end addresses for the ROM and RAM memory areas. The module's Model T.prm file (a PRM file for MC9S12ZVH64 from another CodeWarrior project was adapted), as the following listing shows.
    Listing: Layout of a PRM file for the Linker - Model T.prm
    
    /* This is a linker parameter file for the MC9S12ZVH64 */
    LINK Model_T.elf /* Absolute executable file */
    
    NAMES main.o /* Input object-code files are listed here. */
    
    END
    
    SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in 
    PLACEMENT below. */
    
        Z_RAM                    =  READ_WRITE   0x0080 TO 0x00FF;
    
        RAM                      =  READ_WRITE   0x0100 TO 0x107F;
    
        ROM                      =  READ_ONLY    0x182C TO 0xFFAF;
    
        ROM1                     =  READ_ONLY    0x1080 TO 0x17FF;
    
        ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFCB;
    
     /* INTVECTS                 =  READ_ONLY    0xFFCC TO 0xFFFF; Reserved 
    for Interrupt Vectors */
    
    END
    
    PLACEMENT /* Here all predefined and user segments are placed into the 
    SEGMENTS defined above. */
    
        DEFAULT_RAM,                        /* non-zero page variables */
    
                                            INTO  RAM;
    
        _PRESTART,                          /* startup code */
    
        STARTUP,                            /* startup data structures */
    
        ROM_VAR,                            /* constant variables */
    
        STRINGS,                            /* string literals */
    
        VIRTUAL_TABLE_SEGMENT,              /* C++ virtual table segment */
    
        DEFAULT_ROM,
    
        COPY                                /* copy down information: how 
    to initialize variables */
    
                                            INTO  ROM; /* ,ROM1,ROM2: To use 
    "ROM1,ROM2" as well, pass the option -OnB=b to the compiler */
    
        _DATA_ZEROPAGE,                     /* zero page variables */
    
        MY_ZEROPAGE                         INTO  Z_RAM;
    
    END
    
    STACKSIZE 0x50
    
    VECTOR 0 _Startup /* Reset vector: this is the default entry point for 
    an application. */
    
    Note: If you are adapting a PRM file from a CodeWarrior project, all you really need to add is the LINK portion and the object-code filenames to be linked in the NAMES portion.

    The default size for the stack using the New Bareboard Project wizard for MC9S08GT60 is 80 bytes - ( STACKSIZE 0x50). This Linker statement and __SEG_END_SSTACK in the assembly-code snippet below determine the size and placement of the stack in RAM:

    MyCode:   SECTION   ; code section
    main:
    _Startup:
    
    LDHX #__SEG_END_SSTACK ; initialize stack pointer
    
       TXS
    

    The statements in the linker parameter file are described in the Linker portion of the Build Tool Utilities manual.

  4. Start the SmartLinker tool by double-clicking linker.exe located in the <MCU>\S12lisa_Tools folder in the CodeWarrior installation directory.
  5. Click Close to close the Tip of the Day dialog box.
  6. Load the project's configuration file.

    Use the same <project.ini> file that the Assembler used for its configuration - the project.ini file in the project directory.

  7. Select File > Load Configuration and navigate to and select the project's configuration file.

    The following image displays the Loading configuration dialog box.

    Figure 1. Microcontroller Linker
    Microcontroller Linker
  8. Click Open to load the configuration file.

    The project directory is now the current directory for the Linker.

  9. Select File>Save Configuration to save the configuration.
  10. Select File > Link. The Select File to Link dialog box appears (refer to the figure listed below).
  11. Browse to locate and select the PRM file for your project.
    Figure 2. Select File to Link Dialog Box
    Select File to Link Dialog Box
  12. Click Open.

The Smart Linker links the object-code files in the NAMES section to produce the executable *.elf file, as specified in the LINK portion of the Linker PRM file.

The following image displays the smart linker window after linking.

Figure 3. SmartLinker Window After Linking
SmartLinker Window After Linking

The messages in the linker's project window indicate that:

The TEXTPATH environmental variable was not used for this project. Therefore, the Linker generates its *.map Linker Map file in the same folder that contains the PRM file for the project. Because the ABSPATH environment variable was not used, the *.elf executable file is generated in the same folder as the Linker PRM file. The following image shows the contents of the project directory after the relocatable assembly project is linked.

Figure 4. Project Directory After Linking
Project Directory After Linking