Podstrony
|
[ Pobierz całość w formacie PDF ]
__load_start_secname is defined as the starting load address of the section. The symbol __load_stop_secname is defined as the final load address of the section. Any characters within secname which are not legal within C identifiers are removed. C (or assembler) code may use these symbols to move the overlaid sections around as necessary. Chapter 4. Linker Scripts 45 At the end of the overlay, the value of the location counter is set to the start address of the overlay plus the size of the largest section. Here is an example. Remember that this would appear inside a SECTIONS construct. OVERLAY 0x1000 : AT (0x4000) { .text0 { o1/*.o(.text) } .text1 { o2/*.o(.text) } } This will define both .text0 and .text1 to start at address 0x1000. .text0 will be loaded at address 0x4000, and .text1 will be loaded immediately after .text0. The following symbols will be defined: __load_start_text0, __load_stop_text0, __load_start_text1, __load_stop_text1. C code to copy overlay .text1 into the overlay area might look like the following. extern char __load_start_text1, __load_stop_text1; memcpy ((char *) 0x1000, &__load_start_text1, &__load_stop_text1 - &__load_start_text1); Note that the OVERLAY command is just syntactic sugar, since everything it does can be done using the more basic commands. The above example could have been written identically as follows. .text0 0x1000 : AT (0x4000) { o1/*.o(.text) } __load_start_text0 = LOADADDR (.text0); __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0); .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) } __load_start_text1 = LOADADDR (.text1); __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1); . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1)); 4.7. MEMORY Command The linker s default configuration permits allocation of all available memory. You can override this by using the MEMORY command. The MEMORY command describes the location and size of blocks of memory in the target. You can use it to describe which memory regions may be used by the linker, and which memory regions it must avoid. You can then assign sections to particular memory regions. The linker will set section addresses based on the memory regions, and will warn about regions that become too full. The linker will not shuffle sections around to fit into the available regions. A linker script may contain at most one use of the MEMORY command. However, you can define as many blocks of memory within it as you wish. The syntax is: MEMORY { name [(attr)] : ORIGIN = origin, LENGTH = len ... } The name is a name used in the linker script to refer to the region. The region name has no meaning outside of the linker script. Region names are stored in a separate name space, and will not conflict with symbol names, file names, or section names. Each memory region must have a distinct name. The attr string is an optional list of attributes that specify whether to use a particular memory region for an input section which is not explicitly mapped in the linker script. As described in Section 4.6 46 Chapter 4. Linker Scripts SECTIONS Command, if you do not specify an output section for some input section, the linker will create an output section with the same name as the input section. If you define region attributes, the linker will use them to select the memory region for the output section that it creates. The attr string must consist only of the following characters: R Read-only section W Read/write section X Executable section A Allocatable section I Initialized section L Same as I ! Invert the sense of any of the preceding attributes If a unmapped section matches any of the listed attributes other than !, it will be placed in the memory region. The ! attribute reverses this test, so that an unmapped section will be placed in the memory region only if it does not match any of the listed attributes. The origin is an expression for the start address of the memory region. The expression must evaluate to a constant before memory allocation is performed, which means that you may not use any section relative symbols. The keyword ORIGIN may be abbreviated to org or o (but not, for example, ORG). The len is an expression for the size in bytes of the memory region. As with the origin expres- sion, the expression must evaluate to a constant before memory allocation is performed. The keyword LENGTH may be abbreviated to len or l. In the following example, we specify that there are two memory regions available for allocation: one starting at 0 for 256 kilobytes, and the other starting at 0x40000000 for four megabytes. The linker will place into the rom memory region every section which is not explicitly mapped into a memory region, and is either read-only or executable. The linker will place other sections which are not explicitly mapped into a memory region into the ram memory region. MEMORY { rom (rx) : ORIGIN = 0, LENGTH = 256K
[ Pobierz całość w formacie PDF ]
zanotowane.pldoc.pisz.plpdf.pisz.plkskarol.keep.pl
|