1/*
2 * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9
10.global rcar_pwrc_switch_stack
11
12/*
13 * x0 : jump address,
14 * x1 : stack address,
15 * x2 : arg,
16 * x3 : stack address (temporary)
17 */
18func rcar_pwrc_switch_stack
19
20	/* lr to stack */
21	stp	x29, x30, [sp,#-16]
22
23	/* change stack pointer */
24	mov	x3, sp
25	mov	sp, x1
26
27	/* save stack pointer */
28	sub	sp, sp, #16
29	stp	x0, x3, [sp]
30
31	/* data synchronization barrier */
32	dsb	sy
33
34	/* jump to code */
35	mov	x1, x0
36	mov	x0, x2
37	blr	x1
38
39	/* load stack pointer */
40	ldp 	x0, x2, [sp,#0]
41
42	/* change stack pointer */
43	mov	sp, x2
44
45	/* return */
46	ldp	x29, x30, [sp,#-16]
47	ret
48endfunc rcar_pwrc_switch_stack
49