|
3 | 3 | #define COMBINE_STR2(a,b) COMBINE_STRX(a,b) |
4 | 4 | #define COMBINE_STR3(a,b,c) COMBINE_STR2(COMBINE_STR2(a,b),c) |
5 | 5 |
|
| 6 | +/* helper macro to create a section */ |
| 7 | +#define SECTION_IMPL(name, data) \ |
| 8 | + .name : \ |
| 9 | + { \ |
| 10 | + data \ |
| 11 | + } |
| 12 | + |
| 13 | +/* helper macro to create a section with a attribute */ |
| 14 | +#define SECTION_IMPL_ATTR(name, attr, data) \ |
| 15 | + .name (attr) : \ |
| 16 | + { \ |
| 17 | + data \ |
| 18 | + } |
| 19 | + |
| 20 | +/* helper macro to create a alligned section */ |
| 21 | +#define ALLIGNED_SECTION(name, align, data) \ |
| 22 | + SECTION_IMPL( \ |
| 23 | + name, \ |
| 24 | + . = ALIGN(align); \ |
| 25 | + data \ |
| 26 | + ) |
| 27 | + |
| 28 | +/* helper macro to create a alligned readonly section */ |
| 29 | +#define ALLIGNED_READONLY_SECTION(name, align, data) \ |
| 30 | + SECTION_IMPL_ATTR( \ |
| 31 | + name, \ |
| 32 | + READONLY, \ |
| 33 | + . = ALIGN(align); \ |
| 34 | + data \ |
| 35 | + ) |
| 36 | + |
6 | 37 | /* macro to define the vectors section. Should be pointed to the correct memory region */ |
7 | 38 | #define VECTORS() \ |
8 | | - .vectors (READONLY) : \ |
9 | | - { \ |
10 | | - . = ALIGN(4); \ |
11 | | - /* vector table */ \ |
| 39 | + ALLIGNED_READONLY_SECTION( \ |
| 40 | + vectors, 4, \ |
12 | 41 | KEEP(*(.vectors .vectors.*)); \ |
13 | | - . = ALIGN(4); \ |
14 | | - } |
| 42 | + ) |
15 | 43 |
|
16 | 44 | /* macro to define the rodata section */ |
17 | 45 | #define RODATA() \ |
18 | | - .rodata (READONLY) : \ |
| 46 | + ALLIGNED_READONLY_SECTION( \ |
| 47 | + rodata, 4, \ |
| 48 | + *(.rodata .rodata.* .gnu.linkonce.r.*); \ |
| 49 | + ) |
| 50 | + |
| 51 | +/* macro to define the stack with a size in bytes */ |
| 52 | +#define STACK(size) \ |
| 53 | + .stack (NOLOAD) : \ |
19 | 54 | { \ |
20 | 55 | . = ALIGN(4); \ |
21 | | - /* Constands, strings, etc */ \ |
22 | | - *(.rodata .rodata.* .gnu.linkonce.r.*); \ |
| 56 | + /* provide the __stack_start */ \ |
| 57 | + PROVIDE(__stack_start = .); \ |
| 58 | + /* add the size in bytes to the current address */ \ |
| 59 | + . = . + size; \ |
| 60 | + /* make sure the size is rounded off to 4 bytes */ \ |
23 | 61 | . = ALIGN(4); \ |
| 62 | + /* provide the __stack_end */ \ |
| 63 | + PROVIDE(__stack_end = .); \ |
24 | 64 | } |
25 | 65 |
|
26 | 66 | /* macro to define a init array. Array name is passed as an argument */ |
|
0 commit comments