Daniel Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Daniel Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #ifndef ARM_RECLAIM_INIT_LD_S |
| 7 | #define ARM_RECLAIM_INIT_LD_S |
| 8 | |
| 9 | SECTIONS |
| 10 | { |
| 11 | .init __STACKS_START__ : { |
| 12 | . = . + PLATFORM_STACK_SIZE; |
| 13 | . = ALIGN(PAGE_SIZE); |
| 14 | __INIT_CODE_START__ = .; |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 15 | *(*text.init*); |
Daniel Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 16 | __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 Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 24 | ASSERT(__INIT_CODE_END__ <= __STACKS_END__, |
| 25 | "Init code ends past the end of the stacks") |
Ambroise Vincent | e8b10e2 | 2019-07-16 17:19:38 +0100 | [diff] [blame] | 26 | |
Daniel Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 27 | } |
| 28 | |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 29 | #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 Fedorov | 2a0c36f | 2020-07-21 17:07:45 +0100 | [diff] [blame] | 43 | . = ALIGN(PAGE_SIZE); \ |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 44 | __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 Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 67 | #endif /* ARM_RECLAIM_INIT_LD_S */ |