AsmMacroIoLibV8.h 1.9 KB

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