diff mbox

[edk2,05/26] ArmPkg: introduce ASM_FUNC, MOV32/MOV64 and ADRL/LDRL macros

Message ID 1470842282-8415-6-git-send-email-ard.biesheuvel@linaro.org
State Accepted
Commit d2d0e27c7668017ef3d435a18e5d8008d36632d1
Headers show

Commit Message

Ard Biesheuvel Aug. 10, 2016, 3:17 p.m. UTC
This introduces the ASM_FUNC() macro to annotate function entry points
in assembler files. This allows us to add additional metadata that
marks a function entry point as a function, and allows us to emit
a .section directive for each function, which makes it possible for
the linker to drop unreferenced code.

In addition, introduce a couple of utility macros that we can use to
clean up the code.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmPkg/Include/AsmMacroIoLib.h   | 23 ++++++++++++++++++++
 ArmPkg/Include/AsmMacroIoLibV8.h | 20 ++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Ard Biesheuvel Aug. 10, 2016, 6:29 p.m. UTC | #1
On 10 August 2016 at 20:26, Cohen, Eugene <eugene@hp.com> wrote:
> Ard,

>

>> +#define _ASM_FUNC(Name, Section)    \

>> +  .global   Name                  ; \

>> +  .section  #Section, "ax"        ; \

>> +  .type     Name, %function       ; \

>> +  Name:

>> +

>> +#define ASM_FUNC(Name)            _ASM_FUNC(ASM_PFX(Name),

>> .text. ## Name)

>

> Why does this work?  In my experimentation the C preprocessor would collapse the stuff onto a single line (the backslash being a continuation on the preprocessor input, but preprocessor output revealed the newlines being removed), thereby violating the assembly requirement that labels appear in column 1.

>


I have tested this with both GNU as and Clang, and neither complains.
Is this requirement documented anywhere?

> Thanks for all your work on this, now I'm just trying to understand what I'm looking at!

>


Sure, my pleasure :-)
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/ArmPkg/Include/AsmMacroIoLib.h b/ArmPkg/Include/AsmMacroIoLib.h
index 551b87803d19..fb73ea9a4694 100644
--- a/ArmPkg/Include/AsmMacroIoLib.h
+++ b/ArmPkg/Include/AsmMacroIoLib.h
@@ -3,6 +3,7 @@ 
 
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -51,4 +52,26 @@ 
 
 #endif
 
+#define _ASM_FUNC(Name, Section)    \
+  .global   Name                  ; \
+  .section  #Section, "ax"        ; \
+  .type     Name, %function       ; \
+  Name:
+
+#define ASM_FUNC(Name)            _ASM_FUNC(ASM_PFX(Name), .text. ## Name)
+
+#define MOV32(Reg, Val)                       \
+  movw      Reg, #(Val) & 0xffff            ; \
+  movt      Reg, #(Val) >> 16
+
+#define ADRL(Reg, Sym)                        \
+  movw      Reg, #:lower16:(Sym) - (. + 16) ; \
+  movt      Reg, #:upper16:(Sym) - (. + 12) ; \
+  add       Reg, Reg, pc
+
+#define LDRL(Reg, Sym)                        \
+  movw      Reg, #:lower16:(Sym) - (. + 16) ; \
+  movt      Reg, #:upper16:(Sym) - (. + 12) ; \
+  ldr       Reg, [pc, Reg]
+
 #endif
diff --git a/ArmPkg/Include/AsmMacroIoLibV8.h b/ArmPkg/Include/AsmMacroIoLibV8.h
index 37fa255f842e..e9285f78e7d6 100644
--- a/ArmPkg/Include/AsmMacroIoLibV8.h
+++ b/ArmPkg/Include/AsmMacroIoLibV8.h
@@ -3,6 +3,7 @@ 
 
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   Portions copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -71,5 +72,22 @@ 
 
 #endif // __GNUC__
 
-#endif // __MACRO_IO_LIBV8_H__
+#define _ASM_FUNC(Name, Section)    \
+  .global   Name                  ; \
+  .section  #Section, "ax"        ; \
+  .type     Name, %function       ; \
+  Name:
+
+#define ASM_FUNC(Name)            _ASM_FUNC(ASM_PFX(Name), .text. ## Name)
+
+#define MOV32(Reg, Val)                   \
+  movz      Reg, (Val) >> 16, lsl #16   ; \
+  movk      Reg, (Val) & 0xffff
 
+#define MOV64(Reg, Val)                             \
+  movz      Reg, (Val) >> 48, lsl #48             ; \
+  movk      Reg, ((Val) >> 32) & 0xffff, lsl #32  ; \
+  movk      Reg, ((Val) >> 16) & 0xffff, lsl #16  ; \
+  movk      Reg, (Val) & 0xffff
+
+#endif // __MACRO_IO_LIBV8_H__