1/* SPDX-License-Identifier: Apache-2.0 */
2
3#include <zephyr/linker/iterable_sections.h>
4
5	SECTION_PROLOGUE(initlevel,,)
6	{
7		/*
8		 * link in initialization objects for all objects that are
9		 * automatically initialized by the kernel; the objects are
10		 * sorted in the order they will be initialized (i.e. ordered
11		 * by level, sorted by priority within a level)
12		 */
13		__init_start = .;
14		CREATE_OBJ_LEVEL(init, EARLY)
15		CREATE_OBJ_LEVEL(init, PRE_KERNEL_1)
16		CREATE_OBJ_LEVEL(init, PRE_KERNEL_2)
17		CREATE_OBJ_LEVEL(init, POST_KERNEL)
18		CREATE_OBJ_LEVEL(init, APPLICATION)
19		CREATE_OBJ_LEVEL(init, SMP)
20		__init_end = .;
21		__deferred_init_list_start = .;
22		KEEP(*(.z_deferred_init*))
23		__deferred_init_list_end = .;
24	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
25
26	ITERABLE_SECTION_ROM_NUMERIC(device, Z_LINK_ITERABLE_SUBALIGN)
27
28#if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_SHARED_INTERRUPTS)
29	/* since z_shared_isr() is not referenced anywhere when
30	 * zephyr_pre0.elf is built, the linker will end up dropping it.
31	 * Later on, during the second linking stage (when zephyr.elf is
32	 * built), the symbol will be added to the text section since it's
33	 * now being referenced (thanks to isr_tables.c). This is very
34	 * problematic because adding the z_shared_isr symbol between
35	 * the linking stages will end up shifting the addresses of the
36	 * functions, which, in turn, will end up messing the ISR table
37	 * (as the entries from _sw_isr_table will end up pointing to
38	 * old addresses of the registered ISRs). To prevent this from
39	 * happening, instruct the linker to avoid dropping z_shared_isr
40	 * if it's not being referenced anywhere.
41	 */
42	SECTION_PROLOGUE(.text.z_shared_isr,,)
43	{
44		KEEP(*(.text.z_shared_isr*))
45	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
46#endif
47
48#if defined(CONFIG_GEN_SW_ISR_TABLE) && !defined(CONFIG_DYNAMIC_INTERRUPTS)
49	SECTION_PROLOGUE(sw_isr_table,,)
50	{
51		/*
52		 * Some arch requires an entry to be aligned to arch
53		 * specific boundary for using double word load
54		 * instruction.  See include/sw_isr_table.h.
55		 */
56		. = ALIGN(CONFIG_ARCH_SW_ISR_TABLE_ALIGN);
57		*(_SW_ISR_TABLE_SECTION_SYMS)
58	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
59
60#if defined(CONFIG_SHARED_INTERRUPTS)
61	SECTION_PROLOGUE(shared_sw_isr_table,,)
62	{
63		/* TODO: does this section require alignment? */
64		KEEP(*(_SHARED_SW_ISR_TABLE_SECTION_SYMS))
65	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
66#endif
67
68#endif
69
70	/* verify we don't have rogue .z_init_<something> initlevel sections */
71	SECTION_PROLOGUE(initlevel_error,,)
72	{
73		KEEP(*(SORT(.z_init_[_A-Z0-9]*)))
74	}
75	ASSERT(SIZEOF(initlevel_error) == 0, "Undefined initialization levels used.")
76
77#ifdef CONFIG_USERSPACE
78	/* Build-time assignment of permissions to kernel objects to
79	 * threads declared with K_THREAD_DEFINE()
80	 */
81	ITERABLE_SECTION_ROM(k_object_assignment, Z_LINK_ITERABLE_SUBALIGN)
82#endif
83
84	SECTION_DATA_PROLOGUE(app_shmem_regions,,)
85	{
86		__app_shmem_regions_start = .;
87		KEEP(*(SORT(.app_regions.*)));
88		__app_shmem_regions_end = .;
89	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
90
91	ITERABLE_SECTION_ROM(k_p4wq_initparam, Z_LINK_ITERABLE_SUBALIGN)
92
93	ITERABLE_SECTION_ROM(_static_thread_data, Z_LINK_ITERABLE_SUBALIGN)
94
95#if defined(CONFIG_PCIE)
96	ITERABLE_SECTION_ROM(irq_alloc, Z_LINK_ITERABLE_SUBALIGN)
97#endif /* CONFIG_PCIE */
98
99#if !defined(CONFIG_DEVICE_DEPS_DYNAMIC)
100	SECTION_DATA_PROLOGUE(device_deps,,)
101	{
102#include <zephyr/linker/device-deps.ld>
103	} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
104#endif /* !CONFIG_DEVICE_DEPS_DYNAMIC */
105
106#include <device-api-sections.ld>
107