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 
7   This program and the accompanying materials
8   are licensed and made available under the terms and conditions of the BSD License
9   which accompanies this distribution.  The full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.php
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 
18 #ifndef __MACRO_IO_LIBV8_H__
19 #define __MACRO_IO_LIBV8_H__
20 
21 // CurrentEL : 0xC = EL3; 8 = EL2; 4 = EL1
22 // This only selects between EL1 and EL2, else we die.
23 // Provide the Macro with a safe temp xreg to use.
24 #define EL1_OR_EL2(SAFE_XREG)        \
25         mrs    SAFE_XREG, CurrentEL ;\
26         cmp    SAFE_XREG, #0x8      ;\
27         b.eq   2f                   ;\
28         cmp    SAFE_XREG, #0x4      ;\
29         b.ne   .                    ;// We should never get here
30 // EL1 code starts here
31 
32 // CurrentEL : 0xC = EL3; 8 = EL2; 4 = EL1
33 // This only selects between EL1 and EL2 and EL3, else we die.
34 // Provide the Macro with a safe temp xreg to use.
35 #define EL1_OR_EL2_OR_EL3(SAFE_XREG) \
36         mrs    SAFE_XREG, CurrentEL ;\
37         cmp    SAFE_XREG, #0xC      ;\
38         b.eq   3f                   ;\
39         cmp    SAFE_XREG, #0x8      ;\
40         b.eq   2f                   ;\
41         cmp    SAFE_XREG, #0x4      ;\
42         b.ne   .                    ;// We should never get here
43 // EL1 code starts here
44 #if defined(__clang__)
45 
46 // load x0 with _Data
47 #define LoadConstant(_Data)              \
48   ldr  x0, 1f                          ; \
49   b    2f                              ; \
50 .align(8)                              ; \
51 1:                                       \
52   .8byte (_Data)                       ; \
53 2:
54 
55 // load _Reg with _Data
56 #define LoadConstantToReg(_Data, _Reg)    \
57   ldr  _Reg, 1f                         ; \
58   b    2f                               ; \
59 .align(8)                               ; \
60 1:                                        \
61   .8byte (_Data)                        ; \
62 2:
63 
64 #elif defined (__GNUC__)
65 
66 #define LoadConstant(Data) \
67   ldr  x0, =Data
68 
69 #define LoadConstantToReg(Data, Reg) \
70   ldr  Reg, =Data
71 
72 #endif // __GNUC__
73 
74 #endif // __MACRO_IO_LIBV8_H__
75 
76