1/*
2 * Copyright 2020 Broadcom.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_MACRO_INC_
8#define ZEPHYR_INCLUDE_ARCH_ARM64_MACRO_INC_
9
10#ifdef _ASMLANGUAGE
11
12.macro	switch_el, xreg, el3_label, el2_label, el1_label
13	mrs	\xreg, CurrentEL
14	cmp	\xreg, 0xc
15	beq	\el3_label
16	cmp	\xreg, 0x8
17	beq	\el2_label
18	cmp	\xreg, 0x4
19	beq	\el1_label
20.endm
21
22/*
23 * macro to support mov of immediate constant to 64 bit register
24 * It will generate instruction sequence of 'mov'/ 'movz' and one
25 * to three 'movk' depending on the immediate value.
26 */
27.macro mov_imm, xreg, imm
28	.if ((\imm) == 0)
29		mov	\xreg, \imm
30	.else
31		.if (((\imm) >> 31) == 0 || ((\imm) >> 31) == 0x1ffffffff)
32			movz    \xreg, (\imm >> 16) & 0xffff, lsl 16
33		.else
34			.if (((\imm) >> 47) == 0 || ((\imm) >> 47) == 0x1ffff)
35				movz    \xreg, (\imm >> 32) & 0xffff, lsl 32
36			.else
37				movz    \xreg, (\imm >> 48) & 0xffff, lsl 48
38				movk    \xreg, (\imm >> 32) & 0xffff, lsl 32
39			.endif
40			movk    \xreg, (\imm >> 16) & 0xffff, lsl 16
41		.endif
42		movk    \xreg, (\imm) & 0xffff, lsl 0
43	.endif
44.endm
45#endif /* _ASMLANGUAGE */
46
47#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_MACRO_INC_ */
48