blob: 03976f34f6b397cde96635252cd63c0994587706 [file] [log] [blame]
Daniel Boulbyb1b058d2018-09-18 11:52:49 +01001/*
Alexei Fedorov490ace72020-05-30 17:33:26 +01002 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Daniel Boulbyb1b058d2018-09-18 11:52:49 +01003 *
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__ = .;
Alexei Fedorov490ace72020-05-30 17:33:26 +010015 *(*text.init*);
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010016 __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
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010026 ASSERT(__INIT_CODE_END__ <= __STACKS_END__,
27 "Init code ends past the end of the stacks")
Ambroise Vincente8b10e22019-07-16 17:19:38 +010028
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010029}
30
Alexei Fedorov490ace72020-05-30 17:33:26 +010031#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 }
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010068#endif /* ARM_RECLAIM_INIT_LD_S */