tcg-target.c revision f1d9bf153726533acf659efd796aa484dfd0b412
174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* 274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Tiny Code Generator for QEMU 374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * 474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Copyright (c) 2008 Fabrice Bellard 574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * 674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Permission is hereby granted, free of charge, to any person obtaining a copy 774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * of this software and associated documentation files (the "Software"), to deal 874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * in the Software without restriction, including without limitation the rights 974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * copies of the Software, and to permit persons to whom the Software is 1174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * furnished to do so, subject to the following conditions: 1274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * 1374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * The above copyright notice and this permission notice shall be included in 1474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * all copies or substantial portions of the Software. 1574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * 1674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE SOFTWARE. 2374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt */ 2474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 2574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifndef NDEBUG 2674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { 27f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner "%r0", "%r1", "%rp", "%r3", "%r4", "%r5", "%r6", "%r7", 28f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", 29f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", 30f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner "%r24", "%r25", "%r26", "%dp", "%ret0", "%ret1", "%sp", "%r31", 3174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}; 3274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 3374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 34f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* This is an 8 byte temp slot in the stack frame. */ 35f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define STACK_TEMP_OFS -16 36f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 37f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#ifdef CONFIG_USE_GUEST_BASE 38f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define TCG_GUEST_BASE_REG TCG_REG_R16 39f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#else 40f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define TCG_GUEST_BASE_REG TCG_REG_R0 41f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#endif 42f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 4374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_reg_alloc_order[] = { 4474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R4, 4574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R5, 4674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R6, 4774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R7, 4874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R8, 4974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R9, 5074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R10, 5174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R11, 5274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R12, 5374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R13, 5474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 5574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R17, 5674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R14, 5774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R15, 5874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R16, 59f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 60f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R26, 61f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R25, 62f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R24, 63f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R23, 64f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 65f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_RET0, 66f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_RET1, 6774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}; 6874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 6974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_call_iarg_regs[4] = { 7074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R26, 7174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R25, 7274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R24, 7374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_R23, 7474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}; 7574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 7674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_call_oarg_regs[2] = { 7774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_RET0, 7874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt TCG_REG_RET1, 7974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}; 8074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 81f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* True iff val fits a signed field of width BITS. */ 82f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline int check_fit_tl(tcg_target_long val, unsigned int bits) 83f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 84f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (val << ((sizeof(tcg_target_long) * 8 - bits)) 85f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner >> (sizeof(tcg_target_long) * 8 - bits)) == val; 86f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 87f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 88f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* True iff depi can be used to compute (reg | MASK). 89f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Accept a bit pattern like: 90f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 0....01....1 91f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1....10....0 92f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 0..01..10..0 93f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Copied from gcc sources. */ 94f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline int or_mask_p(tcg_target_ulong mask) 95f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 96f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (mask == 0 || mask == -1) { 97f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return 0; 98f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 99f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner mask += mask & -mask; 100f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (mask & (mask - 1)) == 0; 101f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 102f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 103f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* True iff depi or extru can be used to compute (reg & mask). 104f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Accept a bit pattern like these: 105f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 0....01....1 106f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1....10....0 107f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1..10..01..1 108f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Copied from gcc sources. */ 109f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline int and_mask_p(tcg_target_ulong mask) 110f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 111f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return or_mask_p(~mask); 112f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 113f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 114f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int low_sign_ext(int val, int len) 115f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 116f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (((val << 1) & ~(-1u << len)) | ((val >> (len - 1)) & 1)); 117f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 118f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 119f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int reassemble_12(int as12) 120f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 121f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (((as12 & 0x800) >> 11) | 122f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as12 & 0x400) >> 8) | 123f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as12 & 0x3ff) << 3)); 124f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 125f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 126f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int reassemble_17(int as17) 127f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 128f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (((as17 & 0x10000) >> 16) | 129f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as17 & 0x0f800) << 5) | 130f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as17 & 0x00400) >> 8) | 131f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as17 & 0x003ff) << 3)); 132f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 133f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 134f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int reassemble_21(int as21) 135f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 136f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return (((as21 & 0x100000) >> 20) | 137f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as21 & 0x0ffe00) >> 8) | 138f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as21 & 0x000180) << 7) | 139f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as21 & 0x00007c) << 14) | 140f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ((as21 & 0x000003) << 12)); 141f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 142f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 143f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* ??? Bizzarely, there is no PCREL12F relocation type. I guess all 144f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner such relocations are simply fully handled by the assembler. */ 145f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define R_PARISC_PCREL12F R_PARISC_NONE 146f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 14774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void patch_reloc(uint8_t *code_ptr, int type, 14874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_target_long value, tcg_target_long addend) 14974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 150f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t *insn_ptr = (uint32_t *)code_ptr; 151f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t insn = *insn_ptr; 152f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long pcrel; 153f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 154f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner value += addend; 155f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner pcrel = (value - ((tcg_target_long)code_ptr + 8)) >> 2; 156f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 15774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt switch (type) { 158f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case R_PARISC_PCREL12F: 159f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(check_fit_tl(pcrel, 12)); 160f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* ??? We assume all patches are forward. See tcg_out_brcond 161f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner re setting the NUL bit on the branch and eliding the nop. */ 162f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(pcrel >= 0); 163f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner insn &= ~0x1ffdu; 164f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner insn |= reassemble_12(pcrel); 165f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 16674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case R_PARISC_PCREL17F: 167f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(check_fit_tl(pcrel, 17)); 168f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner insn &= ~0x1f1ffdu; 169f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner insn |= reassemble_17(pcrel); 17074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 17174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt default: 17274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_abort(); 17374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 174f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 175f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner *insn_ptr = insn; 17674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 17774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 17874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* maximum number of register used for input function arguments */ 17974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline int tcg_target_get_call_iarg_regs_count(int flags) 18074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 18174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt return 4; 18274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 18374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 18474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* parse target specific constraints */ 18574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) 18674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 18774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt const char *ct_str; 18874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 18974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt ct_str = *pct_str; 19074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt switch (ct_str[0]) { 19174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 'r': 19274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt ct->ct |= TCG_CT_REG; 19374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set32(ct->u.regs, 0, 0xffffffff); 19474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 19574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 'L': /* qemu_ld/st constraint */ 19674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt ct->ct |= TCG_CT_REG; 19774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set32(ct->u.regs, 0, 0xffffffff); 19874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_reset_reg(ct->u.regs, TCG_REG_R26); 19974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_reset_reg(ct->u.regs, TCG_REG_R25); 20074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_reset_reg(ct->u.regs, TCG_REG_R24); 20174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_reset_reg(ct->u.regs, TCG_REG_R23); 20274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 203f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'Z': 204f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_0; 205f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 206f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'I': 207f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_S11; 208f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 209f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'J': 210f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_S5; 211f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 212f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'K': 213f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_MS11; 214f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 215f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'M': 216f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_AND; 217f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 218f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 'O': 219f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ct->ct |= TCG_CT_CONST_OR; 220f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 22174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt default: 22274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt return -1; 22374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 22474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt ct_str++; 22574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt *pct_str = ct_str; 22674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt return 0; 22774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 22874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 22974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* test if a constant matches the constraint */ 230f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int tcg_target_const_match(tcg_target_long val, 231f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const TCGArgConstraint *arg_ct) 23274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 233f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int ct = arg_ct->ct; 234f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ct & TCG_CT_CONST) { 235f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return 1; 236f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_0) { 237f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return val == 0; 238f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_S5) { 239f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return check_fit_tl(val, 5); 240f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_S11) { 241f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return check_fit_tl(val, 11); 242f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_MS11) { 243f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return check_fit_tl(-val, 11); 244f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_AND) { 245f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return and_mask_p(val); 246f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (ct & TCG_CT_CONST_OR) { 247f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return or_mask_p(val); 248f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 24974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt return 0; 25074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 25174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 25274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OP(x) ((x) << 26) 25374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT3BR(x) ((x) << 13) 25474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT3SH(x) ((x) << 10) 25574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT4(x) ((x) << 6) 25674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT5(x) (x) 25774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT6(x) ((x) << 6) 25874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT7(x) ((x) << 6) 25974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT8A(x) ((x) << 6) 26074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_EXT8B(x) ((x) << 5) 26174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_T(x) (x) 26274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_R1(x) ((x) << 16) 26374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_R2(x) ((x) << 21) 26474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_DEP_LEN(x) (32 - (x)) 26574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_SHDEP_CP(x) ((31 - (x)) << 5) 26674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_SHDEP_P(x) ((x) << 5) 26774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_COND(x) ((x) << 13) 268f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_IM11(x) low_sign_ext(x, 11) 269f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_IM14(x) low_sign_ext(x, 14) 270f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_IM5(x) (low_sign_ext(x, 5) << 16) 271f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 272f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_NEVER 0 273f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_EQ 1 274f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_LT 2 275f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_LE 3 276f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_LTU 4 277f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_LEU 5 278f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_SV 6 279f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_OD 7 280f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define COND_FALSE 8 281f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 282f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ADD (INSN_OP(0x02) | INSN_EXT6(0x18)) 283f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ADDC (INSN_OP(0x02) | INSN_EXT6(0x1c)) 284f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ADDI (INSN_OP(0x2d)) 285f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ADDIL (INSN_OP(0x0a)) 286f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ADDL (INSN_OP(0x02) | INSN_EXT6(0x28)) 287f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_AND (INSN_OP(0x02) | INSN_EXT6(0x08)) 288f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ANDCM (INSN_OP(0x02) | INSN_EXT6(0x00)) 289f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMCLR (INSN_OP(0x02) | INSN_EXT6(0x22)) 290f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMICLR (INSN_OP(0x24)) 291f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_DEP (INSN_OP(0x35) | INSN_EXT3SH(3)) 292f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_DEPI (INSN_OP(0x35) | INSN_EXT3SH(7)) 293f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_EXTRS (INSN_OP(0x34) | INSN_EXT3SH(7)) 294f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_EXTRU (INSN_OP(0x34) | INSN_EXT3SH(6)) 295f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDIL (INSN_OP(0x08)) 296f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDO (INSN_OP(0x0d)) 297f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_MTCTL (INSN_OP(0x00) | INSN_EXT8B(0xc2)) 298f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_OR (INSN_OP(0x02) | INSN_EXT6(0x09)) 299f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_SHD (INSN_OP(0x34) | INSN_EXT3SH(2)) 300f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_SUB (INSN_OP(0x02) | INSN_EXT6(0x10)) 301f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_SUBB (INSN_OP(0x02) | INSN_EXT6(0x14)) 302f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_SUBI (INSN_OP(0x25)) 303f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_VEXTRS (INSN_OP(0x34) | INSN_EXT3SH(5)) 304f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_VEXTRU (INSN_OP(0x34) | INSN_EXT3SH(4)) 305f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_VSHD (INSN_OP(0x34) | INSN_EXT3SH(0)) 306f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_XOR (INSN_OP(0x02) | INSN_EXT6(0x0a)) 307f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ZDEP (INSN_OP(0x35) | INSN_EXT3SH(2)) 308f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_ZVDEP (INSN_OP(0x35) | INSN_EXT3SH(0)) 309f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 310f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BL (INSN_OP(0x3a) | INSN_EXT3BR(0)) 311f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BL_N (INSN_OP(0x3a) | INSN_EXT3BR(0) | 2) 312f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BLR (INSN_OP(0x3a) | INSN_EXT3BR(2)) 313f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BV (INSN_OP(0x3a) | INSN_EXT3BR(6)) 314f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BV_N (INSN_OP(0x3a) | INSN_EXT3BR(6) | 2) 315f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_BLE_SR4 (INSN_OP(0x39) | (1 << 13)) 316f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 317f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDB (INSN_OP(0x10)) 318f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDH (INSN_OP(0x11)) 319f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDW (INSN_OP(0x12)) 320f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDWM (INSN_OP(0x13)) 321f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_FLDDS (INSN_OP(0x0b) | INSN_EXT4(0) | (1 << 12)) 322f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 323f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDBX (INSN_OP(0x03) | INSN_EXT4(0)) 324f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDHX (INSN_OP(0x03) | INSN_EXT4(1)) 325f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_LDWX (INSN_OP(0x03) | INSN_EXT4(2)) 326f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 327f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_STB (INSN_OP(0x18)) 328f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_STH (INSN_OP(0x19)) 329f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_STW (INSN_OP(0x1a)) 330f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_STWM (INSN_OP(0x1b)) 331f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_FSTDS (INSN_OP(0x0b) | INSN_EXT4(8) | (1 << 12)) 332f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 333f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMBT (INSN_OP(0x20)) 334f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMBF (INSN_OP(0x22)) 335f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMIBT (INSN_OP(0x21)) 336f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#define INSN_COMIBF (INSN_OP(0x23)) 337f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 338f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* supplied by libgcc */ 339f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerextern void *__canonicalize_funcptr_for_compare(void *); 340f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 341f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_mov(TCGContext *s, TCGType type, int ret, int arg) 342f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 343f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* PA1.1 defines COPY as OR r,0,t; PA2.0 defines COPY as LDO 0(r),t 344f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner but hppa-dis.c is unaware of this definition */ 345f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ret != arg) { 346f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_OR | INSN_T(ret) | INSN_R1(arg) 347f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_R2(TCG_REG_R0)); 348f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 349f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 350f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 351f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_movi(TCGContext *s, TCGType type, 352f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int ret, tcg_target_long arg) 353f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 354f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (check_fit_tl(arg, 14)) { 355f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_LDO | INSN_R1(ret) 356f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_R2(TCG_REG_R0) | INSN_IM14(arg)); 357f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 358f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t hi, lo; 359f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner hi = arg >> 11; 360f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lo = arg & 0x7ff; 361f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 362f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_LDIL | INSN_R2(ret) | reassemble_21(hi)); 363f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (lo) { 364f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_LDO | INSN_R1(ret) 365f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_R2(ret) | INSN_IM14(lo)); 366f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 367f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 368f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 369f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 370f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_ldst(TCGContext *s, int ret, int addr, 371f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long offset, int op) 372f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 373f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (!check_fit_tl(offset, 14)) { 374f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t hi, lo, op; 375f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 376f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner hi = offset >> 11; 377f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lo = offset & 0x7ff; 378f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 379f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (addr == TCG_REG_R0) { 380f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = INSN_LDIL | INSN_R2(TCG_REG_R1); 381f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 382f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = INSN_ADDIL | INSN_R2(addr); 383f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 384f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | reassemble_21(hi)); 38574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 386f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner addr = TCG_REG_R1; 387f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = lo; 388f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 389f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 390f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ret != addr || offset != 0 || op != INSN_LDO) { 391f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | INSN_R1(ret) | INSN_R2(addr) | INSN_IM14(offset)); 392f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 393f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 39474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 395f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* This function is required by tcg.c. */ 396f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_ld(TCGContext *s, TCGType type, int ret, 397f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int arg1, tcg_target_long arg2) 398f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 399f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, ret, arg1, arg2, INSN_LDW); 400f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 40174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 402f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* This function is required by tcg.c. */ 403f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_st(TCGContext *s, TCGType type, int ret, 404f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int arg1, tcg_target_long arg2) 405f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 406f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, ret, arg1, arg2, INSN_STW); 407f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 40874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 409f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_ldst_index(TCGContext *s, int data, 410f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int base, int index, int op) 411f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 412f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | INSN_T(data) | INSN_R1(index) | INSN_R2(base)); 413f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 41474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 415f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_addi2(TCGContext *s, int ret, int arg1, 416f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long val) 417f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 418f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, ret, arg1, val, INSN_LDO); 419f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 42074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 421f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* This function is required by tcg.c. */ 422f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val) 423f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 424f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_addi2(s, reg, reg, val); 425f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 42674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 427f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_arith(TCGContext *s, int t, int r1, int r2, int op) 428f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 429f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | INSN_T(t) | INSN_R1(r1) | INSN_R2(r2)); 430f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 43174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 432f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_arithi(TCGContext *s, int t, int r1, 433f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long val, int op) 434f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 435f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(check_fit_tl(val, 11)); 436f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | INSN_R1(t) | INSN_R2(r1) | INSN_IM11(val)); 437f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 43874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 439f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_nop(TCGContext *s) 440f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 441f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, TCG_REG_R0, TCG_REG_R0, TCG_REG_R0, INSN_OR); 442f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 44374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 444f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_mtctl_sar(TCGContext *s, int arg) 44574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 446f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_MTCTL | INSN_R2(11) | INSN_R1(arg)); 44774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 44874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 449f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* Extract LEN bits at position OFS from ARG and place in RET. 450f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Note that here the bit ordering is reversed from the PA-RISC 451f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner standard, such that the right-most bit is 0. */ 452f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_extr(TCGContext *s, int ret, int arg, 453f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner unsigned ofs, unsigned len, int sign) 45474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 455f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(ofs < 32 && len <= 32 - ofs); 456f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, (sign ? INSN_EXTRS : INSN_EXTRU) 457f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_R1(ret) | INSN_R2(arg) 458f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_P(31 - ofs) | INSN_DEP_LEN(len)); 459f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 46074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 461f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* Likewise with OFS interpreted little-endian. */ 462f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_dep(TCGContext *s, int ret, int arg, 463f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner unsigned ofs, unsigned len) 464f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 465f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(ofs < 32 && len <= 32 - ofs); 466f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_DEP | INSN_R2(ret) | INSN_R1(arg) 467f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_CP(31 - ofs) | INSN_DEP_LEN(len)); 46874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 46974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 470f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_shd(TCGContext *s, int ret, int hi, int lo, 471f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner unsigned count) 47274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 473f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(count < 32); 474f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_SHD | INSN_R1(hi) | INSN_R2(lo) | INSN_T(ret) 475f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_CP(count)); 476f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 477f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 478f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_vshd(TCGContext *s, int ret, int hi, int lo, int creg) 479f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 480f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mtctl_sar(s, creg); 481f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_VSHD | INSN_T(ret) | INSN_R1(hi) | INSN_R2(lo)); 482f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 483f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 484f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_ori(TCGContext *s, int ret, int arg, tcg_target_ulong m) 485f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 486f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int bs0, bs1; 487f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 488f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that the argument is constrained to match or_mask_p. */ 489f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (bs0 = 0; bs0 < 32; bs0++) { 490f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if ((m & (1u << bs0)) != 0) { 491f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 492f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 493f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 494f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (bs1 = bs0; bs1 < 32; bs1++) { 495f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if ((m & (1u << bs1)) == 0) { 496f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 497f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 498f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 499f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(bs1 == 32 || (1ul << bs1) > m); 500f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 501f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, ret, arg); 502f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_DEPI | INSN_R2(ret) | INSN_IM5(-1) 503f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_CP(31 - bs0) | INSN_DEP_LEN(bs1 - bs0)); 504f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 505f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 506f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_andi(TCGContext *s, int ret, int arg, tcg_target_ulong m) 507f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 508f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int ls0, ls1, ms0; 509f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 510f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that the argument is constrained to match and_mask_p. */ 511f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (ls0 = 0; ls0 < 32; ls0++) { 512f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if ((m & (1u << ls0)) == 0) { 513f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 514f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 515f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 516f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (ls1 = ls0; ls1 < 32; ls1++) { 517f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if ((m & (1u << ls1)) != 0) { 518f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 519f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 520f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 521f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (ms0 = ls1; ms0 < 32; ms0++) { 522f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if ((m & (1u << ms0)) == 0) { 523f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 524f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 525f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 526f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert (ms0 == 32); 527f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 528f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ls1 == 32) { 529f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, arg, 0, ls0, 0); 53074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } else { 531f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, ret, arg); 532f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_DEPI | INSN_R2(ret) | INSN_IM5(0) 533f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_CP(31 - ls0) | INSN_DEP_LEN(ls1 - ls0)); 53474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 53574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 53674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 537f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_ext8s(TCGContext *s, int ret, int arg) 53874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 539f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, arg, 0, 8, 1); 54074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 54174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 542f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_ext16s(TCGContext *s, int ret, int arg) 54374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 544f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, arg, 0, 16, 1); 54574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 54674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 547f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_shli(TCGContext *s, int ret, int arg, int count) 54874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 549f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner count &= 31; 550f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_ZDEP | INSN_R2(ret) | INSN_R1(arg) 551f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_SHDEP_CP(31 - count) | INSN_DEP_LEN(32 - count)); 55274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 55374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 554f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_shl(TCGContext *s, int ret, int arg, int creg) 55574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 556f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, TCG_REG_R20, creg, 31, INSN_SUBI); 557f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mtctl_sar(s, TCG_REG_R20); 558f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_ZVDEP | INSN_R2(ret) | INSN_R1(arg) | INSN_DEP_LEN(32)); 55974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 56074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 561f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_shri(TCGContext *s, int ret, int arg, int count) 56274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 563f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner count &= 31; 564f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, arg, count, 32 - count, 0); 56574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 56674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 567f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_shr(TCGContext *s, int ret, int arg, int creg) 56874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 569f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_vshd(s, ret, TCG_REG_R0, arg, creg); 57074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 57174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 572f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_sari(TCGContext *s, int ret, int arg, int count) 57374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 574f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner count &= 31; 575f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, arg, count, 32 - count, 1); 57674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 57774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 578f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_sar(TCGContext *s, int ret, int arg, int creg) 57974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 580f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, TCG_REG_R20, creg, 31, INSN_SUBI); 581f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mtctl_sar(s, TCG_REG_R20); 582f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_VEXTRS | INSN_R1(ret) | INSN_R2(arg) | INSN_DEP_LEN(32)); 58374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 58474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 585f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_rotli(TCGContext *s, int ret, int arg, int count) 58674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 587f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner count &= 31; 588f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shd(s, ret, arg, arg, 32 - count); 58974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 59074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 591f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_rotl(TCGContext *s, int ret, int arg, int creg) 592f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 593f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, TCG_REG_R20, creg, 32, INSN_SUBI); 594f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_vshd(s, ret, arg, arg, TCG_REG_R20); 59574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 59674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 597f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_rotri(TCGContext *s, int ret, int arg, int count) 598f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 599f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner count &= 31; 600f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shd(s, ret, arg, arg, count); 60174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 60274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 603f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_rotr(TCGContext *s, int ret, int arg, int creg) 604f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 605f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_vshd(s, ret, arg, arg, creg); 60674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 60774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 608f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_bswap16(TCGContext *s, int ret, int arg, int sign) 609f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 610f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ret != arg) { 611f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, ret, arg); /* arg = xxAB */ 612f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 613f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_dep(s, ret, ret, 16, 8); /* ret = xBAB */ 614f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, ret, ret, 8, 16, sign); /* ret = ..BA */ 61574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 61674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 617f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_bswap32(TCGContext *s, int ret, int arg, int temp) 61874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 619f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* arg = ABCD */ 620f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_rotri(s, temp, arg, 16); /* temp = CDAB */ 621f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_dep(s, temp, temp, 16, 8); /* temp = CBAB */ 622f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shd(s, ret, arg, temp, 8); /* ret = DCBA */ 62374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 62474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 625f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_call(TCGContext *s, void *func) 626f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 627f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long val, hi, lo, disp; 62874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 629f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner val = (uint32_t)__canonicalize_funcptr_for_compare(func); 630f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner disp = (val - ((tcg_target_long)s->code_ptr + 8)) >> 2; 63174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 632f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (check_fit_tl(disp, 17)) { 633f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BL_N | INSN_R2(TCG_REG_RP) | reassemble_17(disp)); 634f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 635f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner hi = val >> 11; 636f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lo = val & 0x7ff; 63774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 638f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_LDIL | INSN_R2(TCG_REG_R20) | reassemble_21(hi)); 639f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BLE_SR4 | INSN_R2(TCG_REG_R20) 640f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | reassemble_17(lo >> 2)); 641f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_RP, TCG_REG_R31); 642f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 643f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 64474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 645f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_xmpyu(TCGContext *s, int retl, int reth, 646f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int arg1, int arg2) 64774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 648f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Store both words into the stack for copy to the FPU. */ 649f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, arg1, TCG_REG_SP, STACK_TEMP_OFS, INSN_STW); 650f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, arg2, TCG_REG_SP, STACK_TEMP_OFS + 4, INSN_STW); 651f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 652f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Load both words into the FPU at the same time. We get away 653f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner with this because we can address the left and right half of the 654f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner FPU registers individually once loaded. */ 655f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* fldds stack_temp(sp),fr22 */ 656f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_FLDDS | INSN_R2(TCG_REG_SP) 657f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_IM5(STACK_TEMP_OFS) | INSN_T(22)); 658f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 659f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* xmpyu fr22r,fr22,fr22 */ 660f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, 0x3ad64796); 661f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 662f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Store the 64-bit result back into the stack. */ 663f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* fstds stack_temp(sp),fr22 */ 664f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_FSTDS | INSN_R2(TCG_REG_SP) 665f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner | INSN_IM5(STACK_TEMP_OFS) | INSN_T(22)); 666f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 667f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Load the pieces of the result that the caller requested. */ 668f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (reth) { 669f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, reth, TCG_REG_SP, STACK_TEMP_OFS, INSN_LDW); 670f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 671f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (retl) { 672f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, retl, TCG_REG_SP, STACK_TEMP_OFS + 4, INSN_LDW); 673f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 674f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 67574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 676f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_add2(TCGContext *s, int destl, int desth, 677f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int al, int ah, int bl, int bh, int blconst) 678f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 679f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int tmp = (destl == ah || destl == bh ? TCG_REG_R20 : destl); 68074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 681f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (blconst) { 682f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, tmp, al, bl, INSN_ADDI); 683f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 684f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, tmp, al, bl, INSN_ADD); 685f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 686f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, desth, ah, bh, INSN_ADDC); 68774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 688f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, destl, tmp); 689f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 69074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 691f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_sub2(TCGContext *s, int destl, int desth, int al, int ah, 692f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int bl, int bh, int alconst, int blconst) 693f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 694f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int tmp = (destl == ah || destl == bh ? TCG_REG_R20 : destl); 69574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 696f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (alconst) { 697f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (blconst) { 698f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_R20, bl); 699f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner bl = TCG_REG_R20; 700f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 701f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, tmp, bl, al, INSN_SUBI); 702f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (blconst) { 703f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, tmp, al, -bl, INSN_ADDI); 704f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 705f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, tmp, al, bl, INSN_SUB); 706f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 707f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, desth, ah, bh, INSN_SUBB); 70874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 709f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, destl, tmp); 710f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 71174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 712f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_branch(TCGContext *s, int label_index, int nul) 713f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 714f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGLabel *l = &s->labels[label_index]; 715f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t op = nul ? INSN_BL_N : INSN_BL; 71674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 717f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (l->has_value) { 718f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long val = l->u.value; 71974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 720f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner val -= (tcg_target_long)s->code_ptr + 8; 721f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner val >>= 2; 722f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(check_fit_tl(val, 17)); 72374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 724f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | reassemble_17(val)); 725f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 726f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* We need to keep the offset unchanged for retranslation. */ 727f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t old_insn = *(uint32_t *)s->code_ptr; 72874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 729f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_reloc(s, s->code_ptr, R_PARISC_PCREL17F, label_index, 0); 730f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | (old_insn & 0x1f1ffdu)); 731f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 732f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 73374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 734f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic const uint8_t tcg_cond_to_cmp_cond[10] = 735f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 736f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_EQ] = COND_EQ, 737f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_NE] = COND_EQ | COND_FALSE, 738f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_LT] = COND_LT, 739f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_GE] = COND_LT | COND_FALSE, 740f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_LE] = COND_LE, 741f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_GT] = COND_LE | COND_FALSE, 742f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_LTU] = COND_LTU, 743f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_GEU] = COND_LTU | COND_FALSE, 744f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_LEU] = COND_LEU, 745f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner [TCG_COND_GTU] = COND_LEU | COND_FALSE, 746f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner}; 74774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 748f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_brcond(TCGContext *s, int cond, TCGArg c1, 749f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg c2, int c2const, int label_index) 750f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 751f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGLabel *l = &s->labels[label_index]; 752f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int op, pacond; 753f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 754f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that COMIB operates as if the immediate is the first 755f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner operand. We model brcond with the immediate in the second 756f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner to better match what targets are likely to give us. For 757f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner consistency, model COMB with reversed operands as well. */ 758f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner pacond = tcg_cond_to_cmp_cond[tcg_swap_cond(cond)]; 759f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 760f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (c2const) { 761f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = (pacond & COND_FALSE ? INSN_COMIBF : INSN_COMIBT); 762f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= INSN_IM5(c2); 763f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 764f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = (pacond & COND_FALSE ? INSN_COMBF : INSN_COMBT); 765f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= INSN_R1(c2); 76674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 767f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= INSN_R2(c1); 768f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= INSN_COND(pacond & 7); 76974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 770f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (l->has_value) { 771f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_target_long val = l->u.value; 77274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 773f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner val -= (tcg_target_long)s->code_ptr + 8; 774f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner val >>= 2; 775f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner assert(check_fit_tl(val, 12)); 77674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 777f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* ??? Assume that all branches to defined labels are backward. 778f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Which means that if the nul bit is set, the delay slot is 779f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner executed if the branch is taken, and not executed in fallthru. */ 780f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | reassemble_12(val)); 781f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_nop(s); 782f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 783f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* We need to keep the offset unchanged for retranslation. */ 784f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t old_insn = *(uint32_t *)s->code_ptr; 785f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 786f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_reloc(s, s->code_ptr, R_PARISC_PCREL12F, label_index, 0); 787f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* ??? Assume that all branches to undefined labels are forward. 788f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Which means that if the nul bit is set, the delay slot is 789f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner not executed if the branch is taken, which is what we want. */ 790f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op | 2 | (old_insn & 0x1ffdu)); 791f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 792f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 79374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 794f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_comclr(TCGContext *s, int cond, TCGArg ret, 795f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg c1, TCGArg c2, int c2const) 796f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 797f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int op, pacond; 798f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 799f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that COMICLR operates as if the immediate is the first 800f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner operand. We model setcond with the immediate in the second 801f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner to better match what targets are likely to give us. For 802f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner consistency, model COMCLR with reversed operands as well. */ 803f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner pacond = tcg_cond_to_cmp_cond[tcg_swap_cond(cond)]; 804f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 805f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (c2const) { 806f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = INSN_COMICLR | INSN_R2(c1) | INSN_R1(ret) | INSN_IM11(c2); 807f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 808f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op = INSN_COMCLR | INSN_R2(c1) | INSN_R1(c2) | INSN_T(ret); 80974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 810f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= INSN_COND(pacond & 7); 811f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner op |= pacond & COND_FALSE ? 1 << 12 : 0; 81274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 813f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, op); 81474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 81574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 816f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_brcond2(TCGContext *s, int cond, TCGArg al, TCGArg ah, 817f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg bl, int blconst, TCGArg bh, int bhconst, 818f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int label_index) 81974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 820f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner switch (cond) { 821f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case TCG_COND_EQ: 822f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case TCG_COND_NE: 823f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, tcg_invert_cond(cond), TCG_REG_R0, al, bl, blconst); 824f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond(s, cond, ah, bh, bhconst, label_index); 825f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 82674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 827f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner default: 828f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond(s, cond, ah, bh, bhconst, label_index); 829f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, TCG_COND_NE, TCG_REG_R0, ah, bh, bhconst); 830f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond(s, tcg_unsigned_cond(cond), 831f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner al, bl, blconst, label_index); 832f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 833f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 834f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 835f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 836f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_setcond(TCGContext *s, int cond, TCGArg ret, 837f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg c1, TCGArg c2, int c2const) 838f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 839f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, tcg_invert_cond(cond), ret, c1, c2, c2const); 840f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, ret, 1); 841f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 84274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 843f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_setcond2(TCGContext *s, int cond, TCGArg ret, 844f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg al, TCGArg ah, TCGArg bl, int blconst, 845f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCGArg bh, int bhconst) 846f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 847f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int scratch = TCG_REG_R20; 848f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 849f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (ret != al && ret != ah 850f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner && (blconst || ret != bl) 851f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner && (bhconst || ret != bh)) { 852f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner scratch = ret; 853f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 85474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 855f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner switch (cond) { 856f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case TCG_COND_EQ: 857f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case TCG_COND_NE: 858f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_setcond(s, cond, scratch, al, bl, blconst); 859f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, TCG_COND_EQ, TCG_REG_R0, ah, bh, bhconst); 860f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, scratch, cond == TCG_COND_NE); 861f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 862f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 863f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner default: 864f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_setcond(s, tcg_unsigned_cond(cond), scratch, al, bl, blconst); 865f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, TCG_COND_EQ, TCG_REG_R0, ah, bh, bhconst); 866f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, scratch, 0); 867f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_comclr(s, cond, TCG_REG_R0, ah, bh, bhconst); 868f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, scratch, 1); 869f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 870f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 871f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 872f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, ret, scratch); 873f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 87474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 87574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU) 876f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#include "../../softmmu_defs.h" 87774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 878f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void *qemu_ld_helpers[4] = { 879f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __ldb_mmu, 880f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __ldw_mmu, 881f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __ldl_mmu, 882f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __ldq_mmu, 883f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner}; 884f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 885f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void *qemu_st_helpers[4] = { 886f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __stb_mmu, 887f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __stw_mmu, 888f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __stl_mmu, 889f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner __stq_mmu, 890f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner}; 891f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 892f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner/* Load and compare a TLB entry, and branch if TLB miss. OFFSET is set to 893f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner the offset of the first ADDR_READ or ADDR_WRITE member of the appropriate 894f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TLB for the memory index. The return value is the offset from ENV 895f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner contained in R1 afterward (to be used when loading ADDEND); if the 896f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return value is 0, R1 is not used. */ 89774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 898f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int tcg_out_tlb_read(TCGContext *s, int r0, int r1, int addrlo, 899f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addrhi, int s_bits, int lab_miss, int offset) 900f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 901f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int ret; 902f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 903f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Extracting the index into the TLB. The "normal C operation" is 904f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner r1 = addr_reg >> TARGET_PAGE_BITS; 905f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner r1 &= CPU_TLB_SIZE - 1; 906f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner r1 <<= CPU_TLB_ENTRY_BITS; 907f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner What this does is extract CPU_TLB_BITS beginning at TARGET_PAGE_BITS 908f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner and place them at CPU_TLB_ENTRY_BITS. We can combine the first two 909f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner operations with an EXTRU. Unfortunately, the current value of 910f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner CPU_TLB_ENTRY_BITS is > 3, so we can't merge that shift with the 911f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner add that follows. */ 912f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_extr(s, r1, addrlo, TARGET_PAGE_BITS, CPU_TLB_BITS, 0); 913f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shli(s, r1, r1, CPU_TLB_ENTRY_BITS); 914f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, r1, r1, TCG_AREG0, INSN_ADDL); 915f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 916f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Make sure that both the addr_{read,write} and addend can be 917f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner read with a 14-bit offset from the same base register. */ 918f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (check_fit_tl(offset + CPU_TLB_SIZE, 14)) { 919f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ret = 0; 920f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 921f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner ret = (offset + 0x400) & ~0x7ff; 922f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = ret - offset; 923f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_addi2(s, TCG_REG_R1, r1, ret); 924f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner r1 = TCG_REG_R1; 925f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 92674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 927f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Load the entry from the computed slot. */ 928f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (TARGET_LONG_BITS == 64) { 929f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R23, r1, offset); 930f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R20, r1, offset + 4); 931f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 932f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R20, r1, offset); 933f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 93474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 935f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Compute the value that ought to appear in the TLB for a hit, namely, the page 936f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner of the address. We include the low N bits of the address to catch unaligned 937f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner accesses and force them onto the slow path. Do this computation after having 938f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner issued the load from the TLB slot to give the load time to complete. */ 939f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, r0, addrlo, TARGET_PAGE_MASK | ((1 << s_bits) - 1)); 94074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 941f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* If not equal, jump to lab_miss. */ 942f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (TARGET_LONG_BITS == 64) { 943f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond2(s, TCG_COND_NE, TCG_REG_R20, TCG_REG_R23, 944f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner r0, 0, addrhi, 0, lab_miss); 945f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 946f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond(s, TCG_COND_NE, TCG_REG_R20, r0, 0, lab_miss); 947f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 94874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 949f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return ret; 950f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 951f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#endif 95274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 953f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_qemu_ld_direct(TCGContext *s, int datalo_reg, int datahi_reg, 954f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addr_reg, int addend_reg, int opc) 955f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 956f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#ifdef TARGET_WORDS_BIGENDIAN 957f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const int bswap = 0; 95874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else 959f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const int bswap = 1; 96074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 96174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 962f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner switch (opc) { 963f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 0: 964f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst_index(s, datalo_reg, addr_reg, addend_reg, INSN_LDBX); 965f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 966f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 0 | 4: 967f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst_index(s, datalo_reg, addr_reg, addend_reg, INSN_LDBX); 968f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext8s(s, datalo_reg, datalo_reg); 969f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 970f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 1: 971f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst_index(s, datalo_reg, addr_reg, addend_reg, INSN_LDHX); 972f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 973f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap16(s, datalo_reg, datalo_reg, 0); 97474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 975f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 976f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 1 | 4: 977f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst_index(s, datalo_reg, addr_reg, addend_reg, INSN_LDHX); 978f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 979f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap16(s, datalo_reg, datalo_reg, 1); 980f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 981f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext16s(s, datalo_reg, datalo_reg); 98274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 983f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 984f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 2: 985f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst_index(s, datalo_reg, addr_reg, addend_reg, INSN_LDWX); 986f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 987f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, datalo_reg, datalo_reg, TCG_REG_R20); 988f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 989f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 990f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 3: 991f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 992f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int t = datahi_reg; 993f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datahi_reg = datalo_reg; 994f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datalo_reg = t; 995f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 996f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* We can't access the low-part with a reg+reg addressing mode, 997f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner so perform the addition now and use reg_ofs addressing mode. */ 998f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (addend_reg != TCG_REG_R0) { 999f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, TCG_REG_R20, addr_reg, addend_reg, INSN_ADD); 1000f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner addr_reg = TCG_REG_R20; 1001f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1002f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Make sure not to clobber the base register. */ 1003f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (datahi_reg == addr_reg) { 1004f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 4, INSN_LDW); 1005f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datahi_reg, addr_reg, 0, INSN_LDW); 1006f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1007f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datahi_reg, addr_reg, 0, INSN_LDW); 1008f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 4, INSN_LDW); 1009f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1010f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 1011f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, datalo_reg, datalo_reg, TCG_REG_R20); 1012f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, datahi_reg, datahi_reg, TCG_REG_R20); 1013f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1014f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1015f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner default: 1016f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_abort(); 101774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 1018f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 1019f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1020f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int opc) 1021f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 1022f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int datalo_reg = *args++; 1023f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that datahi_reg is only used for 64-bit loads. */ 1024f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int datahi_reg = (opc == 3 ? *args++ : TCG_REG_R0); 1025f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addrlo_reg = *args++; 1026f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1027f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#if defined(CONFIG_SOFTMMU) 1028f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that addrhi_reg is only used for 64-bit guests. */ 1029f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addrhi_reg = (TARGET_LONG_BITS == 64 ? *args++ : TCG_REG_R0); 1030f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int mem_index = *args; 1031f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int lab1, lab2, argreg, offset; 1032f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1033f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lab1 = gen_new_label(); 1034f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lab2 = gen_new_label(); 103574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1036f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = offsetof(CPUState, tlb_table[mem_index][0].addr_read); 1037f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = tcg_out_tlb_read(s, TCG_REG_R26, TCG_REG_R25, addrlo_reg, addrhi_reg, 1038f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner opc & 3, lab1, offset); 103974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1040f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* TLB Hit. */ 1041f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R20, (offset ? TCG_REG_R1 : TCG_REG_R25), 1042f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offsetof(CPUState, tlb_table[mem_index][0].addend) - offset); 1043f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_ld_direct(s, datalo_reg, datahi_reg, addrlo_reg, TCG_REG_R20, opc); 1044f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_branch(s, lab2, 1); 1045f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1046f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* TLB Miss. */ 104774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt /* label1: */ 1048f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_label(s, lab1, (tcg_target_long)s->code_ptr); 1049f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1050f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner argreg = TCG_REG_R26; 1051f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, argreg--, addrlo_reg); 1052f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (TARGET_LONG_BITS == 64) { 1053f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, argreg--, addrhi_reg); 1054f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1055f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, argreg, mem_index); 1056f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1057f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_call(s, qemu_ld_helpers[opc & 3]); 1058f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1059f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner switch (opc) { 1060f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 0: 1061f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, datalo_reg, TCG_REG_RET0, 0xff); 1062f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1063f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 0 | 4: 1064f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext8s(s, datalo_reg, TCG_REG_RET0); 1065f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1066f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 1: 1067f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, datalo_reg, TCG_REG_RET0, 0xffff); 1068f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1069f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 1 | 4: 1070f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext16s(s, datalo_reg, TCG_REG_RET0); 1071f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1072f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 2: 1073f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 2 | 4: 1074f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, datalo_reg, TCG_REG_RET0); 1075f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1076f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 3: 1077f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, datahi_reg, TCG_REG_RET0); 1078f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, datalo_reg, TCG_REG_RET1); 1079f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1080f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner default: 1081f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_abort(); 1082f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 108374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1084f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* label2: */ 1085f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_label(s, lab2, (tcg_target_long)s->code_ptr); 108674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else 1087f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_ld_direct(s, datalo_reg, datahi_reg, addrlo_reg, 1088f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner (GUEST_BASE ? TCG_GUEST_BASE_REG : TCG_REG_R0), opc); 108974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 1090f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 109174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1092f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_qemu_st_direct(TCGContext *s, int datalo_reg, int datahi_reg, 1093f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addr_reg, int opc) 1094f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 109574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN 1096f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const int bswap = 0; 109774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else 1098f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const int bswap = 1; 109974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 1100f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 110174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt switch (opc) { 110274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 0: 1103f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 0, INSN_STB); 110474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 110574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 1: 110674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt if (bswap) { 1107f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap16(s, TCG_REG_R20, datalo_reg, 0); 1108f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datalo_reg = TCG_REG_R20; 110974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 1110f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 0, INSN_STH); 111174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 111274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 2: 111374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt if (bswap) { 1114f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, TCG_REG_R20, datalo_reg, TCG_REG_R20); 1115f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datalo_reg = TCG_REG_R20; 111674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 1117f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 0, INSN_STW); 111874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 111974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case 3: 1120f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (bswap) { 1121f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, TCG_REG_R20, datalo_reg, TCG_REG_R20); 1122f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, TCG_REG_R23, datahi_reg, TCG_REG_R23); 1123f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datahi_reg = TCG_REG_R20; 1124f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner datalo_reg = TCG_REG_R23; 1125f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1126f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datahi_reg, addr_reg, 0, INSN_STW); 1127f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, datalo_reg, addr_reg, 4, INSN_STW); 1128f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1129f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner default: 113074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_abort(); 1131f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1132f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1133f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 1134f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1135f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int opc) 1136f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 1137f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int datalo_reg = *args++; 1138f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that datahi_reg is only used for 64-bit loads. */ 1139f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int datahi_reg = (opc == 3 ? *args++ : TCG_REG_R0); 1140f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addrlo_reg = *args++; 1141f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1142f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#if defined(CONFIG_SOFTMMU) 1143f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that addrhi_reg is only used for 64-bit guests. */ 1144f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int addrhi_reg = (TARGET_LONG_BITS == 64 ? *args++ : TCG_REG_R0); 1145f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int mem_index = *args; 1146f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int lab1, lab2, argreg, offset; 1147f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1148f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lab1 = gen_new_label(); 1149f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lab2 = gen_new_label(); 1150f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1151f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = offsetof(CPUState, tlb_table[mem_index][0].addr_write); 1152f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offset = tcg_out_tlb_read(s, TCG_REG_R26, TCG_REG_R25, addrlo_reg, addrhi_reg, 1153f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner opc, lab1, offset); 1154f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1155f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* TLB Hit. */ 1156f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R20, (offset ? TCG_REG_R1 : TCG_REG_R25), 1157f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner offsetof(CPUState, tlb_table[mem_index][0].addend) - offset); 1158f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1159f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* There are no indexed stores, so we must do this addition explitly. 1160f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner Careful to avoid R20, which is used for the bswaps to follow. */ 1161f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, TCG_REG_R31, addrlo_reg, TCG_REG_R20, INSN_ADDL); 1162f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_st_direct(s, datalo_reg, datahi_reg, TCG_REG_R31, opc); 1163f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_branch(s, lab2, 1); 1164f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1165f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* TLB Miss. */ 1166f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* label1: */ 1167f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_label(s, lab1, (tcg_target_long)s->code_ptr); 1168f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1169f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner argreg = TCG_REG_R26; 1170f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, argreg--, addrlo_reg); 1171f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (TARGET_LONG_BITS == 64) { 1172f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, argreg--, addrhi_reg); 1173f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1174f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1175f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner switch(opc) { 1176f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 0: 1177f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, argreg--, datalo_reg, 0xff); 1178f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, argreg, mem_index); 1179f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1180f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 1: 1181f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, argreg--, datalo_reg, 0xffff); 1182f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, argreg, mem_index); 1183f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1184f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 2: 1185f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, argreg--, datalo_reg); 1186f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, argreg, mem_index); 1187f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1188f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case 3: 1189f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Because of the alignment required by the 64-bit data argument, 1190f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner we will always use R23/R24. Also, we will always run out of 1191f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner argument registers for storing mem_index, so that will have 1192f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner to go on the stack. */ 1193f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (mem_index == 0) { 1194f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner argreg = TCG_REG_R0; 119574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } else { 1196f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner argreg = TCG_REG_R20; 1197f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, argreg, mem_index); 119874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 1199f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R23, datahi_reg); 1200f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R24, datalo_reg); 1201f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_st(s, TCG_TYPE_I32, argreg, TCG_REG_SP, 1202f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_TARGET_CALL_STACK_OFFSET - 4); 120374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 120474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt default: 120574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_abort(); 120674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 120774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1208f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_call(s, qemu_st_helpers[opc]); 1209f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 121074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt /* label2: */ 1211f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_label(s, lab2, (tcg_target_long)s->code_ptr); 1212f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#else 1213f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* There are no indexed stores, so if GUEST_BASE is set we must do the add 1214f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner explicitly. Careful to avoid R20, which is used for the bswaps to follow. */ 1215f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (GUEST_BASE != 0) { 1216f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, TCG_REG_R31, addrlo_reg, TCG_GUEST_BASE_REG, INSN_ADDL); 1217f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner addrlo_reg = TCG_REG_R31; 1218f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1219f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_st_direct(s, datalo_reg, datahi_reg, addrlo_reg, opc); 122074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 122174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 122274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1223f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_exit_tb(TCGContext *s, TCGArg arg) 1224f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 1225f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (!check_fit_tl(arg, 14)) { 1226f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner uint32_t hi, lo; 1227f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner hi = arg & ~0x7ff; 1228f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner lo = arg & 0x7ff; 1229f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (lo) { 1230f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RET0, hi); 1231f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BV | INSN_R2(TCG_REG_R18)); 1232f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_addi(s, TCG_REG_RET0, lo); 1233f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner return; 1234f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1235f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner arg = hi; 1236f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1237f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BV | INSN_R2(TCG_REG_R18)); 1238f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RET0, arg); 1239f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 1240f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1241f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_goto_tb(TCGContext *s, TCGArg arg) 124274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 1243f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (s->tb_jmp_offset) { 1244f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* direct jump method */ 1245f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner fprintf(stderr, "goto_tb direct\n"); 1246f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_abort(); 1247f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1248f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* indirect jump method */ 1249f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R20, TCG_REG_R0, 1250f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner (tcg_target_long)(s->tb_next + arg)); 1251f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BV_N | INSN_R2(TCG_REG_R20)); 1252f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1253f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner s->tb_next_offset[arg] = s->code_ptr - s->code_buf; 1254f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 125574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1256f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, 1257f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner const int *const_args) 1258f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 125974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt switch (opc) { 126074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_exit_tb: 1261f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_exit_tb(s, args[0]); 126274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 126374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_goto_tb: 1264f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_goto_tb(s, args[0]); 126574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1266f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 126774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_call: 1268f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[0]) { 1269f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_call(s, (void *)args[0]); 1270f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1271f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* ??? FIXME: the value in the register in args[0] is almost 1272f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner certainly a procedure descriptor, not a code address. We 1273f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner probably need to use the millicode $$dyncall routine. */ 1274f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_abort(); 1275f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 127674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1277f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 127874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_jmp: 127974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt fprintf(stderr, "unimplemented jmp\n"); 128074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_abort(); 128174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1282f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 128374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_br: 1284f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_branch(s, args[0], 1); 128574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1286f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 128774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_movi_i32: 128874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]); 128974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 129074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 129174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_ld8u_i32: 1292f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_LDB); 129374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 129474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_ld8s_i32: 1295f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_LDB); 129674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_ext8s(s, args[0], args[0]); 129774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 129874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_ld16u_i32: 1299f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_LDH); 130074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 130174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_ld16s_i32: 1302f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_LDH); 130374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_ext16s(s, args[0], args[0]); 130474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 130574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_ld_i32: 1306f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_LDW); 130774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 130874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 130974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_st8_i32: 1310f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_STB); 131174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 131274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_st16_i32: 1313f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_STH); 131474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 131574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_st_i32: 1316f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, args[0], args[1], args[2], INSN_STW); 1317f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1318f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1319f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_add_i32: 1320f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1321f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_addi2(s, args[0], args[1], args[2]); 1322f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1323f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_ADDL); 1324f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 132574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 132674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 132774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_sub_i32: 1328f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[1]) { 1329f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1330f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1] - args[2]); 1331f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1332f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Recall that SUBI is a reversed subtract. */ 1333f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, args[0], args[2], args[1], INSN_SUBI); 1334f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1335f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else if (const_args[2]) { 1336f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_addi2(s, args[0], args[1], -args[2]); 1337f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1338f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_SUB); 1339f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1340f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1341f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 134274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_and_i32: 1343f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1344f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, args[0], args[1], args[2]); 1345f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1346f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_AND); 1347f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1348f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1349f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 135074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_or_i32: 1351f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1352f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ori(s, args[0], args[1], args[2]); 1353f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1354f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_OR); 1355f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1356f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1357f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 135874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_xor_i32: 1359f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_XOR); 1360f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1361f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1362f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_andc_i32: 1363f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1364f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_andi(s, args[0], args[1], ~args[2]); 1365f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1366f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arith(s, args[0], args[1], args[2], INSN_ANDCM); 1367f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1368f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 136974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 137074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_shl_i32: 1371f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1372f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shli(s, args[0], args[1], args[2]); 1373f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1374f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shl(s, args[0], args[1], args[2]); 1375f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 137674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1377f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 137874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_shr_i32: 1379f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1380f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shri(s, args[0], args[1], args[2]); 1381f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1382f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_shr(s, args[0], args[1], args[2]); 1383f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 138474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1385f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 138674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_sar_i32: 1387f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1388f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_sari(s, args[0], args[1], args[2]); 1389f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1390f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_sar(s, args[0], args[1], args[2]); 1391f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1392f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1393f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1394f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_rotl_i32: 1395f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1396f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_rotli(s, args[0], args[1], args[2]); 1397f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1398f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_rotl(s, args[0], args[1], args[2]); 1399f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1400f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1401f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1402f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_rotr_i32: 1403f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (const_args[2]) { 1404f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_rotri(s, args[0], args[1], args[2]); 1405f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } else { 1406f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_rotr(s, args[0], args[1], args[2]); 1407f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 140874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 140974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 141074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_mul_i32: 1411f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_xmpyu(s, args[0], TCG_REG_R0, args[1], args[2]); 141274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 141374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_mulu2_i32: 1414f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_xmpyu(s, args[0], args[1], args[2], args[3]); 141574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1416f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1417f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_bswap16_i32: 1418f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap16(s, args[0], args[1], 0); 141974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1420f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_bswap32_i32: 1421f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_bswap32(s, args[0], args[1], TCG_REG_R20); 1422f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1423f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1424f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_not_i32: 1425f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_arithi(s, args[0], args[1], -1, INSN_SUBI); 1426f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1427f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_ext8s_i32: 1428f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext8s(s, args[0], args[1]); 1429f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1430f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_ext16s_i32: 1431f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ext16s(s, args[0], args[1]); 143274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 143374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 143474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_brcond_i32: 1435f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond(s, args[2], args[0], args[1], const_args[1], args[3]); 1436f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1437f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_brcond2_i32: 1438f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_brcond2(s, args[4], args[0], args[1], 1439f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner args[2], const_args[2], 1440f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner args[3], const_args[3], args[5]); 1441f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1442f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1443f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_setcond_i32: 1444f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_setcond(s, args[3], args[0], args[1], args[2], const_args[2]); 1445f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1446f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_setcond2_i32: 1447f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_setcond2(s, args[5], args[0], args[1], args[2], 1448f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner args[3], const_args[3], args[4], const_args[4]); 1449f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1450f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1451f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_add2_i32: 1452f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_add2(s, args[0], args[1], args[2], args[3], 1453f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner args[4], args[5], const_args[4]); 1454f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 1455f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1456f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_sub2_i32: 1457f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_sub2(s, args[0], args[1], args[2], args[3], 1458f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner args[4], args[5], const_args[2], const_args[4]); 145974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 146074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 146174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_ld8u: 146274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_ld(s, args, 0); 146374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 146474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_ld8s: 146574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_ld(s, args, 0 | 4); 146674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 146774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_ld16u: 146874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_ld(s, args, 1); 146974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 147074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_ld16s: 147174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_ld(s, args, 1 | 4); 147274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1473f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_qemu_ld32: 147474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_ld(s, args, 2); 147574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1476f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_qemu_ld64: 1477f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_ld(s, args, 3); 1478f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 147974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 148074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_st8: 148174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_st(s, args, 0); 148274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 148374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_st16: 148474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_st(s, args, 1); 148574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 148674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt case INDEX_op_qemu_st32: 148774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_out_qemu_st(s, args, 2); 148874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt break; 1489f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner case INDEX_op_qemu_st64: 1490f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_qemu_st(s, args, 3); 1491f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner break; 149274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 149374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt default: 149474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt fprintf(stderr, "unknown opcode 0x%x\n", opc); 149574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_abort(); 149674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt } 149774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 149874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 149974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const TCGTargetOpDef hppa_op_defs[] = { 150074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_exit_tb, { } }, 150174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_goto_tb, { } }, 150274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1503f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_call, { "ri" } }, 150474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_jmp, { "r" } }, 150574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_br, { } }, 150674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 150774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_mov_i32, { "r", "r" } }, 150874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_movi_i32, { "r" } }, 1509f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 151074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_ld8u_i32, { "r", "r" } }, 151174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_ld8s_i32, { "r", "r" } }, 151274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_ld16u_i32, { "r", "r" } }, 151374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_ld16s_i32, { "r", "r" } }, 151474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_ld_i32, { "r", "r" } }, 1515f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_st8_i32, { "rZ", "r" } }, 1516f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_st16_i32, { "rZ", "r" } }, 1517f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_st_i32, { "rZ", "r" } }, 151874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1519f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_add_i32, { "r", "rZ", "ri" } }, 1520f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_sub_i32, { "r", "rI", "ri" } }, 1521f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_and_i32, { "r", "rZ", "rM" } }, 1522f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_or_i32, { "r", "rZ", "rO" } }, 1523f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_xor_i32, { "r", "rZ", "rZ" } }, 1524f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Note that the second argument will be inverted, which means 1525f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner we want a constant whose inversion matches M, and that O = ~M. 1526f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner See the implementation of and_mask_p. */ 1527f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_andc_i32, { "r", "rZ", "rO" } }, 152874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1529f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_mul_i32, { "r", "r", "r" } }, 1530f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_mulu2_i32, { "r", "r", "r", "r" } }, 153174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1532f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_shl_i32, { "r", "r", "ri" } }, 1533f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_shr_i32, { "r", "r", "ri" } }, 1534f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_sar_i32, { "r", "r", "ri" } }, 1535f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_rotl_i32, { "r", "r", "ri" } }, 1536f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_rotr_i32, { "r", "r", "ri" } }, 1537f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1538f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_bswap16_i32, { "r", "r" } }, 1539f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_bswap32_i32, { "r", "r" } }, 1540f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_not_i32, { "r", "r" } }, 1541f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1542f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_ext8s_i32, { "r", "r" } }, 1543f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_ext16s_i32, { "r", "r" } }, 1544f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1545f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_brcond_i32, { "rZ", "rJ" } }, 1546f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_brcond2_i32, { "rZ", "rZ", "rJ", "rJ" } }, 1547f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1548f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_setcond_i32, { "r", "rZ", "rI" } }, 1549f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_setcond2_i32, { "r", "rZ", "rZ", "rI", "rI" } }, 1550f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1551f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_add2_i32, { "r", "r", "rZ", "rZ", "rI", "rZ" } }, 1552f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_sub2_i32, { "r", "r", "rI", "rZ", "rK", "rZ" } }, 155374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 155474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32 155574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld8u, { "r", "L" } }, 155674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld8s, { "r", "L" } }, 155774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld16u, { "r", "L" } }, 155874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld16s, { "r", "L" } }, 1559f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_ld32, { "r", "L" } }, 156074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld64, { "r", "r", "L" } }, 156174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1562f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st8, { "LZ", "L" } }, 1563f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st16, { "LZ", "L" } }, 1564f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st32, { "LZ", "L" } }, 1565f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st64, { "LZ", "LZ", "L" } }, 156674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else 156774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld8u, { "r", "L", "L" } }, 156874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld8s, { "r", "L", "L" } }, 156974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld16u, { "r", "L", "L" } }, 157074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld16s, { "r", "L", "L" } }, 1571f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_ld32, { "r", "L", "L" } }, 157274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { INDEX_op_qemu_ld64, { "r", "r", "L", "L" } }, 157374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1574f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st8, { "LZ", "L", "L" } }, 1575f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st16, { "LZ", "L", "L" } }, 1576f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st32, { "LZ", "L", "L" } }, 1577f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner { INDEX_op_qemu_st64, { "LZ", "LZ", "L", "L" } }, 157874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif 157974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt { -1 }, 158074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}; 158174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 1582f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic int tcg_target_callee_save_regs[] = { 1583f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* R2, the return address register, is saved specially 1584f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner in the caller's frame. */ 1585f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* R3, the frame pointer, is not currently modified. */ 1586f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R4, 1587f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R5, 1588f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R6, 1589f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R7, 1590f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R8, 1591f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R9, 1592f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R10, 1593f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R11, 1594f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R12, 1595f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R13, 1596f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R14, 1597f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R15, 1598f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R16, 1599f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* R17 is the global env, so no need to save. */ 1600f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_R18 1601f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner}; 1602f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1603f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_target_qemu_prologue(TCGContext *s) 1604f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner{ 1605f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner int frame_size, i; 1606f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1607f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Allocate space for the fixed frame marker. */ 1608f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner frame_size = -TCG_TARGET_CALL_STACK_OFFSET; 1609f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner frame_size += TCG_TARGET_STATIC_CALL_ARGS_SIZE; 1610f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1611f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Allocate space for the saved registers. */ 1612f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner frame_size += ARRAY_SIZE(tcg_target_callee_save_regs) * 4; 1613f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1614f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Align the allocated space. */ 1615f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner frame_size = ((frame_size + TCG_TARGET_STACK_ALIGN - 1) 1616f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner & -TCG_TARGET_STACK_ALIGN); 1617f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1618f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* The return address is stored in the caller's frame. */ 1619f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_RP, TCG_REG_SP, -20); 1620f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1621f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Allocate stack frame, saving the first register at the same time. */ 1622f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, tcg_target_callee_save_regs[0], 1623f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_SP, frame_size, INSN_STWM); 1624f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1625f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Save all callee saved registers. */ 1626f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (i = 1; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { 1627f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_st(s, TCG_TYPE_PTR, tcg_target_callee_save_regs[i], 1628f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_SP, -frame_size + i * 4); 1629f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1630f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1631f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#ifdef CONFIG_USE_GUEST_BASE 1632f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner if (GUEST_BASE != 0) { 1633f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, GUEST_BASE); 1634f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); 1635f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1636f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#endif 1637f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1638f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Jump to TB, and adjust R18 to be the return address. */ 1639f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BLE_SR4 | INSN_R2(TCG_REG_R26)); 1640f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R18, TCG_REG_R31); 1641f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1642f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Restore callee saved registers. */ 1643f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_RP, TCG_REG_SP, -frame_size - 20); 1644f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner for (i = 1; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { 1645f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ld(s, TCG_TYPE_PTR, tcg_target_callee_save_regs[i], 1646f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_SP, -frame_size + i * 4); 1647f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner } 1648f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1649f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner /* Deallocate stack frame and return. */ 1650f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out32(s, INSN_BV | INSN_R2(TCG_REG_RP)); 1651f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_out_ldst(s, tcg_target_callee_save_regs[0], 1652f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner TCG_REG_SP, -frame_size, INSN_LDWM); 1653f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner} 1654f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1655f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_target_init(TCGContext *s) 165674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{ 165774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff); 1658f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner 1659f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_clear(tcg_target_call_clobber_regs); 1660f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R20); 1661f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R21); 1662f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R22); 1663f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R23); 1664f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R24); 1665f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R25); 1666f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R26); 1667f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_RET0); 1668f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_RET1); 166974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 167074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_clear(s->reserved_regs); 167174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0); /* hardwired to zero */ 167274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R1); /* addil target */ 167374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_RP); /* link register */ 167474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R3); /* frame pointer */ 167574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R18); /* return pointer */ 167674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R19); /* clobbered w/o pic */ 167774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R20); /* reserved */ 167874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_DP); /* data pointer */ 167974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_SP); /* stack pointer */ 168074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_regset_set_reg(s->reserved_regs, TCG_REG_R31); /* ble link reg */ 168174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt 168274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt tcg_add_target_add_op_defs(hppa_op_defs); 168374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt} 1684