-
Notifications
You must be signed in to change notification settings - Fork 9
/
mlibc.ld
155 lines (132 loc) · 4.43 KB
/
mlibc.ld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (c) mlibc & plct lab
*
* SPDX-License-Identifier: MIT
*
* Change Logs:
* Date Author Notes
* 2024/8/23 0Bitbiscuits the first version
*/
ENTRY(_start)
DEFAULT_FLASH_ADDR = 0x00000000; /* Default flash addr is 0x00000000 */
DEFAULT_FLASH_SIZE = 0x00001000; /* Default flash size is 4k */
DEFAULT_RAM_ADDR = 0x20000000; /* Default ram addr is 0x20000000 */
DEFAULT_RAM_SIZE = 0x00010000; /* Default ram size is 16k */
DEFAULT_ALIGNMENT = 0x00000010; /* Default ALIGNMENT */
DEFAULT_STACK_SIZE = 0x00000400; /* Default stack size is 1k */
MEMORY
{
flash (rx!w) :
ORIGIN = DEFINED(__flash) ? __flash : DEFAULT_FLASH_ADDR,
LENGTH = DEFINED(__flash_size) ? __flash_size : DEFAULT_FLASH_SIZE
ram (w!rx) :
ORIGIN = DEFINED(__ram) ? __ram : DEFAULT_RAM_ADDR,
LENGTH = DEFINED(__ram_size) ? __ram_size : DEFAULT_RAM_SIZE
}
PHDRS
{
text PT_LOAD;
ram_init PT_LOAD;
ram PT_LOAD;
}
SECTIONS
{
PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram));
.text : {
/* code */
*(.text.unlikely .text.unlikely.*)
*(.text.startup .text.startup.*)
*(.text .text.* .opd .opd.*)
*(.gnu.linkonce.t.*)
KEEP (*(.init .init.*))
KEEP (*(.fini .fini.*))
__text_end = .;
PROVIDE (__etext = __text_end);
PROVIDE (_etext = __text_end);
PROVIDE (etext = __text_end);
/* Need to pre-align so that the symbols come after padding */
. = ALIGN(DEFAULT_ALIGNMENT);
PROVIDE_HIDDEN ( __init_array_start = . );
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN ( __init_array_end = . );
PROVIDE_HIDDEN ( __fini_array_start = . );
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array .dtors))
PROVIDE_HIDDEN ( __fini_array_end = . );
} >flash AT>flash :text
.rodata : {
/* read-only data */
*(.rdata)
*(.rodata .rodata.*)
*(.gnu.linkonce.r.*)
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
} >flash AT>flash :text
/*
* Data values which are preserved across reset
*/
.preserve (NOLOAD) : {
PROVIDE(__preserve_start__ = .);
KEEP(*(SORT_BY_NAME(.preserve.*)))
KEEP(*(.preserve))
PROVIDE(__preserve_end__ = .);
} >ram AT>ram :ram
.data : ALIGN_WITH_INPUT {
*(.data .data.*)
*(.gnu.linkonce.d.*)
/* Need to pre-align so that the symbols come after padding */
. = ALIGN(DEFAULT_ALIGNMENT);
PROVIDE( __global_pointer$ = . + 0x800 );
PROVIDE( _gp = . + 0x8000);
*(.sdata .sdata.* .sdata2.*)
*(.gnu.linkonce.s.*)
} >ram AT>flash :ram_init
PROVIDE(__data_start = ADDR(.data));
PROVIDE(__data_source = LOADADDR(.data));
PROVIDE(__data_end = .);
PROVIDE(__data_source_end = LOADADDR(.data) + SIZEOF(.data));
PROVIDE(__edata = __data_end);
PROVIDE(_edata = __data_end);
PROVIDE(edata = __data_end);
PROVIDE(__data_size = __data_end - __data_start);
PROVIDE(__data_source_size = __data_source_end - __data_source);
.bss (NOLOAD) : {
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
/* Align the heap */
. = ALIGN(DEFAULT_ALIGNMENT);
__bss_end = .;
} >ram AT>ram :ram
PROVIDE(__bss_start = ADDR(.bss));
PROVIDE(__end = __bss_end);
_end = __bss_end;
PROVIDE(end = __bss_end);
PROVIDE(__bss_size = __bss_end - __bss_start);
/* Make the rest of memory available for heap storage */
PROVIDE(__heap_start = __end);
PROVIDE(__heap_end = __stack - (DEFINED(__stack_size) ? __stack_size : DEFAULT_STACK_SIZE));
PROVIDE(__heap_size = __heap_end - __heap_start);
/* Allow a minimum heap size to be specified */
.heap (NOLOAD) : {
. += (DEFINED(__heap_size_min) ? __heap_size_min : 0);
} >ram :ram
/* Define a stack region to make sure it fits in memory */
.stack (NOLOAD) : {
. += (DEFINED(__stack_size) ? __stack_size : DEFAULT_STACK_SIZE);
} >ram :ram
/* @C_START@ */
/DISCARD/ : {
*(.note .note.*)
*(.eh_frame .eh_frame.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
*(.ARM.exidx*)
}
/* @C_END@ */
}