]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Include/AsmMacroIoLib.h
ArmPkg/AsmMacroIoLib: force word alignment for functions
[mirror_edk2.git] / ArmPkg / Include / AsmMacroIoLib.h
1 /** @file
2 Macros to work around lack of Apple support for LDR register, =expr
3
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
7
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18
19 #ifndef __MACRO_IO_LIB_H__
20 #define __MACRO_IO_LIB_H__
21
22 #if defined(__APPLE__)
23
24 //
25 // ldr reg, =expr does not work with current Apple tool chain. So do the work our selves
26 //
27
28 // load _Reg with _Data
29 #define LoadConstantToReg(_Data, _Reg) \
30 ldr _Reg, [pc, #0] ; \
31 b 1f ; \
32 .long (_Data) ; \
33 1:
34
35 #elif defined (__GNUC__)
36
37 #define LoadConstantToReg(Data, Reg) \
38 ldr Reg, =Data
39
40 #else
41
42 //
43 // Use ARM assembly macros, form armasam
44 //
45 // Less magic in the macros if ldr reg, =expr works
46 //
47
48 // load _Reg with _Data
49
50
51 #define LoadConstantToReg(Data, Reg) LoadConstantToRegMacro Data, Reg
52
53 #endif
54
55 #define _ASM_FUNC(Name, Section) \
56 .global Name ; \
57 .section #Section, "ax" ; \
58 .type Name, %function ; \
59 .p2align 2 ; \
60 Name:
61
62 #define ASM_FUNC(Name) _ASM_FUNC(ASM_PFX(Name), .text. ## Name)
63
64 #define MOV32(Reg, Val) \
65 movw Reg, #(Val) & 0xffff ; \
66 movt Reg, #(Val) >> 16
67
68 #define ADRL(Reg, Sym) \
69 movw Reg, #:lower16:(Sym) - (. + 16) ; \
70 movt Reg, #:upper16:(Sym) - (. + 12) ; \
71 add Reg, Reg, pc
72
73 #define LDRL(Reg, Sym) \
74 movw Reg, #:lower16:(Sym) - (. + 16) ; \
75 movt Reg, #:upper16:(Sym) - (. + 12) ; \
76 ldr Reg, [pc, Reg]
77
78 #endif