1afa05235SAurelien Jarno /* 2afa05235SAurelien Jarno * Tiny Code Generator for QEMU 3afa05235SAurelien Jarno * 4afa05235SAurelien Jarno * Copyright (c) 2008-2009 Arnaud Patard <arnaud.patard@rtp-net.org> 5afa05235SAurelien Jarno * Copyright (c) 2009 Aurelien Jarno <aurelien@aurel32.net> 6afa05235SAurelien Jarno * Based on i386/tcg-target.c - Copyright (c) 2008 Fabrice Bellard 7afa05235SAurelien Jarno * 8afa05235SAurelien Jarno * Permission is hereby granted, free of charge, to any person obtaining a copy 9afa05235SAurelien Jarno * of this software and associated documentation files (the "Software"), to deal 10afa05235SAurelien Jarno * in the Software without restriction, including without limitation the rights 11afa05235SAurelien Jarno * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12afa05235SAurelien Jarno * copies of the Software, and to permit persons to whom the Software is 13afa05235SAurelien Jarno * furnished to do so, subject to the following conditions: 14afa05235SAurelien Jarno * 15afa05235SAurelien Jarno * The above copyright notice and this permission notice shall be included in 16afa05235SAurelien Jarno * all copies or substantial portions of the Software. 17afa05235SAurelien Jarno * 18afa05235SAurelien Jarno * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19afa05235SAurelien Jarno * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20afa05235SAurelien Jarno * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21afa05235SAurelien Jarno * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22afa05235SAurelien Jarno * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23afa05235SAurelien Jarno * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24afa05235SAurelien Jarno * THE SOFTWARE. 25afa05235SAurelien Jarno */ 2614e54f8eSMarkus Armbruster 2714e54f8eSMarkus Armbruster #ifndef MIPS_TCG_TARGET_H 2814e54f8eSMarkus Armbruster #define MIPS_TCG_TARGET_H 29afa05235SAurelien Jarno 30ae0218e3SRichard Henderson #define TCG_TARGET_INSN_UNIT_SIZE 4 31afa05235SAurelien Jarno #define TCG_TARGET_NB_REGS 32 32afa05235SAurelien Jarno 335a8f0a5dSRichard Henderson #define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) 3426a75d12SRichard Henderson 35771142c2SRichard Henderson typedef enum { 36afa05235SAurelien Jarno TCG_REG_ZERO = 0, 37afa05235SAurelien Jarno TCG_REG_AT, 38afa05235SAurelien Jarno TCG_REG_V0, 39afa05235SAurelien Jarno TCG_REG_V1, 40afa05235SAurelien Jarno TCG_REG_A0, 41afa05235SAurelien Jarno TCG_REG_A1, 42afa05235SAurelien Jarno TCG_REG_A2, 43afa05235SAurelien Jarno TCG_REG_A3, 44afa05235SAurelien Jarno TCG_REG_T0, 45afa05235SAurelien Jarno TCG_REG_T1, 46afa05235SAurelien Jarno TCG_REG_T2, 47afa05235SAurelien Jarno TCG_REG_T3, 48afa05235SAurelien Jarno TCG_REG_T4, 49afa05235SAurelien Jarno TCG_REG_T5, 50afa05235SAurelien Jarno TCG_REG_T6, 51afa05235SAurelien Jarno TCG_REG_T7, 52afa05235SAurelien Jarno TCG_REG_S0, 53afa05235SAurelien Jarno TCG_REG_S1, 54afa05235SAurelien Jarno TCG_REG_S2, 55afa05235SAurelien Jarno TCG_REG_S3, 56afa05235SAurelien Jarno TCG_REG_S4, 57afa05235SAurelien Jarno TCG_REG_S5, 58afa05235SAurelien Jarno TCG_REG_S6, 59afa05235SAurelien Jarno TCG_REG_S7, 60afa05235SAurelien Jarno TCG_REG_T8, 61afa05235SAurelien Jarno TCG_REG_T9, 62afa05235SAurelien Jarno TCG_REG_K0, 63afa05235SAurelien Jarno TCG_REG_K1, 64afa05235SAurelien Jarno TCG_REG_GP, 65afa05235SAurelien Jarno TCG_REG_SP, 6641883904SRichard Henderson TCG_REG_S8, 67afa05235SAurelien Jarno TCG_REG_RA, 6841883904SRichard Henderson 6941883904SRichard Henderson TCG_REG_CALL_STACK = TCG_REG_SP, 70d721cc94SRichard Henderson TCG_AREG0 = TCG_REG_S8, 71771142c2SRichard Henderson } TCGReg; 72afa05235SAurelien Jarno 73afa05235SAurelien Jarno /* used for function call generation */ 74999b9416SJin Guojie #define TCG_TARGET_STACK_ALIGN 16 75999b9416SJin Guojie #if _MIPS_SIM == _ABIO32 76afa05235SAurelien Jarno # define TCG_TARGET_CALL_STACK_OFFSET 16 77c8eef960SRichard Henderson # define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_EVEN 7825acc3f2SRichard Henderson # define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_BY_REF 79999b9416SJin Guojie #else 80999b9416SJin Guojie # define TCG_TARGET_CALL_STACK_OFFSET 0 81c8eef960SRichard Henderson # define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL 8225acc3f2SRichard Henderson # define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_NORMAL 83999b9416SJin Guojie #endif 84eb8b0224SRichard Henderson #define TCG_TARGET_CALL_ARG_I32 TCG_CALL_ARG_NORMAL 855427a9a7SRichard Henderson #define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_EVEN 86afa05235SAurelien Jarno 87988902fcSAurelien Jarno /* MOVN/MOVZ instructions detection */ 88988902fcSAurelien Jarno #if (defined(__mips_isa_rev) && (__mips_isa_rev >= 1)) || \ 89988902fcSAurelien Jarno defined(_MIPS_ARCH_LOONGSON2E) || defined(_MIPS_ARCH_LOONGSON2F) || \ 90988902fcSAurelien Jarno defined(_MIPS_ARCH_MIPS4) 91988902fcSAurelien Jarno #define use_movnz_instructions 1 92988902fcSAurelien Jarno #else 93988902fcSAurelien Jarno extern bool use_movnz_instructions; 94988902fcSAurelien Jarno #endif 95988902fcSAurelien Jarno 96988902fcSAurelien Jarno /* MIPS32 instruction set detection */ 97988902fcSAurelien Jarno #if defined(__mips_isa_rev) && (__mips_isa_rev >= 1) 98988902fcSAurelien Jarno #define use_mips32_instructions 1 99988902fcSAurelien Jarno #else 100988902fcSAurelien Jarno extern bool use_mips32_instructions; 101988902fcSAurelien Jarno #endif 102988902fcSAurelien Jarno 103988902fcSAurelien Jarno /* MIPS32R2 instruction set detection */ 104988902fcSAurelien Jarno #if defined(__mips_isa_rev) && (__mips_isa_rev >= 2) 105988902fcSAurelien Jarno #define use_mips32r2_instructions 1 106988902fcSAurelien Jarno #else 107988902fcSAurelien Jarno extern bool use_mips32r2_instructions; 108988902fcSAurelien Jarno #endif 109988902fcSAurelien Jarno 110ce14bd4dSJames Hogan /* MIPS32R6 instruction set detection */ 111ce14bd4dSJames Hogan #if defined(__mips_isa_rev) && (__mips_isa_rev >= 6) 112ce14bd4dSJames Hogan #define use_mips32r6_instructions 1 113ce14bd4dSJames Hogan #else 114ce14bd4dSJames Hogan #define use_mips32r6_instructions 0 115ce14bd4dSJames Hogan #endif 116ce14bd4dSJames Hogan 117afa05235SAurelien Jarno /* optional instructions */ 11825c4d9ccSRichard Henderson #define TCG_TARGET_HAS_div_i32 1 119ca675f46SRichard Henderson #define TCG_TARGET_HAS_rem_i32 1 12025c4d9ccSRichard Henderson #define TCG_TARGET_HAS_not_i32 1 12125c4d9ccSRichard Henderson #define TCG_TARGET_HAS_nor_i32 1 12225c4d9ccSRichard Henderson #define TCG_TARGET_HAS_andc_i32 0 12325c4d9ccSRichard Henderson #define TCG_TARGET_HAS_orc_i32 0 12425c4d9ccSRichard Henderson #define TCG_TARGET_HAS_eqv_i32 0 12525c4d9ccSRichard Henderson #define TCG_TARGET_HAS_nand_i32 0 126bc6d0c22SJames Hogan #define TCG_TARGET_HAS_mulu2_i32 (!use_mips32r6_instructions) 127bc6d0c22SJames Hogan #define TCG_TARGET_HAS_muls2_i32 (!use_mips32r6_instructions) 1283c9a8f17SRichard Henderson #define TCG_TARGET_HAS_muluh_i32 1 1293c9a8f17SRichard Henderson #define TCG_TARGET_HAS_mulsh_i32 1 130bb08afe9SJin Guojie #define TCG_TARGET_HAS_bswap32_i32 1 1313635502dSRichard Henderson #define TCG_TARGET_HAS_negsetcond_i32 0 1327d7c4930SAurelien Jarno 1330119b192SJin Guojie #if TCG_TARGET_REG_BITS == 64 1340119b192SJin Guojie #define TCG_TARGET_HAS_add2_i32 0 1350119b192SJin Guojie #define TCG_TARGET_HAS_sub2_i32 0 13613d885b0SRichard Henderson #define TCG_TARGET_HAS_extr_i64_i32 1 1370119b192SJin Guojie #define TCG_TARGET_HAS_div_i64 1 1380119b192SJin Guojie #define TCG_TARGET_HAS_rem_i64 1 1390119b192SJin Guojie #define TCG_TARGET_HAS_not_i64 1 1400119b192SJin Guojie #define TCG_TARGET_HAS_nor_i64 1 1410119b192SJin Guojie #define TCG_TARGET_HAS_andc_i64 0 1420119b192SJin Guojie #define TCG_TARGET_HAS_orc_i64 0 1430119b192SJin Guojie #define TCG_TARGET_HAS_eqv_i64 0 1440119b192SJin Guojie #define TCG_TARGET_HAS_nand_i64 0 1450119b192SJin Guojie #define TCG_TARGET_HAS_add2_i64 0 1460119b192SJin Guojie #define TCG_TARGET_HAS_sub2_i64 0 1470119b192SJin Guojie #define TCG_TARGET_HAS_mulu2_i64 (!use_mips32r6_instructions) 1480119b192SJin Guojie #define TCG_TARGET_HAS_muls2_i64 (!use_mips32r6_instructions) 1490119b192SJin Guojie #define TCG_TARGET_HAS_muluh_i64 1 1500119b192SJin Guojie #define TCG_TARGET_HAS_mulsh_i64 1 1510119b192SJin Guojie #define TCG_TARGET_HAS_ext32s_i64 1 1520119b192SJin Guojie #define TCG_TARGET_HAS_ext32u_i64 1 1533635502dSRichard Henderson #define TCG_TARGET_HAS_negsetcond_i64 0 1540119b192SJin Guojie #endif 1550119b192SJin Guojie 156988902fcSAurelien Jarno /* optional instructions detected at runtime */ 157988902fcSAurelien Jarno #define TCG_TARGET_HAS_bswap16_i32 use_mips32r2_instructions 158988902fcSAurelien Jarno #define TCG_TARGET_HAS_deposit_i32 use_mips32r2_instructions 159befbb3ceSRichard Henderson #define TCG_TARGET_HAS_extract_i32 use_mips32r2_instructions 1607ec8bab3SRichard Henderson #define TCG_TARGET_HAS_sextract_i32 0 161fce1296fSRichard Henderson #define TCG_TARGET_HAS_extract2_i32 0 1623207bf25SAurelien Jarno #define TCG_TARGET_HAS_ext8s_i32 use_mips32r2_instructions 1633207bf25SAurelien Jarno #define TCG_TARGET_HAS_ext16s_i32 use_mips32r2_instructions 164988902fcSAurelien Jarno #define TCG_TARGET_HAS_rot_i32 use_mips32r2_instructions 1652a1d9d41SRichard Henderson #define TCG_TARGET_HAS_clz_i32 use_mips32r2_instructions 1662a1d9d41SRichard Henderson #define TCG_TARGET_HAS_ctz_i32 0 167a768e4e9SRichard Henderson #define TCG_TARGET_HAS_ctpop_i32 0 16807ce0b05SRichard Henderson #define TCG_TARGET_HAS_qemu_st8_i32 0 169c1cf85c9SAurelien Jarno 1700119b192SJin Guojie #if TCG_TARGET_REG_BITS == 64 1710119b192SJin Guojie #define TCG_TARGET_HAS_bswap16_i64 use_mips32r2_instructions 1720119b192SJin Guojie #define TCG_TARGET_HAS_bswap32_i64 use_mips32r2_instructions 1730119b192SJin Guojie #define TCG_TARGET_HAS_bswap64_i64 use_mips32r2_instructions 1740119b192SJin Guojie #define TCG_TARGET_HAS_deposit_i64 use_mips32r2_instructions 175befbb3ceSRichard Henderson #define TCG_TARGET_HAS_extract_i64 use_mips32r2_instructions 176befbb3ceSRichard Henderson #define TCG_TARGET_HAS_sextract_i64 0 177fce1296fSRichard Henderson #define TCG_TARGET_HAS_extract2_i64 0 1780119b192SJin Guojie #define TCG_TARGET_HAS_ext8s_i64 use_mips32r2_instructions 1790119b192SJin Guojie #define TCG_TARGET_HAS_ext16s_i64 use_mips32r2_instructions 1800119b192SJin Guojie #define TCG_TARGET_HAS_rot_i64 use_mips32r2_instructions 1812a1d9d41SRichard Henderson #define TCG_TARGET_HAS_clz_i64 use_mips32r2_instructions 1822a1d9d41SRichard Henderson #define TCG_TARGET_HAS_ctz_i64 0 183a768e4e9SRichard Henderson #define TCG_TARGET_HAS_ctpop_i64 0 1840119b192SJin Guojie #endif 1850119b192SJin Guojie 186afa05235SAurelien Jarno /* optional instructions automatically implemented */ 18725c4d9ccSRichard Henderson #define TCG_TARGET_HAS_ext8u_i32 0 /* andi rt, rs, 0xff */ 18825c4d9ccSRichard Henderson #define TCG_TARGET_HAS_ext16u_i32 0 /* andi rt, rs, 0xffff */ 189afa05235SAurelien Jarno 1900119b192SJin Guojie #if TCG_TARGET_REG_BITS == 64 1910119b192SJin Guojie #define TCG_TARGET_HAS_ext8u_i64 0 /* andi rt, rs, 0xff */ 1920119b192SJin Guojie #define TCG_TARGET_HAS_ext16u_i64 0 /* andi rt, rs, 0xffff */ 1930119b192SJin Guojie #endif 1940119b192SJin Guojie 19512fde9bcSRichard Henderson #define TCG_TARGET_HAS_qemu_ldst_i128 0 19612fde9bcSRichard Henderson 197*caf3eaccSRichard Henderson #define TCG_TARGET_HAS_tst 0 198*caf3eaccSRichard Henderson 199a7995621SRichard Henderson #define TCG_TARGET_DEFAULT_MO 0 200659ef5cbSRichard Henderson #define TCG_TARGET_NEED_LDST_LABELS 20148c12ba7SRichard Henderson #define TCG_TARGET_NEED_POOL_LABELS 202659ef5cbSRichard Henderson 203cb9c377fSPaolo Bonzini #endif 204