xref: /netbsd-src/external/gpl3/binutils/dist/ld/scripttempl/pru.sc (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
1cat <<EOF
2OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
3OUTPUT_ARCH(${ARCH})
4
5EOF
6
7test -n "${RELOCATING}" && cat <<EOF
8/* Allow memory sizes to be overridden from command line.  */
9__IMEM_SIZE = DEFINED(__IMEM_SIZE) ? __IMEM_SIZE : $TEXT_LENGTH;
10__DMEM_SIZE = DEFINED(__DMEM_SIZE) ? __DMEM_SIZE : $DATA_LENGTH;
11
12MEMORY
13{
14  imem   (x)   : ORIGIN = $TEXT_ORIGIN, LENGTH = __IMEM_SIZE
15  dmem   (rw!x) : ORIGIN = $DATA_ORIGIN, LENGTH = __DMEM_SIZE
16}
17
18__HEAP_SIZE = DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : 32;
19__STACK_SIZE = DEFINED(__STACK_SIZE) ? __STACK_SIZE : 512;
20
21PROVIDE (_stack_top = ORIGIN(dmem) + LENGTH(dmem));
22
23ENTRY (_start)
24
25EOF
26
27OUTPUT_SECTION_ALIGN="
28    ${RELOCATING+/* In case this is the last input section,
29      align to keep the loadable segment size a multiple of the common page size.
30      Some SoCs have stricter memory size requirements than others.  */
31    . = ALIGN (CONSTANT (COMMONPAGESIZE));}"
32
33cat <<EOF
34SECTIONS
35{
36  /* Read-only sections, merged into text segment: */
37  ${TEXT_DYNAMIC+${DYNAMIC}}
38  .hash        ${RELOCATING-0} : { *(.hash)		}
39  .dynsym      ${RELOCATING-0} : { *(.dynsym)		}
40  .dynstr      ${RELOCATING-0} : { *(.dynstr)		}
41  .gnu.version ${RELOCATING-0} : { *(.gnu.version)	}
42  .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)	}
43  .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)	}
44
45  .rel.init    ${RELOCATING-0} : { *(.rel.init)		}
46  .rela.init   ${RELOCATING-0} : { *(.rela.init)	}
47  .rel.text    ${RELOCATING-0} :
48    {
49      *(.rel.text)
50      ${RELOCATING+*(.rel.text.*)}
51      ${RELOCATING+*(.rel.text:*)}
52      ${RELOCATING+*(.rel.gnu.linkonce.t*)}
53    }
54  .rela.text   ${RELOCATING-0} :
55    {
56      *(.rela.text)
57      ${RELOCATING+*(.rela.text.*)}
58      ${RELOCATING+*(.rela.text:*)}
59      ${RELOCATING+*(.rela.gnu.linkonce.t*)}
60    }
61  .rel.fini    ${RELOCATING-0} : { *(.rel.fini)		}
62  .rela.fini   ${RELOCATING-0} : { *(.rela.fini)	}
63  .rel.rodata  ${RELOCATING-0} :
64    {
65      *(.rel.rodata)
66      ${RELOCATING+*(.rel.rodata.*)}
67      ${RELOCATING+*(.rel.rodata:*)}
68      ${RELOCATING+*(.rel.gnu.linkonce.r*)}
69    }
70  .rela.rodata ${RELOCATING-0} :
71    {
72      *(.rela.rodata)
73      ${RELOCATING+*(.rela.rodata.*)}
74      ${RELOCATING+*(.rela.rodata:*)}
75      ${RELOCATING+*(.rela.gnu.linkonce.r*)}
76    }
77  .rel.data    ${RELOCATING-0} :
78    {
79      *(.rel.data)
80      ${RELOCATING+*(.rel.data.*)}
81      ${RELOCATING+*(.rel.data:*)}
82      ${RELOCATING+*(.rel.gnu.linkonce.d*)}
83    }
84  .rela.data   ${RELOCATING-0} :
85    {
86      *(.rela.data)
87      ${RELOCATING+*(.rela.data.*)}
88      ${RELOCATING+*(.rela.data:*)}
89      ${RELOCATING+*(.rela.gnu.linkonce.d*)}
90    }
91  .rel.init_array   	${RELOCATING-0} : { *(.rel.init_array)	}
92  .rela.init_array  	${RELOCATING-0} : { *(.rela.init_array)	}
93  .rel.fini_array   	${RELOCATING-0} : { *(.rel.fini_array)	}
94  .rela.fini_array  	${RELOCATING-0} : { *(.rela.fini_array)	}
95  .rel.got     		${RELOCATING-0} : { *(.rel.got)		}
96  .rela.got    		${RELOCATING-0} : { *(.rela.got)	}
97  .rel.bss     		${RELOCATING-0} : { *(.rel.bss)		}
98  .rela.bss    		${RELOCATING-0} : { *(.rela.bss)	}
99  .rel.plt     		${RELOCATING-0} : { *(.rel.plt)		}
100  .rela.plt    		${RELOCATING-0} : { *(.rela.plt)	}
101
102  /* Internal text space.  */
103  .text ${RELOCATING-0} :
104  {
105    ${RELOCATING+ _text_start = . ; }
106
107    ${RELOCATING+. = ALIGN(4);}
108
109    ${RELOCATING+*(.init0)  /* Start here after reset.  */}
110    ${RELOCATING+KEEP (*(.init0))}
111
112    ${RELOCATING+. = ALIGN(4);}
113    *(.text)
114    ${RELOCATING+. = ALIGN(4);}
115    ${RELOCATING+*(.text.*)}
116    ${RELOCATING+. = ALIGN(4);}
117    ${RELOCATING+*(.text:*)}
118    ${RELOCATING+. = ALIGN(4);}
119    ${RELOCATING+*(.gnu.linkonce.t*)}
120    ${RELOCATING+. = ALIGN(4);}
121
122    ${RELOCATING+ _text_end = . ; }
123  } ${RELOCATING+ > imem}
124
125  .data        ${RELOCATING-0} :
126  {
127    /* Optional variable that user is prepared to have NULL address.  */
128    ${RELOCATING+ *(.data.atzero*)}
129
130    /* CRT is prepared for constructor/destructor table to have
131       a "valid" NULL address.  */
132    ${CONSTRUCTING+ __init_array_start = . ; }
133    ${CONSTRUCTING+ KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))}
134    ${CONSTRUCTING+ KEEP (*(.init_array))}
135    ${CONSTRUCTING+ __init_array_end = . ; }
136    ${CONSTRUCTING+ __fini_array_start = . ; }
137    ${CONSTRUCTING+ KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*)))}
138    ${CONSTRUCTING+ KEEP (*(.fini_array))}
139    ${CONSTRUCTING+ __fini_array_end = . ; }
140
141    ${RELOCATING+/* DATA memory starts at address 0.  So to avoid placing a valid static
142       variable at the invalid NULL address, we introduce the .data.atzero
143       section.  If CRT can make some use of it - great.  Otherwise skip a
144       word.  In all cases .data/.bss sections must start at non-zero.  */
145    . += (. == 0 ? 4 : 0);}
146
147    ${RELOCATING+ PROVIDE (_data_start = .) ; }
148    *(.data)
149    ${RELOCATING+ *(.data*)}
150    ${RELOCATING+ *(.data:*)}
151    ${RELOCATING+ *(.rodata)  /* We need to include .rodata here if gcc is used.  */}
152    ${RELOCATING+ *(.rodata.*) /* with -fdata-sections.  */}
153    ${RELOCATING+ *(.rodata:*)}
154    ${RELOCATING+*(.gnu.linkonce.d*)}
155    ${RELOCATING+*(.gnu.linkonce.r*)}
156    ${RELOCATING+ PROVIDE (_data_end = .) ; }
157
158    ${RELOCATING+/* Merge the bss input sections into the output
159      data section.  The Linux kernel's remoteproc PRU ELF loader
160      will not memzero the bss section.  The CRT0 will not either, in order
161      to reduce the final firmware's instruction memory size.  Hence
162      present bss sections as regular data sections, at the negligible
163      expense of increasing the ELF file size.  */}
164    ${RELOCATING+ PROVIDE (_bss_start = .) ; }
165    *(.bss)
166    ${RELOCATING+ *(.bss.*)}
167    ${RELOCATING+ *(.bss:*)}
168    ${RELOCATING+*(.gnu.linkonce.b*)}
169    ${RELOCATING+*(COMMON)}
170    ${RELOCATING+ PROVIDE (_bss_end = .) ; }
171
172    ${OUTPUT_SECTION_ALIGN}
173  } ${RELOCATING+ > dmem}
174
175  .eh_frame ${RELOCATING-0} :
176  {
177    KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)}
178    ${OUTPUT_SECTION_ALIGN}
179  } ${RELOCATING+ > dmem}
180
181  .gnu_extab ${RELOCATING-0} :
182  {
183    *(.gnu_extab)
184    ${OUTPUT_SECTION_ALIGN}
185  } ${RELOCATING+ > dmem}
186
187  .gcc_except_table ${RELOCATING-0} :
188  {
189    *(.gcc_except_table${RELOCATING+ .gcc_except_table.*})
190    ${OUTPUT_SECTION_ALIGN}
191  } ${RELOCATING+ > dmem}
192
193  /* Linux remoteproc loader requires the resource_table section
194     start address to be aligned to 8 bytes for SoCs with AARCH64
195     host processors.  */
196  .resource_table ${RELOCATING-0} ${RELOCATING+ ALIGN (CONSTANT (MAXPAGESIZE))} :
197  {
198    KEEP (*(.resource_table))
199    ${OUTPUT_SECTION_ALIGN}
200  } ${RELOCATING+ > dmem}
201
202  /* Global data not cleared after reset.  */
203  .noinit ${RELOCATING-0} :
204  {
205    ${RELOCATING+ PROVIDE (_noinit_start = .) ; }
206    *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
207    ${RELOCATING+ PROVIDE (_noinit_end = .) ; }
208    ${RELOCATING+ PROVIDE (_heap_start = .) ; }
209    ${RELOCATING+ . += __HEAP_SIZE ; }
210    ${RELOCATING+/* Stack is not here really.  It will be put at the end of DMEM.
211       But we take into account its size here, in order to allow
212       for MEMORY overflow checking during link time.  */}
213    ${RELOCATING+ . += __STACK_SIZE ; }
214  } ${RELOCATING+ > dmem}
215
216  /* Remoteproc loader in Linux kernel 5.10 and later reads this section
217     to setup the PRUSS interrupt controller.  The interrupt map section
218     is never referenced from PRU firmware, so there is no need to
219     place it in the target dmem memory.  */
220  .pru_irq_map 0 : { *(.pru_irq_map) }
221
222  .note.gnu.build-id ${RELOCATING-0} : { *(.note.gnu.build-id) }
223EOF
224
225source_sh $srcdir/scripttempl/misc-sections.sc
226source_sh $srcdir/scripttempl/DWARF.sc
227
228cat <<EOF
229}
230EOF
231