xref: /rk3399_ARM-atf/include/plat/arm/common/arm_reclaim_init.ld.S (revision 0aa9f3c0f2f2ff675c3c12ae5ac6ceb475d6a16f)
1/*
2 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#ifndef ARM_RECLAIM_INIT_LD_S
7#define ARM_RECLAIM_INIT_LD_S
8
9SECTIONS
10{
11        .init __STACKS_START__ : {
12            . = . + PLATFORM_STACK_SIZE;
13            . = ALIGN(PAGE_SIZE);
14            __INIT_CODE_START__ = .;
15	    *(*text.init*);
16            __INIT_CODE_UNALIGNED__ = .;
17            .  = ALIGN(PAGE_SIZE);
18            __INIT_CODE_END__ = .;
19        } >RAM
20
21#ifdef BL31_PROGBITS_LIMIT
22    ASSERT(__INIT_CODE_END__ <= BL31_PROGBITS_LIMIT,
23            "BL31 init has exceeded progbits limit.")
24#endif
25
26    ASSERT(__INIT_CODE_END__ <= __STACKS_END__,
27        "Init code ends past the end of the stacks")
28
29}
30
31#undef	MIN
32#define	ABS		ABSOLUTE
33#define	COUNT		PLATFORM_CORE_COUNT
34#define	ALIGN_MASK	~(CACHE_WRITEBACK_GRANULE - 1)
35
36#define PRIMARY_STACK							\
37	__STACKS_START__ = .;						\
38	*(tzfw_normal_stacks)						\
39	OFFSET = ABS(SIZEOF(.init) - (. - __STACKS_START__));		\
40	/* Offset sign */						\
41	SIGN = ABS(OFFSET) & (1 << 63);					\
42	/* Offset mask */						\
43	MASK = ABS(SIGN >> 63) - 1;					\
44	. +=  ABS(OFFSET) & ABS(MASK);					\
45	__STACKS_END__ = .;						\
46	/* Total stack size */						\
47	SIZE = ABS(. - __STACKS_START__);				\
48	/* Maximum primary CPU stack */					\
49	STACK = ABS(__STACKS_START__ + SIZE / COUNT) & ALIGN_MASK;	\
50	/* Primary CPU stack */						\
51	__PRIMARY_STACK__ = MIN(STACK, ABS(__INIT_CODE_START__));
52
53#if (COUNT > 1)
54#define	SECONDARY_STACK					\
55	/* Size of the secondary CPUs' stack */		\
56	REST = ABS(__STACKS_END__ - __PRIMARY_STACK__);	\
57	/* Secondary per-CPU stack size */		\
58	__STACK_SIZE__ = ABS(REST / (COUNT - 1));
59#else
60#define	SECONDARY_STACK
61#endif
62
63#define STACK_SECTION		\
64	stacks (NOLOAD) : {	\
65		PRIMARY_STACK	\
66		SECONDARY_STACK	\
67	}
68#endif /* ARM_RECLAIM_INIT_LD_S */
69