blob: e4d4f1254ab742e0013c7250135994b894e28ffd [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_END__ = .;
17 } >RAM
18
19#ifdef BL31_PROGBITS_LIMIT
20 ASSERT(__INIT_CODE_END__ <= BL31_PROGBITS_LIMIT,
21 "BL31 init has exceeded progbits limit.")
22#endif
23
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010024 ASSERT(__INIT_CODE_END__ <= __STACKS_END__,
25 "Init code ends past the end of the stacks")
Ambroise Vincente8b10e22019-07-16 17:19:38 +010026
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010027}
28
Alexei Fedorov490ace72020-05-30 17:33:26 +010029#undef MIN
30#define ABS ABSOLUTE
31#define COUNT PLATFORM_CORE_COUNT
32#define ALIGN_MASK ~(CACHE_WRITEBACK_GRANULE - 1)
33
34#define PRIMARY_STACK \
35 __STACKS_START__ = .; \
36 *(tzfw_normal_stacks) \
37 OFFSET = ABS(SIZEOF(.init) - (. - __STACKS_START__)); \
38 /* Offset sign */ \
39 SIGN = ABS(OFFSET) & (1 << 63); \
40 /* Offset mask */ \
41 MASK = ABS(SIGN >> 63) - 1; \
42 . += ABS(OFFSET) & ABS(MASK); \
Alexei Fedorov2a0c36f2020-07-21 17:07:45 +010043 . = ALIGN(PAGE_SIZE); \
Alexei Fedorov490ace72020-05-30 17:33:26 +010044 __STACKS_END__ = .; \
45 /* Total stack size */ \
46 SIZE = ABS(. - __STACKS_START__); \
47 /* Maximum primary CPU stack */ \
48 STACK = ABS(__STACKS_START__ + SIZE / COUNT) & ALIGN_MASK; \
49 /* Primary CPU stack */ \
50 __PRIMARY_STACK__ = MIN(STACK, ABS(__INIT_CODE_START__));
51
52#if (COUNT > 1)
53#define SECONDARY_STACK \
54 /* Size of the secondary CPUs' stack */ \
55 REST = ABS(__STACKS_END__ - __PRIMARY_STACK__); \
56 /* Secondary per-CPU stack size */ \
57 __STACK_SIZE__ = ABS(REST / (COUNT - 1));
58#else
59#define SECONDARY_STACK
60#endif
61
62#define STACK_SECTION \
63 stacks (NOLOAD) : { \
64 PRIMARY_STACK \
65 SECONDARY_STACK \
66 }
Daniel Boulbyb1b058d2018-09-18 11:52:49 +010067#endif /* ARM_RECLAIM_INIT_LD_S */