1738b1fd7SSoby Mathew/* 2738b1fd7SSoby Mathew * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 3738b1fd7SSoby Mathew * 4738b1fd7SSoby Mathew * Redistribution and use in source and binary forms, with or without 5738b1fd7SSoby Mathew * modification, are permitted provided that the following conditions are met: 6738b1fd7SSoby Mathew * 7738b1fd7SSoby Mathew * Redistributions of source code must retain the above copyright notice, this 8738b1fd7SSoby Mathew * list of conditions and the following disclaimer. 9738b1fd7SSoby Mathew * 10738b1fd7SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 11738b1fd7SSoby Mathew * this list of conditions and the following disclaimer in the documentation 12738b1fd7SSoby Mathew * and/or other materials provided with the distribution. 13738b1fd7SSoby Mathew * 14738b1fd7SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 15738b1fd7SSoby Mathew * to endorse or promote products derived from this software without specific 16738b1fd7SSoby Mathew * prior written permission. 17738b1fd7SSoby Mathew * 18738b1fd7SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19738b1fd7SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20738b1fd7SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21738b1fd7SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22738b1fd7SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23738b1fd7SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24738b1fd7SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25738b1fd7SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26738b1fd7SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27738b1fd7SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28738b1fd7SSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 29738b1fd7SSoby Mathew */ 30738b1fd7SSoby Mathew#ifndef __ASM_MACROS_COMMON_S__ 31738b1fd7SSoby Mathew#define __ASM_MACROS_COMMON_S__ 32738b1fd7SSoby Mathew 33738b1fd7SSoby Mathew /* 34738b1fd7SSoby Mathew * This macro is used to create a function label and place the 35738b1fd7SSoby Mathew * code into a separate text section based on the function name 36*b91d935fSDouglas Raillard * to enable elimination of unused code during linking. It also adds 37*b91d935fSDouglas Raillard * basic debug information to enable call stack printing most of the 38*b91d935fSDouglas Raillard * time. 39738b1fd7SSoby Mathew */ 40738b1fd7SSoby Mathew .macro func _name 41*b91d935fSDouglas Raillard /* 42*b91d935fSDouglas Raillard * Add Call Frame Information entry in the .debug_frame section for 43*b91d935fSDouglas Raillard * debugger consumption. This enables callstack printing in debuggers. 44*b91d935fSDouglas Raillard * This does not use any space in the final loaded binary, only in the 45*b91d935fSDouglas Raillard * ELF file. 46*b91d935fSDouglas Raillard * Note that a function manipulating the CFA pointer location (i.e. the 47*b91d935fSDouglas Raillard * x29 frame pointer on AArch64) should declare it using the 48*b91d935fSDouglas Raillard * appropriate .cfi* directives, or be prepared to have a degraded 49*b91d935fSDouglas Raillard * debugging experience. 50*b91d935fSDouglas Raillard */ 51*b91d935fSDouglas Raillard .cfi_sections .debug_frame 52738b1fd7SSoby Mathew .section .text.\_name, "ax" 53738b1fd7SSoby Mathew .type \_name, %function 54738b1fd7SSoby Mathew .func \_name 55*b91d935fSDouglas Raillard /* 56*b91d935fSDouglas Raillard * .cfi_startproc and .cfi_endproc are needed to output entries in 57*b91d935fSDouglas Raillard * .debug_frame 58*b91d935fSDouglas Raillard */ 59*b91d935fSDouglas Raillard .cfi_startproc 60738b1fd7SSoby Mathew \_name: 61738b1fd7SSoby Mathew .endm 62738b1fd7SSoby Mathew 63738b1fd7SSoby Mathew /* 64738b1fd7SSoby Mathew * This macro is used to mark the end of a function. 65738b1fd7SSoby Mathew */ 66738b1fd7SSoby Mathew .macro endfunc _name 67738b1fd7SSoby Mathew .endfunc 68*b91d935fSDouglas Raillard .cfi_endproc 69738b1fd7SSoby Mathew .size \_name, . - \_name 70738b1fd7SSoby Mathew .endm 71738b1fd7SSoby Mathew 72738b1fd7SSoby Mathew /* 73738b1fd7SSoby Mathew * Theses macros are used to create function labels for deprecated 74738b1fd7SSoby Mathew * APIs. If ERROR_DEPRECATED is non zero, the callers of these APIs 75738b1fd7SSoby Mathew * will fail to link and cause build failure. 76738b1fd7SSoby Mathew */ 77738b1fd7SSoby Mathew#if ERROR_DEPRECATED 78738b1fd7SSoby Mathew .macro func_deprecated _name 79738b1fd7SSoby Mathew func deprecated\_name 80738b1fd7SSoby Mathew .endm 81738b1fd7SSoby Mathew 82738b1fd7SSoby Mathew .macro endfunc_deprecated _name 83738b1fd7SSoby Mathew endfunc deprecated\_name 84738b1fd7SSoby Mathew .endm 85738b1fd7SSoby Mathew#else 86738b1fd7SSoby Mathew .macro func_deprecated _name 87738b1fd7SSoby Mathew func \_name 88738b1fd7SSoby Mathew .endm 89738b1fd7SSoby Mathew 90738b1fd7SSoby Mathew .macro endfunc_deprecated _name 91738b1fd7SSoby Mathew endfunc \_name 92738b1fd7SSoby Mathew .endm 93738b1fd7SSoby Mathew#endif 94738b1fd7SSoby Mathew 95738b1fd7SSoby Mathew /* 96738b1fd7SSoby Mathew * Helper assembler macro to count trailing zeros. The output is 97738b1fd7SSoby Mathew * populated in the `TZ_COUNT` symbol. 98738b1fd7SSoby Mathew */ 99738b1fd7SSoby Mathew .macro count_tz _value, _tz_count 100738b1fd7SSoby Mathew .if \_value 101738b1fd7SSoby Mathew count_tz "(\_value >> 1)", "(\_tz_count + 1)" 102738b1fd7SSoby Mathew .else 103738b1fd7SSoby Mathew .equ TZ_COUNT, (\_tz_count - 1) 104738b1fd7SSoby Mathew .endif 105738b1fd7SSoby Mathew .endm 106738b1fd7SSoby Mathew 107738b1fd7SSoby Mathew /* 108738b1fd7SSoby Mathew * This macro declares an array of 1 or more stacks, properly 109738b1fd7SSoby Mathew * aligned and in the requested section 110738b1fd7SSoby Mathew */ 111738b1fd7SSoby Mathew#define DEFAULT_STACK_ALIGN (1 << 6) /* In case the caller doesnt provide alignment */ 112738b1fd7SSoby Mathew 113738b1fd7SSoby Mathew .macro declare_stack _name, _section, _size, _count, _align=DEFAULT_STACK_ALIGN 114738b1fd7SSoby Mathew count_tz \_align, 0 115738b1fd7SSoby Mathew .if (\_align - (1 << TZ_COUNT)) 116738b1fd7SSoby Mathew .error "Incorrect stack alignment specified (Must be a power of 2)." 117738b1fd7SSoby Mathew .endif 118738b1fd7SSoby Mathew .if ((\_size & ((1 << TZ_COUNT) - 1)) <> 0) 119738b1fd7SSoby Mathew .error "Stack size not correctly aligned" 120738b1fd7SSoby Mathew .endif 121738b1fd7SSoby Mathew .section \_section, "aw", %nobits 122738b1fd7SSoby Mathew .align TZ_COUNT 123738b1fd7SSoby Mathew \_name: 124738b1fd7SSoby Mathew .space ((\_count) * (\_size)), 0 125738b1fd7SSoby Mathew .endm 126738b1fd7SSoby Mathew 127738b1fd7SSoby Mathew 128738b1fd7SSoby Mathew#endif /* __ASM_MACROS_COMMON_S__ */ 129