1 /** @file
2   Macros to work around lack of Clang support for LDR register, =expr
3 
4   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5   Portions copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
6   Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
7 
8   SPDX-License-Identifier: BSD-2-Clause-Patent
9 
10 **/
11 
12 
13 #ifndef __MACRO_IO_LIBV8_H__
14 #define __MACRO_IO_LIBV8_H__
15 
16 // CurrentEL : 0xC = EL3; 8 = EL2; 4 = EL1
17 // This only selects between EL1 and EL2, else we die.
18 // Provide the Macro with a safe temp xreg to use.
19 #define EL1_OR_EL2(SAFE_XREG)        \
20         mrs    SAFE_XREG, CurrentEL ;\
21         cmp    SAFE_XREG, #0x8      ;\
22         b.gt   .                    ;\
23         b.eq   2f                   ;\
24         cbnz   SAFE_XREG, 1f        ;\
25         b      .                    ;// We should never get here
26 
27 
28 // CurrentEL : 0xC = EL3; 8 = EL2; 4 = EL1
29 // This only selects between EL1 and EL2 and EL3, else we die.
30 // Provide the Macro with a safe temp xreg to use.
31 #define EL1_OR_EL2_OR_EL3(SAFE_XREG) \
32         mrs    SAFE_XREG, CurrentEL ;\
33         cmp    SAFE_XREG, #0x8      ;\
34         b.gt   3f                   ;\
35         b.eq   2f                   ;\
36         cbnz   SAFE_XREG, 1f        ;\
37         b      .                    ;// We should never get here
38 
39 #define _ASM_FUNC(Name, Section)    \
40   .global   Name                  ; \
41   .section  #Section, "ax"        ; \
42   .type     Name, %function       ; \
43   Name:
44 
45 #define ASM_FUNC(Name)            _ASM_FUNC(ASM_PFX(Name), .text. ## Name)
46 
47 #define MOV32(Reg, Val)                   \
48   movz      Reg, (Val) >> 16, lsl #16   ; \
49   movk      Reg, (Val) & 0xffff
50 
51 #define MOV64(Reg, Val)                             \
52   movz      Reg, (Val) >> 48, lsl #48             ; \
53   movk      Reg, ((Val) >> 32) & 0xffff, lsl #32  ; \
54   movk      Reg, ((Val) >> 16) & 0xffff, lsl #16  ; \
55   movk      Reg, (Val) & 0xffff
56 
57 #endif // __MACRO_IO_LIBV8_H__
58