1/*
2 * Copyright (c) 2017,2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef CONFIG_USERSPACE
8#ifdef CONFIG_GEN_PRIV_STACKS
9	SECTION_DATA_PROLOGUE(priv_stacks_noinit,,)
10	{
11	z_priv_stacks_ram_start = .;
12
13	/* During LINKER_KOBJECT_PREBUILT and LINKER_ZEPHYR_PREBUILT,
14	 * space needs to be reserved for the rodata that will be
15	 * produced by gperf during the final stages of linking.
16	 * The alignment and size are produced by
17	 * scripts/gen_kobject_placeholders.py. These are here
18	 * so the addresses to kobjects would remain the same
19	 * during the final stages of linking (LINKER_ZEPHYR_FINAL).
20	 */
21
22#if defined(LINKER_ZEPHYR_PREBUILT)
23#include <linker-kobject-prebuilt-priv-stacks.h>
24#ifdef KOBJECT_PRIV_STACKS_ALIGN
25	. = ALIGN(KOBJECT_PRIV_STACKS_ALIGN);
26	. = . + KOBJECT_PRIV_STACKS_SZ;
27#endif
28#endif /* LINKER_ZEPHYR_PREBUILT */
29
30#if defined(LINKER_ZEPHYR_FINAL)
31#include <linker-kobject-prebuilt-priv-stacks.h>
32#ifdef KOBJECT_PRIV_STACKS_ALIGN
33	. = ALIGN(KOBJECT_PRIV_STACKS_ALIGN);
34#endif
35	*(".priv_stacks.noinit")
36#endif /* LINKER_ZEPHYR_FINAL */
37
38	z_priv_stacks_ram_end = .;
39
40#if defined(LINKER_ZEPHYR_FINAL)
41#ifdef KOBJECT_PRIV_STACKS_ALIGN
42	z_priv_stacks_ram_used = z_priv_stacks_ram_end - z_priv_stacks_ram_start;
43
44	ASSERT(z_priv_stacks_ram_used <= KOBJECT_PRIV_STACKS_SZ,
45"scripts/gen_kobject_placeholders.py did not reserve enough space \
46for priviledged stacks."
47	);
48
49	/* Padding is needed to preserve kobject addresses
50	 * if we have reserved more space than needed.
51	 */
52	. = MAX(., z_priv_stacks_ram_start + KOBJECT_PRIV_STACKS_SZ);
53#endif /* KOBJECT_PRIV_STACKS_ALIGN */
54#endif /* LINKER_ZEPHYR_FINAL */
55
56	} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
57#endif /* CONFIG_GEN_PRIV_STACKS */
58#endif /* CONFIG_USERSPACE */
59