2020#include < zephyr/linker/linker-tool.h>
2121
2222#define RAMABLE_REGION RAM :sram0_phdr
23- #define ROMABLE_REGION rom0_seg :rom0_phdr
23+ #define ROMABLE_REGION RAM :sram0_phdr
2424
2525#ifdef CONFIG_MMU
2626#define MMU_PAGE_ALIGN . = ALIGN (CONFIG_MMU_PAGE_SIZE);
@@ -287,6 +287,9 @@ SECTIONS
287287 _DoubleExceptionVector_text_end = ABSOLUTE (.);
288288 } >sram0_18_seg :sram0_18_phdr
289289
290+ #define LIB_OBJ_FUNC_IN_SECT (library, obj_file, func ) \
291+ *##library## :##obj_file##(.literal .##func .text .##func) \
292+
290293#ifdef CONFIG_XTENSA_MMU
291294 .vec_helpers :
292295 {
@@ -301,48 +304,45 @@ SECTIONS
301304 * TLB multi-hit exception.
302305 */
303306
304- *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.literal )
305- *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.text )
306- *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.iram .text )
307- *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.iram0 .text )
307+ *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.literal .text )
308+ *libarch__xtensa__core.a :xtensa-asm2-util.S .obj (.iram .text .iram0 .text )
308309
309310 *libarch__xtensa__core.a :window_vectors.S .obj (.iram .text )
310311
311- *libarch__xtensa__core.a :xtensa-asm2.c .obj (.literal .*)
312- *libarch__xtensa__core.a :xtensa-asm2.c .obj (.text .*)
313-
314- *libarch__xtensa__core.a :fatal.c .obj (.literal .*)
315- *libarch__xtensa__core.a :fatal.c .obj (.text .*)
316-
317- *libarch__xtensa__core.a :crt1.S .obj (.literal )
318- *libarch__xtensa__core.a :crt1.S .obj (.text )
312+ *libarch__xtensa__core.a :crt1.S .obj (.literal .text )
319313
320- *libarch__xtensa__core.a :cpu_idle.c .obj (.literal .*)
321- *libarch__xtensa__core.a :cpu_idle.c .obj (.text .*)
314+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,xtensa-asm2.c .obj ,*)
315+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,fatal.c .obj ,*)
316+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,cpu_idle.c .obj ,*)
322317
323318 *(.text .arch_is_in_isr )
324319
325320 /* To support backtracing */
326- *libarch__xtensa__core.a :xtensa_backtrace.c .obj (.literal .*)
327- *libarch__xtensa__core.a :xtensa_backtrace.c .obj (.text .*)
328- *libarch__xtensa__core.a :debug_helpers_asm.S .obj (.iram1 .literal )
329- *libarch__xtensa__core.a :debug_helpers_asm.S .obj (.iram1 )
321+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,xtensa_backtrace.c .obj ,*)
330322
331- *libkernel.a :fatal.c .obj (.literal .*)
332- *libkernel.a :fatal.c .obj (.text .*)
323+ *libarch__xtensa__core.a :debug_helpers_asm.S .obj (.iram1 .literal .iram1 )
324+
325+ /* Userspace related stuff */
326+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,userspace.S .obj ,z_xtensa_do_syscall)
327+ LIB_OBJ_FUNC_IN_SECT (libarch__xtensa__core.a ,xtensa_mmu.c .obj ,z_xtensa_swap_update_page_tables)
333328
334329 /* Below are to speed up execution by avoiding TLB misses
335330 * on frequently used functions.
331+ *
332+ * There is almost 1MB space (due to TLB pinning) so we can
333+ * be generous.
336334 */
337- *libkernel.a :sched.c .obj (.literal .*)
338- *libkernel.a :sched.c .obj (.text .*)
339- *libkernel.a :timeout.c .obj (.literal .*)
340- *libkernel.a :timeout.c .obj (.text .*)
341-
342- *libdrivers__console.a :(.literal .*)
343- *libdrivers__console.a :(.text .*)
344- *libdrivers__timer.a :(.literal .*)
345- *libdrivers__timer.a :(.text .*)
335+ LIB_OBJ_FUNC_IN_SECT (libkernel.a ,,*)
336+
337+ LIB_OBJ_FUNC_IN_SECT (libdrivers__console.a ,,*)
338+ LIB_OBJ_FUNC_IN_SECT (libdrivers__timer.a ,,*)
339+
340+ *(.literal .z_vrfy_ * .text .z_vrfy_ *)
341+ *(.literal .z_mrsh_ * .text .z_mrsh_ *)
342+ *(.literal .z_impl_ * .text .z_impl_ *)
343+ *(.literal .z_obj_ * .text .z_obj_ *)
344+
345+ *(.literal .k_sys_fatal_error_handler .text .k_sys_fatal_error_handler )
346346 } >vec_helpers :vec_helpers_phdr
347347#endif /* CONFIG_XTENSA_MMU */
348348
@@ -380,7 +380,7 @@ SECTIONS
380380
381381 _text_end = ABSOLUTE (.);
382382 _etext = .;
383- } >RAM :sram0_phdr
383+ } >RAMABLE_REGION
384384 __text_region_end = .;
385385
386386 .rodata : HDR_MMU_PAGE_ALIGN
@@ -394,7 +394,16 @@ SECTIONS
394394 . = ALIGN (4 );
395395 #include < snippets-rodata.ld>
396396 #include < zephyr/linker/kobject-rom.ld>
397+ } >RAMABLE_REGION
398+
399+ #include < zephyr/linker/common-rom.ld>
400+
401+ #include < zephyr/linker/thread-local-storage.ld>
397402
403+ #include < zephyr/linker/cplusplus-rom.ld>
404+
405+ .rodata_end : ALIGN (4 )
406+ {
398407 . = ALIGN (4 ); /* this table MUST be 4-byte aligned */
399408 _bss_table_start = ABSOLUTE (.);
400409 LONG (_bss_start)
@@ -404,19 +413,26 @@ SECTIONS
404413 MMU_PAGE_ALIGN
405414
406415 __rodata_region_end = ABSOLUTE (.);
407- } >RAM :sram0_phdr
416+ } >RAMABLE_REGION
408417
409- #include < zephyr/linker/common-rom.ld>
418+ #ifdef CONFIG_USERSPACE
419+ #define SMEM_PARTITION_ALIGN (size ) MMU_PAGE_ALIGN
420+ #define APP_SHARED_ALIGN MMU_PAGE_ALIGN
410421
411- #include < zephyr/linker/thread-local-storage .ld>
422+ #include < app_smem .ld>
412423
413- #include < zephyr/linker/cplusplus-rom.ld>
414-
415- #include < snippets-sections.ld>
424+ _image_ram_start = _app_smem_start;
425+ _app_smem_size = _app_smem_end - _app_smem_start;
426+ _app_smem_num_words = _app_smem_size >> 2 ;
427+ _app_smem_rom_start = LOADADDR (_APP_SMEM_SECTION_NAME);
428+ _app_smem_num_words = _app_smem_size >> 2 ;
429+ #endif /* CONFIG_USERSPACE */
416430
417431 .data : HDR_MMU_PAGE_ALIGN
418432 {
433+ #ifndef CONFIG_USERSPACE
419434 _image_ram_start = ABSOLUTE (.);
435+ #endif
420436 __data_start = ABSOLUTE (.);
421437 *(.data )
422438 *(.data .*)
@@ -438,7 +454,9 @@ SECTIONS
438454 MMU_PAGE_ALIGN
439455
440456 __data_end = ABSOLUTE (.);
441- } >RAM :sram0_phdr
457+ } >RAMABLE_REGION
458+
459+ #include < snippets-sections.ld>
442460
443461#include < snippets-data-sections.ld>
444462
0 commit comments