SLAU131Y October 2004 – June 2021
This example links three object files named demo.c.obj, ctrl.c.obj, and tables.c.obj and creates a program called demo.out. The symbol SETUP is the program entry point.
Assume that target memory has the following program memory configuration:
Address Range | Contents | ||
---|---|---|---|
0x0080 to 0x7000 | On-chip RAM_PG | ||
0xC000 to 0xFF80 | On-chip ROM |
Address Range | Contents | ||
---|---|---|---|
0x0080 to 0x0FFF | RAM block ONCHIP | ||
0x0060 to 0xFFFF | Mapped external addresses EXT |
Address Range | Contents | ||
---|---|---|---|
0x0200 to 0x0A00 | RAM | ||
0x1100 to 0xFFF0 | FLASH | ||
0xFFE0 to 0xFFFF | VECTORS |
The output sections are constructed in the following manner:
Linker Command File, demo.cmd shows the linker command file for this example. Output Map File, demo.map shows the map file.
/****************************************************************************/
/* Specify Linker Options */
/****************************************************************************/
--entry_point=SETUP /* Define the program entry point */
--output_file=demo.out /* Name the output file */
--map_file=demo.map /* Create an output map file */
/****************************************************************************/
/* Specify Input Files */
/****************************************************************************/
demo.c.obj
ctrl.c.obj
tables.c.obj
/****************************************************************************/
/* Specify System Memory Map */
/****************************************************************************/
MEMORY
{
SFR(R) : origin = 0x0000, length = 0x0010
PERIPHERALS_8BIT : origin = 0x0010, length = 0x00F0
PERIPHERALS_16BIT: origin = 0x0100, length = 0x0100
RAM(RW) : origin = 0x0200, length = 0x0800
INFOA : origin = 0x1080, length = 0x0080
INFOB : origin = 0x1000, length = 0x0080
FLASH : origin = 0x1100, length = 0xEEE0
VECTORS(R) : origin = 0xFFE0, length = 0x001E
RESET : origin = 0xFFFE, length = 0x0002
}
/****************************************************************************/
/* Specify Output Sections */
/****************************************************************************/
SECTIONS
{
.text : {} > FLASH /* Link all .text section into flash */
.intvecs : {} > 0xFFE0 /* Link interrupt vectors. at 0xFFE0 */
.data : /* Link .data sections */
{
tables.c.obj(.data)
. = 0x400; /* Create hole at end of block */
} > FLASH, fill = 0xFF00 /* Fill and link into FLASH */
ctrl_vars : /* Create new sections for ctrl variables */
{
ctrl.c.obj(.bss)
} > RAM, fill = 0x0100 /* Fill with 0x0100 and link into RAM */
.bss : {} > RAM /* Link remaining .bss sections into RAM */
}
/****************************************************************************/
/* End of Command File */
/****************************************************************************/
Invoke the linker by entering the following command:
cl430 --run_linker demo.cmd
This creates the map file shown in Output Map File, demo.map and an output file called demo.out that can be run on an MSP430.
OUTPUT FILE NAME: <demo.out>
ENTRY POINT SYMBOL: "SETUP" address: 000000d4
MEMORY CONFIGURATION
name origin length attributes fill
-------- -------- --------- ---------- --------
P_MEM 00000000 000001000 RWIX
D_MEM 00001000 000001000 RWIX
EEPROM 08000000 000000400 RWIX
SECTION ALLOCATION MAP
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 00000020 00000138
00000020 000000a0 ctrl.c.obj (.text)
000000c0 00000000 tables.c.obj (.text)
000000c0 00000098 demo.c.obj (.text)
.intvecs 0 00000000 00000020
00000000 00000020 tables.c.obj (.intvecs)
.data 0 08000000 00000400
08000000 00000168 tables.c.obj (.data)
08000168 00000298 --HOLE-- [fill = ff00ff00]
08000400 00000000 ctrl.c.obj (.data)
08000400 00000000 demo.c.obj (.data)
ctrl_var 0 00001000 00000500
00001000 00000500 ctrl.c.obj (.bss) [fill = 00000100]
.bss 0 00001500 00000100 UNINITIALIZED
00001500 00000100 demo.c.obj (.bss)
00001600 00000000 tables.c.obj (.bss)
GLOBAL SYMBOLS
address name
-------- ----
000000d4 SETUP 00000020 clear
00000020 clear 000000b8 set
000000b8 set 000000c0 x42
000000c0 x42 000000d4 SETUP
[4 symbols]