1/*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date         Author      Notes
8 * 2009-10-14   Bernard     first version
9 * 2010-12-22   onelife     Modify for EFM32
10 * 2011-07-06   onelife     Modify to make use the start code in libraries
11 * 2012-05-15   onelife     Modified to compatible with CMSIS v3
12 */
13
14MEMORY
15{
16    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 131072
17    RAM (rwx)  : ORIGIN = 0x20000000, LENGTH = 16384
18}
19_system_stack_size = 0x200;
20
21/* Linker script to place sections and symbol values. Should be used together
22 * with other linker script that defines memory regions FLASH and RAM.
23 * It references following symbols, which must be defined in code:
24 *   Reset_Handler : Entry of reset handler
25 *
26 * It defines following symbols, which code can use without definition:
27 *   __exidx_start
28 *   __exidx_end
29 *   __etext
30 *   __data_start__
31 *   __preinit_array_start
32 *   __preinit_array_end
33 *   __init_array_start
34 *   __init_array_end
35 *   __fini_array_start
36 *   __fini_array_end
37 *   __data_end__
38 *   __bss_start__
39 *   __bss_end__
40 *   __end__
41 *   end
42 *   __HeapLimit
43 *   __StackLimit
44 *   __StackTop
45 *   __stack
46 */
47ENTRY(Reset_Handler)
48
49SECTIONS
50{
51    .text :
52    {
53        KEEP(*(.isr_vector))
54        *(.text*)
55
56        KEEP(*(.init))
57        KEEP(*(.fini))
58
59        /* .ctors */
60        *crtbegin.o(.ctors)
61        *crtbegin?.o(.ctors)
62        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
63        *(SORT(.ctors.*))
64        *(.ctors)
65
66        /* .dtors */
67        *crtbegin.o(.dtors)
68        *crtbegin?.o(.dtors)
69        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
70        *(SORT(.dtors.*))
71        *(.dtors)
72
73        *(.rodata*)
74
75        KEEP(*(.eh_frame*))
76
77        /* section information for finsh shell */
78        . = ALIGN(4);
79        __fsymtab_start = .;
80        KEEP(*(FSymTab))
81        __fsymtab_end = .;
82        . = ALIGN(4);
83        __vsymtab_start = .;
84        KEEP(*(VSymTab))
85        __vsymtab_end = .;
86
87        . = ALIGN(4);
88        __rt_init_start = .;
89        KEEP(*(SORT(.rti_fn*)))
90        __rt_init_end = .;
91        . = ALIGN(4);
92
93    } > FLASH = 0
94
95    .ARM.extab :
96    {
97        *(.ARM.extab* .gnu.linkonce.armextab.*)
98    } > FLASH
99
100    __exidx_start = .;
101    .ARM.exidx :
102    {
103        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
104    } > FLASH
105    __exidx_end = .;
106
107    __etext = .;
108
109    .data : AT (__etext)
110    {
111        __data_start__ = .;
112        *(vtable)
113        *(.data*)
114        *(.ram)
115
116        . = ALIGN(4);
117        /* preinit data */
118        PROVIDE_HIDDEN (__preinit_array_start = .);
119        KEEP(*(.preinit_array))
120        PROVIDE_HIDDEN (__preinit_array_end = .);
121
122        . = ALIGN(4);
123        /* init data */
124        PROVIDE_HIDDEN (__init_array_start = .);
125        KEEP(*(SORT(.init_array.*)))
126        KEEP(*(.init_array))
127        PROVIDE_HIDDEN (__init_array_end = .);
128
129
130        . = ALIGN(4);
131        /* finit data */
132        PROVIDE_HIDDEN (__fini_array_start = .);
133        KEEP(*(SORT(.fini_array.*)))
134        KEEP(*(.fini_array))
135        PROVIDE_HIDDEN (__fini_array_end = .);
136
137        . = ALIGN(4);
138        /* All data end */
139        __data_end__ = .;
140
141    } > RAM
142
143    .bss :
144    {
145        __bss_start__ = .;
146        *(.bss*)
147        *(COMMON)
148        __bss_end__ = .;
149    } > RAM
150
151    .heap :
152    {
153        __end__ = .;
154        end = __end__;
155        _end = __end__;
156        *(.heap*)
157        __HeapLimit = .;
158    } > RAM
159
160    /* .stack_dummy section doesn't contains any symbols. It is only
161     * used for linker to calculate size of stack sections, and assign
162     * values to stack symbols later */
163    .stack_dummy :
164    {
165        *(.stack)
166    } > RAM
167
168    /* Set stack top to end of RAM, and stack limit move down by
169     * size of stack_dummy section */
170    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
171    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
172    PROVIDE(__stack = __StackTop);
173
174    /* Check if data + heap + stack exceeds RAM limit */
175    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
176}
177