1 /* asm-common-s390x.h - Common macros for zSeries assembly 2 * 3 * Copyright (C) 2020 Jussi Kivilinna <jussi.kivilinna@iki.fi> 4 * 5 * This file is part of Libgcrypt. 6 * 7 * Libgcrypt is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * Libgcrypt is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this program; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef GCRY_ASM_COMMON_S390X_H 22 #define GCRY_ASM_COMMON_S390X_H 23 24 #include <config.h> 25 26 #ifdef HAVE_GCC_ASM_ELF_DIRECTIVES 27 # define ELF(...) __VA_ARGS__ 28 #else 29 # define ELF(...) /*_*/ 30 #endif 31 32 #ifdef HAVE_GCC_ASM_CFI_DIRECTIVES 33 /* CFI directives to emit DWARF stack unwinding information. */ 34 # define CFI_STARTPROC() .cfi_startproc 35 # define CFI_ENDPROC() .cfi_endproc 36 # define CFI_REMEMBER_STATE() .cfi_remember_state 37 # define CFI_RESTORE_STATE() .cfi_restore_state 38 # define CFI_ADJUST_CFA_OFFSET(off) .cfi_adjust_cfa_offset off 39 # define CFI_REL_OFFSET(reg,off) .cfi_rel_offset reg, off 40 # define CFI_DEF_CFA_REGISTER(reg) .cfi_def_cfa_register reg 41 # define CFI_REGISTER(ro,rn) .cfi_register ro, rn 42 # define CFI_RESTORE(reg) .cfi_restore reg 43 44 /* CFA expressions are used for pointing CFA and registers to 45 * SP relative offsets. */ 46 # define DW_REGNO_SP 15 47 48 /* Fixed length encoding used for integers for now. */ 49 # define DW_SLEB128_7BIT(value) \ 50 0x00|((value) & 0x7f) 51 # define DW_SLEB128_28BIT(value) \ 52 0x80|((value)&0x7f), \ 53 0x80|(((value)>>7)&0x7f), \ 54 0x80|(((value)>>14)&0x7f), \ 55 0x00|(((value)>>21)&0x7f) 56 57 # define CFI_CFA_ON_STACK(rsp_offs,cfa_depth) \ 58 .cfi_escape \ 59 0x0f, /* DW_CFA_def_cfa_expression */ \ 60 DW_SLEB128_7BIT(11), /* length */ \ 61 0x7f, /* DW_OP_breg15, rsp + constant */ \ 62 DW_SLEB128_28BIT(rsp_offs), \ 63 0x06, /* DW_OP_deref */ \ 64 0x23, /* DW_OP_plus_constu */ \ 65 DW_SLEB128_28BIT((cfa_depth)+160) 66 67 # define CFI_REG_ON_STACK(regno,rsp_offs) \ 68 .cfi_escape \ 69 0x10, /* DW_CFA_expression */ \ 70 DW_SLEB128_7BIT(regno), \ 71 DW_SLEB128_7BIT(5), /* length */ \ 72 0x7f, /* DW_OP_breg15, rsp + constant */ \ 73 DW_SLEB128_28BIT(rsp_offs) 74 75 #else 76 # define CFI_STARTPROC() 77 # define CFI_ENDPROC() 78 # define CFI_REMEMBER_STATE() 79 # define CFI_RESTORE_STATE() 80 # define CFI_ADJUST_CFA_OFFSET(off) 81 # define CFI_REL_OFFSET(reg,off) 82 # define CFI_DEF_CFA_REGISTER(reg) 83 # define CFI_REGISTER(ro,rn) 84 # define CFI_RESTORE(reg) 85 86 # define CFI_CFA_ON_STACK(rsp_offs,cfa_depth) 87 # define CFI_REG_ON_STACK(reg,rsp_offs) 88 #endif 89 90 #endif /* GCRY_ASM_COMMON_AMD64_H */ 91