Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 2 | |
| 3 | /* Macro to initialize stack, perform seeding if required and finally call the |
| 4 | * function provided |
| 5 | * @stack_top : First address above the stack |
| 6 | * @stack_bottom : Lowest address on the stack |
| 7 | * @seed : Stack seeding required (1=yes/otherwise=no) |
| 8 | * @func : Function to call after initializing stack |
| 9 | */ |
| 10 | .macro stack_init stack_top, stack_bottom, seed, func |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 11 | /* Check if stack seeding is required */ |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 12 | mov r0, #\seed |
| 13 | cmp r0, #1 |
| 14 | bne call_func |
| 15 | /* Stack seeding */ |
| 16 | ldr r0, =\stack_bottom |
| 17 | ldr r1, =\stack_top |
| 18 | ldr r2, =0xdeadbeef |
| 19 | init_stack_loop: |
| 20 | str r2, [r0] |
| 21 | add r0, #4 |
| 22 | cmp r0, r1 |
| 23 | bne init_stack_loop |
| 24 | |
| 25 | call_func: |
| 26 | ldr sp, =\stack_top /* Set up stack pointer */ |
| 27 | bl \func |
| 28 | .endm |