13704993fSRichard Henderson /* 23704993fSRichard Henderson * Tiny Code Generator for QEMU 33704993fSRichard Henderson * 43704993fSRichard Henderson * Copyright (c) 2009 Ulrich Hecht <uli@suse.de> 53704993fSRichard Henderson * 63704993fSRichard Henderson * Permission is hereby granted, free of charge, to any person obtaining a copy 73704993fSRichard Henderson * of this software and associated documentation files (the "Software"), to deal 83704993fSRichard Henderson * in the Software without restriction, including without limitation the rights 93704993fSRichard Henderson * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 103704993fSRichard Henderson * copies of the Software, and to permit persons to whom the Software is 113704993fSRichard Henderson * furnished to do so, subject to the following conditions: 123704993fSRichard Henderson * 133704993fSRichard Henderson * The above copyright notice and this permission notice shall be included in 143704993fSRichard Henderson * all copies or substantial portions of the Software. 153704993fSRichard Henderson * 163704993fSRichard Henderson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 173704993fSRichard Henderson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 183704993fSRichard Henderson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 193704993fSRichard Henderson * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 203704993fSRichard Henderson * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 213704993fSRichard Henderson * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 223704993fSRichard Henderson * THE SOFTWARE. 233704993fSRichard Henderson */ 243704993fSRichard Henderson 253704993fSRichard Henderson #ifndef S390_TCG_TARGET_H 263704993fSRichard Henderson #define S390_TCG_TARGET_H 273704993fSRichard Henderson 283704993fSRichard Henderson #define TCG_TARGET_INSN_UNIT_SIZE 2 293704993fSRichard Henderson #define TCG_TARGET_TLB_DISPLACEMENT_BITS 19 303704993fSRichard Henderson 313704993fSRichard Henderson /* We have a +- 4GB range on the branches; leave some slop. */ 323704993fSRichard Henderson #define MAX_CODE_GEN_BUFFER_SIZE (3 * GiB) 333704993fSRichard Henderson 343704993fSRichard Henderson typedef enum TCGReg { 35eee6251bSRichard Henderson TCG_REG_R0, TCG_REG_R1, TCG_REG_R2, TCG_REG_R3, 36eee6251bSRichard Henderson TCG_REG_R4, TCG_REG_R5, TCG_REG_R6, TCG_REG_R7, 37eee6251bSRichard Henderson TCG_REG_R8, TCG_REG_R9, TCG_REG_R10, TCG_REG_R11, 38eee6251bSRichard Henderson TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15, 39eee6251bSRichard Henderson 4034ef7676SRichard Henderson TCG_REG_V0 = 32, TCG_REG_V1, TCG_REG_V2, TCG_REG_V3, 4134ef7676SRichard Henderson TCG_REG_V4, TCG_REG_V5, TCG_REG_V6, TCG_REG_V7, 4234ef7676SRichard Henderson TCG_REG_V8, TCG_REG_V9, TCG_REG_V10, TCG_REG_V11, 4334ef7676SRichard Henderson TCG_REG_V12, TCG_REG_V13, TCG_REG_V14, TCG_REG_V15, 4434ef7676SRichard Henderson TCG_REG_V16, TCG_REG_V17, TCG_REG_V18, TCG_REG_V19, 4534ef7676SRichard Henderson TCG_REG_V20, TCG_REG_V21, TCG_REG_V22, TCG_REG_V23, 4634ef7676SRichard Henderson TCG_REG_V24, TCG_REG_V25, TCG_REG_V26, TCG_REG_V27, 4734ef7676SRichard Henderson TCG_REG_V28, TCG_REG_V29, TCG_REG_V30, TCG_REG_V31, 4834ef7676SRichard Henderson 49eee6251bSRichard Henderson TCG_AREG0 = TCG_REG_R10, 50eee6251bSRichard Henderson TCG_REG_CALL_STACK = TCG_REG_R15 513704993fSRichard Henderson } TCGReg; 523704993fSRichard Henderson 5334ef7676SRichard Henderson #define TCG_TARGET_NB_REGS 64 543704993fSRichard Henderson 55761ea522SRichard Henderson /* Facilities required for proper operation; checked at startup. */ 563704993fSRichard Henderson 57748b7f3eSRichard Henderson #define FACILITY_ZARCH_ACTIVE 2 58748b7f3eSRichard Henderson #define FACILITY_LONG_DISP 18 593e25f7daSRichard Henderson #define FACILITY_EXT_IMM 21 60*9c3bfb79SRichard Henderson #define FACILITY_GEN_INST_EXT 34 61761ea522SRichard Henderson 62761ea522SRichard Henderson /* Facilities that are checked at runtime. */ 63761ea522SRichard Henderson 64748b7f3eSRichard Henderson #define FACILITY_LOAD_ON_COND 45 653704993fSRichard Henderson #define FACILITY_FAST_BCR_SER FACILITY_LOAD_ON_COND 663704993fSRichard Henderson #define FACILITY_DISTINCT_OPS FACILITY_LOAD_ON_COND 67748b7f3eSRichard Henderson #define FACILITY_LOAD_ON_COND2 53 6834ef7676SRichard Henderson #define FACILITY_VECTOR 129 69ae77bbe5SRichard Henderson #define FACILITY_VECTOR_ENH1 135 703704993fSRichard Henderson 7134ef7676SRichard Henderson extern uint64_t s390_facilities[3]; 72748b7f3eSRichard Henderson 73748b7f3eSRichard Henderson #define HAVE_FACILITY(X) \ 74748b7f3eSRichard Henderson ((s390_facilities[FACILITY_##X / 64] >> (63 - FACILITY_##X % 64)) & 1) 753704993fSRichard Henderson 763704993fSRichard Henderson /* optional instructions */ 773704993fSRichard Henderson #define TCG_TARGET_HAS_div2_i32 1 783704993fSRichard Henderson #define TCG_TARGET_HAS_rot_i32 1 793704993fSRichard Henderson #define TCG_TARGET_HAS_ext8s_i32 1 803704993fSRichard Henderson #define TCG_TARGET_HAS_ext16s_i32 1 813704993fSRichard Henderson #define TCG_TARGET_HAS_ext8u_i32 1 823704993fSRichard Henderson #define TCG_TARGET_HAS_ext16u_i32 1 833704993fSRichard Henderson #define TCG_TARGET_HAS_bswap16_i32 1 843704993fSRichard Henderson #define TCG_TARGET_HAS_bswap32_i32 1 853704993fSRichard Henderson #define TCG_TARGET_HAS_not_i32 0 863704993fSRichard Henderson #define TCG_TARGET_HAS_neg_i32 1 873704993fSRichard Henderson #define TCG_TARGET_HAS_andc_i32 0 883704993fSRichard Henderson #define TCG_TARGET_HAS_orc_i32 0 893704993fSRichard Henderson #define TCG_TARGET_HAS_eqv_i32 0 903704993fSRichard Henderson #define TCG_TARGET_HAS_nand_i32 0 913704993fSRichard Henderson #define TCG_TARGET_HAS_nor_i32 0 923704993fSRichard Henderson #define TCG_TARGET_HAS_clz_i32 0 933704993fSRichard Henderson #define TCG_TARGET_HAS_ctz_i32 0 943704993fSRichard Henderson #define TCG_TARGET_HAS_ctpop_i32 0 95*9c3bfb79SRichard Henderson #define TCG_TARGET_HAS_deposit_i32 1 96*9c3bfb79SRichard Henderson #define TCG_TARGET_HAS_extract_i32 1 973704993fSRichard Henderson #define TCG_TARGET_HAS_sextract_i32 0 983704993fSRichard Henderson #define TCG_TARGET_HAS_extract2_i32 0 993704993fSRichard Henderson #define TCG_TARGET_HAS_movcond_i32 1 1003704993fSRichard Henderson #define TCG_TARGET_HAS_add2_i32 1 1013704993fSRichard Henderson #define TCG_TARGET_HAS_sub2_i32 1 1023704993fSRichard Henderson #define TCG_TARGET_HAS_mulu2_i32 0 1033704993fSRichard Henderson #define TCG_TARGET_HAS_muls2_i32 0 1043704993fSRichard Henderson #define TCG_TARGET_HAS_muluh_i32 0 1053704993fSRichard Henderson #define TCG_TARGET_HAS_mulsh_i32 0 1063704993fSRichard Henderson #define TCG_TARGET_HAS_extrl_i64_i32 0 1073704993fSRichard Henderson #define TCG_TARGET_HAS_extrh_i64_i32 0 1086bd739edSRichard Henderson #define TCG_TARGET_HAS_direct_jump 1 1093704993fSRichard Henderson #define TCG_TARGET_HAS_qemu_st8_i32 0 1103704993fSRichard Henderson 1113704993fSRichard Henderson #define TCG_TARGET_HAS_div2_i64 1 1123704993fSRichard Henderson #define TCG_TARGET_HAS_rot_i64 1 1133704993fSRichard Henderson #define TCG_TARGET_HAS_ext8s_i64 1 1143704993fSRichard Henderson #define TCG_TARGET_HAS_ext16s_i64 1 1153704993fSRichard Henderson #define TCG_TARGET_HAS_ext32s_i64 1 1163704993fSRichard Henderson #define TCG_TARGET_HAS_ext8u_i64 1 1173704993fSRichard Henderson #define TCG_TARGET_HAS_ext16u_i64 1 1183704993fSRichard Henderson #define TCG_TARGET_HAS_ext32u_i64 1 1193704993fSRichard Henderson #define TCG_TARGET_HAS_bswap16_i64 1 1203704993fSRichard Henderson #define TCG_TARGET_HAS_bswap32_i64 1 1213704993fSRichard Henderson #define TCG_TARGET_HAS_bswap64_i64 1 1223704993fSRichard Henderson #define TCG_TARGET_HAS_not_i64 0 1233704993fSRichard Henderson #define TCG_TARGET_HAS_neg_i64 1 1243704993fSRichard Henderson #define TCG_TARGET_HAS_andc_i64 0 1253704993fSRichard Henderson #define TCG_TARGET_HAS_orc_i64 0 1263704993fSRichard Henderson #define TCG_TARGET_HAS_eqv_i64 0 1273704993fSRichard Henderson #define TCG_TARGET_HAS_nand_i64 0 1283704993fSRichard Henderson #define TCG_TARGET_HAS_nor_i64 0 1293e25f7daSRichard Henderson #define TCG_TARGET_HAS_clz_i64 1 1303704993fSRichard Henderson #define TCG_TARGET_HAS_ctz_i64 0 1313704993fSRichard Henderson #define TCG_TARGET_HAS_ctpop_i64 0 132*9c3bfb79SRichard Henderson #define TCG_TARGET_HAS_deposit_i64 1 133*9c3bfb79SRichard Henderson #define TCG_TARGET_HAS_extract_i64 1 1343704993fSRichard Henderson #define TCG_TARGET_HAS_sextract_i64 0 1353704993fSRichard Henderson #define TCG_TARGET_HAS_extract2_i64 0 1363704993fSRichard Henderson #define TCG_TARGET_HAS_movcond_i64 1 1373704993fSRichard Henderson #define TCG_TARGET_HAS_add2_i64 1 1383704993fSRichard Henderson #define TCG_TARGET_HAS_sub2_i64 1 1393704993fSRichard Henderson #define TCG_TARGET_HAS_mulu2_i64 1 1403704993fSRichard Henderson #define TCG_TARGET_HAS_muls2_i64 0 1413704993fSRichard Henderson #define TCG_TARGET_HAS_muluh_i64 0 1423704993fSRichard Henderson #define TCG_TARGET_HAS_mulsh_i64 0 1433704993fSRichard Henderson 14434ef7676SRichard Henderson #define TCG_TARGET_HAS_v64 HAVE_FACILITY(VECTOR) 14534ef7676SRichard Henderson #define TCG_TARGET_HAS_v128 HAVE_FACILITY(VECTOR) 14634ef7676SRichard Henderson #define TCG_TARGET_HAS_v256 0 14734ef7676SRichard Henderson 148ae77bbe5SRichard Henderson #define TCG_TARGET_HAS_andc_vec 1 149ae77bbe5SRichard Henderson #define TCG_TARGET_HAS_orc_vec HAVE_FACILITY(VECTOR_ENH1) 15021eab5bfSRichard Henderson #define TCG_TARGET_HAS_nand_vec HAVE_FACILITY(VECTOR_ENH1) 15121eab5bfSRichard Henderson #define TCG_TARGET_HAS_nor_vec 1 15221eab5bfSRichard Henderson #define TCG_TARGET_HAS_eqv_vec HAVE_FACILITY(VECTOR_ENH1) 153ae77bbe5SRichard Henderson #define TCG_TARGET_HAS_not_vec 1 154ae77bbe5SRichard Henderson #define TCG_TARGET_HAS_neg_vec 1 155ae77bbe5SRichard Henderson #define TCG_TARGET_HAS_abs_vec 1 15622cb37b4SRichard Henderson #define TCG_TARGET_HAS_roti_vec 1 15722cb37b4SRichard Henderson #define TCG_TARGET_HAS_rots_vec 1 15822cb37b4SRichard Henderson #define TCG_TARGET_HAS_rotv_vec 1 15922cb37b4SRichard Henderson #define TCG_TARGET_HAS_shi_vec 1 16022cb37b4SRichard Henderson #define TCG_TARGET_HAS_shs_vec 1 16122cb37b4SRichard Henderson #define TCG_TARGET_HAS_shv_vec 1 162479b61cbSRichard Henderson #define TCG_TARGET_HAS_mul_vec 1 16334ef7676SRichard Henderson #define TCG_TARGET_HAS_sat_vec 0 164220db7a6SRichard Henderson #define TCG_TARGET_HAS_minmax_vec 1 1659bca986dSRichard Henderson #define TCG_TARGET_HAS_bitsel_vec 1 16634ef7676SRichard Henderson #define TCG_TARGET_HAS_cmpsel_vec 0 16734ef7676SRichard Henderson 1683704993fSRichard Henderson /* used for function call generation */ 1693704993fSRichard Henderson #define TCG_TARGET_STACK_ALIGN 8 1703704993fSRichard Henderson #define TCG_TARGET_CALL_STACK_OFFSET 160 171eb8b0224SRichard Henderson #define TCG_TARGET_CALL_ARG_I32 TCG_CALL_ARG_EXTEND 172c8eef960SRichard Henderson #define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL 1733704993fSRichard Henderson 1743704993fSRichard Henderson #define TCG_TARGET_HAS_MEMORY_BSWAP 1 1753704993fSRichard Henderson 1763704993fSRichard Henderson #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) 1773704993fSRichard Henderson 1783704993fSRichard Henderson static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx, 1793704993fSRichard Henderson uintptr_t jmp_rw, uintptr_t addr) 1803704993fSRichard Henderson { 1813704993fSRichard Henderson /* patch the branch destination */ 1823704993fSRichard Henderson intptr_t disp = addr - (jmp_rx - 2); 1833704993fSRichard Henderson qatomic_set((int32_t *)jmp_rw, disp / 2); 1843704993fSRichard Henderson /* no need to flush icache explicitly */ 1853704993fSRichard Henderson } 1863704993fSRichard Henderson 1873704993fSRichard Henderson #define TCG_TARGET_NEED_LDST_LABELS 1883704993fSRichard Henderson #define TCG_TARGET_NEED_POOL_LABELS 1893704993fSRichard Henderson 1903704993fSRichard Henderson #endif 191