@micro-os-plus/architecture-riscv 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/CMakeLists.txt +87 -0
  3. package/LICENSE +21 -0
  4. package/README.md +317 -0
  5. package/include/micro-os-plus/architecture-riscv/core-functions-inlines.h +86 -0
  6. package/include/micro-os-plus/architecture-riscv/core-functions.h +105 -0
  7. package/include/micro-os-plus/architecture-riscv/csr-functions-inlines.h +466 -0
  8. package/include/micro-os-plus/architecture-riscv/csr-functions.h +241 -0
  9. package/include/micro-os-plus/architecture-riscv/declarations.h +58 -0
  10. package/include/micro-os-plus/architecture-riscv/defines.h +185 -0
  11. package/include/micro-os-plus/architecture-riscv/device-functions-inlines.h +235 -0
  12. package/include/micro-os-plus/architecture-riscv/device-functions.h +166 -0
  13. package/include/micro-os-plus/architecture-riscv/instructions-inlines.h +172 -0
  14. package/include/micro-os-plus/architecture-riscv/instructions.h +153 -0
  15. package/include/micro-os-plus/architecture-riscv/platform-functions-inlines.h +81 -0
  16. package/include/micro-os-plus/architecture-riscv/platform-functions.h +75 -0
  17. package/include/micro-os-plus/architecture-riscv/plic-functions.h +278 -0
  18. package/include/micro-os-plus/architecture-riscv/semihosting-inlines.h +79 -0
  19. package/include/micro-os-plus/architecture-riscv/types.h +135 -0
  20. package/include/micro-os-plus/architecture.h +38 -0
  21. package/linker-scripts/README.md +7 -0
  22. package/linker-scripts/sections-flash.ld +425 -0
  23. package/linker-scripts/sections-ram.ld +425 -0
  24. package/linker-scripts/sections.ld +377 -0
  25. package/meson.build +46 -0
  26. package/package.json +37 -0
  27. package/src/.gitkeep +0 -0
  28. package/xpack.json +23 -0
@@ -0,0 +1,425 @@
1
+ /*
2
+ * This file is part of the µOS++ distribution.
3
+ * (https://github.com/micro-os-plus/)
4
+ * Copyright (c) 2022 Liviu Ionescu.
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software
7
+ * for any purpose is hereby granted, under the terms of the MIT license.
8
+ *
9
+ * If a copy of the license was not distributed with this file, it can
10
+ * be obtained from https://opensource.org/licenses/MIT/.
11
+ */
12
+
13
+ /*
14
+ * Linker script for RAM only configurations.
15
+ *
16
+ * Static constructors/destructors use the new .init_array/.fini_array
17
+ * definitions; the old .init/.fini are no longer used, but the sections
18
+ * must still be present when using librdimon.
19
+ *
20
+ * TODO: check elf-redboot.ld
21
+ *
22
+ * The heap starts immediately after the last statically allocated
23
+ * .bss/.noinit section (the _end symbol), and extends up to the stack.
24
+ *
25
+ * To make use of the multi-region initialisations, define
26
+ * MICRO_OS_PLUS_INCLUDE_STARTUP_INIT_MULTIPLE_RAM_SECTIONS
27
+ * for the startup.cpp file.
28
+ */
29
+
30
+ /* TODO: set OUTPUT_FORMAT & OUTPUT_ARCH */
31
+ /*
32
+ * The entry point is important for debuggers and simulators, the
33
+ * hardware has its own notion of the startup address.
34
+ */
35
+ ENTRY(reset_entry)
36
+
37
+ /*
38
+ * The '__stack' definition is required by newlib crt0; do not remove it.
39
+ * The stack is located at the very end of the RAM region.
40
+ */
41
+ __stack = DEFINED(__stack) ? __stack : ORIGIN(RAM) + LENGTH(RAM);
42
+ __stack_size = DEFINED(__stack_size) ? __stack_size : 16K;
43
+
44
+
45
+ SECTIONS
46
+ {
47
+ /*
48
+ * On RISC-V devices the startup address is a regular address, so this
49
+ * must be the very first section.
50
+ * Apart from the assembly code used to initialise the stack,
51
+ * do not place anything else into this section.
52
+ */
53
+ .reset_entry : ALIGN(4)
54
+ {
55
+ KEEP(*(SORT_NONE(.reset_entry) SORT_NONE(.reset_entry.*)))
56
+ } >RAM
57
+
58
+ /*
59
+ * Dynamic Run Time Metadata.
60
+ * Normally the debugger reaches this section by resolving a symbol,
61
+ * but in case it should scan memory for the magic, better place this
62
+ * section as early as possible.
63
+ */
64
+ .drtm : ALIGN(4)
65
+ {
66
+ KEEP(*(.drtm .drtm.*))
67
+ } >RAM
68
+
69
+ /*
70
+ * For convenience, place the trap code at the beginning.
71
+ */
72
+ .trap_entry : ALIGN(4)
73
+ {
74
+ *(.exceptions_array .exceptions_array.*)
75
+ *(.interrupts_local_array .interrupts_local_array.*)
76
+ *(.interrupts_global_array .interrupts_global_array.*)
77
+ *(.trap_entry .trap_entry.*)
78
+ *(.traps_handlers .traps_handlers.*)
79
+ } >RAM
80
+
81
+ /*
82
+ * This section is here for convenience, to store the
83
+ * startup code at the beginning of the memory, hoping that
84
+ * this will increase the readability of the listing.
85
+ */
86
+ .after_vectors : ALIGN(4)
87
+ {
88
+ *(.after_vectors .after_vectors.*) /* Startup code and ISRs */
89
+ } >RAM
90
+
91
+ /*
92
+ * Memory regions initialization arrays.
93
+ *
94
+ * There are two kinds of arrays for each RAM region, one for
95
+ * data and one for bss. Each is iterated at startup and the
96
+ * region initialization is performed.
97
+ *
98
+ * The data array includes:
99
+ * - from (LOADADDR())
100
+ * - region_begin (ADDR())
101
+ * - region_end (ADDR()+SIZEOF())
102
+ *
103
+ * The bss array includes:
104
+ * - region_begin (ADDR())
105
+ * - region_end (ADDR()+SIZEOF())
106
+ *
107
+ * WARNING: It is mandatory that the regions are word aligned,
108
+ * since the initialization code works only on words.
109
+ */
110
+ .mem_inits : ALIGN(4)
111
+ {
112
+ PROVIDE_HIDDEN(__data_regions_array_begin__ = .); /* µOS++ specific. */
113
+
114
+ LONG(LOADADDR(.data));
115
+ LONG(ADDR(.data));
116
+ LONG(ADDR(.data)+SIZEOF(.data));
117
+
118
+ /* If more DATA regions are needed, add more such records. */
119
+
120
+ PROVIDE_HIDDEN(__data_regions_array_end__ = .); /* µOS++ specific. */
121
+
122
+ PROVIDE_HIDDEN(__bss_regions_array_begin__ = .); /* µOS++ specific. */
123
+
124
+ LONG(ADDR(.bss));
125
+ LONG(ADDR(.bss)+SIZEOF(.bss));
126
+
127
+ /* If more BSS regions are needed, add more such records. */
128
+
129
+ PROVIDE_HIDDEN(__bss_regions_array_end__ = .); /* µOS++ specific. */
130
+ } >RAM
131
+
132
+ /*
133
+ * The preinit code, i.e. an array of pointers to initialization
134
+ * functions to be performed before constructors.
135
+ */
136
+ .preinit_array : ALIGN(4)
137
+ {
138
+ /*
139
+ * PROVIDE not used intentionally,
140
+ * this symbol must not be used for other purposes.
141
+ */
142
+ __preinit_array_start = .; /* Used by crt0.S */
143
+
144
+ /*
145
+ * Used to run the system inits before anything else.
146
+ */
147
+ KEEP(*(.preinit_array_sysinit .preinit_array_sysinit.*))
148
+
149
+ /*
150
+ * Used for other platform inits.
151
+ */
152
+ KEEP(*(.preinit_array_platform .preinit_array_platform.*))
153
+
154
+ /*
155
+ * The application inits. If you need to enforce some order in
156
+ * execution, create new sections, as before.
157
+ */
158
+ KEEP(*(.preinit_array .preinit_array.*))
159
+
160
+ __preinit_array_end = .; /* Used by crt0.S */
161
+ } >RAM
162
+
163
+ /*
164
+ * The init code, i.e. an array of pointers to static constructors.
165
+ */
166
+ .init_array : ALIGN(4)
167
+ {
168
+ /* PROVIDE not used intentionally, this symbol must not be used */
169
+ __init_array_start = .; /* Used by crt0.S */
170
+
171
+ KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
172
+ KEEP(*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
173
+
174
+ __init_array_end = .; /* Used by crt0.S */
175
+ } >RAM
176
+
177
+ /*
178
+ * The fini code, i.e. an array of pointers to static destructors.
179
+ */
180
+ .fini_array : ALIGN(4)
181
+ {
182
+ /* PROVIDE not used intentionally, this symbol must not be used. */
183
+ __fini_array_start = .; /* Standard newlib definition. */
184
+
185
+ KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
186
+ KEEP(*(.fini_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
187
+
188
+ __fini_array_end = .; /* Standard newlib definition. */
189
+ } >RAM
190
+
191
+ /*
192
+ * The program code.
193
+ */
194
+ .text : ALIGN(4)
195
+ {
196
+ *(.text.unlikely .text.unlikely.*)
197
+ *(.text.startup .text.startup.*)
198
+ *(.text .text.*)
199
+ *(.gnu.linkonce.t.*)
200
+ } >RAM
201
+
202
+
203
+ /*
204
+ * Mandatory for _init() to work, with crt0.
205
+ * Called in __libc_fini_array().
206
+ */
207
+ .init : ALIGN(4)
208
+ {
209
+ KEEP (*(.init))
210
+ } >RAM
211
+
212
+ /*
213
+ * Mandatory for _fini() to work, with crt0.
214
+ * Called in __libc_fini_array().
215
+ */
216
+ .fini : ALIGN(4)
217
+ {
218
+ KEEP (*(.fini))
219
+ } >RAM
220
+
221
+ . = ALIGN(4);
222
+ PROVIDE(__etext = .);
223
+ PROVIDE(_etext = .);
224
+ PROVIDE(etext = .);
225
+
226
+ /*
227
+ * C++ virtual tables.
228
+ */
229
+ .vtable : ALIGN(4)
230
+ {
231
+ KEEP(*(vtable))
232
+ } >RAM
233
+
234
+ /*
235
+ * Exception frames.
236
+ */
237
+ .exceptions : ALIGN(4)
238
+ {
239
+ KEEP(*(.eh_frame*))
240
+ *(.gcc_except_table)
241
+ } >RAM
242
+
243
+ /*
244
+ * Stub sections generated by the linker, to glue together
245
+ * ARM and Thumb code. .glue_7 is used for ARM code calling
246
+ * Thumb code, and .glue_7t is used for Thumb code calling
247
+ * ARM code. Apparently always generated by the linker, for some
248
+ * architectures, so better leave them here.
249
+ */
250
+ .glue : ALIGN(4)
251
+ {
252
+ *(.glue_7)
253
+ *(.glue_7t)
254
+ } >RAM
255
+
256
+ /*
257
+ * Read-only data (constants)
258
+ */
259
+ .rodata : ALIGN(4)
260
+ {
261
+ *(.rodata .rodata.*)
262
+ *(.constdata .constdata.*)
263
+ *(.gnu.linkonce.r.*)
264
+ } >RAM
265
+
266
+ . = ALIGN(4);
267
+ PROVIDE( _data = . );
268
+
269
+ /*
270
+ * The initialised data section.
271
+ *
272
+ * The program executes knowing that the data is in RAM
273
+ * but the loader puts the initial values in FLASH.
274
+ * The startup will copy the initial values from FLASH to RAM.
275
+ */
276
+ .data : ALIGN(4)
277
+ {
278
+ FILL(0xFF)
279
+
280
+ __data_start__ = . ; /* Standard newlib definition. */
281
+ __data_begin__ = . ; /* µOS++ specific */
282
+ *(.data_begin .data_begin.*) /* µOS++ __data_begin_guard */
283
+
284
+ . = ALIGN(8);
285
+ /*
286
+ * RISC-V specific; the compiler optimises memory accesses
287
+ * in the +/- 2K range around __global_pointer$ to GP relative.
288
+ * For this to work, GP must be loaded during startup with the
289
+ * address of __global_pointer$.
290
+ * This optimisation favours a 4K range. Newlib places
291
+ * several impure and malloc pointers in the .sdata section.
292
+ */
293
+ PROVIDE( __global_pointer$ = . + (4K / 2) );
294
+
295
+ *(.data .data.*)
296
+ *(.gnu.linkonce.d.*)
297
+
298
+ *(.sdata .sdata.*)
299
+ *(.gnu.linkonce.s.*)
300
+
301
+ *(.data_end .data_end.*) /* µOS++ __data_end_guard; must be last */
302
+ . = ALIGN(4);
303
+ __data_end__ = . ; /* Standard newlib definition. */
304
+ } >RAM
305
+
306
+ /*
307
+ * This address is used by the µOS++ startup code to
308
+ * initialise the .data section.
309
+ */
310
+ __data_load_addr__ = LOADADDR(.data);
311
+
312
+ . = ALIGN(4);
313
+ PROVIDE( __edata = . );
314
+ PROVIDE( _edata = . );
315
+ PROVIDE( edata = . );
316
+
317
+ /*
318
+ * The uninitialised data sections. NOLOAD is used to avoid
319
+ * the "section `.bss' type changed to PROGBITS" warning
320
+ */
321
+
322
+ /* The primary uninitialised data section. */
323
+ .bss (NOLOAD) : ALIGN(4)
324
+ {
325
+ __bss_start = .; /* Standard newlib definition. */
326
+ __bss_start__ = .; /* Standard newlib definition. */
327
+ __bss_begin__ = .; /* µOS++ specific */
328
+ *(.bss_begin .bss_begin.*) /* µOS++ __bss_begin_guard */
329
+
330
+ *(.sbss .sbss.*)
331
+ *(.gnu.linkonce.sb.*)
332
+
333
+ *(.bss .bss.*)
334
+ *(.gnu.linkonce.b.*)
335
+ *(COMMON)
336
+
337
+ *(.bss_end .bss_end.*) /* µOS++ __bss_end_guard; must be last */
338
+ . = ALIGN(4);
339
+ __bss_end__ = .; /* Standard newlib definition. */
340
+ __bss_end = .; /* Standard newlib definition. */
341
+ } >RAM
342
+
343
+ /*
344
+ * Similar to .bss, but not initialised to zero. µOS++ extension.
345
+ */
346
+ .noinit (NOLOAD) : ALIGN(4)
347
+ {
348
+ __noinit_begin__ = .; /* µOS++ extension. */
349
+
350
+ *(.noinit .noinit.*)
351
+
352
+ . = ALIGN(4) ;
353
+ __noinit_end__ = .; /* µOS++ extension. */
354
+ } >RAM
355
+
356
+ /* _sbrk() expects at least word alignment. */
357
+ . = ALIGN(8);
358
+ PROVIDE( __end__ = . ); /* Used by crt0.S arm & aarch64 */
359
+ PROVIDE( __end = . ); /* Used by crt0.S sparc, m68k */
360
+ PROVIDE( _end = . ); /* Used by libgloss sbrk() */
361
+ PROVIDE( end = . ); /* Used by newlib _sbrk() arm & aarch64 */
362
+
363
+ PROVIDE( __heap_begin__ = . ); /* µOS++ extension. */
364
+
365
+ /*
366
+ * It should generate an error if the heap overrides the stack.
367
+ */
368
+ .stack __stack - __stack_size :
369
+ {
370
+ PROVIDE( _heap_end = . ); /* Used by sbrk in some architectures */
371
+ PROVIDE( _heap_end_ = . ); /* Used by sbrk in some architectures */
372
+ PROVIDE( __heap_end = . ); /* Used by sbrk in some architectures */
373
+
374
+ PROVIDE( __heap_end__ = . ); /* µOS++ extension. */
375
+
376
+ /*
377
+ * libgloss also uses `__heap_limit` in _sbrk(), initially set to
378
+ * 0xcafedead and later updated to the value returned by SYS_HEAPINFO.
379
+ */
380
+ . += __stack_size;
381
+ } >RAM
382
+
383
+ /* ---------------------------------------------------------------------- */
384
+ /* After that there are only debugging sections. */
385
+
386
+ /*
387
+ * Stabs debugging sections.
388
+ */
389
+ .stab 0 : { *(.stab) }
390
+ .stabstr 0 : { *(.stabstr) }
391
+ .stab.excl 0 : { *(.stab.excl) }
392
+ .stab.exclstr 0 : { *(.stab.exclstr) }
393
+ .stab.index 0 : { *(.stab.index) }
394
+ .stab.indexstr 0 : { *(.stab.indexstr) }
395
+ .comment 0 : { *(.comment) }
396
+
397
+ /*
398
+ * DWARF debug sections.
399
+ * Symbols in the DWARF debugging sections are relative to the beginning
400
+ * of the section so we begin them at 0.
401
+ */
402
+
403
+ /* DWARF 1 */
404
+ .debug 0 : { *(.debug) }
405
+ .line 0 : { *(.line) }
406
+ /* GNU DWARF 1 extensions */
407
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
408
+ .debug_sfnames 0 : { *(.debug_sfnames) }
409
+ /* DWARF 1.1 and DWARF 2 */
410
+ .debug_aranges 0 : { *(.debug_aranges) }
411
+ .debug_pubnames 0 : { *(.debug_pubnames) }
412
+ /* DWARF 2 */
413
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
414
+ .debug_abbrev 0 : { *(.debug_abbrev) }
415
+ .debug_line 0 : { *(.debug_line) }
416
+ .debug_frame 0 : { *(.debug_frame) }
417
+ .debug_str 0 : { *(.debug_str) }
418
+ .debug_loc 0 : { *(.debug_loc) }
419
+ .debug_macinfo 0 : { *(.debug_macinfo) }
420
+ /* SGI/MIPS DWARF 2 extensions */
421
+ .debug_weaknames 0 : { *(.debug_weaknames) }
422
+ .debug_funcnames 0 : { *(.debug_funcnames) }
423
+ .debug_typenames 0 : { *(.debug_typenames) }
424
+ .debug_varnames 0 : { *(.debug_varnames) }
425
+ }