bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Tiny Code Generator for QEMU |
| 3 | * |
| 4 | * Copyright (c) 2008 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef TCG_H |
| 26 | #define TCG_H |
| 27 | |
aurel32 | f839394 | 2009-04-13 18:45:38 +0000 | [diff] [blame] | 28 | #include "qemu-common.h" |
Paolo Bonzini | 33c1187 | 2016-03-15 16:58:45 +0100 | [diff] [blame] | 29 | #include "cpu.h" |
Paolo Bonzini | 00f6da6 | 2016-03-15 13:16:36 +0100 | [diff] [blame] | 30 | #include "exec/tb-context.h" |
Richard Henderson | 0ec9eab | 2013-09-19 12:16:45 -0700 | [diff] [blame] | 31 | #include "qemu/bitops.h" |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 32 | #include "qemu/queue.h" |
Alex Bennée | 2093714 | 2017-02-23 18:29:07 +0000 | [diff] [blame] | 33 | #include "tcg-mo.h" |
Richard Henderson | 78cd7b8 | 2013-08-20 14:41:29 -0700 | [diff] [blame] | 34 | #include "tcg-target.h" |
Richard Henderson | e6cd4bb | 2018-08-15 16:31:47 -0700 | [diff] [blame] | 35 | #include "qemu/int128.h" |
Richard Henderson | 78cd7b8 | 2013-08-20 14:41:29 -0700 | [diff] [blame] | 36 | |
Paolo Bonzini | 00f6da6 | 2016-03-15 13:16:36 +0100 | [diff] [blame] | 37 | /* XXX: make safe guess about sizes */ |
| 38 | #define MAX_OP_PER_INSTR 266 |
| 39 | |
| 40 | #if HOST_LONG_BITS == 32 |
| 41 | #define MAX_OPC_PARAM_PER_ARG 2 |
| 42 | #else |
| 43 | #define MAX_OPC_PARAM_PER_ARG 1 |
| 44 | #endif |
Richard Henderson | 1df3caa | 2017-12-13 16:52:57 -0600 | [diff] [blame] | 45 | #define MAX_OPC_PARAM_IARGS 6 |
Paolo Bonzini | 00f6da6 | 2016-03-15 13:16:36 +0100 | [diff] [blame] | 46 | #define MAX_OPC_PARAM_OARGS 1 |
| 47 | #define MAX_OPC_PARAM_ARGS (MAX_OPC_PARAM_IARGS + MAX_OPC_PARAM_OARGS) |
| 48 | |
| 49 | /* A Call op needs up to 4 + 2N parameters on 32-bit archs, |
| 50 | * and up to 4 + N parameters on 64-bit archs |
| 51 | * (N = number of input arguments + output arguments). */ |
| 52 | #define MAX_OPC_PARAM (4 + (MAX_OPC_PARAM_PER_ARG * MAX_OPC_PARAM_ARGS)) |
Paolo Bonzini | 00f6da6 | 2016-03-15 13:16:36 +0100 | [diff] [blame] | 53 | |
Peter Crosthwaite | 6e0b073 | 2015-05-30 23:11:34 -0700 | [diff] [blame] | 54 | #define CPU_TEMP_BUF_NLONGS 128 |
| 55 | |
Richard Henderson | 78cd7b8 | 2013-08-20 14:41:29 -0700 | [diff] [blame] | 56 | /* Default target word size to pointer size. */ |
| 57 | #ifndef TCG_TARGET_REG_BITS |
| 58 | # if UINTPTR_MAX == UINT32_MAX |
| 59 | # define TCG_TARGET_REG_BITS 32 |
| 60 | # elif UINTPTR_MAX == UINT64_MAX |
| 61 | # define TCG_TARGET_REG_BITS 64 |
| 62 | # else |
| 63 | # error Unknown pointer size for tcg target |
| 64 | # endif |
Stefan Weil | 817b838 | 2011-09-17 22:00:27 +0200 | [diff] [blame] | 65 | #endif |
| 66 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 67 | #if TCG_TARGET_REG_BITS == 32 |
| 68 | typedef int32_t tcg_target_long; |
| 69 | typedef uint32_t tcg_target_ulong; |
| 70 | #define TCG_PRIlx PRIx32 |
| 71 | #define TCG_PRIld PRId32 |
| 72 | #elif TCG_TARGET_REG_BITS == 64 |
| 73 | typedef int64_t tcg_target_long; |
| 74 | typedef uint64_t tcg_target_ulong; |
| 75 | #define TCG_PRIlx PRIx64 |
| 76 | #define TCG_PRIld PRId64 |
| 77 | #else |
| 78 | #error unsupported |
| 79 | #endif |
| 80 | |
KONRAD Frederic | 8d4e914 | 2017-02-23 18:29:08 +0000 | [diff] [blame] | 81 | /* Oversized TCG guests make things like MTTCG hard |
| 82 | * as we can't use atomics for cputlb updates. |
| 83 | */ |
| 84 | #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS |
| 85 | #define TCG_OVERSIZED_GUEST 1 |
| 86 | #else |
| 87 | #define TCG_OVERSIZED_GUEST 0 |
| 88 | #endif |
| 89 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 90 | #if TCG_TARGET_NB_REGS <= 32 |
| 91 | typedef uint32_t TCGRegSet; |
| 92 | #elif TCG_TARGET_NB_REGS <= 64 |
| 93 | typedef uint64_t TCGRegSet; |
| 94 | #else |
| 95 | #error unsupported |
| 96 | #endif |
| 97 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 98 | #if TCG_TARGET_REG_BITS == 32 |
Richard Henderson | e6a7273 | 2013-02-19 23:51:49 -0800 | [diff] [blame] | 99 | /* Turn some undef macros into false macros. */ |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 100 | #define TCG_TARGET_HAS_extrl_i64_i32 0 |
| 101 | #define TCG_TARGET_HAS_extrh_i64_i32 0 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 102 | #define TCG_TARGET_HAS_div_i64 0 |
Richard Henderson | ca675f4 | 2013-03-11 22:41:47 -0700 | [diff] [blame] | 103 | #define TCG_TARGET_HAS_rem_i64 0 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 104 | #define TCG_TARGET_HAS_div2_i64 0 |
| 105 | #define TCG_TARGET_HAS_rot_i64 0 |
| 106 | #define TCG_TARGET_HAS_ext8s_i64 0 |
| 107 | #define TCG_TARGET_HAS_ext16s_i64 0 |
| 108 | #define TCG_TARGET_HAS_ext32s_i64 0 |
| 109 | #define TCG_TARGET_HAS_ext8u_i64 0 |
| 110 | #define TCG_TARGET_HAS_ext16u_i64 0 |
| 111 | #define TCG_TARGET_HAS_ext32u_i64 0 |
| 112 | #define TCG_TARGET_HAS_bswap16_i64 0 |
| 113 | #define TCG_TARGET_HAS_bswap32_i64 0 |
| 114 | #define TCG_TARGET_HAS_bswap64_i64 0 |
| 115 | #define TCG_TARGET_HAS_neg_i64 0 |
| 116 | #define TCG_TARGET_HAS_not_i64 0 |
| 117 | #define TCG_TARGET_HAS_andc_i64 0 |
| 118 | #define TCG_TARGET_HAS_orc_i64 0 |
| 119 | #define TCG_TARGET_HAS_eqv_i64 0 |
| 120 | #define TCG_TARGET_HAS_nand_i64 0 |
| 121 | #define TCG_TARGET_HAS_nor_i64 0 |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 122 | #define TCG_TARGET_HAS_clz_i64 0 |
| 123 | #define TCG_TARGET_HAS_ctz_i64 0 |
Richard Henderson | a768e4e | 2016-11-21 11:13:39 +0100 | [diff] [blame] | 124 | #define TCG_TARGET_HAS_ctpop_i64 0 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 125 | #define TCG_TARGET_HAS_deposit_i64 0 |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 126 | #define TCG_TARGET_HAS_extract_i64 0 |
| 127 | #define TCG_TARGET_HAS_sextract_i64 0 |
Richard Henderson | ffc5ea0 | 2012-09-21 10:13:34 -0700 | [diff] [blame] | 128 | #define TCG_TARGET_HAS_movcond_i64 0 |
Richard Henderson | d7156f7 | 2013-02-19 23:51:52 -0800 | [diff] [blame] | 129 | #define TCG_TARGET_HAS_add2_i64 0 |
| 130 | #define TCG_TARGET_HAS_sub2_i64 0 |
| 131 | #define TCG_TARGET_HAS_mulu2_i64 0 |
Richard Henderson | 4d3203f | 2013-02-19 23:51:53 -0800 | [diff] [blame] | 132 | #define TCG_TARGET_HAS_muls2_i64 0 |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 133 | #define TCG_TARGET_HAS_muluh_i64 0 |
| 134 | #define TCG_TARGET_HAS_mulsh_i64 0 |
Richard Henderson | e6a7273 | 2013-02-19 23:51:49 -0800 | [diff] [blame] | 135 | /* Turn some undef macros into true macros. */ |
| 136 | #define TCG_TARGET_HAS_add2_i32 1 |
| 137 | #define TCG_TARGET_HAS_sub2_i32 1 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
Jan Kiszka | a477332 | 2011-09-29 18:52:11 +0200 | [diff] [blame] | 140 | #ifndef TCG_TARGET_deposit_i32_valid |
| 141 | #define TCG_TARGET_deposit_i32_valid(ofs, len) 1 |
| 142 | #endif |
| 143 | #ifndef TCG_TARGET_deposit_i64_valid |
| 144 | #define TCG_TARGET_deposit_i64_valid(ofs, len) 1 |
| 145 | #endif |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 146 | #ifndef TCG_TARGET_extract_i32_valid |
| 147 | #define TCG_TARGET_extract_i32_valid(ofs, len) 1 |
| 148 | #endif |
| 149 | #ifndef TCG_TARGET_extract_i64_valid |
| 150 | #define TCG_TARGET_extract_i64_valid(ofs, len) 1 |
| 151 | #endif |
Jan Kiszka | a477332 | 2011-09-29 18:52:11 +0200 | [diff] [blame] | 152 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 153 | /* Only one of DIV or DIV2 should be defined. */ |
| 154 | #if defined(TCG_TARGET_HAS_div_i32) |
| 155 | #define TCG_TARGET_HAS_div2_i32 0 |
| 156 | #elif defined(TCG_TARGET_HAS_div2_i32) |
| 157 | #define TCG_TARGET_HAS_div_i32 0 |
Richard Henderson | ca675f4 | 2013-03-11 22:41:47 -0700 | [diff] [blame] | 158 | #define TCG_TARGET_HAS_rem_i32 0 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 159 | #endif |
| 160 | #if defined(TCG_TARGET_HAS_div_i64) |
| 161 | #define TCG_TARGET_HAS_div2_i64 0 |
| 162 | #elif defined(TCG_TARGET_HAS_div2_i64) |
| 163 | #define TCG_TARGET_HAS_div_i64 0 |
Richard Henderson | ca675f4 | 2013-03-11 22:41:47 -0700 | [diff] [blame] | 164 | #define TCG_TARGET_HAS_rem_i64 0 |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 165 | #endif |
| 166 | |
Richard Henderson | df9ebea | 2014-03-26 10:59:14 -0700 | [diff] [blame] | 167 | /* For 32-bit targets, some sort of unsigned widening multiply is required. */ |
| 168 | #if TCG_TARGET_REG_BITS == 32 \ |
| 169 | && !(defined(TCG_TARGET_HAS_mulu2_i32) \ |
| 170 | || defined(TCG_TARGET_HAS_muluh_i32)) |
| 171 | # error "Missing unsigned widening multiply" |
| 172 | #endif |
| 173 | |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 174 | #if !defined(TCG_TARGET_HAS_v64) \ |
| 175 | && !defined(TCG_TARGET_HAS_v128) \ |
| 176 | && !defined(TCG_TARGET_HAS_v256) |
| 177 | #define TCG_TARGET_MAYBE_vec 0 |
| 178 | #define TCG_TARGET_HAS_neg_vec 0 |
| 179 | #define TCG_TARGET_HAS_not_vec 0 |
| 180 | #define TCG_TARGET_HAS_andc_vec 0 |
| 181 | #define TCG_TARGET_HAS_orc_vec 0 |
Richard Henderson | d0ec979 | 2017-11-17 14:35:11 +0100 | [diff] [blame] | 182 | #define TCG_TARGET_HAS_shi_vec 0 |
| 183 | #define TCG_TARGET_HAS_shs_vec 0 |
| 184 | #define TCG_TARGET_HAS_shv_vec 0 |
Richard Henderson | 3774030 | 2017-11-21 10:11:14 +0100 | [diff] [blame] | 185 | #define TCG_TARGET_HAS_mul_vec 0 |
Richard Henderson | 8afaf05 | 2018-12-17 18:01:47 -0800 | [diff] [blame^] | 186 | #define TCG_TARGET_HAS_sat_vec 0 |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 187 | #else |
| 188 | #define TCG_TARGET_MAYBE_vec 1 |
| 189 | #endif |
| 190 | #ifndef TCG_TARGET_HAS_v64 |
| 191 | #define TCG_TARGET_HAS_v64 0 |
| 192 | #endif |
| 193 | #ifndef TCG_TARGET_HAS_v128 |
| 194 | #define TCG_TARGET_HAS_v128 0 |
| 195 | #endif |
| 196 | #ifndef TCG_TARGET_HAS_v256 |
| 197 | #define TCG_TARGET_HAS_v256 0 |
| 198 | #endif |
| 199 | |
Richard Henderson | 9aef40e | 2015-08-30 09:21:33 -0700 | [diff] [blame] | 200 | #ifndef TARGET_INSN_START_EXTRA_WORDS |
| 201 | # define TARGET_INSN_START_WORDS 1 |
| 202 | #else |
| 203 | # define TARGET_INSN_START_WORDS (1 + TARGET_INSN_START_EXTRA_WORDS) |
| 204 | #endif |
| 205 | |
Richard Henderson | a975160 | 2010-03-19 11:12:29 -0700 | [diff] [blame] | 206 | typedef enum TCGOpcode { |
Aurelien Jarno | c61aaf7 | 2010-06-03 19:40:04 +0200 | [diff] [blame] | 207 | #define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name, |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 208 | #include "tcg-opc.h" |
| 209 | #undef DEF |
| 210 | NB_OPS, |
Richard Henderson | a975160 | 2010-03-19 11:12:29 -0700 | [diff] [blame] | 211 | } TCGOpcode; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 212 | |
Richard Henderson | 80a8b9a | 2017-09-11 12:50:42 -0700 | [diff] [blame] | 213 | #define tcg_regset_set_reg(d, r) ((d) |= (TCGRegSet)1 << (r)) |
| 214 | #define tcg_regset_reset_reg(d, r) ((d) &= ~((TCGRegSet)1 << (r))) |
| 215 | #define tcg_regset_test_reg(d, r) (((d) >> (r)) & 1) |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 216 | |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 217 | #ifndef TCG_TARGET_INSN_UNIT_SIZE |
Richard Henderson | 5053361 | 2014-04-28 12:01:23 -0700 | [diff] [blame] | 218 | # error "Missing TCG_TARGET_INSN_UNIT_SIZE" |
| 219 | #elif TCG_TARGET_INSN_UNIT_SIZE == 1 |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 220 | typedef uint8_t tcg_insn_unit; |
| 221 | #elif TCG_TARGET_INSN_UNIT_SIZE == 2 |
| 222 | typedef uint16_t tcg_insn_unit; |
| 223 | #elif TCG_TARGET_INSN_UNIT_SIZE == 4 |
| 224 | typedef uint32_t tcg_insn_unit; |
| 225 | #elif TCG_TARGET_INSN_UNIT_SIZE == 8 |
| 226 | typedef uint64_t tcg_insn_unit; |
| 227 | #else |
| 228 | /* The port better have done this. */ |
| 229 | #endif |
| 230 | |
| 231 | |
Paolo Bonzini | 8bff06a | 2016-07-15 18:27:40 +0200 | [diff] [blame] | 232 | #if defined CONFIG_DEBUG_TCG || defined QEMU_STATIC_ANALYSIS |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 233 | # define tcg_debug_assert(X) do { assert(X); } while (0) |
Thomas Huth | 6fa2cef | 2018-12-03 13:48:19 +0100 | [diff] [blame] | 234 | #else |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 235 | # define tcg_debug_assert(X) \ |
| 236 | do { if (!(X)) { __builtin_unreachable(); } } while (0) |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 237 | #endif |
| 238 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 239 | typedef struct TCGRelocation { |
| 240 | struct TCGRelocation *next; |
| 241 | int type; |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 242 | tcg_insn_unit *ptr; |
Richard Henderson | 2ba7fae2 | 2013-08-20 15:30:10 -0700 | [diff] [blame] | 243 | intptr_t addend; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 244 | } TCGRelocation; |
| 245 | |
| 246 | typedef struct TCGLabel { |
Richard Henderson | 51e3972 | 2015-02-13 18:51:05 -0800 | [diff] [blame] | 247 | unsigned has_value : 1; |
Richard Henderson | d88a117 | 2018-11-26 12:47:28 -0800 | [diff] [blame] | 248 | unsigned id : 15; |
| 249 | unsigned refs : 16; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 250 | union { |
Richard Henderson | 2ba7fae2 | 2013-08-20 15:30:10 -0700 | [diff] [blame] | 251 | uintptr_t value; |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 252 | tcg_insn_unit *value_ptr; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 253 | TCGRelocation *first_reloc; |
| 254 | } u; |
| 255 | } TCGLabel; |
| 256 | |
| 257 | typedef struct TCGPool { |
| 258 | struct TCGPool *next; |
blueswir1 | c44f945 | 2008-05-19 16:32:18 +0000 | [diff] [blame] | 259 | int size; |
| 260 | uint8_t data[0] __attribute__ ((aligned)); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 261 | } TCGPool; |
| 262 | |
| 263 | #define TCG_POOL_CHUNK_SIZE 32768 |
| 264 | |
blueswir1 | c4071c9 | 2008-03-16 19:21:07 +0000 | [diff] [blame] | 265 | #define TCG_MAX_TEMPS 512 |
Richard Henderson | 190ce7f | 2015-08-31 14:34:41 -0700 | [diff] [blame] | 266 | #define TCG_MAX_INSNS 512 |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 267 | |
bellard | b03cce8 | 2008-05-10 10:52:05 +0000 | [diff] [blame] | 268 | /* when the size of the arguments of a called function is smaller than |
| 269 | this value, they are statically allocated in the TB stack frame */ |
| 270 | #define TCG_STATIC_CALL_ARGS_SIZE 128 |
| 271 | |
Richard Henderson | c02244a | 2010-03-19 11:36:30 -0700 | [diff] [blame] | 272 | typedef enum TCGType { |
| 273 | TCG_TYPE_I32, |
| 274 | TCG_TYPE_I64, |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 275 | |
| 276 | TCG_TYPE_V64, |
| 277 | TCG_TYPE_V128, |
| 278 | TCG_TYPE_V256, |
| 279 | |
Richard Henderson | c02244a | 2010-03-19 11:36:30 -0700 | [diff] [blame] | 280 | TCG_TYPE_COUNT, /* number of different types */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 281 | |
Richard Henderson | 3b6dac3 | 2010-06-02 17:26:55 -0700 | [diff] [blame] | 282 | /* An alias for the size of the host register. */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 283 | #if TCG_TARGET_REG_BITS == 32 |
Richard Henderson | 3b6dac3 | 2010-06-02 17:26:55 -0700 | [diff] [blame] | 284 | TCG_TYPE_REG = TCG_TYPE_I32, |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 285 | #else |
Richard Henderson | 3b6dac3 | 2010-06-02 17:26:55 -0700 | [diff] [blame] | 286 | TCG_TYPE_REG = TCG_TYPE_I64, |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 287 | #endif |
Richard Henderson | 3b6dac3 | 2010-06-02 17:26:55 -0700 | [diff] [blame] | 288 | |
Richard Henderson | d289837 | 2013-08-20 14:48:46 -0700 | [diff] [blame] | 289 | /* An alias for the size of the native pointer. */ |
| 290 | #if UINTPTR_MAX == UINT32_MAX |
| 291 | TCG_TYPE_PTR = TCG_TYPE_I32, |
| 292 | #else |
| 293 | TCG_TYPE_PTR = TCG_TYPE_I64, |
| 294 | #endif |
Richard Henderson | 3b6dac3 | 2010-06-02 17:26:55 -0700 | [diff] [blame] | 295 | |
| 296 | /* An alias for the size of the target "long", aka register. */ |
Richard Henderson | c02244a | 2010-03-19 11:36:30 -0700 | [diff] [blame] | 297 | #if TARGET_LONG_BITS == 64 |
| 298 | TCG_TYPE_TL = TCG_TYPE_I64, |
| 299 | #else |
| 300 | TCG_TYPE_TL = TCG_TYPE_I32, |
| 301 | #endif |
| 302 | } TCGType; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 303 | |
Richard Henderson | 6c5f4ea | 2013-09-03 13:52:19 -0700 | [diff] [blame] | 304 | /* Constants for qemu_ld and qemu_st for the Memory Operation field. */ |
| 305 | typedef enum TCGMemOp { |
| 306 | MO_8 = 0, |
| 307 | MO_16 = 1, |
| 308 | MO_32 = 2, |
| 309 | MO_64 = 3, |
| 310 | MO_SIZE = 3, /* Mask for the above. */ |
| 311 | |
| 312 | MO_SIGN = 4, /* Sign-extended, otherwise zero-extended. */ |
| 313 | |
| 314 | MO_BSWAP = 8, /* Host reverse endian. */ |
| 315 | #ifdef HOST_WORDS_BIGENDIAN |
| 316 | MO_LE = MO_BSWAP, |
| 317 | MO_BE = 0, |
| 318 | #else |
| 319 | MO_LE = 0, |
| 320 | MO_BE = MO_BSWAP, |
| 321 | #endif |
| 322 | #ifdef TARGET_WORDS_BIGENDIAN |
| 323 | MO_TE = MO_BE, |
| 324 | #else |
| 325 | MO_TE = MO_LE, |
| 326 | #endif |
| 327 | |
Richard Henderson | dfb3630 | 2015-05-13 11:25:20 -0700 | [diff] [blame] | 328 | /* MO_UNALN accesses are never checked for alignment. |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 329 | * MO_ALIGN accesses will result in a call to the CPU's |
| 330 | * do_unaligned_access hook if the guest address is not aligned. |
| 331 | * The default depends on whether the target CPU defines ALIGNED_ONLY. |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 332 | * |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 333 | * Some architectures (e.g. ARMv8) need the address which is aligned |
| 334 | * to a size more than the size of the memory access. |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 335 | * Some architectures (e.g. SPARCv9) need an address which is aligned, |
| 336 | * but less strictly than the natural alignment. |
| 337 | * |
| 338 | * MO_ALIGN supposes the alignment size is the size of a memory access. |
| 339 | * |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 340 | * There are three options: |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 341 | * - unaligned access permitted (MO_UNALN). |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 342 | * - an alignment to the size of an access (MO_ALIGN); |
| 343 | * - an alignment to a specified size, which may be more or less than |
| 344 | * the access size (MO_ALIGN_x where 'x' is a size in bytes); |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 345 | */ |
| 346 | MO_ASHIFT = 4, |
| 347 | MO_AMASK = 7 << MO_ASHIFT, |
Richard Henderson | dfb3630 | 2015-05-13 11:25:20 -0700 | [diff] [blame] | 348 | #ifdef ALIGNED_ONLY |
| 349 | MO_ALIGN = 0, |
| 350 | MO_UNALN = MO_AMASK, |
| 351 | #else |
| 352 | MO_ALIGN = MO_AMASK, |
| 353 | MO_UNALN = 0, |
| 354 | #endif |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 355 | MO_ALIGN_2 = 1 << MO_ASHIFT, |
| 356 | MO_ALIGN_4 = 2 << MO_ASHIFT, |
| 357 | MO_ALIGN_8 = 3 << MO_ASHIFT, |
| 358 | MO_ALIGN_16 = 4 << MO_ASHIFT, |
| 359 | MO_ALIGN_32 = 5 << MO_ASHIFT, |
| 360 | MO_ALIGN_64 = 6 << MO_ASHIFT, |
Richard Henderson | dfb3630 | 2015-05-13 11:25:20 -0700 | [diff] [blame] | 361 | |
Richard Henderson | 6c5f4ea | 2013-09-03 13:52:19 -0700 | [diff] [blame] | 362 | /* Combinations of the above, for ease of use. */ |
| 363 | MO_UB = MO_8, |
| 364 | MO_UW = MO_16, |
| 365 | MO_UL = MO_32, |
| 366 | MO_SB = MO_SIGN | MO_8, |
| 367 | MO_SW = MO_SIGN | MO_16, |
| 368 | MO_SL = MO_SIGN | MO_32, |
| 369 | MO_Q = MO_64, |
| 370 | |
| 371 | MO_LEUW = MO_LE | MO_UW, |
| 372 | MO_LEUL = MO_LE | MO_UL, |
| 373 | MO_LESW = MO_LE | MO_SW, |
| 374 | MO_LESL = MO_LE | MO_SL, |
| 375 | MO_LEQ = MO_LE | MO_Q, |
| 376 | |
| 377 | MO_BEUW = MO_BE | MO_UW, |
| 378 | MO_BEUL = MO_BE | MO_UL, |
| 379 | MO_BESW = MO_BE | MO_SW, |
| 380 | MO_BESL = MO_BE | MO_SL, |
| 381 | MO_BEQ = MO_BE | MO_Q, |
| 382 | |
| 383 | MO_TEUW = MO_TE | MO_UW, |
| 384 | MO_TEUL = MO_TE | MO_UL, |
| 385 | MO_TESW = MO_TE | MO_SW, |
| 386 | MO_TESL = MO_TE | MO_SL, |
| 387 | MO_TEQ = MO_TE | MO_Q, |
| 388 | |
| 389 | MO_SSIZE = MO_SIZE | MO_SIGN, |
| 390 | } TCGMemOp; |
| 391 | |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 392 | /** |
| 393 | * get_alignment_bits |
| 394 | * @memop: TCGMemOp value |
| 395 | * |
| 396 | * Extract the alignment size from the memop. |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 397 | */ |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 398 | static inline unsigned get_alignment_bits(TCGMemOp memop) |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 399 | { |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 400 | unsigned a = memop & MO_AMASK; |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 401 | |
| 402 | if (a == MO_UNALN) { |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 403 | /* No alignment required. */ |
| 404 | a = 0; |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 405 | } else if (a == MO_ALIGN) { |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 406 | /* A natural alignment requirement. */ |
| 407 | a = memop & MO_SIZE; |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 408 | } else { |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 409 | /* A specific alignment requirement. */ |
| 410 | a = a >> MO_ASHIFT; |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 411 | } |
| 412 | #if defined(CONFIG_SOFTMMU) |
| 413 | /* The requested alignment cannot overlap the TLB flags. */ |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 414 | tcg_debug_assert((TLB_FLAGS_MASK & ((1 << a) - 1)) == 0); |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 415 | #endif |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 416 | return a; |
Sergey Sorokin | 1f00b27 | 2016-06-23 21:16:46 +0300 | [diff] [blame] | 417 | } |
| 418 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 419 | typedef tcg_target_ulong TCGArg; |
| 420 | |
Peter Maydell | a40d470 | 2016-10-21 17:38:42 +0100 | [diff] [blame] | 421 | /* Define type and accessor macros for TCG variables. |
| 422 | |
| 423 | TCG variables are the inputs and outputs of TCG ops, as described |
| 424 | in tcg/README. Target CPU front-end code uses these types to deal |
| 425 | with TCG variables as it emits TCG code via the tcg_gen_* functions. |
| 426 | They come in several flavours: |
| 427 | * TCGv_i32 : 32 bit integer type |
| 428 | * TCGv_i64 : 64 bit integer type |
| 429 | * TCGv_ptr : a host pointer type |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 430 | * TCGv_vec : a host vector type; the exact size is not exposed |
| 431 | to the CPU front-end code. |
Peter Maydell | a40d470 | 2016-10-21 17:38:42 +0100 | [diff] [blame] | 432 | * TCGv : an integer type the same size as target_ulong |
| 433 | (an alias for either TCGv_i32 or TCGv_i64) |
| 434 | The compiler's type checking will complain if you mix them |
| 435 | up and pass the wrong sized TCGv to a function. |
| 436 | |
| 437 | Users of tcg_gen_* don't need to know about any of the internal |
| 438 | details of these, and should treat them as opaque types. |
| 439 | You won't be able to look inside them in a debugger either. |
| 440 | |
| 441 | Internal implementation details follow: |
| 442 | |
| 443 | Note that there is no definition of the structs TCGv_i32_d etc anywhere. |
| 444 | This is deliberate, because the values we store in variables of type |
| 445 | TCGv_i32 are not really pointers-to-structures. They're just small |
| 446 | integers, but keeping them in pointer types like this means that the |
| 447 | compiler will complain if you accidentally pass a TCGv_i32 to a |
| 448 | function which takes a TCGv_i64, and so on. Only the internals of |
Richard Henderson | dc41aa7 | 2017-10-20 00:30:24 -0700 | [diff] [blame] | 449 | TCG need to care about the actual contents of the types. */ |
pbrook | ac56dd4 | 2008-02-03 19:56:33 +0000 | [diff] [blame] | 450 | |
Richard Henderson | b6c73a6 | 2014-09-16 09:51:46 -0700 | [diff] [blame] | 451 | typedef struct TCGv_i32_d *TCGv_i32; |
| 452 | typedef struct TCGv_i64_d *TCGv_i64; |
| 453 | typedef struct TCGv_ptr_d *TCGv_ptr; |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 454 | typedef struct TCGv_vec_d *TCGv_vec; |
LluĂs Vilanova | 1bcea73 | 2016-02-25 17:43:15 +0100 | [diff] [blame] | 455 | typedef TCGv_ptr TCGv_env; |
LluĂs Vilanova | 5d4e1a1 | 2016-02-25 17:43:21 +0100 | [diff] [blame] | 456 | #if TARGET_LONG_BITS == 32 |
| 457 | #define TCGv TCGv_i32 |
| 458 | #elif TARGET_LONG_BITS == 64 |
| 459 | #define TCGv TCGv_i64 |
| 460 | #else |
| 461 | #error Unhandled TARGET_LONG_BITS value |
| 462 | #endif |
pbrook | ac56dd4 | 2008-02-03 19:56:33 +0000 | [diff] [blame] | 463 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 464 | /* call flags */ |
Aurelien Jarno | 7850527 | 2012-10-09 21:53:08 +0200 | [diff] [blame] | 465 | /* Helper does not read globals (either directly or through an exception). It |
| 466 | implies TCG_CALL_NO_WRITE_GLOBALS. */ |
Richard Henderson | 3b50352 | 2018-11-26 10:37:34 -0800 | [diff] [blame] | 467 | #define TCG_CALL_NO_READ_GLOBALS 0x0001 |
Aurelien Jarno | 7850527 | 2012-10-09 21:53:08 +0200 | [diff] [blame] | 468 | /* Helper does not write globals */ |
Richard Henderson | 3b50352 | 2018-11-26 10:37:34 -0800 | [diff] [blame] | 469 | #define TCG_CALL_NO_WRITE_GLOBALS 0x0002 |
Aurelien Jarno | 7850527 | 2012-10-09 21:53:08 +0200 | [diff] [blame] | 470 | /* Helper can be safely suppressed if the return value is not used. */ |
Richard Henderson | 3b50352 | 2018-11-26 10:37:34 -0800 | [diff] [blame] | 471 | #define TCG_CALL_NO_SIDE_EFFECTS 0x0004 |
Richard Henderson | 15d7409 | 2018-11-26 11:32:38 -0800 | [diff] [blame] | 472 | /* Helper is QEMU_NORETURN. */ |
| 473 | #define TCG_CALL_NO_RETURN 0x0008 |
Aurelien Jarno | 7850527 | 2012-10-09 21:53:08 +0200 | [diff] [blame] | 474 | |
| 475 | /* convenience version of most used call flags */ |
| 476 | #define TCG_CALL_NO_RWG TCG_CALL_NO_READ_GLOBALS |
| 477 | #define TCG_CALL_NO_WG TCG_CALL_NO_WRITE_GLOBALS |
| 478 | #define TCG_CALL_NO_SE TCG_CALL_NO_SIDE_EFFECTS |
| 479 | #define TCG_CALL_NO_RWG_SE (TCG_CALL_NO_RWG | TCG_CALL_NO_SE) |
| 480 | #define TCG_CALL_NO_WG_SE (TCG_CALL_NO_WG | TCG_CALL_NO_SE) |
| 481 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 482 | /* Used to align parameters. See the comment before tcgv_i32_temp. */ |
| 483 | #define TCG_CALL_DUMMY_ARG ((TCGArg)0) |
bellard | 39cf05d | 2008-05-22 14:59:57 +0000 | [diff] [blame] | 484 | |
Stefan Weil | a93cf9d | 2012-11-02 08:29:53 +0100 | [diff] [blame] | 485 | /* Conditions. Note that these are laid out for easy manipulation by |
| 486 | the functions below: |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 487 | bit 0 is used for inverting; |
| 488 | bit 1 is signed, |
| 489 | bit 2 is unsigned, |
| 490 | bit 3 is used with bit 0 for swapping signed/unsigned. */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 491 | typedef enum { |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 492 | /* non-signed */ |
| 493 | TCG_COND_NEVER = 0 | 0 | 0 | 0, |
| 494 | TCG_COND_ALWAYS = 0 | 0 | 0 | 1, |
| 495 | TCG_COND_EQ = 8 | 0 | 0 | 0, |
| 496 | TCG_COND_NE = 8 | 0 | 0 | 1, |
| 497 | /* signed */ |
| 498 | TCG_COND_LT = 0 | 0 | 2 | 0, |
| 499 | TCG_COND_GE = 0 | 0 | 2 | 1, |
| 500 | TCG_COND_LE = 8 | 0 | 2 | 0, |
| 501 | TCG_COND_GT = 8 | 0 | 2 | 1, |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 502 | /* unsigned */ |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 503 | TCG_COND_LTU = 0 | 4 | 0 | 0, |
| 504 | TCG_COND_GEU = 0 | 4 | 0 | 1, |
| 505 | TCG_COND_LEU = 8 | 4 | 0 | 0, |
| 506 | TCG_COND_GTU = 8 | 4 | 0 | 1, |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 507 | } TCGCond; |
| 508 | |
Richard Henderson | 1c08622 | 2010-02-09 12:33:09 -0800 | [diff] [blame] | 509 | /* Invert the sense of the comparison. */ |
Richard Henderson | 401d466 | 2010-01-07 10:15:20 -0800 | [diff] [blame] | 510 | static inline TCGCond tcg_invert_cond(TCGCond c) |
| 511 | { |
| 512 | return (TCGCond)(c ^ 1); |
| 513 | } |
| 514 | |
Richard Henderson | 1c08622 | 2010-02-09 12:33:09 -0800 | [diff] [blame] | 515 | /* Swap the operands in a comparison. */ |
| 516 | static inline TCGCond tcg_swap_cond(TCGCond c) |
| 517 | { |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 518 | return c & 6 ? (TCGCond)(c ^ 9) : c; |
Richard Henderson | 1c08622 | 2010-02-09 12:33:09 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Richard Henderson | d1e321b | 2012-09-24 14:21:41 -0700 | [diff] [blame] | 521 | /* Create an "unsigned" version of a "signed" comparison. */ |
Richard Henderson | ff44c2f | 2009-12-27 09:09:41 +0000 | [diff] [blame] | 522 | static inline TCGCond tcg_unsigned_cond(TCGCond c) |
| 523 | { |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 524 | return c & 2 ? (TCGCond)(c ^ 6) : c; |
Richard Henderson | ff44c2f | 2009-12-27 09:09:41 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Richard Henderson | 923ed17 | 2017-11-20 14:47:02 +0100 | [diff] [blame] | 527 | /* Create a "signed" version of an "unsigned" comparison. */ |
| 528 | static inline TCGCond tcg_signed_cond(TCGCond c) |
| 529 | { |
| 530 | return c & 4 ? (TCGCond)(c ^ 6) : c; |
| 531 | } |
| 532 | |
Richard Henderson | d1e321b | 2012-09-24 14:21:41 -0700 | [diff] [blame] | 533 | /* Must a comparison be considered unsigned? */ |
Richard Henderson | bcc6656 | 2012-09-24 14:21:39 -0700 | [diff] [blame] | 534 | static inline bool is_unsigned_cond(TCGCond c) |
| 535 | { |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 536 | return (c & 4) != 0; |
Richard Henderson | bcc6656 | 2012-09-24 14:21:39 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Richard Henderson | d1e321b | 2012-09-24 14:21:41 -0700 | [diff] [blame] | 539 | /* Create a "high" version of a double-word comparison. |
| 540 | This removes equality from a LTE or GTE comparison. */ |
| 541 | static inline TCGCond tcg_high_cond(TCGCond c) |
| 542 | { |
| 543 | switch (c) { |
| 544 | case TCG_COND_GE: |
| 545 | case TCG_COND_LE: |
| 546 | case TCG_COND_GEU: |
| 547 | case TCG_COND_LEU: |
| 548 | return (TCGCond)(c ^ 8); |
| 549 | default: |
| 550 | return c; |
| 551 | } |
| 552 | } |
| 553 | |
Emilio G. Cota | 00c8fa9 | 2015-04-02 20:07:53 -0400 | [diff] [blame] | 554 | typedef enum TCGTempVal { |
| 555 | TEMP_VAL_DEAD, |
| 556 | TEMP_VAL_REG, |
| 557 | TEMP_VAL_MEM, |
| 558 | TEMP_VAL_CONST, |
| 559 | } TCGTempVal; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 560 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 561 | typedef struct TCGTemp { |
Richard Henderson | b663866 | 2013-09-18 14:54:45 -0700 | [diff] [blame] | 562 | TCGReg reg:8; |
Emilio G. Cota | 00c8fa9 | 2015-04-02 20:07:53 -0400 | [diff] [blame] | 563 | TCGTempVal val_type:8; |
| 564 | TCGType base_type:8; |
| 565 | TCGType type:8; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 566 | unsigned int fixed_reg:1; |
Richard Henderson | b3915db | 2013-09-19 10:36:18 -0700 | [diff] [blame] | 567 | unsigned int indirect_reg:1; |
| 568 | unsigned int indirect_base:1; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 569 | unsigned int mem_coherent:1; |
| 570 | unsigned int mem_allocated:1; |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame] | 571 | /* If true, the temp is saved across both basic blocks and |
| 572 | translation blocks. */ |
| 573 | unsigned int temp_global:1; |
| 574 | /* If true, the temp is saved across basic blocks but dead |
| 575 | at the end of translation blocks. If false, the temp is |
| 576 | dead at the end of basic blocks. */ |
| 577 | unsigned int temp_local:1; |
| 578 | unsigned int temp_allocated:1; |
Emilio G. Cota | 00c8fa9 | 2015-04-02 20:07:53 -0400 | [diff] [blame] | 579 | |
| 580 | tcg_target_long val; |
Richard Henderson | b3a6293 | 2013-09-18 14:12:53 -0700 | [diff] [blame] | 581 | struct TCGTemp *mem_base; |
Emilio G. Cota | 00c8fa9 | 2015-04-02 20:07:53 -0400 | [diff] [blame] | 582 | intptr_t mem_offset; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 583 | const char *name; |
Richard Henderson | b83eabe | 2016-11-01 15:56:04 -0600 | [diff] [blame] | 584 | |
| 585 | /* Pass-specific information that can be stored for a temporary. |
| 586 | One word worth of integer data, and one pointer to data |
| 587 | allocated separately. */ |
| 588 | uintptr_t state; |
| 589 | void *state_ptr; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 590 | } TCGTemp; |
| 591 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 592 | typedef struct TCGContext TCGContext; |
| 593 | |
Richard Henderson | 0ec9eab | 2013-09-19 12:16:45 -0700 | [diff] [blame] | 594 | typedef struct TCGTempSet { |
| 595 | unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)]; |
| 596 | } TCGTempSet; |
| 597 | |
Richard Henderson | a1b3c48 | 2016-06-22 15:46:09 -0700 | [diff] [blame] | 598 | /* While we limit helpers to 6 arguments, for 32-bit hosts, with padding, |
| 599 | this imples a max of 6*2 (64-bit in) + 2 (64-bit out) = 14 operands. |
| 600 | There are never more than 2 outputs, which means that we can store all |
| 601 | dead + sync data within 16 bits. */ |
| 602 | #define DEAD_ARG 4 |
| 603 | #define SYNC_ARG 1 |
| 604 | typedef uint16_t TCGLifeData; |
| 605 | |
Richard Henderson | 75e8b9b | 2016-12-08 10:52:57 -0800 | [diff] [blame] | 606 | /* The layout here is designed to avoid a bitfield crossing of |
| 607 | a 32-bit boundary, which would cause GCC to add extra padding. */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 608 | typedef struct TCGOp { |
Richard Henderson | bee158c | 2016-06-22 20:43:29 -0700 | [diff] [blame] | 609 | TCGOpcode opc : 8; /* 8 */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 610 | |
Richard Henderson | cd9090a | 2017-11-14 13:02:51 +0100 | [diff] [blame] | 611 | /* Parameters for this opcode. See below. */ |
| 612 | unsigned param1 : 4; /* 12 */ |
| 613 | unsigned param2 : 4; /* 16 */ |
Richard Henderson | bee158c | 2016-06-22 20:43:29 -0700 | [diff] [blame] | 614 | |
Richard Henderson | bee158c | 2016-06-22 20:43:29 -0700 | [diff] [blame] | 615 | /* Lifetime data of the operands. */ |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 616 | unsigned life : 16; /* 32 */ |
| 617 | |
| 618 | /* Next and previous opcodes. */ |
| 619 | QTAILQ_ENTRY(TCGOp) link; |
Richard Henderson | 75e8b9b | 2016-12-08 10:52:57 -0800 | [diff] [blame] | 620 | |
| 621 | /* Arguments for the opcode. */ |
| 622 | TCGArg args[MAX_OPC_PARAM]; |
Richard Henderson | 69e3706 | 2018-11-27 07:44:51 -0800 | [diff] [blame] | 623 | |
| 624 | /* Register preferences for the output(s). */ |
| 625 | TCGRegSet output_pref[2]; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 626 | } TCGOp; |
| 627 | |
Richard Henderson | cd9090a | 2017-11-14 13:02:51 +0100 | [diff] [blame] | 628 | #define TCGOP_CALLI(X) (X)->param1 |
| 629 | #define TCGOP_CALLO(X) (X)->param2 |
| 630 | |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 631 | #define TCGOP_VECL(X) (X)->param1 |
| 632 | #define TCGOP_VECE(X) (X)->param2 |
| 633 | |
Richard Henderson | dcb8e75 | 2016-06-22 19:42:31 -0700 | [diff] [blame] | 634 | /* Make sure operands fit in the bitfields above. */ |
| 635 | QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 636 | |
Emilio G. Cota | c3fac11 | 2017-07-05 19:35:06 -0400 | [diff] [blame] | 637 | typedef struct TCGProfile { |
Emilio G. Cota | 72fd2ef | 2018-10-10 10:48:53 -0400 | [diff] [blame] | 638 | int64_t cpu_exec_time; |
Emilio G. Cota | c3fac11 | 2017-07-05 19:35:06 -0400 | [diff] [blame] | 639 | int64_t tb_count1; |
| 640 | int64_t tb_count; |
| 641 | int64_t op_count; /* total insn count */ |
| 642 | int op_count_max; /* max insn per TB */ |
Emilio G. Cota | c3fac11 | 2017-07-05 19:35:06 -0400 | [diff] [blame] | 643 | int temp_count_max; |
Emilio G. Cota | dd1d7da | 2018-10-10 10:48:52 -0400 | [diff] [blame] | 644 | int64_t temp_count; |
Emilio G. Cota | c3fac11 | 2017-07-05 19:35:06 -0400 | [diff] [blame] | 645 | int64_t del_op_count; |
| 646 | int64_t code_in_len; |
| 647 | int64_t code_out_len; |
| 648 | int64_t search_out_len; |
| 649 | int64_t interm_time; |
| 650 | int64_t code_time; |
| 651 | int64_t la_time; |
| 652 | int64_t opt_time; |
| 653 | int64_t restore_count; |
| 654 | int64_t restore_time; |
| 655 | int64_t table_op_count[NB_OPS]; |
| 656 | } TCGProfile; |
| 657 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 658 | struct TCGContext { |
| 659 | uint8_t *pool_cur, *pool_end; |
Kirill Batuzov | 4055299 | 2012-03-02 13:22:17 +0400 | [diff] [blame] | 660 | TCGPool *pool_first, *pool_current, *pool_first_large; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 661 | int nb_labels; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 662 | int nb_globals; |
| 663 | int nb_temps; |
Richard Henderson | 5a18407 | 2016-06-23 20:34:33 -0700 | [diff] [blame] | 664 | int nb_indirects; |
Richard Henderson | abebf92 | 2018-05-08 19:18:59 +0000 | [diff] [blame] | 665 | int nb_ops; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 666 | |
| 667 | /* goto_tb support */ |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 668 | tcg_insn_unit *code_buf; |
Sergey Fedorov | f309101 | 2016-04-10 23:35:45 +0300 | [diff] [blame] | 669 | uint16_t *tb_jmp_reset_offset; /* tb->jmp_reset_offset */ |
Richard Henderson | a858339 | 2017-07-31 22:02:31 -0700 | [diff] [blame] | 670 | uintptr_t *tb_jmp_insn_offset; /* tb->jmp_target_arg if direct_jump */ |
| 671 | uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_arg if !direct_jump */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 672 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 673 | TCGRegSet reserved_regs; |
Emilio G. Cota | e82d5a2 | 2017-07-16 15:13:52 -0400 | [diff] [blame] | 674 | uint32_t tb_cflags; /* cflags of the current TB */ |
Richard Henderson | e2c6d1b | 2013-08-20 15:12:31 -0700 | [diff] [blame] | 675 | intptr_t current_frame_offset; |
| 676 | intptr_t frame_start; |
| 677 | intptr_t frame_end; |
Richard Henderson | b3a6293 | 2013-09-18 14:12:53 -0700 | [diff] [blame] | 678 | TCGTemp *frame_temp; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 679 | |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 680 | tcg_insn_unit *code_ptr; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 681 | |
bellard | a23a9ec | 2008-05-23 09:52:20 +0000 | [diff] [blame] | 682 | #ifdef CONFIG_PROFILER |
Emilio G. Cota | c3fac11 | 2017-07-05 19:35:06 -0400 | [diff] [blame] | 683 | TCGProfile prof; |
bellard | a23a9ec | 2008-05-23 09:52:20 +0000 | [diff] [blame] | 684 | #endif |
Peter Maydell | 27bfd83 | 2011-03-06 21:39:53 +0000 | [diff] [blame] | 685 | |
| 686 | #ifdef CONFIG_DEBUG_TCG |
| 687 | int temps_in_use; |
Richard Henderson | 0a209d4 | 2012-09-21 17:18:16 -0700 | [diff] [blame] | 688 | int goto_tb_issue_mask; |
Peter Maydell | 27bfd83 | 2011-03-06 21:39:53 +0000 | [diff] [blame] | 689 | #endif |
Yeongkyoon Lee | b76f0d8 | 2012-10-31 16:04:25 +0900 | [diff] [blame] | 690 | |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 691 | /* Code generation. Note that we specifically do not use tcg_insn_unit |
| 692 | here, because there's too much arithmetic throughout that relies |
| 693 | on addition and subtraction working on bytes. Rely on the GCC |
| 694 | extension that allows arithmetic on void*. */ |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 695 | void *code_gen_prologue; |
Emilio G. Cota | cedbcb0 | 2017-04-26 23:29:14 -0400 | [diff] [blame] | 696 | void *code_gen_epilogue; |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 697 | void *code_gen_buffer; |
Evgeny Voevodin | 0b0d332 | 2013-02-01 01:47:22 +0700 | [diff] [blame] | 698 | size_t code_gen_buffer_size; |
Richard Henderson | 1813e17 | 2014-03-28 12:56:22 -0700 | [diff] [blame] | 699 | void *code_gen_ptr; |
Richard Henderson | 57a2694 | 2017-07-30 13:13:21 -0700 | [diff] [blame] | 700 | void *data_gen_ptr; |
Evgeny Voevodin | 0b0d332 | 2013-02-01 01:47:22 +0700 | [diff] [blame] | 701 | |
Richard Henderson | b125f9d | 2015-09-22 13:01:15 -0700 | [diff] [blame] | 702 | /* Threshold to flush the translated code buffer. */ |
| 703 | void *code_gen_highwater; |
| 704 | |
Emilio G. Cota | 128ed22 | 2017-08-01 15:11:12 -0400 | [diff] [blame] | 705 | size_t tb_phys_invalidate_count; |
| 706 | |
LluĂs Vilanova | 7c25504 | 2016-06-09 19:31:41 +0200 | [diff] [blame] | 707 | /* Track which vCPU triggers events */ |
| 708 | CPUState *cpu; /* *_trans */ |
LluĂs Vilanova | 7c25504 | 2016-06-09 19:31:41 +0200 | [diff] [blame] | 709 | |
Richard Henderson | 659ef5c | 2017-07-30 12:30:41 -0700 | [diff] [blame] | 710 | /* These structures are private to tcg-target.inc.c. */ |
| 711 | #ifdef TCG_TARGET_NEED_LDST_LABELS |
Paolo Bonzini | b58deb3 | 2018-12-06 11:58:10 +0100 | [diff] [blame] | 712 | QSIMPLEQ_HEAD(, TCGLabelQemuLdst) ldst_labels; |
Richard Henderson | 659ef5c | 2017-07-30 12:30:41 -0700 | [diff] [blame] | 713 | #endif |
Richard Henderson | 57a2694 | 2017-07-30 13:13:21 -0700 | [diff] [blame] | 714 | #ifdef TCG_TARGET_NEED_POOL_LABELS |
| 715 | struct TCGLabelPoolData *pool_labels; |
| 716 | #endif |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 717 | |
Emilio G. Cota | 2668978 | 2017-07-04 13:54:21 -0400 | [diff] [blame] | 718 | TCGLabel *exitreq_label; |
| 719 | |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 720 | TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; |
| 721 | TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ |
| 722 | |
Paolo Bonzini | eae3eb3 | 2018-12-06 13:10:34 +0100 | [diff] [blame] | 723 | QTAILQ_HEAD(, TCGOp) ops, free_ops; |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 724 | |
Richard Henderson | f8b2f20 | 2013-09-18 15:21:56 -0700 | [diff] [blame] | 725 | /* Tells which temporary holds a given register. |
| 726 | It does not take into account fixed registers */ |
| 727 | TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS]; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 728 | |
Richard Henderson | fca8a50 | 2015-09-01 19:11:45 -0700 | [diff] [blame] | 729 | uint16_t gen_insn_end_off[TCG_MAX_INSNS]; |
| 730 | target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 731 | }; |
| 732 | |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 733 | extern TCGContext tcg_init_ctx; |
Emilio G. Cota | 3468b59 | 2017-07-19 18:57:58 -0400 | [diff] [blame] | 734 | extern __thread TCGContext *tcg_ctx; |
Richard Henderson | 1c2adb9 | 2017-10-10 14:34:37 -0700 | [diff] [blame] | 735 | extern TCGv_env cpu_env; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 736 | |
Richard Henderson | 1807f4c | 2017-06-20 12:24:57 -0700 | [diff] [blame] | 737 | static inline size_t temp_idx(TCGTemp *ts) |
| 738 | { |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 739 | ptrdiff_t n = ts - tcg_ctx->temps; |
| 740 | tcg_debug_assert(n >= 0 && n < tcg_ctx->nb_temps); |
Richard Henderson | 1807f4c | 2017-06-20 12:24:57 -0700 | [diff] [blame] | 741 | return n; |
| 742 | } |
| 743 | |
| 744 | static inline TCGArg temp_arg(TCGTemp *ts) |
| 745 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 746 | return (uintptr_t)ts; |
Richard Henderson | 1807f4c | 2017-06-20 12:24:57 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Richard Henderson | 4343913 | 2017-06-19 23:18:10 -0700 | [diff] [blame] | 749 | static inline TCGTemp *arg_temp(TCGArg a) |
| 750 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 751 | return (TCGTemp *)(uintptr_t)a; |
Richard Henderson | 4343913 | 2017-06-19 23:18:10 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 754 | /* Using the offset of a temporary, relative to TCGContext, rather than |
| 755 | its index means that we don't use 0. That leaves offset 0 free for |
| 756 | a NULL representation without having to leave index 0 unused. */ |
| 757 | static inline TCGTemp *tcgv_i32_temp(TCGv_i32 v) |
Richard Henderson | 6349039 | 2017-06-20 13:43:15 -0700 | [diff] [blame] | 758 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 759 | uintptr_t o = (uintptr_t)v; |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 760 | TCGTemp *t = (void *)tcg_ctx + o; |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 761 | tcg_debug_assert(offsetof(TCGContext, temps[temp_idx(t)]) == o); |
| 762 | return t; |
Richard Henderson | 6349039 | 2017-06-20 13:43:15 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 765 | static inline TCGTemp *tcgv_i64_temp(TCGv_i64 v) |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 766 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 767 | return tcgv_i32_temp((TCGv_i32)v); |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 770 | static inline TCGTemp *tcgv_ptr_temp(TCGv_ptr v) |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 771 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 772 | return tcgv_i32_temp((TCGv_i32)v); |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 775 | static inline TCGTemp *tcgv_vec_temp(TCGv_vec v) |
| 776 | { |
| 777 | return tcgv_i32_temp((TCGv_i32)v); |
| 778 | } |
| 779 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 780 | static inline TCGArg tcgv_i32_arg(TCGv_i32 v) |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 781 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 782 | return temp_arg(tcgv_i32_temp(v)); |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 785 | static inline TCGArg tcgv_i64_arg(TCGv_i64 v) |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 786 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 787 | return temp_arg(tcgv_i64_temp(v)); |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 790 | static inline TCGArg tcgv_ptr_arg(TCGv_ptr v) |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 791 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 792 | return temp_arg(tcgv_ptr_temp(v)); |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 795 | static inline TCGArg tcgv_vec_arg(TCGv_vec v) |
| 796 | { |
| 797 | return temp_arg(tcgv_vec_temp(v)); |
| 798 | } |
| 799 | |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 800 | static inline TCGv_i32 temp_tcgv_i32(TCGTemp *t) |
| 801 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 802 | (void)temp_idx(t); /* trigger embedded assert */ |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 803 | return (TCGv_i32)((void *)t - (void *)tcg_ctx); |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static inline TCGv_i64 temp_tcgv_i64(TCGTemp *t) |
| 807 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 808 | return (TCGv_i64)temp_tcgv_i32(t); |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | static inline TCGv_ptr temp_tcgv_ptr(TCGTemp *t) |
| 812 | { |
Richard Henderson | e89b28a | 2017-10-20 12:08:19 -0700 | [diff] [blame] | 813 | return (TCGv_ptr)temp_tcgv_i32(t); |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 816 | static inline TCGv_vec temp_tcgv_vec(TCGTemp *t) |
| 817 | { |
| 818 | return (TCGv_vec)temp_tcgv_i32(t); |
| 819 | } |
| 820 | |
Richard Henderson | dc41aa7 | 2017-10-20 00:30:24 -0700 | [diff] [blame] | 821 | #if TCG_TARGET_REG_BITS == 32 |
| 822 | static inline TCGv_i32 TCGV_LOW(TCGv_i64 t) |
| 823 | { |
| 824 | return temp_tcgv_i32(tcgv_i64_temp(t)); |
| 825 | } |
| 826 | |
| 827 | static inline TCGv_i32 TCGV_HIGH(TCGv_i64 t) |
| 828 | { |
| 829 | return temp_tcgv_i32(tcgv_i64_temp(t) + 1); |
| 830 | } |
| 831 | #endif |
| 832 | |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 833 | static inline void tcg_set_insn_param(TCGOp *op, int arg, TCGArg v) |
Edgar E. Iglesias | 1d41478 | 2016-05-12 13:22:26 +0100 | [diff] [blame] | 834 | { |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 835 | op->args[arg] = v; |
Edgar E. Iglesias | 1d41478 | 2016-05-12 13:22:26 +0100 | [diff] [blame] | 836 | } |
| 837 | |
Richard Henderson | 9743cd5 | 2018-04-10 13:02:26 +0100 | [diff] [blame] | 838 | static inline void tcg_set_insn_start_param(TCGOp *op, int arg, target_ulong v) |
| 839 | { |
| 840 | #if TARGET_LONG_BITS <= TCG_TARGET_REG_BITS |
| 841 | tcg_set_insn_param(op, arg, v); |
| 842 | #else |
| 843 | tcg_set_insn_param(op, arg * 2, v); |
| 844 | tcg_set_insn_param(op, arg * 2 + 1, v >> 32); |
| 845 | #endif |
| 846 | } |
| 847 | |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 848 | /* The last op that was emitted. */ |
| 849 | static inline TCGOp *tcg_last_op(void) |
Richard Henderson | fe700ad | 2014-03-30 15:36:56 -0700 | [diff] [blame] | 850 | { |
Paolo Bonzini | eae3eb3 | 2018-12-06 13:10:34 +0100 | [diff] [blame] | 851 | return QTAILQ_LAST(&tcg_ctx->ops); |
Richard Henderson | fe700ad | 2014-03-30 15:36:56 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /* Test for whether to terminate the TB for using too many opcodes. */ |
| 855 | static inline bool tcg_op_buf_full(void) |
| 856 | { |
Richard Henderson | abebf92 | 2018-05-08 19:18:59 +0000 | [diff] [blame] | 857 | /* This is not a hard limit, it merely stops translation when |
| 858 | * we have produced "enough" opcodes. We want to limit TB size |
| 859 | * such that a RISC host can reasonably use a 16-bit signed |
Richard Henderson | 9f75462 | 2018-06-14 19:57:03 -1000 | [diff] [blame] | 860 | * branch within the TB. We also need to be mindful of the |
| 861 | * 16-bit unsigned offsets, TranslationBlock.jmp_reset_offset[] |
| 862 | * and TCGContext.gen_insn_end_off[]. |
Richard Henderson | abebf92 | 2018-05-08 19:18:59 +0000 | [diff] [blame] | 863 | */ |
Richard Henderson | 9f75462 | 2018-06-14 19:57:03 -1000 | [diff] [blame] | 864 | return tcg_ctx->nb_ops >= 4000; |
Richard Henderson | fe700ad | 2014-03-30 15:36:56 -0700 | [diff] [blame] | 865 | } |
| 866 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 867 | /* pool based memory allocation */ |
| 868 | |
Emilio G. Cota | 0ac2031 | 2017-08-04 23:46:31 -0400 | [diff] [blame] | 869 | /* user-mode: mmap_lock must be held for tcg_malloc_internal. */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 870 | void *tcg_malloc_internal(TCGContext *s, int size); |
| 871 | void tcg_pool_reset(TCGContext *s); |
Emilio G. Cota | 6e3b2bf | 2017-06-06 19:12:25 -0400 | [diff] [blame] | 872 | TranslationBlock *tcg_tb_alloc(TCGContext *s); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 873 | |
Emilio G. Cota | e8feb96 | 2017-07-07 19:24:20 -0400 | [diff] [blame] | 874 | void tcg_region_init(void); |
| 875 | void tcg_region_reset_all(void); |
| 876 | |
| 877 | size_t tcg_code_size(void); |
| 878 | size_t tcg_code_capacity(void); |
| 879 | |
Emilio G. Cota | be2cdc5 | 2017-07-26 16:58:05 -0400 | [diff] [blame] | 880 | void tcg_tb_insert(TranslationBlock *tb); |
| 881 | void tcg_tb_remove(TranslationBlock *tb); |
Emilio G. Cota | 128ed22 | 2017-08-01 15:11:12 -0400 | [diff] [blame] | 882 | size_t tcg_tb_phys_invalidate_count(void); |
Emilio G. Cota | be2cdc5 | 2017-07-26 16:58:05 -0400 | [diff] [blame] | 883 | TranslationBlock *tcg_tb_lookup(uintptr_t tc_ptr); |
| 884 | void tcg_tb_foreach(GTraverseFunc func, gpointer user_data); |
| 885 | size_t tcg_nb_tbs(void); |
| 886 | |
Emilio G. Cota | 0ac2031 | 2017-08-04 23:46:31 -0400 | [diff] [blame] | 887 | /* user-mode: Called with mmap_lock held. */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 888 | static inline void *tcg_malloc(int size) |
| 889 | { |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 890 | TCGContext *s = tcg_ctx; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 891 | uint8_t *ptr, *ptr_end; |
Richard Henderson | 13aaef6 | 2017-08-02 14:50:04 -0700 | [diff] [blame] | 892 | |
| 893 | /* ??? This is a weak placeholder for minimum malloc alignment. */ |
| 894 | size = QEMU_ALIGN_UP(size, 8); |
| 895 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 896 | ptr = s->pool_cur; |
| 897 | ptr_end = ptr + size; |
| 898 | if (unlikely(ptr_end > s->pool_end)) { |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 899 | return tcg_malloc_internal(tcg_ctx, size); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 900 | } else { |
| 901 | s->pool_cur = ptr_end; |
| 902 | return ptr; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | void tcg_context_init(TCGContext *s); |
Emilio G. Cota | 3468b59 | 2017-07-19 18:57:58 -0400 | [diff] [blame] | 907 | void tcg_register_thread(void); |
Richard Henderson | 9002ec7 | 2010-05-06 08:50:41 -0700 | [diff] [blame] | 908 | void tcg_prologue_init(TCGContext *s); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 909 | void tcg_func_start(TCGContext *s); |
| 910 | |
Alex Bennée | 5bd2ec3 | 2016-03-15 14:30:16 +0000 | [diff] [blame] | 911 | int tcg_gen_code(TCGContext *s, TranslationBlock *tb); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 912 | |
Richard Henderson | b663866 | 2013-09-18 14:54:45 -0700 | [diff] [blame] | 913 | void tcg_set_frame(TCGContext *s, TCGReg reg, intptr_t start, intptr_t size); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 914 | |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 915 | TCGTemp *tcg_global_mem_new_internal(TCGType, TCGv_ptr, |
| 916 | intptr_t, const char *); |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 917 | TCGTemp *tcg_temp_new_internal(TCGType, bool); |
| 918 | void tcg_temp_free_internal(TCGTemp *); |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 919 | TCGv_vec tcg_temp_new_vec(TCGType type); |
| 920 | TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match); |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 921 | |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 922 | static inline void tcg_temp_free_i32(TCGv_i32 arg) |
| 923 | { |
| 924 | tcg_temp_free_internal(tcgv_i32_temp(arg)); |
| 925 | } |
| 926 | |
| 927 | static inline void tcg_temp_free_i64(TCGv_i64 arg) |
| 928 | { |
| 929 | tcg_temp_free_internal(tcgv_i64_temp(arg)); |
| 930 | } |
| 931 | |
| 932 | static inline void tcg_temp_free_ptr(TCGv_ptr arg) |
| 933 | { |
| 934 | tcg_temp_free_internal(tcgv_ptr_temp(arg)); |
| 935 | } |
| 936 | |
| 937 | static inline void tcg_temp_free_vec(TCGv_vec arg) |
| 938 | { |
| 939 | tcg_temp_free_internal(tcgv_vec_temp(arg)); |
| 940 | } |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 941 | |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 942 | static inline TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t offset, |
| 943 | const char *name) |
| 944 | { |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 945 | TCGTemp *t = tcg_global_mem_new_internal(TCG_TYPE_I32, reg, offset, name); |
| 946 | return temp_tcgv_i32(t); |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 947 | } |
| 948 | |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 949 | static inline TCGv_i32 tcg_temp_new_i32(void) |
bellard | 641d5fb | 2008-05-25 17:24:00 +0000 | [diff] [blame] | 950 | { |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 951 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, false); |
| 952 | return temp_tcgv_i32(t); |
bellard | 641d5fb | 2008-05-25 17:24:00 +0000 | [diff] [blame] | 953 | } |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 954 | |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 955 | static inline TCGv_i32 tcg_temp_local_new_i32(void) |
bellard | 641d5fb | 2008-05-25 17:24:00 +0000 | [diff] [blame] | 956 | { |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 957 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, true); |
| 958 | return temp_tcgv_i32(t); |
bellard | 641d5fb | 2008-05-25 17:24:00 +0000 | [diff] [blame] | 959 | } |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 960 | |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 961 | static inline TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t offset, |
| 962 | const char *name) |
| 963 | { |
Richard Henderson | 085272b | 2017-10-20 00:05:45 -0700 | [diff] [blame] | 964 | TCGTemp *t = tcg_global_mem_new_internal(TCG_TYPE_I64, reg, offset, name); |
| 965 | return temp_tcgv_i64(t); |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 966 | } |
| 967 | |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 968 | static inline TCGv_i64 tcg_temp_new_i64(void) |
| 969 | { |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 970 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, false); |
| 971 | return temp_tcgv_i64(t); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 972 | } |
Richard Henderson | e1ccc05 | 2013-09-18 12:53:09 -0700 | [diff] [blame] | 973 | |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 974 | static inline TCGv_i64 tcg_temp_local_new_i64(void) |
| 975 | { |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 976 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, true); |
| 977 | return temp_tcgv_i64(t); |
| 978 | } |
| 979 | |
| 980 | static inline TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t offset, |
| 981 | const char *name) |
| 982 | { |
| 983 | TCGTemp *t = tcg_global_mem_new_internal(TCG_TYPE_PTR, reg, offset, name); |
| 984 | return temp_tcgv_ptr(t); |
| 985 | } |
| 986 | |
| 987 | static inline TCGv_ptr tcg_temp_new_ptr(void) |
| 988 | { |
| 989 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, false); |
| 990 | return temp_tcgv_ptr(t); |
| 991 | } |
| 992 | |
| 993 | static inline TCGv_ptr tcg_temp_local_new_ptr(void) |
| 994 | { |
| 995 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, true); |
| 996 | return temp_tcgv_ptr(t); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 997 | } |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 998 | |
Peter Maydell | 27bfd83 | 2011-03-06 21:39:53 +0000 | [diff] [blame] | 999 | #if defined(CONFIG_DEBUG_TCG) |
| 1000 | /* If you call tcg_clear_temp_count() at the start of a section of |
| 1001 | * code which is not supposed to leak any TCG temporaries, then |
| 1002 | * calling tcg_check_temp_count() at the end of the section will |
| 1003 | * return 1 if the section did in fact leak a temporary. |
| 1004 | */ |
| 1005 | void tcg_clear_temp_count(void); |
| 1006 | int tcg_check_temp_count(void); |
| 1007 | #else |
| 1008 | #define tcg_clear_temp_count() do { } while (0) |
| 1009 | #define tcg_check_temp_count() 0 |
| 1010 | #endif |
| 1011 | |
Emilio G. Cota | 72fd2ef | 2018-10-10 10:48:53 -0400 | [diff] [blame] | 1012 | int64_t tcg_cpu_exec_time(void); |
Stefan Weil | 405cf9f | 2010-10-22 23:03:31 +0200 | [diff] [blame] | 1013 | void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf); |
Max Filippov | 246ae24 | 2014-11-02 11:04:18 +0300 | [diff] [blame] | 1014 | void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf); |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1015 | |
| 1016 | #define TCG_CT_ALIAS 0x80 |
| 1017 | #define TCG_CT_IALIAS 0x40 |
Richard Henderson | 82790a8 | 2016-11-18 08:35:03 +0100 | [diff] [blame] | 1018 | #define TCG_CT_NEWREG 0x20 /* output requires a new register */ |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1019 | #define TCG_CT_REG 0x01 |
| 1020 | #define TCG_CT_CONST 0x02 /* any constant of register size */ |
| 1021 | |
| 1022 | typedef struct TCGArgConstraint { |
bellard | 5ff9d6a | 2008-02-04 00:37:54 +0000 | [diff] [blame] | 1023 | uint16_t ct; |
| 1024 | uint8_t alias_index; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1025 | union { |
| 1026 | TCGRegSet regs; |
| 1027 | } u; |
| 1028 | } TCGArgConstraint; |
| 1029 | |
| 1030 | #define TCG_MAX_OP_ARGS 16 |
| 1031 | |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1032 | /* Bits for TCGOpDef->flags, 8 bits available. */ |
| 1033 | enum { |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1034 | /* Instruction exits the translation block. */ |
| 1035 | TCG_OPF_BB_EXIT = 0x01, |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1036 | /* Instruction defines the end of a basic block. */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1037 | TCG_OPF_BB_END = 0x02, |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1038 | /* Instruction clobbers call registers and potentially update globals. */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1039 | TCG_OPF_CALL_CLOBBER = 0x04, |
Aurelien Jarno | 3d5c5f8 | 2012-10-09 21:53:08 +0200 | [diff] [blame] | 1040 | /* Instruction has side effects: it cannot be removed if its outputs |
| 1041 | are not used, and might trigger exceptions. */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1042 | TCG_OPF_SIDE_EFFECTS = 0x08, |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1043 | /* Instruction operands are 64-bits (otherwise 32-bits). */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1044 | TCG_OPF_64BIT = 0x10, |
Richard Henderson | c1a61f6 | 2013-05-02 11:57:40 +0100 | [diff] [blame] | 1045 | /* Instruction is optional and not implemented by the host, or insn |
| 1046 | is generic and should not be implemened by the host. */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1047 | TCG_OPF_NOT_PRESENT = 0x20, |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 1048 | /* Instruction operands are vectors. */ |
Richard Henderson | ae36a24 | 2018-11-27 13:45:08 -0800 | [diff] [blame] | 1049 | TCG_OPF_VECTOR = 0x40, |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1050 | }; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1051 | |
| 1052 | typedef struct TCGOpDef { |
| 1053 | const char *name; |
| 1054 | uint8_t nb_oargs, nb_iargs, nb_cargs, nb_args; |
| 1055 | uint8_t flags; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1056 | TCGArgConstraint *args_ct; |
| 1057 | int *sorted_args; |
Stefan Weil | c68aaa1 | 2010-02-15 17:17:21 +0100 | [diff] [blame] | 1058 | #if defined(CONFIG_DEBUG_TCG) |
| 1059 | int used; |
| 1060 | #endif |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1061 | } TCGOpDef; |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 1062 | |
| 1063 | extern TCGOpDef tcg_op_defs[]; |
Stefan Weil | 2a24374 | 2011-09-29 18:33:21 +0200 | [diff] [blame] | 1064 | extern const size_t tcg_op_defs_max; |
| 1065 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1066 | typedef struct TCGTargetOpDef { |
Richard Henderson | a975160 | 2010-03-19 11:12:29 -0700 | [diff] [blame] | 1067 | TCGOpcode op; |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1068 | const char *args_ct_str[TCG_MAX_OP_ARGS]; |
| 1069 | } TCGTargetOpDef; |
| 1070 | |
bellard | c896fe2 | 2008-02-01 10:05:41 +0000 | [diff] [blame] | 1071 | #define tcg_abort() \ |
| 1072 | do {\ |
| 1073 | fprintf(stderr, "%s:%d: tcg fatal error\n", __FILE__, __LINE__);\ |
| 1074 | abort();\ |
| 1075 | } while (0) |
| 1076 | |
Richard Henderson | be0f34b | 2017-08-17 07:43:20 -0700 | [diff] [blame] | 1077 | bool tcg_op_supported(TCGOpcode op); |
| 1078 | |
Richard Henderson | ae8b75d | 2017-10-15 13:27:56 -0700 | [diff] [blame] | 1079 | void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 1080 | |
Richard Henderson | 15fa08f | 2017-11-02 15:19:14 +0100 | [diff] [blame] | 1081 | TCGOp *tcg_emit_op(TCGOpcode opc); |
Richard Henderson | 0c627cd | 2014-03-30 16:51:54 -0700 | [diff] [blame] | 1082 | void tcg_op_remove(TCGContext *s, TCGOp *op); |
Emilio G. Cota | ac1043f | 2018-12-09 14:37:19 -0500 | [diff] [blame] | 1083 | TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op, TCGOpcode opc); |
| 1084 | TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op, TCGOpcode opc); |
Richard Henderson | 5a18407 | 2016-06-23 20:34:33 -0700 | [diff] [blame] | 1085 | |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1086 | void tcg_optimize(TCGContext *s); |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1087 | |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 1088 | TCGv_i32 tcg_const_i32(int32_t val); |
| 1089 | TCGv_i64 tcg_const_i64(int64_t val); |
| 1090 | TCGv_i32 tcg_const_local_i32(int32_t val); |
| 1091 | TCGv_i64 tcg_const_local_i64(int64_t val); |
Richard Henderson | d2fd745 | 2017-09-14 13:53:46 -0700 | [diff] [blame] | 1092 | TCGv_vec tcg_const_zeros_vec(TCGType); |
| 1093 | TCGv_vec tcg_const_ones_vec(TCGType); |
| 1094 | TCGv_vec tcg_const_zeros_vec_matching(TCGv_vec); |
| 1095 | TCGv_vec tcg_const_ones_vec_matching(TCGv_vec); |
pbrook | a7812ae | 2008-11-17 14:43:54 +0000 | [diff] [blame] | 1096 | |
Richard Henderson | 5bfa803 | 2018-02-22 18:17:57 -0800 | [diff] [blame] | 1097 | #if UINTPTR_MAX == UINT32_MAX |
| 1098 | # define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i32((intptr_t)(x))) |
| 1099 | # define tcg_const_local_ptr(x) ((TCGv_ptr)tcg_const_local_i32((intptr_t)(x))) |
| 1100 | #else |
| 1101 | # define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i64((intptr_t)(x))) |
| 1102 | # define tcg_const_local_ptr(x) ((TCGv_ptr)tcg_const_local_i64((intptr_t)(x))) |
| 1103 | #endif |
| 1104 | |
Richard Henderson | 42a268c | 2015-02-13 12:51:55 -0800 | [diff] [blame] | 1105 | TCGLabel *gen_new_label(void); |
| 1106 | |
| 1107 | /** |
| 1108 | * label_arg |
| 1109 | * @l: label |
| 1110 | * |
| 1111 | * Encode a label for storage in the TCG opcode stream. |
| 1112 | */ |
| 1113 | |
| 1114 | static inline TCGArg label_arg(TCGLabel *l) |
| 1115 | { |
Richard Henderson | 51e3972 | 2015-02-13 18:51:05 -0800 | [diff] [blame] | 1116 | return (uintptr_t)l; |
Richard Henderson | 42a268c | 2015-02-13 12:51:55 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * arg_label |
| 1121 | * @i: value |
| 1122 | * |
| 1123 | * The opposite of label_arg. Retrieve a label from the |
| 1124 | * encoding of the TCG opcode stream. |
| 1125 | */ |
| 1126 | |
Richard Henderson | 51e3972 | 2015-02-13 18:51:05 -0800 | [diff] [blame] | 1127 | static inline TCGLabel *arg_label(TCGArg i) |
Richard Henderson | 42a268c | 2015-02-13 12:51:55 -0800 | [diff] [blame] | 1128 | { |
Richard Henderson | 51e3972 | 2015-02-13 18:51:05 -0800 | [diff] [blame] | 1129 | return (TCGLabel *)(uintptr_t)i; |
Richard Henderson | 42a268c | 2015-02-13 12:51:55 -0800 | [diff] [blame] | 1130 | } |
| 1131 | |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1132 | /** |
Richard Henderson | 52a1f64 | 2014-03-31 14:27:27 -0700 | [diff] [blame] | 1133 | * tcg_ptr_byte_diff |
| 1134 | * @a, @b: addresses to be differenced |
| 1135 | * |
| 1136 | * There are many places within the TCG backends where we need a byte |
| 1137 | * difference between two pointers. While this can be accomplished |
| 1138 | * with local casting, it's easy to get wrong -- especially if one is |
| 1139 | * concerned with the signedness of the result. |
| 1140 | * |
| 1141 | * This version relies on GCC's void pointer arithmetic to get the |
| 1142 | * correct result. |
| 1143 | */ |
| 1144 | |
| 1145 | static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b) |
| 1146 | { |
| 1147 | return a - b; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * tcg_pcrel_diff |
| 1152 | * @s: the tcg context |
| 1153 | * @target: address of the target |
| 1154 | * |
| 1155 | * Produce a pc-relative difference, from the current code_ptr |
| 1156 | * to the destination address. |
| 1157 | */ |
| 1158 | |
| 1159 | static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, void *target) |
| 1160 | { |
| 1161 | return tcg_ptr_byte_diff(target, s->code_ptr); |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * tcg_current_code_size |
| 1166 | * @s: the tcg context |
| 1167 | * |
| 1168 | * Compute the current code size within the translation block. |
| 1169 | * This is used to fill in qemu's data structures for goto_tb. |
| 1170 | */ |
| 1171 | |
| 1172 | static inline size_t tcg_current_code_size(TCGContext *s) |
| 1173 | { |
| 1174 | return tcg_ptr_byte_diff(s->code_ptr, s->code_buf); |
| 1175 | } |
| 1176 | |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 1177 | /* Combine the TCGMemOp and mmu_idx parameters into a single value. */ |
| 1178 | typedef uint32_t TCGMemOpIdx; |
| 1179 | |
| 1180 | /** |
| 1181 | * make_memop_idx |
| 1182 | * @op: memory operation |
| 1183 | * @idx: mmu index |
| 1184 | * |
| 1185 | * Encode these values into a single parameter. |
| 1186 | */ |
| 1187 | static inline TCGMemOpIdx make_memop_idx(TCGMemOp op, unsigned idx) |
| 1188 | { |
| 1189 | tcg_debug_assert(idx <= 15); |
| 1190 | return (op << 4) | idx; |
| 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * get_memop |
| 1195 | * @oi: combined op/idx parameter |
| 1196 | * |
| 1197 | * Extract the memory operation from the combined value. |
| 1198 | */ |
| 1199 | static inline TCGMemOp get_memop(TCGMemOpIdx oi) |
| 1200 | { |
| 1201 | return oi >> 4; |
| 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * get_mmuidx |
| 1206 | * @oi: combined op/idx parameter |
| 1207 | * |
| 1208 | * Extract the mmu index from the combined value. |
| 1209 | */ |
| 1210 | static inline unsigned get_mmuidx(TCGMemOpIdx oi) |
| 1211 | { |
| 1212 | return oi & 15; |
| 1213 | } |
| 1214 | |
Richard Henderson | 52a1f64 | 2014-03-31 14:27:27 -0700 | [diff] [blame] | 1215 | /** |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1216 | * tcg_qemu_tb_exec: |
Sergey Fedorov | 819af24 | 2016-04-21 15:58:23 +0300 | [diff] [blame] | 1217 | * @env: pointer to CPUArchState for the CPU |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1218 | * @tb_ptr: address of generated code for the TB to execute |
| 1219 | * |
| 1220 | * Start executing code from a given translation block. |
| 1221 | * Where translation blocks have been linked, execution |
| 1222 | * may proceed from the given TB into successive ones. |
| 1223 | * Control eventually returns only when some action is needed |
| 1224 | * from the top-level loop: either control must pass to a TB |
| 1225 | * which has not yet been directly linked, or an asynchronous |
| 1226 | * event such as an interrupt needs handling. |
| 1227 | * |
Sergey Fedorov | 819af24 | 2016-04-21 15:58:23 +0300 | [diff] [blame] | 1228 | * Return: The return value is the value passed to the corresponding |
| 1229 | * tcg_gen_exit_tb() at translation time of the last TB attempted to execute. |
| 1230 | * The value is either zero or a 4-byte aligned pointer to that TB combined |
| 1231 | * with additional information in its two least significant bits. The |
| 1232 | * additional information is encoded as follows: |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1233 | * 0, 1: the link between this TB and the next is via the specified |
| 1234 | * TB index (0 or 1). That is, we left the TB via (the equivalent |
| 1235 | * of) "goto_tb <index>". The main loop uses this to determine |
| 1236 | * how to link the TB just executed to the next. |
| 1237 | * 2: we are using instruction counting code generation, and we |
| 1238 | * did not start executing this TB because the instruction counter |
Sergey Fedorov | 819af24 | 2016-04-21 15:58:23 +0300 | [diff] [blame] | 1239 | * would hit zero midway through it. In this case the pointer |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1240 | * returned is the TB we were about to execute, and the caller must |
| 1241 | * arrange to execute the remaining count of instructions. |
Peter Maydell | 378df4b | 2013-02-22 18:10:03 +0000 | [diff] [blame] | 1242 | * 3: we stopped because the CPU's exit_request flag was set |
| 1243 | * (usually meaning that there is an interrupt that needs to be |
Sergey Fedorov | 819af24 | 2016-04-21 15:58:23 +0300 | [diff] [blame] | 1244 | * handled). The pointer returned is the TB we were about to execute |
| 1245 | * when we noticed the pending exit request. |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1246 | * |
| 1247 | * If the bottom two bits indicate an exit-via-index then the CPU |
| 1248 | * state is correctly synchronised and ready for execution of the next |
| 1249 | * TB (and in particular the guest PC is the address to execute next). |
| 1250 | * Otherwise, we gave up on execution of this TB before it started, and |
Peter Crosthwaite | fee068e | 2015-04-29 00:52:21 -0700 | [diff] [blame] | 1251 | * the caller must fix up the CPU state by calling the CPU's |
Sergey Fedorov | 819af24 | 2016-04-21 15:58:23 +0300 | [diff] [blame] | 1252 | * synchronize_from_tb() method with the TB pointer we return (falling |
Peter Crosthwaite | fee068e | 2015-04-29 00:52:21 -0700 | [diff] [blame] | 1253 | * back to calling the CPU's set_pc method with tb->pb if no |
| 1254 | * synchronize_from_tb() method exists). |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1255 | * |
| 1256 | * Note that TCG targets may use a different definition of tcg_qemu_tb_exec |
| 1257 | * to this default (which just calls the prologue.code emitted by |
| 1258 | * tcg_target_qemu_prologue()). |
| 1259 | */ |
Richard Henderson | 07ea28b | 2018-05-30 18:06:23 -0700 | [diff] [blame] | 1260 | #define TB_EXIT_MASK 3 |
| 1261 | #define TB_EXIT_IDX0 0 |
| 1262 | #define TB_EXIT_IDX1 1 |
| 1263 | #define TB_EXIT_IDXMAX 1 |
Peter Maydell | 378df4b | 2013-02-22 18:10:03 +0000 | [diff] [blame] | 1264 | #define TB_EXIT_REQUESTED 3 |
Peter Maydell | 0980011 | 2013-02-22 18:10:00 +0000 | [diff] [blame] | 1265 | |
Paolo Bonzini | 5a58e88 | 2015-05-19 09:59:34 +0200 | [diff] [blame] | 1266 | #ifdef HAVE_TCG_QEMU_TB_EXEC |
| 1267 | uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr); |
| 1268 | #else |
Stefan Weil | ce285b1 | 2011-09-30 21:23:06 +0200 | [diff] [blame] | 1269 | # define tcg_qemu_tb_exec(env, tb_ptr) \ |
Emilio G. Cota | b1311c4 | 2017-07-12 17:15:52 -0400 | [diff] [blame] | 1270 | ((uintptr_t (*)(void *, void *))tcg_ctx->code_gen_prologue)(env, tb_ptr) |
bellard | 932a690 | 2008-05-30 20:56:52 +0000 | [diff] [blame] | 1271 | #endif |
Richard Henderson | 813da62 | 2012-03-19 12:25:11 -0700 | [diff] [blame] | 1272 | |
| 1273 | void tcg_register_jit(void *buf, size_t buf_size); |
Yeongkyoon Lee | b76f0d8 | 2012-10-31 16:04:25 +0900 | [diff] [blame] | 1274 | |
Richard Henderson | db43267 | 2017-09-15 14:11:45 -0700 | [diff] [blame] | 1275 | #if TCG_TARGET_MAYBE_vec |
| 1276 | /* Return zero if the tuple (opc, type, vece) is unsupportable; |
| 1277 | return > 0 if it is directly supportable; |
| 1278 | return < 0 if we must call tcg_expand_vec_op. */ |
| 1279 | int tcg_can_emit_vec_op(TCGOpcode, TCGType, unsigned); |
| 1280 | #else |
| 1281 | static inline int tcg_can_emit_vec_op(TCGOpcode o, TCGType t, unsigned ve) |
| 1282 | { |
| 1283 | return 0; |
| 1284 | } |
| 1285 | #endif |
| 1286 | |
| 1287 | /* Expand the tuple (opc, type, vece) on the given arguments. */ |
| 1288 | void tcg_expand_vec_op(TCGOpcode, TCGType, unsigned, TCGArg, ...); |
| 1289 | |
| 1290 | /* Replicate a constant C accoring to the log2 of the element size. */ |
| 1291 | uint64_t dup_const(unsigned vece, uint64_t c); |
| 1292 | |
| 1293 | #define dup_const(VECE, C) \ |
| 1294 | (__builtin_constant_p(VECE) \ |
| 1295 | ? ( (VECE) == MO_8 ? 0x0101010101010101ull * (uint8_t)(C) \ |
| 1296 | : (VECE) == MO_16 ? 0x0001000100010001ull * (uint16_t)(C) \ |
| 1297 | : (VECE) == MO_32 ? 0x0000000100000001ull * (uint32_t)(C) \ |
| 1298 | : dup_const(VECE, C)) \ |
| 1299 | : dup_const(VECE, C)) |
| 1300 | |
| 1301 | |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1302 | /* |
| 1303 | * Memory helpers that will be used by TCG generated code. |
| 1304 | */ |
| 1305 | #ifdef CONFIG_SOFTMMU |
Richard Henderson | c8f94df | 2013-08-27 14:09:14 -0700 | [diff] [blame] | 1306 | /* Value zero-extended to tcg register size. */ |
| 1307 | tcg_target_ulong helper_ret_ldub_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1308 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1309 | tcg_target_ulong helper_le_lduw_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1310 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1311 | tcg_target_ulong helper_le_ldul_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1312 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1313 | uint64_t helper_le_ldq_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1314 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1315 | tcg_target_ulong helper_be_lduw_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1316 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1317 | tcg_target_ulong helper_be_ldul_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1318 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1319 | uint64_t helper_be_ldq_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1320 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1321 | |
Richard Henderson | c8f94df | 2013-08-27 14:09:14 -0700 | [diff] [blame] | 1322 | /* Value sign-extended to tcg register size. */ |
| 1323 | tcg_target_ulong helper_ret_ldsb_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1324 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1325 | tcg_target_ulong helper_le_ldsw_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1326 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1327 | tcg_target_ulong helper_le_ldsl_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1328 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1329 | tcg_target_ulong helper_be_ldsw_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1330 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1331 | tcg_target_ulong helper_be_ldsl_mmu(CPUArchState *env, target_ulong addr, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1332 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | c8f94df | 2013-08-27 14:09:14 -0700 | [diff] [blame] | 1333 | |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1334 | void helper_ret_stb_mmu(CPUArchState *env, target_ulong addr, uint8_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1335 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1336 | void helper_le_stw_mmu(CPUArchState *env, target_ulong addr, uint16_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1337 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1338 | void helper_le_stl_mmu(CPUArchState *env, target_ulong addr, uint32_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1339 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1340 | void helper_le_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1341 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1342 | void helper_be_stw_mmu(CPUArchState *env, target_ulong addr, uint16_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1343 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1344 | void helper_be_stl_mmu(CPUArchState *env, target_ulong addr, uint32_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1345 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1346 | void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1347 | TCGMemOpIdx oi, uintptr_t retaddr); |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1348 | |
Pavel Dovgalyuk | 282dffc | 2015-07-10 12:56:50 +0300 | [diff] [blame] | 1349 | uint8_t helper_ret_ldb_cmmu(CPUArchState *env, target_ulong addr, |
| 1350 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1351 | uint16_t helper_le_ldw_cmmu(CPUArchState *env, target_ulong addr, |
| 1352 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1353 | uint32_t helper_le_ldl_cmmu(CPUArchState *env, target_ulong addr, |
| 1354 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1355 | uint64_t helper_le_ldq_cmmu(CPUArchState *env, target_ulong addr, |
| 1356 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1357 | uint16_t helper_be_ldw_cmmu(CPUArchState *env, target_ulong addr, |
| 1358 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1359 | uint32_t helper_be_ldl_cmmu(CPUArchState *env, target_ulong addr, |
| 1360 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1361 | uint64_t helper_be_ldq_cmmu(CPUArchState *env, target_ulong addr, |
| 1362 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1363 | |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1364 | /* Temporary aliases until backends are converted. */ |
| 1365 | #ifdef TARGET_WORDS_BIGENDIAN |
| 1366 | # define helper_ret_ldsw_mmu helper_be_ldsw_mmu |
| 1367 | # define helper_ret_lduw_mmu helper_be_lduw_mmu |
| 1368 | # define helper_ret_ldsl_mmu helper_be_ldsl_mmu |
| 1369 | # define helper_ret_ldul_mmu helper_be_ldul_mmu |
Pavel Dovgalyuk | 282dffc | 2015-07-10 12:56:50 +0300 | [diff] [blame] | 1370 | # define helper_ret_ldl_mmu helper_be_ldul_mmu |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1371 | # define helper_ret_ldq_mmu helper_be_ldq_mmu |
| 1372 | # define helper_ret_stw_mmu helper_be_stw_mmu |
| 1373 | # define helper_ret_stl_mmu helper_be_stl_mmu |
| 1374 | # define helper_ret_stq_mmu helper_be_stq_mmu |
Pavel Dovgalyuk | 282dffc | 2015-07-10 12:56:50 +0300 | [diff] [blame] | 1375 | # define helper_ret_ldw_cmmu helper_be_ldw_cmmu |
| 1376 | # define helper_ret_ldl_cmmu helper_be_ldl_cmmu |
| 1377 | # define helper_ret_ldq_cmmu helper_be_ldq_cmmu |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1378 | #else |
| 1379 | # define helper_ret_ldsw_mmu helper_le_ldsw_mmu |
| 1380 | # define helper_ret_lduw_mmu helper_le_lduw_mmu |
| 1381 | # define helper_ret_ldsl_mmu helper_le_ldsl_mmu |
| 1382 | # define helper_ret_ldul_mmu helper_le_ldul_mmu |
Pavel Dovgalyuk | 282dffc | 2015-07-10 12:56:50 +0300 | [diff] [blame] | 1383 | # define helper_ret_ldl_mmu helper_le_ldul_mmu |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1384 | # define helper_ret_ldq_mmu helper_le_ldq_mmu |
| 1385 | # define helper_ret_stw_mmu helper_le_stw_mmu |
| 1386 | # define helper_ret_stl_mmu helper_le_stl_mmu |
| 1387 | # define helper_ret_stq_mmu helper_le_stq_mmu |
Pavel Dovgalyuk | 282dffc | 2015-07-10 12:56:50 +0300 | [diff] [blame] | 1388 | # define helper_ret_ldw_cmmu helper_le_ldw_cmmu |
| 1389 | # define helper_ret_ldl_cmmu helper_le_ldl_cmmu |
| 1390 | # define helper_ret_ldq_cmmu helper_le_ldq_cmmu |
Richard Henderson | 867b320 | 2013-09-04 11:45:20 -0700 | [diff] [blame] | 1391 | #endif |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1392 | |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1393 | uint32_t helper_atomic_cmpxchgb_mmu(CPUArchState *env, target_ulong addr, |
| 1394 | uint32_t cmpv, uint32_t newv, |
| 1395 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1396 | uint32_t helper_atomic_cmpxchgw_le_mmu(CPUArchState *env, target_ulong addr, |
| 1397 | uint32_t cmpv, uint32_t newv, |
| 1398 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1399 | uint32_t helper_atomic_cmpxchgl_le_mmu(CPUArchState *env, target_ulong addr, |
| 1400 | uint32_t cmpv, uint32_t newv, |
| 1401 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1402 | uint64_t helper_atomic_cmpxchgq_le_mmu(CPUArchState *env, target_ulong addr, |
| 1403 | uint64_t cmpv, uint64_t newv, |
| 1404 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1405 | uint32_t helper_atomic_cmpxchgw_be_mmu(CPUArchState *env, target_ulong addr, |
| 1406 | uint32_t cmpv, uint32_t newv, |
| 1407 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1408 | uint32_t helper_atomic_cmpxchgl_be_mmu(CPUArchState *env, target_ulong addr, |
| 1409 | uint32_t cmpv, uint32_t newv, |
| 1410 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1411 | uint64_t helper_atomic_cmpxchgq_be_mmu(CPUArchState *env, target_ulong addr, |
| 1412 | uint64_t cmpv, uint64_t newv, |
| 1413 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1414 | |
| 1415 | #define GEN_ATOMIC_HELPER(NAME, TYPE, SUFFIX) \ |
| 1416 | TYPE helper_atomic_ ## NAME ## SUFFIX ## _mmu \ |
| 1417 | (CPUArchState *env, target_ulong addr, TYPE val, \ |
| 1418 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1419 | |
Richard Henderson | df79b99 | 2016-09-02 12:23:57 -0700 | [diff] [blame] | 1420 | #ifdef CONFIG_ATOMIC64 |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1421 | #define GEN_ATOMIC_HELPER_ALL(NAME) \ |
Richard Henderson | df79b99 | 2016-09-02 12:23:57 -0700 | [diff] [blame] | 1422 | GEN_ATOMIC_HELPER(NAME, uint32_t, b) \ |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1423 | GEN_ATOMIC_HELPER(NAME, uint32_t, w_le) \ |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1424 | GEN_ATOMIC_HELPER(NAME, uint32_t, w_be) \ |
Richard Henderson | df79b99 | 2016-09-02 12:23:57 -0700 | [diff] [blame] | 1425 | GEN_ATOMIC_HELPER(NAME, uint32_t, l_le) \ |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1426 | GEN_ATOMIC_HELPER(NAME, uint32_t, l_be) \ |
Richard Henderson | df79b99 | 2016-09-02 12:23:57 -0700 | [diff] [blame] | 1427 | GEN_ATOMIC_HELPER(NAME, uint64_t, q_le) \ |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1428 | GEN_ATOMIC_HELPER(NAME, uint64_t, q_be) |
Richard Henderson | df79b99 | 2016-09-02 12:23:57 -0700 | [diff] [blame] | 1429 | #else |
| 1430 | #define GEN_ATOMIC_HELPER_ALL(NAME) \ |
| 1431 | GEN_ATOMIC_HELPER(NAME, uint32_t, b) \ |
| 1432 | GEN_ATOMIC_HELPER(NAME, uint32_t, w_le) \ |
| 1433 | GEN_ATOMIC_HELPER(NAME, uint32_t, w_be) \ |
| 1434 | GEN_ATOMIC_HELPER(NAME, uint32_t, l_le) \ |
| 1435 | GEN_ATOMIC_HELPER(NAME, uint32_t, l_be) |
| 1436 | #endif |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1437 | |
| 1438 | GEN_ATOMIC_HELPER_ALL(fetch_add) |
| 1439 | GEN_ATOMIC_HELPER_ALL(fetch_sub) |
| 1440 | GEN_ATOMIC_HELPER_ALL(fetch_and) |
| 1441 | GEN_ATOMIC_HELPER_ALL(fetch_or) |
| 1442 | GEN_ATOMIC_HELPER_ALL(fetch_xor) |
Richard Henderson | 5507c2b | 2018-05-10 18:10:57 +0100 | [diff] [blame] | 1443 | GEN_ATOMIC_HELPER_ALL(fetch_smin) |
| 1444 | GEN_ATOMIC_HELPER_ALL(fetch_umin) |
| 1445 | GEN_ATOMIC_HELPER_ALL(fetch_smax) |
| 1446 | GEN_ATOMIC_HELPER_ALL(fetch_umax) |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1447 | |
| 1448 | GEN_ATOMIC_HELPER_ALL(add_fetch) |
| 1449 | GEN_ATOMIC_HELPER_ALL(sub_fetch) |
| 1450 | GEN_ATOMIC_HELPER_ALL(and_fetch) |
| 1451 | GEN_ATOMIC_HELPER_ALL(or_fetch) |
| 1452 | GEN_ATOMIC_HELPER_ALL(xor_fetch) |
Richard Henderson | 5507c2b | 2018-05-10 18:10:57 +0100 | [diff] [blame] | 1453 | GEN_ATOMIC_HELPER_ALL(smin_fetch) |
| 1454 | GEN_ATOMIC_HELPER_ALL(umin_fetch) |
| 1455 | GEN_ATOMIC_HELPER_ALL(smax_fetch) |
| 1456 | GEN_ATOMIC_HELPER_ALL(umax_fetch) |
Richard Henderson | c482cb1 | 2016-06-28 11:37:27 -0700 | [diff] [blame] | 1457 | |
| 1458 | GEN_ATOMIC_HELPER_ALL(xchg) |
| 1459 | |
| 1460 | #undef GEN_ATOMIC_HELPER_ALL |
| 1461 | #undef GEN_ATOMIC_HELPER |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1462 | #endif /* CONFIG_SOFTMMU */ |
| 1463 | |
Richard Henderson | e6cd4bb | 2018-08-15 16:31:47 -0700 | [diff] [blame] | 1464 | /* |
| 1465 | * These aren't really a "proper" helpers because TCG cannot manage Int128. |
| 1466 | * However, use the same format as the others, for use by the backends. |
| 1467 | * |
| 1468 | * The cmpxchg functions are only defined if HAVE_CMPXCHG128; |
| 1469 | * the ld/st functions are only defined if HAVE_ATOMIC128, |
| 1470 | * as defined by <qemu/atomic128.h>. |
| 1471 | */ |
Richard Henderson | 7ebee43 | 2016-06-29 21:10:59 -0700 | [diff] [blame] | 1472 | Int128 helper_atomic_cmpxchgo_le_mmu(CPUArchState *env, target_ulong addr, |
| 1473 | Int128 cmpv, Int128 newv, |
| 1474 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1475 | Int128 helper_atomic_cmpxchgo_be_mmu(CPUArchState *env, target_ulong addr, |
| 1476 | Int128 cmpv, Int128 newv, |
| 1477 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1478 | |
| 1479 | Int128 helper_atomic_ldo_le_mmu(CPUArchState *env, target_ulong addr, |
| 1480 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1481 | Int128 helper_atomic_ldo_be_mmu(CPUArchState *env, target_ulong addr, |
| 1482 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1483 | void helper_atomic_sto_le_mmu(CPUArchState *env, target_ulong addr, Int128 val, |
| 1484 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1485 | void helper_atomic_sto_be_mmu(CPUArchState *env, target_ulong addr, Int128 val, |
| 1486 | TCGMemOpIdx oi, uintptr_t retaddr); |
| 1487 | |
Richard Henderson | e58eb53 | 2013-08-27 13:13:44 -0700 | [diff] [blame] | 1488 | #endif /* TCG_H */ |