blob: acab70c9ecb8d9601503afe61cfb3f26af9a1664 [file] [log] [blame]
Furquan Shaikhe5d014c2014-07-07 11:45:15 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Furquan Shaikhe5d014c2014-07-07 11:45:15 -070014 */
15
16/* Macro to initialize stack, perform seeding if required and finally call the
17 * function provided
Julius Wernerec5e5e02014-08-20 15:29:56 -070018 * @stack_top : First address above the stack
19 * @stack_bottom : Lowest address on the stack
20 * @seed : Stack seeding required (1=yes/otherwise=no)
21 * @func : Function to call after initializing stack
Furquan Shaikhe5d014c2014-07-07 11:45:15 -070022 */
Julius Wernerec5e5e02014-08-20 15:29:56 -070023.macro stack_init stack_top, stack_bottom, seed, func
Furquan Shaikhe5d014c2014-07-07 11:45:15 -070024 /* Check if stack seeding is required */
25 mov r0, #\seed
26 cmp r0, #1
27 bne call_func
28 /* Stack seeding */
Julius Wernerec5e5e02014-08-20 15:29:56 -070029 ldr r0, =\stack_bottom
30 ldr r1, =\stack_top
Furquan Shaikhe5d014c2014-07-07 11:45:15 -070031 ldr r2, =0xdeadbeef
32init_stack_loop:
33 str r2, [r0]
34 add r0, #4
35 cmp r0, r1
36 bne init_stack_loop
37
38call_func:
Julius Wernerec5e5e02014-08-20 15:29:56 -070039 ldr sp, =\stack_top /* Set up stack pointer */
Furquan Shaikhe5d014c2014-07-07 11:45:15 -070040 bl \func
41.endm