C30 User's manual 裏有說明: 利用 address(0xnnnn) 的指定位址或利用 section name 的方式由 GLD 檔安排。
For example, to locate function PrintString at address 0x8000 in program memory:
int __attribute__ ((address(0x8000))) PrintString (const char *s);
Likewise, to locate variable Mabonga at address 0x1000 in data memory:
int __attribute__ ((address(0x1000))) Mabonga = 1;
Another way to locate code or data is by placing the function or
variable into a user-defined section, and specifying the starting
address of that section in a custom linker script. This is done as
follows:
Modify the code or data declaration in the C source to specify a
user-defined section.
Add the user-defined section to a custom linker script file to
specify the starting address of the section.
For example, to locate the function PrintString at address 0x8000
in program memory, first declare the function as follows in the C source:
int __attribute__((__section__(".myTextSection")))
PrintString(const char *s);
The section attribute specifies that the function should be placed in a section named .myTextSection, rather than the default .text
section. It does not specify where the user-defined section is to be located. That must be done in a custom linker script, as follows.
Using the device-specific linker script as a base, add the following section definition:
.myTextSection 0x8000 :
{
*(.myTextSection);
} >program
This specifies that the output file should contain a section named .myTextSection starting at location 0x8000 and containing all
input sections named.myTextSection. Since, in this example, there is a single function PrintString in that section, then the function will
be located at address 0x8000 in program memory.