Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Tiny Code Generator for QEMU |
| 3 | * |
| 4 | * Copyright (c) 2009 Ulrich Hecht <uli@suse.de> |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 5 | * Copyright (c) 2009 Alexander Graf <agraf@suse.de> |
| 6 | * Copyright (c) 2010 Richard Henderson <rth@twiddle.net> |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Richard Henderson | a01fc30 | 2013-03-26 16:39:50 -0400 | [diff] [blame] | 27 | /* We only support generating code for 64-bit mode. */ |
| 28 | #if TCG_TARGET_REG_BITS != 64 |
| 29 | #error "unsupported code generation mode" |
| 30 | #endif |
| 31 | |
Paolo Bonzini | 139c183 | 2020-02-04 12:41:01 +0100 | [diff] [blame] | 32 | #include "../tcg-pool.c.inc" |
Richard Henderson | c9baa30 | 2013-06-07 07:43:33 -0700 | [diff] [blame] | 33 | #include "elf.h" |
| 34 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 35 | /* ??? The translation blocks produced by TCG are generally small enough to |
| 36 | be entirely reachable with a 16-bit displacement. Leaving the option for |
| 37 | a 32-bit displacement here Just In Case. */ |
| 38 | #define USE_LONG_BRANCHES 0 |
| 39 | |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 40 | #define TCG_CT_CONST_S16 0x100 |
| 41 | #define TCG_CT_CONST_S32 0x200 |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 42 | #define TCG_CT_CONST_S33 0x400 |
| 43 | #define TCG_CT_CONST_ZERO 0x800 |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 44 | |
Richard Henderson | c947deb | 2020-10-16 20:09:02 -0700 | [diff] [blame] | 45 | #define ALL_GENERAL_REGS MAKE_64BIT_MASK(0, 16) |
| 46 | /* |
| 47 | * For softmmu, we need to avoid conflicts with the first 3 |
| 48 | * argument registers to perform the tlb lookup, and to call |
| 49 | * the helper function. |
| 50 | */ |
| 51 | #ifdef CONFIG_SOFTMMU |
| 52 | #define SOFTMMU_RESERVE_REGS MAKE_64BIT_MASK(TCG_REG_R2, 3) |
| 53 | #else |
| 54 | #define SOFTMMU_RESERVE_REGS 0 |
| 55 | #endif |
| 56 | |
| 57 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 58 | /* Several places within the instruction set 0 means "no register" |
| 59 | rather than TCG_REG_R0. */ |
| 60 | #define TCG_REG_NONE 0 |
| 61 | |
| 62 | /* A scratch register that may be be used throughout the backend. */ |
Richard Henderson | ce41106 | 2016-11-16 16:10:37 +0100 | [diff] [blame] | 63 | #define TCG_TMP0 TCG_REG_R1 |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 64 | |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 65 | /* A scratch register that holds a pointer to the beginning of the TB. |
| 66 | We don't need this when we have pc-relative loads with the general |
| 67 | instructions extension facility. */ |
| 68 | #define TCG_REG_TB TCG_REG_R12 |
| 69 | #define USE_REG_TB (!(s390_facilities & FACILITY_GEN_INST_EXT)) |
| 70 | |
Laurent Vivier | 4cbea59 | 2015-08-24 01:42:07 +0200 | [diff] [blame] | 71 | #ifndef CONFIG_SOFTMMU |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 72 | #define TCG_GUEST_BASE_REG TCG_REG_R13 |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 75 | /* All of the following instructions are prefixed with their instruction |
| 76 | format, and are defined as 8- or 16-bit quantities, even when the two |
| 77 | halves of the 16-bit quantity may appear 32 bits apart in the insn. |
| 78 | This makes it easy to copy the values from the tables in Appendix B. */ |
| 79 | typedef enum S390Opcode { |
| 80 | RIL_AFI = 0xc209, |
| 81 | RIL_AGFI = 0xc208, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 82 | RIL_ALFI = 0xc20b, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 83 | RIL_ALGFI = 0xc20a, |
| 84 | RIL_BRASL = 0xc005, |
| 85 | RIL_BRCL = 0xc004, |
| 86 | RIL_CFI = 0xc20d, |
| 87 | RIL_CGFI = 0xc20c, |
| 88 | RIL_CLFI = 0xc20f, |
| 89 | RIL_CLGFI = 0xc20e, |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 90 | RIL_CLRL = 0xc60f, |
| 91 | RIL_CLGRL = 0xc60a, |
| 92 | RIL_CRL = 0xc60d, |
| 93 | RIL_CGRL = 0xc608, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 94 | RIL_IIHF = 0xc008, |
| 95 | RIL_IILF = 0xc009, |
| 96 | RIL_LARL = 0xc000, |
| 97 | RIL_LGFI = 0xc001, |
| 98 | RIL_LGRL = 0xc408, |
| 99 | RIL_LLIHF = 0xc00e, |
| 100 | RIL_LLILF = 0xc00f, |
| 101 | RIL_LRL = 0xc40d, |
| 102 | RIL_MSFI = 0xc201, |
| 103 | RIL_MSGFI = 0xc200, |
| 104 | RIL_NIHF = 0xc00a, |
| 105 | RIL_NILF = 0xc00b, |
| 106 | RIL_OIHF = 0xc00c, |
| 107 | RIL_OILF = 0xc00d, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 108 | RIL_SLFI = 0xc205, |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 109 | RIL_SLGFI = 0xc204, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 110 | RIL_XIHF = 0xc006, |
| 111 | RIL_XILF = 0xc007, |
| 112 | |
| 113 | RI_AGHI = 0xa70b, |
| 114 | RI_AHI = 0xa70a, |
| 115 | RI_BRC = 0xa704, |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 116 | RI_CHI = 0xa70e, |
| 117 | RI_CGHI = 0xa70f, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 118 | RI_IIHH = 0xa500, |
| 119 | RI_IIHL = 0xa501, |
| 120 | RI_IILH = 0xa502, |
| 121 | RI_IILL = 0xa503, |
| 122 | RI_LGHI = 0xa709, |
| 123 | RI_LLIHH = 0xa50c, |
| 124 | RI_LLIHL = 0xa50d, |
| 125 | RI_LLILH = 0xa50e, |
| 126 | RI_LLILL = 0xa50f, |
| 127 | RI_MGHI = 0xa70d, |
| 128 | RI_MHI = 0xa70c, |
| 129 | RI_NIHH = 0xa504, |
| 130 | RI_NIHL = 0xa505, |
| 131 | RI_NILH = 0xa506, |
| 132 | RI_NILL = 0xa507, |
| 133 | RI_OIHH = 0xa508, |
| 134 | RI_OIHL = 0xa509, |
| 135 | RI_OILH = 0xa50a, |
| 136 | RI_OILL = 0xa50b, |
| 137 | |
| 138 | RIE_CGIJ = 0xec7c, |
| 139 | RIE_CGRJ = 0xec64, |
| 140 | RIE_CIJ = 0xec7e, |
| 141 | RIE_CLGRJ = 0xec65, |
| 142 | RIE_CLIJ = 0xec7f, |
| 143 | RIE_CLGIJ = 0xec7d, |
| 144 | RIE_CLRJ = 0xec77, |
| 145 | RIE_CRJ = 0xec76, |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 146 | RIE_LOCGHI = 0xec46, |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 147 | RIE_RISBG = 0xec55, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 148 | |
| 149 | RRE_AGR = 0xb908, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 150 | RRE_ALGR = 0xb90a, |
| 151 | RRE_ALCR = 0xb998, |
| 152 | RRE_ALCGR = 0xb988, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 153 | RRE_CGR = 0xb920, |
| 154 | RRE_CLGR = 0xb921, |
| 155 | RRE_DLGR = 0xb987, |
| 156 | RRE_DLR = 0xb997, |
| 157 | RRE_DSGFR = 0xb91d, |
| 158 | RRE_DSGR = 0xb90d, |
Richard Henderson | ce41106 | 2016-11-16 16:10:37 +0100 | [diff] [blame] | 159 | RRE_FLOGR = 0xb983, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 160 | RRE_LGBR = 0xb906, |
| 161 | RRE_LCGR = 0xb903, |
| 162 | RRE_LGFR = 0xb914, |
| 163 | RRE_LGHR = 0xb907, |
| 164 | RRE_LGR = 0xb904, |
| 165 | RRE_LLGCR = 0xb984, |
| 166 | RRE_LLGFR = 0xb916, |
| 167 | RRE_LLGHR = 0xb985, |
| 168 | RRE_LRVR = 0xb91f, |
| 169 | RRE_LRVGR = 0xb90f, |
| 170 | RRE_LTGR = 0xb902, |
Richard Henderson | 36017dc | 2013-03-26 16:50:29 -0400 | [diff] [blame] | 171 | RRE_MLGR = 0xb986, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 172 | RRE_MSGR = 0xb90c, |
| 173 | RRE_MSR = 0xb252, |
| 174 | RRE_NGR = 0xb980, |
| 175 | RRE_OGR = 0xb981, |
| 176 | RRE_SGR = 0xb909, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 177 | RRE_SLGR = 0xb90b, |
| 178 | RRE_SLBR = 0xb999, |
| 179 | RRE_SLBGR = 0xb989, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 180 | RRE_XGR = 0xb982, |
| 181 | |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 182 | RRF_LOCR = 0xb9f2, |
| 183 | RRF_LOCGR = 0xb9e2, |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 184 | RRF_NRK = 0xb9f4, |
| 185 | RRF_NGRK = 0xb9e4, |
| 186 | RRF_ORK = 0xb9f6, |
| 187 | RRF_OGRK = 0xb9e6, |
| 188 | RRF_SRK = 0xb9f9, |
| 189 | RRF_SGRK = 0xb9e9, |
| 190 | RRF_SLRK = 0xb9fb, |
| 191 | RRF_SLGRK = 0xb9eb, |
| 192 | RRF_XRK = 0xb9f7, |
| 193 | RRF_XGRK = 0xb9e7, |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 194 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 195 | RR_AR = 0x1a, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 196 | RR_ALR = 0x1e, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 197 | RR_BASR = 0x0d, |
| 198 | RR_BCR = 0x07, |
| 199 | RR_CLR = 0x15, |
| 200 | RR_CR = 0x19, |
| 201 | RR_DR = 0x1d, |
| 202 | RR_LCR = 0x13, |
| 203 | RR_LR = 0x18, |
| 204 | RR_LTR = 0x12, |
| 205 | RR_NR = 0x14, |
| 206 | RR_OR = 0x16, |
| 207 | RR_SR = 0x1b, |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 208 | RR_SLR = 0x1f, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 209 | RR_XR = 0x17, |
| 210 | |
| 211 | RSY_RLL = 0xeb1d, |
| 212 | RSY_RLLG = 0xeb1c, |
| 213 | RSY_SLLG = 0xeb0d, |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 214 | RSY_SLLK = 0xebdf, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 215 | RSY_SRAG = 0xeb0a, |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 216 | RSY_SRAK = 0xebdc, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 217 | RSY_SRLG = 0xeb0c, |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 218 | RSY_SRLK = 0xebde, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 219 | |
| 220 | RS_SLL = 0x89, |
| 221 | RS_SRA = 0x8a, |
| 222 | RS_SRL = 0x88, |
| 223 | |
| 224 | RXY_AG = 0xe308, |
| 225 | RXY_AY = 0xe35a, |
| 226 | RXY_CG = 0xe320, |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 227 | RXY_CLG = 0xe321, |
| 228 | RXY_CLY = 0xe355, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 229 | RXY_CY = 0xe359, |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 230 | RXY_LAY = 0xe371, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 231 | RXY_LB = 0xe376, |
| 232 | RXY_LG = 0xe304, |
| 233 | RXY_LGB = 0xe377, |
| 234 | RXY_LGF = 0xe314, |
| 235 | RXY_LGH = 0xe315, |
| 236 | RXY_LHY = 0xe378, |
| 237 | RXY_LLGC = 0xe390, |
| 238 | RXY_LLGF = 0xe316, |
| 239 | RXY_LLGH = 0xe391, |
| 240 | RXY_LMG = 0xeb04, |
| 241 | RXY_LRV = 0xe31e, |
| 242 | RXY_LRVG = 0xe30f, |
| 243 | RXY_LRVH = 0xe31f, |
| 244 | RXY_LY = 0xe358, |
Richard Henderson | bdcd5d1 | 2017-07-25 18:59:13 -0400 | [diff] [blame] | 245 | RXY_NG = 0xe380, |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 246 | RXY_OG = 0xe381, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 247 | RXY_STCY = 0xe372, |
| 248 | RXY_STG = 0xe324, |
| 249 | RXY_STHY = 0xe370, |
| 250 | RXY_STMG = 0xeb24, |
| 251 | RXY_STRV = 0xe33e, |
| 252 | RXY_STRVG = 0xe32f, |
| 253 | RXY_STRVH = 0xe33f, |
| 254 | RXY_STY = 0xe350, |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 255 | RXY_XG = 0xe382, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 256 | |
| 257 | RX_A = 0x5a, |
| 258 | RX_C = 0x59, |
| 259 | RX_L = 0x58, |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 260 | RX_LA = 0x41, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 261 | RX_LH = 0x48, |
| 262 | RX_ST = 0x50, |
| 263 | RX_STC = 0x42, |
| 264 | RX_STH = 0x40, |
Sergey Fedorov | ed3d51e | 2016-04-22 19:08:48 +0300 | [diff] [blame] | 265 | |
| 266 | NOP = 0x0707, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 267 | } S390Opcode; |
| 268 | |
Aurelien Jarno | 8d8fdba | 2016-04-21 10:48:50 +0200 | [diff] [blame] | 269 | #ifdef CONFIG_DEBUG_TCG |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 270 | static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { |
| 271 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
| 272 | "%r8", "%r9", "%r10" "%r11" "%r12" "%r13" "%r14" "%r15" |
| 273 | }; |
| 274 | #endif |
| 275 | |
| 276 | /* Since R6 is a potential argument register, choose it last of the |
| 277 | call-saved registers. Likewise prefer the call-clobbered registers |
| 278 | in reverse order to maximize the chance of avoiding the arguments. */ |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 279 | static const int tcg_target_reg_alloc_order[] = { |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 280 | /* Call saved registers. */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 281 | TCG_REG_R13, |
| 282 | TCG_REG_R12, |
| 283 | TCG_REG_R11, |
| 284 | TCG_REG_R10, |
| 285 | TCG_REG_R9, |
| 286 | TCG_REG_R8, |
| 287 | TCG_REG_R7, |
| 288 | TCG_REG_R6, |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 289 | /* Call clobbered registers. */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 290 | TCG_REG_R14, |
| 291 | TCG_REG_R0, |
| 292 | TCG_REG_R1, |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 293 | /* Argument registers, in reverse order of allocation. */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 294 | TCG_REG_R5, |
| 295 | TCG_REG_R4, |
| 296 | TCG_REG_R3, |
| 297 | TCG_REG_R2, |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static const int tcg_target_call_iarg_regs[] = { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 301 | TCG_REG_R2, |
| 302 | TCG_REG_R3, |
| 303 | TCG_REG_R4, |
| 304 | TCG_REG_R5, |
| 305 | TCG_REG_R6, |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | static const int tcg_target_call_oarg_regs[] = { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 309 | TCG_REG_R2, |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 310 | }; |
| 311 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 312 | #define S390_CC_EQ 8 |
| 313 | #define S390_CC_LT 4 |
| 314 | #define S390_CC_GT 2 |
| 315 | #define S390_CC_OV 1 |
| 316 | #define S390_CC_NE (S390_CC_LT | S390_CC_GT) |
| 317 | #define S390_CC_LE (S390_CC_LT | S390_CC_EQ) |
| 318 | #define S390_CC_GE (S390_CC_GT | S390_CC_EQ) |
| 319 | #define S390_CC_NEVER 0 |
| 320 | #define S390_CC_ALWAYS 15 |
| 321 | |
| 322 | /* Condition codes that result from a COMPARE and COMPARE LOGICAL. */ |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 323 | static const uint8_t tcg_cond_to_s390_cond[] = { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 324 | [TCG_COND_EQ] = S390_CC_EQ, |
| 325 | [TCG_COND_NE] = S390_CC_NE, |
| 326 | [TCG_COND_LT] = S390_CC_LT, |
| 327 | [TCG_COND_LE] = S390_CC_LE, |
| 328 | [TCG_COND_GT] = S390_CC_GT, |
| 329 | [TCG_COND_GE] = S390_CC_GE, |
| 330 | [TCG_COND_LTU] = S390_CC_LT, |
| 331 | [TCG_COND_LEU] = S390_CC_LE, |
| 332 | [TCG_COND_GTU] = S390_CC_GT, |
| 333 | [TCG_COND_GEU] = S390_CC_GE, |
| 334 | }; |
| 335 | |
| 336 | /* Condition codes that result from a LOAD AND TEST. Here, we have no |
| 337 | unsigned instruction variation, however since the test is vs zero we |
| 338 | can re-map the outcomes appropriately. */ |
Richard Henderson | 0aed257 | 2012-09-24 14:21:40 -0700 | [diff] [blame] | 339 | static const uint8_t tcg_cond_to_ltr_cond[] = { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 340 | [TCG_COND_EQ] = S390_CC_EQ, |
| 341 | [TCG_COND_NE] = S390_CC_NE, |
| 342 | [TCG_COND_LT] = S390_CC_LT, |
| 343 | [TCG_COND_LE] = S390_CC_LE, |
| 344 | [TCG_COND_GT] = S390_CC_GT, |
| 345 | [TCG_COND_GE] = S390_CC_GE, |
| 346 | [TCG_COND_LTU] = S390_CC_NEVER, |
| 347 | [TCG_COND_LEU] = S390_CC_EQ, |
| 348 | [TCG_COND_GTU] = S390_CC_NE, |
| 349 | [TCG_COND_GEU] = S390_CC_ALWAYS, |
| 350 | }; |
| 351 | |
| 352 | #ifdef CONFIG_SOFTMMU |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 353 | static void * const qemu_ld_helpers[16] = { |
| 354 | [MO_UB] = helper_ret_ldub_mmu, |
| 355 | [MO_SB] = helper_ret_ldsb_mmu, |
| 356 | [MO_LEUW] = helper_le_lduw_mmu, |
| 357 | [MO_LESW] = helper_le_ldsw_mmu, |
| 358 | [MO_LEUL] = helper_le_ldul_mmu, |
| 359 | [MO_LESL] = helper_le_ldsl_mmu, |
| 360 | [MO_LEQ] = helper_le_ldq_mmu, |
| 361 | [MO_BEUW] = helper_be_lduw_mmu, |
| 362 | [MO_BESW] = helper_be_ldsw_mmu, |
| 363 | [MO_BEUL] = helper_be_ldul_mmu, |
| 364 | [MO_BESL] = helper_be_ldsl_mmu, |
| 365 | [MO_BEQ] = helper_be_ldq_mmu, |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 366 | }; |
| 367 | |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 368 | static void * const qemu_st_helpers[16] = { |
| 369 | [MO_UB] = helper_ret_stb_mmu, |
| 370 | [MO_LEUW] = helper_le_stw_mmu, |
| 371 | [MO_LEUL] = helper_le_stl_mmu, |
| 372 | [MO_LEQ] = helper_le_stq_mmu, |
| 373 | [MO_BEUW] = helper_be_stw_mmu, |
| 374 | [MO_BEUL] = helper_be_stl_mmu, |
| 375 | [MO_BEQ] = helper_be_stq_mmu, |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 376 | }; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 377 | #endif |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 378 | |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 379 | static const tcg_insn_unit *tb_ret_addr; |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 380 | uint64_t s390_facilities; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 381 | |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 382 | static bool patch_reloc(tcg_insn_unit *src_rw, int type, |
Richard Henderson | 2ba7fae2 | 2013-08-20 15:30:10 -0700 | [diff] [blame] | 383 | intptr_t value, intptr_t addend) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 384 | { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 385 | const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); |
Richard Henderson | e692a34 | 2017-07-30 13:58:01 -0700 | [diff] [blame] | 386 | intptr_t pcrel2; |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 387 | uint32_t old; |
Richard Henderson | e692a34 | 2017-07-30 13:58:01 -0700 | [diff] [blame] | 388 | |
| 389 | value += addend; |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 390 | pcrel2 = (tcg_insn_unit *)value - src_rx; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 391 | |
| 392 | switch (type) { |
| 393 | case R_390_PC16DBL: |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 394 | if (pcrel2 == (int16_t)pcrel2) { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 395 | tcg_patch16(src_rw, pcrel2); |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 396 | return true; |
| 397 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 398 | break; |
| 399 | case R_390_PC32DBL: |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 400 | if (pcrel2 == (int32_t)pcrel2) { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 401 | tcg_patch32(src_rw, pcrel2); |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 402 | return true; |
| 403 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 404 | break; |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 405 | case R_390_20: |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 406 | if (value == sextract64(value, 0, 20)) { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 407 | old = *(uint32_t *)src_rw & 0xf00000ff; |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 408 | old |= ((value & 0xfff) << 16) | ((value & 0xff000) >> 4); |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 409 | tcg_patch32(src_rw, old); |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 410 | return true; |
| 411 | } |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 412 | break; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 413 | default: |
Richard Henderson | e692a34 | 2017-07-30 13:58:01 -0700 | [diff] [blame] | 414 | g_assert_not_reached(); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 415 | } |
Richard Henderson | 55dfd8f | 2018-11-30 21:41:51 +0000 | [diff] [blame] | 416 | return false; |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 419 | /* Test if a constant matches the constraint. */ |
Richard Henderson | f6c6afc | 2014-03-30 21:22:11 -0700 | [diff] [blame] | 420 | static int tcg_target_const_match(tcg_target_long val, TCGType type, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 421 | const TCGArgConstraint *arg_ct) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 422 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 423 | int ct = arg_ct->ct; |
| 424 | |
| 425 | if (ct & TCG_CT_CONST) { |
| 426 | return 1; |
| 427 | } |
| 428 | |
Richard Henderson | 671c835 | 2014-03-31 02:25:26 -0400 | [diff] [blame] | 429 | if (type == TCG_TYPE_I32) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 430 | val = (int32_t)val; |
| 431 | } |
| 432 | |
| 433 | /* The following are mutually exclusive. */ |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 434 | if (ct & TCG_CT_CONST_S16) { |
| 435 | return val == (int16_t)val; |
| 436 | } else if (ct & TCG_CT_CONST_S32) { |
| 437 | return val == (int32_t)val; |
Richard Henderson | ba18b07 | 2017-06-16 14:59:55 -0700 | [diff] [blame] | 438 | } else if (ct & TCG_CT_CONST_S33) { |
| 439 | return val >= -0xffffffffll && val <= 0xffffffffll; |
Richard Henderson | 752b1be | 2016-10-17 17:00:46 -0700 | [diff] [blame] | 440 | } else if (ct & TCG_CT_CONST_ZERO) { |
| 441 | return val == 0; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 447 | /* Emit instructions according to the given instruction format. */ |
| 448 | |
| 449 | static void tcg_out_insn_RR(TCGContext *s, S390Opcode op, TCGReg r1, TCGReg r2) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 450 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 451 | tcg_out16(s, (op << 8) | (r1 << 4) | r2); |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 454 | static void tcg_out_insn_RRE(TCGContext *s, S390Opcode op, |
| 455 | TCGReg r1, TCGReg r2) |
| 456 | { |
| 457 | tcg_out32(s, (op << 16) | (r1 << 4) | r2); |
| 458 | } |
| 459 | |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 460 | static void tcg_out_insn_RRF(TCGContext *s, S390Opcode op, |
| 461 | TCGReg r1, TCGReg r2, int m3) |
| 462 | { |
| 463 | tcg_out32(s, (op << 16) | (m3 << 12) | (r1 << 4) | r2); |
| 464 | } |
| 465 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 466 | static void tcg_out_insn_RI(TCGContext *s, S390Opcode op, TCGReg r1, int i2) |
| 467 | { |
| 468 | tcg_out32(s, (op << 16) | (r1 << 20) | (i2 & 0xffff)); |
| 469 | } |
| 470 | |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 471 | static void tcg_out_insn_RIE(TCGContext *s, S390Opcode op, TCGReg r1, |
| 472 | int i2, int m3) |
| 473 | { |
| 474 | tcg_out16(s, (op & 0xff00) | (r1 << 4) | m3); |
| 475 | tcg_out32(s, (i2 << 16) | (op & 0xff)); |
| 476 | } |
| 477 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 478 | static void tcg_out_insn_RIL(TCGContext *s, S390Opcode op, TCGReg r1, int i2) |
| 479 | { |
| 480 | tcg_out16(s, op | (r1 << 4)); |
| 481 | tcg_out32(s, i2); |
| 482 | } |
| 483 | |
| 484 | static void tcg_out_insn_RS(TCGContext *s, S390Opcode op, TCGReg r1, |
| 485 | TCGReg b2, TCGReg r3, int disp) |
| 486 | { |
| 487 | tcg_out32(s, (op << 24) | (r1 << 20) | (r3 << 16) | (b2 << 12) |
| 488 | | (disp & 0xfff)); |
| 489 | } |
| 490 | |
| 491 | static void tcg_out_insn_RSY(TCGContext *s, S390Opcode op, TCGReg r1, |
| 492 | TCGReg b2, TCGReg r3, int disp) |
| 493 | { |
| 494 | tcg_out16(s, (op & 0xff00) | (r1 << 4) | r3); |
| 495 | tcg_out32(s, (op & 0xff) | (b2 << 28) |
| 496 | | ((disp & 0xfff) << 16) | ((disp & 0xff000) >> 4)); |
| 497 | } |
| 498 | |
| 499 | #define tcg_out_insn_RX tcg_out_insn_RS |
| 500 | #define tcg_out_insn_RXY tcg_out_insn_RSY |
| 501 | |
| 502 | /* Emit an opcode with "type-checking" of the format. */ |
| 503 | #define tcg_out_insn(S, FMT, OP, ...) \ |
| 504 | glue(tcg_out_insn_,FMT)(S, glue(glue(FMT,_),OP), ## __VA_ARGS__) |
| 505 | |
| 506 | |
| 507 | /* emit 64-bit shifts */ |
| 508 | static void tcg_out_sh64(TCGContext* s, S390Opcode op, TCGReg dest, |
| 509 | TCGReg src, TCGReg sh_reg, int sh_imm) |
| 510 | { |
| 511 | tcg_out_insn_RSY(s, op, dest, sh_reg, src, sh_imm); |
| 512 | } |
| 513 | |
| 514 | /* emit 32-bit shifts */ |
| 515 | static void tcg_out_sh32(TCGContext* s, S390Opcode op, TCGReg dest, |
| 516 | TCGReg sh_reg, int sh_imm) |
| 517 | { |
| 518 | tcg_out_insn_RS(s, op, dest, sh_reg, 0, sh_imm); |
| 519 | } |
| 520 | |
Richard Henderson | 78113e8 | 2019-03-16 17:48:18 +0000 | [diff] [blame] | 521 | static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg dst, TCGReg src) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 522 | { |
| 523 | if (src != dst) { |
| 524 | if (type == TCG_TYPE_I32) { |
| 525 | tcg_out_insn(s, RR, LR, dst, src); |
| 526 | } else { |
| 527 | tcg_out_insn(s, RRE, LGR, dst, src); |
| 528 | } |
| 529 | } |
Richard Henderson | 78113e8 | 2019-03-16 17:48:18 +0000 | [diff] [blame] | 530 | return true; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 533 | static const S390Opcode lli_insns[4] = { |
| 534 | RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH |
| 535 | }; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 536 | |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 537 | static bool maybe_out_small_movi(TCGContext *s, TCGType type, |
| 538 | TCGReg ret, tcg_target_long sval) |
| 539 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 540 | tcg_target_ulong uval = sval; |
| 541 | int i; |
| 542 | |
| 543 | if (type == TCG_TYPE_I32) { |
| 544 | uval = (uint32_t)sval; |
| 545 | sval = (int32_t)sval; |
| 546 | } |
| 547 | |
| 548 | /* Try all 32-bit insns that can load it in one go. */ |
| 549 | if (sval >= -0x8000 && sval < 0x8000) { |
| 550 | tcg_out_insn(s, RI, LGHI, ret, sval); |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 551 | return true; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | for (i = 0; i < 4; i++) { |
| 555 | tcg_target_long mask = 0xffffull << i*16; |
| 556 | if ((uval & mask) == uval) { |
| 557 | tcg_out_insn_RI(s, lli_insns[i], ret, uval >> i*16); |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 558 | return true; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 562 | return false; |
| 563 | } |
| 564 | |
| 565 | /* load a register with an immediate value */ |
| 566 | static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, |
| 567 | tcg_target_long sval, bool in_prologue) |
| 568 | { |
| 569 | tcg_target_ulong uval; |
| 570 | |
| 571 | /* Try all 32-bit insns that can load it in one go. */ |
| 572 | if (maybe_out_small_movi(s, type, ret, sval)) { |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | uval = sval; |
| 577 | if (type == TCG_TYPE_I32) { |
| 578 | uval = (uint32_t)sval; |
| 579 | sval = (int32_t)sval; |
| 580 | } |
| 581 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 582 | /* Try all 48-bit insns that can load it in one go. */ |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 583 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 584 | if (sval == (int32_t)sval) { |
| 585 | tcg_out_insn(s, RIL, LGFI, ret, sval); |
| 586 | return; |
| 587 | } |
| 588 | if (uval <= 0xffffffff) { |
| 589 | tcg_out_insn(s, RIL, LLILF, ret, uval); |
| 590 | return; |
| 591 | } |
| 592 | if ((uval & 0xffffffff) == 0) { |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 593 | tcg_out_insn(s, RIL, LLIHF, ret, uval >> 32); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | } |
| 597 | |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 598 | /* Try for PC-relative address load. For odd addresses, |
| 599 | attempt to use an offset from the start of the TB. */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 600 | if ((sval & 1) == 0) { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 601 | ptrdiff_t off = tcg_pcrel_diff(s, (void *)sval) >> 1; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 602 | if (off == (int32_t)off) { |
| 603 | tcg_out_insn(s, RIL, LARL, ret, off); |
| 604 | return; |
| 605 | } |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 606 | } else if (USE_REG_TB && !in_prologue) { |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 607 | ptrdiff_t off = tcg_tbrel_diff(s, (void *)sval); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 608 | if (off == sextract64(off, 0, 20)) { |
| 609 | /* This is certain to be an address within TB, and therefore |
| 610 | OFF will be negative; don't try RX_LA. */ |
| 611 | tcg_out_insn(s, RXY, LAY, ret, TCG_REG_TB, TCG_REG_NONE, off); |
| 612 | return; |
| 613 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 616 | /* A 32-bit unsigned value can be loaded in 2 insns. And given |
| 617 | that LLILL, LLIHL, LLILF above did not succeed, we know that |
| 618 | both insns are required. */ |
| 619 | if (uval <= 0xffffffff) { |
| 620 | tcg_out_insn(s, RI, LLILL, ret, uval); |
| 621 | tcg_out_insn(s, RI, IILH, ret, uval >> 16); |
| 622 | return; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Richard Henderson | ba2c747 | 2017-10-25 18:03:27 +0200 | [diff] [blame] | 625 | /* Otherwise, stuff it in the constant pool. */ |
| 626 | if (s390_facilities & FACILITY_GEN_INST_EXT) { |
| 627 | tcg_out_insn(s, RIL, LGRL, ret, 0); |
| 628 | new_pool_label(s, sval, R_390_PC32DBL, s->code_ptr - 2, 2); |
| 629 | } else if (USE_REG_TB && !in_prologue) { |
| 630 | tcg_out_insn(s, RXY, LG, ret, TCG_REG_TB, TCG_REG_NONE, 0); |
| 631 | new_pool_label(s, sval, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 632 | tcg_tbrel_diff(s, NULL)); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 633 | } else { |
Richard Henderson | ba2c747 | 2017-10-25 18:03:27 +0200 | [diff] [blame] | 634 | TCGReg base = ret ? ret : TCG_TMP0; |
| 635 | tcg_out_insn(s, RIL, LARL, base, 0); |
| 636 | new_pool_label(s, sval, R_390_PC32DBL, s->code_ptr - 2, 2); |
| 637 | tcg_out_insn(s, RXY, LG, ret, base, TCG_REG_NONE, 0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 641 | static void tcg_out_movi(TCGContext *s, TCGType type, |
| 642 | TCGReg ret, tcg_target_long sval) |
| 643 | { |
| 644 | tcg_out_movi_int(s, type, ret, sval, false); |
| 645 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 646 | |
| 647 | /* Emit a load/store type instruction. Inputs are: |
| 648 | DATA: The register to be loaded or stored. |
| 649 | BASE+OFS: The effective address. |
| 650 | OPC_RX: If the operation has an RX format opcode (e.g. STC), otherwise 0. |
| 651 | OPC_RXY: The RXY format opcode for the operation (e.g. STCY). */ |
| 652 | |
| 653 | static void tcg_out_mem(TCGContext *s, S390Opcode opc_rx, S390Opcode opc_rxy, |
| 654 | TCGReg data, TCGReg base, TCGReg index, |
| 655 | tcg_target_long ofs) |
| 656 | { |
| 657 | if (ofs < -0x80000 || ofs >= 0x80000) { |
Richard Henderson | 78c9f7c | 2013-03-27 14:37:42 -0400 | [diff] [blame] | 658 | /* Combine the low 20 bits of the offset with the actual load insn; |
| 659 | the high 44 bits must come from an immediate load. */ |
| 660 | tcg_target_long low = ((ofs & 0xfffff) ^ 0x80000) - 0x80000; |
| 661 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_TMP0, ofs - low); |
| 662 | ofs = low; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 663 | |
| 664 | /* If we were already given an index register, add it in. */ |
| 665 | if (index != TCG_REG_NONE) { |
| 666 | tcg_out_insn(s, RRE, AGR, TCG_TMP0, index); |
| 667 | } |
| 668 | index = TCG_TMP0; |
| 669 | } |
| 670 | |
| 671 | if (opc_rx && ofs >= 0 && ofs < 0x1000) { |
| 672 | tcg_out_insn_RX(s, opc_rx, data, base, index, ofs); |
| 673 | } else { |
| 674 | tcg_out_insn_RXY(s, opc_rxy, data, base, index, ofs); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 679 | /* load data without address translation or endianness conversion */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 680 | static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg data, |
Richard Henderson | a05b5b9 | 2013-08-20 17:07:26 -0700 | [diff] [blame] | 681 | TCGReg base, intptr_t ofs) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 682 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 683 | if (type == TCG_TYPE_I32) { |
| 684 | tcg_out_mem(s, RX_L, RXY_LY, data, base, TCG_REG_NONE, ofs); |
| 685 | } else { |
| 686 | tcg_out_mem(s, 0, RXY_LG, data, base, TCG_REG_NONE, ofs); |
| 687 | } |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 690 | static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg data, |
Richard Henderson | a05b5b9 | 2013-08-20 17:07:26 -0700 | [diff] [blame] | 691 | TCGReg base, intptr_t ofs) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 692 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 693 | if (type == TCG_TYPE_I32) { |
| 694 | tcg_out_mem(s, RX_ST, RXY_STY, data, base, TCG_REG_NONE, ofs); |
| 695 | } else { |
| 696 | tcg_out_mem(s, 0, RXY_STG, data, base, TCG_REG_NONE, ofs); |
| 697 | } |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Richard Henderson | 59d7c14 | 2016-06-19 22:59:13 -0700 | [diff] [blame] | 700 | static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, |
| 701 | TCGReg base, intptr_t ofs) |
| 702 | { |
| 703 | return false; |
| 704 | } |
| 705 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 706 | /* load data from an absolute host address */ |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 707 | static void tcg_out_ld_abs(TCGContext *s, TCGType type, |
| 708 | TCGReg dest, const void *abs) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 709 | { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 710 | intptr_t addr = (intptr_t)abs; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 711 | |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 712 | if ((s390_facilities & FACILITY_GEN_INST_EXT) && !(addr & 1)) { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 713 | ptrdiff_t disp = tcg_pcrel_diff(s, abs) >> 1; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 714 | if (disp == (int32_t)disp) { |
| 715 | if (type == TCG_TYPE_I32) { |
| 716 | tcg_out_insn(s, RIL, LRL, dest, disp); |
| 717 | } else { |
| 718 | tcg_out_insn(s, RIL, LGRL, dest, disp); |
| 719 | } |
| 720 | return; |
| 721 | } |
| 722 | } |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 723 | if (USE_REG_TB) { |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 724 | ptrdiff_t disp = tcg_tbrel_diff(s, abs); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 725 | if (disp == sextract64(disp, 0, 20)) { |
| 726 | tcg_out_ld(s, type, dest, TCG_REG_TB, disp); |
| 727 | return; |
| 728 | } |
| 729 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 730 | |
| 731 | tcg_out_movi(s, TCG_TYPE_PTR, dest, addr & ~0xffff); |
| 732 | tcg_out_ld(s, type, dest, dest, addr & 0xffff); |
| 733 | } |
| 734 | |
Richard Henderson | f0bffc2 | 2013-03-27 12:28:22 -0400 | [diff] [blame] | 735 | static inline void tcg_out_risbg(TCGContext *s, TCGReg dest, TCGReg src, |
| 736 | int msb, int lsb, int ofs, int z) |
| 737 | { |
| 738 | /* Format RIE-f */ |
| 739 | tcg_out16(s, (RIE_RISBG & 0xff00) | (dest << 4) | src); |
| 740 | tcg_out16(s, (msb << 8) | (z << 7) | lsb); |
| 741 | tcg_out16(s, (ofs << 8) | (RIE_RISBG & 0xff)); |
| 742 | } |
| 743 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 744 | static void tgen_ext8s(TCGContext *s, TCGType type, TCGReg dest, TCGReg src) |
| 745 | { |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 746 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 747 | tcg_out_insn(s, RRE, LGBR, dest, src); |
| 748 | return; |
| 749 | } |
| 750 | |
| 751 | if (type == TCG_TYPE_I32) { |
| 752 | if (dest == src) { |
| 753 | tcg_out_sh32(s, RS_SLL, dest, TCG_REG_NONE, 24); |
| 754 | } else { |
| 755 | tcg_out_sh64(s, RSY_SLLG, dest, src, TCG_REG_NONE, 24); |
| 756 | } |
| 757 | tcg_out_sh32(s, RS_SRA, dest, TCG_REG_NONE, 24); |
| 758 | } else { |
| 759 | tcg_out_sh64(s, RSY_SLLG, dest, src, TCG_REG_NONE, 56); |
| 760 | tcg_out_sh64(s, RSY_SRAG, dest, dest, TCG_REG_NONE, 56); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | static void tgen_ext8u(TCGContext *s, TCGType type, TCGReg dest, TCGReg src) |
| 765 | { |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 766 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 767 | tcg_out_insn(s, RRE, LLGCR, dest, src); |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | if (dest == src) { |
| 772 | tcg_out_movi(s, type, TCG_TMP0, 0xff); |
| 773 | src = TCG_TMP0; |
| 774 | } else { |
| 775 | tcg_out_movi(s, type, dest, 0xff); |
| 776 | } |
| 777 | if (type == TCG_TYPE_I32) { |
| 778 | tcg_out_insn(s, RR, NR, dest, src); |
| 779 | } else { |
| 780 | tcg_out_insn(s, RRE, NGR, dest, src); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | static void tgen_ext16s(TCGContext *s, TCGType type, TCGReg dest, TCGReg src) |
| 785 | { |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 786 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 787 | tcg_out_insn(s, RRE, LGHR, dest, src); |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | if (type == TCG_TYPE_I32) { |
| 792 | if (dest == src) { |
| 793 | tcg_out_sh32(s, RS_SLL, dest, TCG_REG_NONE, 16); |
| 794 | } else { |
| 795 | tcg_out_sh64(s, RSY_SLLG, dest, src, TCG_REG_NONE, 16); |
| 796 | } |
| 797 | tcg_out_sh32(s, RS_SRA, dest, TCG_REG_NONE, 16); |
| 798 | } else { |
| 799 | tcg_out_sh64(s, RSY_SLLG, dest, src, TCG_REG_NONE, 48); |
| 800 | tcg_out_sh64(s, RSY_SRAG, dest, dest, TCG_REG_NONE, 48); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | static void tgen_ext16u(TCGContext *s, TCGType type, TCGReg dest, TCGReg src) |
| 805 | { |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 806 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 807 | tcg_out_insn(s, RRE, LLGHR, dest, src); |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | if (dest == src) { |
| 812 | tcg_out_movi(s, type, TCG_TMP0, 0xffff); |
| 813 | src = TCG_TMP0; |
| 814 | } else { |
| 815 | tcg_out_movi(s, type, dest, 0xffff); |
| 816 | } |
| 817 | if (type == TCG_TYPE_I32) { |
| 818 | tcg_out_insn(s, RR, NR, dest, src); |
| 819 | } else { |
| 820 | tcg_out_insn(s, RRE, NGR, dest, src); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | static inline void tgen_ext32s(TCGContext *s, TCGReg dest, TCGReg src) |
| 825 | { |
| 826 | tcg_out_insn(s, RRE, LGFR, dest, src); |
| 827 | } |
| 828 | |
| 829 | static inline void tgen_ext32u(TCGContext *s, TCGReg dest, TCGReg src) |
| 830 | { |
| 831 | tcg_out_insn(s, RRE, LLGFR, dest, src); |
| 832 | } |
| 833 | |
Richard Henderson | f0bffc2 | 2013-03-27 12:28:22 -0400 | [diff] [blame] | 834 | /* Accept bit patterns like these: |
| 835 | 0....01....1 |
| 836 | 1....10....0 |
| 837 | 1..10..01..1 |
| 838 | 0..01..10..0 |
| 839 | Copied from gcc sources. */ |
| 840 | static inline bool risbg_mask(uint64_t c) |
| 841 | { |
| 842 | uint64_t lsb; |
| 843 | /* We don't change the number of transitions by inverting, |
| 844 | so make sure we start with the LSB zero. */ |
| 845 | if (c & 1) { |
| 846 | c = ~c; |
| 847 | } |
| 848 | /* Reject all zeros or all ones. */ |
| 849 | if (c == 0) { |
| 850 | return false; |
| 851 | } |
| 852 | /* Find the first transition. */ |
| 853 | lsb = c & -c; |
| 854 | /* Invert to look for a second transition. */ |
| 855 | c = ~c; |
| 856 | /* Erase the first transition. */ |
| 857 | c &= -lsb; |
| 858 | /* Find the second transition, if any. */ |
| 859 | lsb = c & -c; |
| 860 | /* Match if all the bits are 1's, or if c is zero. */ |
| 861 | return c == -lsb; |
| 862 | } |
| 863 | |
Richard Henderson | 547ec12 | 2014-03-23 19:35:44 -0400 | [diff] [blame] | 864 | static void tgen_andi_risbg(TCGContext *s, TCGReg out, TCGReg in, uint64_t val) |
| 865 | { |
| 866 | int msb, lsb; |
| 867 | if ((val & 0x8000000000000001ull) == 0x8000000000000001ull) { |
| 868 | /* Achieve wraparound by swapping msb and lsb. */ |
| 869 | msb = 64 - ctz64(~val); |
| 870 | lsb = clz64(~val) - 1; |
| 871 | } else { |
| 872 | msb = clz64(val); |
| 873 | lsb = 63 - ctz64(val); |
| 874 | } |
| 875 | tcg_out_risbg(s, out, in, msb, lsb, 0, 1); |
| 876 | } |
| 877 | |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 878 | static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 879 | { |
| 880 | static const S390Opcode ni_insns[4] = { |
| 881 | RI_NILL, RI_NILH, RI_NIHL, RI_NIHH |
| 882 | }; |
| 883 | static const S390Opcode nif_insns[2] = { |
| 884 | RIL_NILF, RIL_NIHF |
| 885 | }; |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 886 | uint64_t valid = (type == TCG_TYPE_I32 ? 0xffffffffull : -1ull); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 887 | int i; |
| 888 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 889 | /* Look for the zero-extensions. */ |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 890 | if ((val & valid) == 0xffffffff) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 891 | tgen_ext32u(s, dest, dest); |
| 892 | return; |
| 893 | } |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 894 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 895 | if ((val & valid) == 0xff) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 896 | tgen_ext8u(s, TCG_TYPE_I64, dest, dest); |
| 897 | return; |
| 898 | } |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 899 | if ((val & valid) == 0xffff) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 900 | tgen_ext16u(s, TCG_TYPE_I64, dest, dest); |
| 901 | return; |
| 902 | } |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 903 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 904 | |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 905 | /* Try all 32-bit insns that can perform it in one go. */ |
| 906 | for (i = 0; i < 4; i++) { |
| 907 | tcg_target_ulong mask = ~(0xffffull << i*16); |
| 908 | if (((val | ~valid) & mask) == mask) { |
| 909 | tcg_out_insn_RI(s, ni_insns[i], dest, val >> i*16); |
| 910 | return; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | /* Try all 48-bit insns that can perform it in one go. */ |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 915 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 916 | for (i = 0; i < 2; i++) { |
| 917 | tcg_target_ulong mask = ~(0xffffffffull << i*32); |
| 918 | if (((val | ~valid) & mask) == mask) { |
| 919 | tcg_out_insn_RIL(s, nif_insns[i], dest, val >> i*32); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | } |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 923 | } |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 924 | if ((s390_facilities & FACILITY_GEN_INST_EXT) && risbg_mask(val)) { |
Richard Henderson | 547ec12 | 2014-03-23 19:35:44 -0400 | [diff] [blame] | 925 | tgen_andi_risbg(s, dest, dest, val); |
Richard Henderson | f0bffc2 | 2013-03-27 12:28:22 -0400 | [diff] [blame] | 926 | return; |
| 927 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 928 | |
Richard Henderson | bdcd5d1 | 2017-07-25 18:59:13 -0400 | [diff] [blame] | 929 | /* Use the constant pool if USE_REG_TB, but not for small constants. */ |
| 930 | if (USE_REG_TB) { |
| 931 | if (!maybe_out_small_movi(s, type, TCG_TMP0, val)) { |
| 932 | tcg_out_insn(s, RXY, NG, dest, TCG_REG_TB, TCG_REG_NONE, 0); |
| 933 | new_pool_label(s, val & valid, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 934 | tcg_tbrel_diff(s, NULL)); |
Richard Henderson | bdcd5d1 | 2017-07-25 18:59:13 -0400 | [diff] [blame] | 935 | return; |
| 936 | } |
| 937 | } else { |
| 938 | tcg_out_movi(s, type, TCG_TMP0, val); |
| 939 | } |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 940 | if (type == TCG_TYPE_I32) { |
| 941 | tcg_out_insn(s, RR, NR, dest, TCG_TMP0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 942 | } else { |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 943 | tcg_out_insn(s, RRE, NGR, dest, TCG_TMP0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 947 | static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 948 | { |
| 949 | static const S390Opcode oi_insns[4] = { |
| 950 | RI_OILL, RI_OILH, RI_OIHL, RI_OIHH |
| 951 | }; |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 952 | static const S390Opcode oif_insns[2] = { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 953 | RIL_OILF, RIL_OIHF |
| 954 | }; |
| 955 | |
| 956 | int i; |
| 957 | |
| 958 | /* Look for no-op. */ |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 959 | if (unlikely(val == 0)) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 963 | /* Try all 32-bit insns that can perform it in one go. */ |
| 964 | for (i = 0; i < 4; i++) { |
| 965 | tcg_target_ulong mask = (0xffffull << i*16); |
| 966 | if ((val & mask) != 0 && (val & ~mask) == 0) { |
| 967 | tcg_out_insn_RI(s, oi_insns[i], dest, val >> i*16); |
| 968 | return; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 969 | } |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 970 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 971 | |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 972 | /* Try all 48-bit insns that can perform it in one go. */ |
| 973 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 974 | for (i = 0; i < 2; i++) { |
| 975 | tcg_target_ulong mask = (0xffffffffull << i*32); |
| 976 | if ((val & mask) != 0 && (val & ~mask) == 0) { |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 977 | tcg_out_insn_RIL(s, oif_insns[i], dest, val >> i*32); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 978 | return; |
| 979 | } |
| 980 | } |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 981 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 982 | |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 983 | /* Use the constant pool if USE_REG_TB, but not for small constants. */ |
| 984 | if (maybe_out_small_movi(s, type, TCG_TMP0, val)) { |
| 985 | if (type == TCG_TYPE_I32) { |
| 986 | tcg_out_insn(s, RR, OR, dest, TCG_TMP0); |
| 987 | } else { |
| 988 | tcg_out_insn(s, RRE, OGR, dest, TCG_TMP0); |
| 989 | } |
| 990 | } else if (USE_REG_TB) { |
| 991 | tcg_out_insn(s, RXY, OG, dest, TCG_REG_TB, TCG_REG_NONE, 0); |
| 992 | new_pool_label(s, val, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 993 | tcg_tbrel_diff(s, NULL)); |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 994 | } else { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 995 | /* Perform the OR via sequential modifications to the high and |
| 996 | low parts. Do this via recursion to handle 16-bit vs 32-bit |
| 997 | masks in each half. */ |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 998 | tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM); |
| 999 | tgen_ori(s, type, dest, val & 0x00000000ffffffffull); |
| 1000 | tgen_ori(s, type, dest, val & 0xffffffff00000000ull); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 1004 | static void tgen_xori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1005 | { |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 1006 | /* Try all 48-bit insns that can perform it in one go. */ |
| 1007 | if (s390_facilities & FACILITY_EXT_IMM) { |
| 1008 | if ((val & 0xffffffff00000000ull) == 0) { |
| 1009 | tcg_out_insn(s, RIL, XILF, dest, val); |
| 1010 | return; |
| 1011 | } |
| 1012 | if ((val & 0x00000000ffffffffull) == 0) { |
| 1013 | tcg_out_insn(s, RIL, XIHF, dest, val >> 32); |
| 1014 | return; |
| 1015 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1016 | } |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 1017 | |
| 1018 | /* Use the constant pool if USE_REG_TB, but not for small constants. */ |
| 1019 | if (maybe_out_small_movi(s, type, TCG_TMP0, val)) { |
| 1020 | if (type == TCG_TYPE_I32) { |
| 1021 | tcg_out_insn(s, RR, XR, dest, TCG_TMP0); |
| 1022 | } else { |
| 1023 | tcg_out_insn(s, RRE, XGR, dest, TCG_TMP0); |
| 1024 | } |
| 1025 | } else if (USE_REG_TB) { |
| 1026 | tcg_out_insn(s, RXY, XG, dest, TCG_REG_TB, TCG_REG_NONE, 0); |
| 1027 | new_pool_label(s, val, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 1028 | tcg_tbrel_diff(s, NULL)); |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 1029 | } else { |
| 1030 | /* Perform the xor by parts. */ |
| 1031 | tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM); |
| 1032 | if (val & 0xffffffff) { |
| 1033 | tcg_out_insn(s, RIL, XILF, dest, val); |
| 1034 | } |
| 1035 | if (val > 0xffffffff) { |
| 1036 | tcg_out_insn(s, RIL, XIHF, dest, val >> 32); |
| 1037 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1042 | TCGArg c2, bool c2const, bool need_carry) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1043 | { |
Richard Henderson | bcc6656 | 2012-09-24 14:21:39 -0700 | [diff] [blame] | 1044 | bool is_unsigned = is_unsigned_cond(c); |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1045 | S390Opcode op; |
| 1046 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1047 | if (c2const) { |
| 1048 | if (c2 == 0) { |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1049 | if (!(is_unsigned && need_carry)) { |
| 1050 | if (type == TCG_TYPE_I32) { |
| 1051 | tcg_out_insn(s, RR, LTR, r1, r1); |
| 1052 | } else { |
| 1053 | tcg_out_insn(s, RRE, LTGR, r1, r1); |
| 1054 | } |
| 1055 | return tcg_cond_to_ltr_cond[c]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1056 | } |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | if (!is_unsigned && c2 == (int16_t)c2) { |
| 1060 | op = (type == TCG_TYPE_I32 ? RI_CHI : RI_CGHI); |
| 1061 | tcg_out_insn_RI(s, op, r1, c2); |
| 1062 | goto exit; |
| 1063 | } |
| 1064 | |
| 1065 | if (s390_facilities & FACILITY_EXT_IMM) { |
| 1066 | if (type == TCG_TYPE_I32) { |
| 1067 | op = (is_unsigned ? RIL_CLFI : RIL_CFI); |
| 1068 | tcg_out_insn_RIL(s, op, r1, c2); |
| 1069 | goto exit; |
| 1070 | } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) { |
| 1071 | op = (is_unsigned ? RIL_CLGFI : RIL_CGFI); |
| 1072 | tcg_out_insn_RIL(s, op, r1, c2); |
| 1073 | goto exit; |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1074 | } |
| 1075 | } |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1076 | |
| 1077 | /* Use the constant pool, but not for small constants. */ |
| 1078 | if (maybe_out_small_movi(s, type, TCG_TMP0, c2)) { |
| 1079 | c2 = TCG_TMP0; |
| 1080 | /* fall through to reg-reg */ |
| 1081 | } else if (USE_REG_TB) { |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1082 | if (type == TCG_TYPE_I32) { |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1083 | op = (is_unsigned ? RXY_CLY : RXY_CY); |
| 1084 | tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); |
| 1085 | new_pool_label(s, (uint32_t)c2, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 1086 | 4 - tcg_tbrel_diff(s, NULL)); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1087 | } else { |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1088 | op = (is_unsigned ? RXY_CLG : RXY_CG); |
| 1089 | tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); |
| 1090 | new_pool_label(s, c2, R_390_20, s->code_ptr - 2, |
Richard Henderson | dd90043 | 2020-11-04 18:00:35 -0800 | [diff] [blame] | 1091 | tcg_tbrel_diff(s, NULL)); |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1092 | } |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1093 | goto exit; |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1094 | } else { |
| 1095 | if (type == TCG_TYPE_I32) { |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1096 | op = (is_unsigned ? RIL_CLRL : RIL_CRL); |
| 1097 | tcg_out_insn_RIL(s, op, r1, 0); |
| 1098 | new_pool_label(s, (uint32_t)c2, R_390_PC32DBL, |
| 1099 | s->code_ptr - 2, 2 + 4); |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1100 | } else { |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1101 | op = (is_unsigned ? RIL_CLGRL : RIL_CGRL); |
| 1102 | tcg_out_insn_RIL(s, op, r1, 0); |
| 1103 | new_pool_label(s, c2, R_390_PC32DBL, s->code_ptr - 2, 2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1104 | } |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1105 | goto exit; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 1108 | |
| 1109 | if (type == TCG_TYPE_I32) { |
| 1110 | op = (is_unsigned ? RR_CLR : RR_CR); |
| 1111 | tcg_out_insn_RR(s, op, r1, c2); |
| 1112 | } else { |
| 1113 | op = (is_unsigned ? RRE_CLGR : RRE_CGR); |
| 1114 | tcg_out_insn_RRE(s, op, r1, c2); |
| 1115 | } |
| 1116 | |
| 1117 | exit: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1118 | return tcg_cond_to_s390_cond[c]; |
| 1119 | } |
| 1120 | |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1121 | static void tgen_setcond(TCGContext *s, TCGType type, TCGCond cond, |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1122 | TCGReg dest, TCGReg c1, TCGArg c2, int c2const) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1123 | { |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1124 | int cc; |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1125 | bool have_loc; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1126 | |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1127 | /* With LOC2, we can always emit the minimum 3 insns. */ |
| 1128 | if (s390_facilities & FACILITY_LOAD_ON_COND2) { |
| 1129 | /* Emit: d = 0, d = (cc ? 1 : d). */ |
| 1130 | cc = tgen_cmp(s, type, cond, c1, c2, c2const, false); |
| 1131 | tcg_out_movi(s, TCG_TYPE_I64, dest, 0); |
| 1132 | tcg_out_insn(s, RIE, LOCGHI, dest, 1, cc); |
| 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | have_loc = (s390_facilities & FACILITY_LOAD_ON_COND) != 0; |
| 1137 | |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1138 | /* For HAVE_LOC, only the paths through GTU/GT/LEU/LE are smaller. */ |
| 1139 | restart: |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1140 | switch (cond) { |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1141 | case TCG_COND_NE: |
| 1142 | /* X != 0 is X > 0. */ |
| 1143 | if (c2const && c2 == 0) { |
| 1144 | cond = TCG_COND_GTU; |
| 1145 | } else { |
| 1146 | break; |
| 1147 | } |
| 1148 | /* fallthru */ |
| 1149 | |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1150 | case TCG_COND_GTU: |
| 1151 | case TCG_COND_GT: |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1152 | /* The result of a compare has CC=2 for GT and CC=3 unused. |
| 1153 | ADD LOGICAL WITH CARRY considers (CC & 2) the carry bit. */ |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1154 | tgen_cmp(s, type, cond, c1, c2, c2const, true); |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1155 | tcg_out_movi(s, type, dest, 0); |
| 1156 | tcg_out_insn(s, RRE, ALCGR, dest, dest); |
| 1157 | return; |
| 1158 | |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1159 | case TCG_COND_EQ: |
| 1160 | /* X == 0 is X <= 0. */ |
| 1161 | if (c2const && c2 == 0) { |
| 1162 | cond = TCG_COND_LEU; |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1163 | } else { |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1164 | break; |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1165 | } |
| 1166 | /* fallthru */ |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1167 | |
| 1168 | case TCG_COND_LEU: |
| 1169 | case TCG_COND_LE: |
| 1170 | /* As above, but we're looking for borrow, or !carry. |
| 1171 | The second insn computes d - d - borrow, or -1 for true |
| 1172 | and 0 for false. So we must mask to 1 bit afterward. */ |
| 1173 | tgen_cmp(s, type, cond, c1, c2, c2const, true); |
| 1174 | tcg_out_insn(s, RRE, SLBGR, dest, dest); |
| 1175 | tgen_andi(s, type, dest, 1); |
| 1176 | return; |
| 1177 | |
| 1178 | case TCG_COND_GEU: |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1179 | case TCG_COND_LTU: |
| 1180 | case TCG_COND_LT: |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1181 | case TCG_COND_GE: |
| 1182 | /* Swap operands so that we can use LEU/GTU/GT/LE. */ |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1183 | if (c2const) { |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1184 | if (have_loc) { |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1185 | break; |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1186 | } |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1187 | tcg_out_movi(s, type, TCG_TMP0, c2); |
| 1188 | c2 = c1; |
| 1189 | c2const = 0; |
| 1190 | c1 = TCG_TMP0; |
| 1191 | } else { |
| 1192 | TCGReg t = c1; |
| 1193 | c1 = c2; |
| 1194 | c2 = t; |
| 1195 | } |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1196 | cond = tcg_swap_cond(cond); |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1197 | goto restart; |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1198 | |
| 1199 | default: |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1200 | g_assert_not_reached(); |
Richard Henderson | 7b7066b | 2014-03-31 12:57:06 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1203 | cc = tgen_cmp(s, type, cond, c1, c2, c2const, false); |
Richard Henderson | 4609190 | 2017-07-25 23:09:17 -0400 | [diff] [blame] | 1204 | if (have_loc) { |
| 1205 | /* Emit: d = 0, t = 1, d = (cc ? t : d). */ |
| 1206 | tcg_out_movi(s, TCG_TYPE_I64, dest, 0); |
| 1207 | tcg_out_movi(s, TCG_TYPE_I64, TCG_TMP0, 1); |
| 1208 | tcg_out_insn(s, RRF, LOCGR, dest, TCG_TMP0, cc); |
| 1209 | } else { |
| 1210 | /* Emit: d = 1; if (cc) goto over; d = 0; over: */ |
| 1211 | tcg_out_movi(s, type, dest, 1); |
| 1212 | tcg_out_insn(s, RI, BRC, cc, (4 + 4) >> 1); |
| 1213 | tcg_out_movi(s, type, dest, 0); |
| 1214 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1217 | static void tgen_movcond(TCGContext *s, TCGType type, TCGCond c, TCGReg dest, |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1218 | TCGReg c1, TCGArg c2, int c2const, |
| 1219 | TCGArg v3, int v3const) |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1220 | { |
| 1221 | int cc; |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 1222 | if (s390_facilities & FACILITY_LOAD_ON_COND) { |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1223 | cc = tgen_cmp(s, type, c, c1, c2, c2const, false); |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1224 | if (v3const) { |
| 1225 | tcg_out_insn(s, RIE, LOCGHI, dest, v3, cc); |
| 1226 | } else { |
| 1227 | tcg_out_insn(s, RRF, LOCGR, dest, v3, cc); |
| 1228 | } |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1229 | } else { |
| 1230 | c = tcg_invert_cond(c); |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1231 | cc = tgen_cmp(s, type, c, c1, c2, c2const, false); |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1232 | |
| 1233 | /* Emit: if (cc) goto over; dest = r3; over: */ |
| 1234 | tcg_out_insn(s, RI, BRC, cc, (4 + 4) >> 1); |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1235 | tcg_out_insn(s, RRE, LGR, dest, v3); |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | |
Richard Henderson | ce41106 | 2016-11-16 16:10:37 +0100 | [diff] [blame] | 1239 | static void tgen_clz(TCGContext *s, TCGReg dest, TCGReg a1, |
| 1240 | TCGArg a2, int a2const) |
| 1241 | { |
| 1242 | /* Since this sets both R and R+1, we have no choice but to store the |
| 1243 | result into R0, allowing R1 == TCG_TMP0 to be clobbered as well. */ |
| 1244 | QEMU_BUILD_BUG_ON(TCG_TMP0 != TCG_REG_R1); |
| 1245 | tcg_out_insn(s, RRE, FLOGR, TCG_REG_R0, a1); |
| 1246 | |
| 1247 | if (a2const && a2 == 64) { |
| 1248 | tcg_out_mov(s, TCG_TYPE_I64, dest, TCG_REG_R0); |
| 1249 | } else { |
| 1250 | if (a2const) { |
| 1251 | tcg_out_movi(s, TCG_TYPE_I64, dest, a2); |
| 1252 | } else { |
| 1253 | tcg_out_mov(s, TCG_TYPE_I64, dest, a2); |
| 1254 | } |
| 1255 | if (s390_facilities & FACILITY_LOAD_ON_COND) { |
| 1256 | /* Emit: if (one bit found) dest = r0. */ |
| 1257 | tcg_out_insn(s, RRF, LOCGR, dest, TCG_REG_R0, 2); |
| 1258 | } else { |
| 1259 | /* Emit: if (no one bit found) goto over; dest = r0; over: */ |
| 1260 | tcg_out_insn(s, RI, BRC, 8, (4 + 4) >> 1); |
| 1261 | tcg_out_insn(s, RRE, LGR, dest, TCG_REG_R0); |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 1266 | static void tgen_deposit(TCGContext *s, TCGReg dest, TCGReg src, |
Richard Henderson | 752b1be | 2016-10-17 17:00:46 -0700 | [diff] [blame] | 1267 | int ofs, int len, int z) |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 1268 | { |
| 1269 | int lsb = (63 - ofs); |
| 1270 | int msb = lsb - (len - 1); |
Richard Henderson | 752b1be | 2016-10-17 17:00:46 -0700 | [diff] [blame] | 1271 | tcg_out_risbg(s, dest, src, msb, lsb, ofs, z); |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Richard Henderson | b0bf5fe | 2016-10-14 14:26:40 -0500 | [diff] [blame] | 1274 | static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src, |
| 1275 | int ofs, int len) |
| 1276 | { |
| 1277 | tcg_out_risbg(s, dest, src, 64 - len, 63, 64 - ofs, 1); |
| 1278 | } |
| 1279 | |
Richard Henderson | ffd0e50 | 2020-10-30 15:55:28 -0700 | [diff] [blame] | 1280 | static void tgen_gotoi(TCGContext *s, int cc, const tcg_insn_unit *dest) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1281 | { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1282 | ptrdiff_t off = tcg_pcrel_diff(s, dest) >> 1; |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1283 | if (off == (int16_t)off) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1284 | tcg_out_insn(s, RI, BRC, cc, off); |
| 1285 | } else if (off == (int32_t)off) { |
| 1286 | tcg_out_insn(s, RIL, BRCL, cc, off); |
| 1287 | } else { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1288 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_TMP0, (uintptr_t)dest); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1289 | tcg_out_insn(s, RR, BCR, cc, TCG_TMP0); |
| 1290 | } |
| 1291 | } |
| 1292 | |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1293 | static void tgen_branch(TCGContext *s, int cc, TCGLabel *l) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1294 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1295 | if (l->has_value) { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1296 | tgen_gotoi(s, cc, l->u.value_ptr); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1297 | } else if (USE_LONG_BRANCHES) { |
| 1298 | tcg_out16(s, RIL_BRCL | (cc << 4)); |
Richard Henderson | e692a34 | 2017-07-30 13:58:01 -0700 | [diff] [blame] | 1299 | tcg_out_reloc(s, s->code_ptr, R_390_PC32DBL, l, 2); |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1300 | s->code_ptr += 2; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1301 | } else { |
| 1302 | tcg_out16(s, RI_BRC | (cc << 4)); |
Richard Henderson | e692a34 | 2017-07-30 13:58:01 -0700 | [diff] [blame] | 1303 | tcg_out_reloc(s, s->code_ptr, R_390_PC16DBL, l, 2); |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1304 | s->code_ptr += 1; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | static void tgen_compare_branch(TCGContext *s, S390Opcode opc, int cc, |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1309 | TCGReg r1, TCGReg r2, TCGLabel *l) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1310 | { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1311 | tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1312 | tcg_out16(s, (opc & 0xff00) | (r1 << 4) | r2); |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1313 | tcg_out16(s, 0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1314 | tcg_out16(s, cc << 12 | (opc & 0xff)); |
| 1315 | } |
| 1316 | |
| 1317 | static void tgen_compare_imm_branch(TCGContext *s, S390Opcode opc, int cc, |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1318 | TCGReg r1, int i2, TCGLabel *l) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1319 | { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1320 | tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1321 | tcg_out16(s, (opc & 0xff00) | (r1 << 4) | cc); |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1322 | tcg_out16(s, 0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1323 | tcg_out16(s, (i2 << 8) | (opc & 0xff)); |
| 1324 | } |
| 1325 | |
| 1326 | static void tgen_brcond(TCGContext *s, TCGType type, TCGCond c, |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1327 | TCGReg r1, TCGArg c2, int c2const, TCGLabel *l) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1328 | { |
| 1329 | int cc; |
| 1330 | |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 1331 | if (s390_facilities & FACILITY_GEN_INST_EXT) { |
Richard Henderson | b879f30 | 2013-04-05 14:10:28 -0400 | [diff] [blame] | 1332 | bool is_unsigned = is_unsigned_cond(c); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1333 | bool in_range; |
| 1334 | S390Opcode opc; |
| 1335 | |
| 1336 | cc = tcg_cond_to_s390_cond[c]; |
| 1337 | |
| 1338 | if (!c2const) { |
| 1339 | opc = (type == TCG_TYPE_I32 |
| 1340 | ? (is_unsigned ? RIE_CLRJ : RIE_CRJ) |
| 1341 | : (is_unsigned ? RIE_CLGRJ : RIE_CGRJ)); |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1342 | tgen_compare_branch(s, opc, cc, r1, c2, l); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1343 | return; |
| 1344 | } |
| 1345 | |
| 1346 | /* COMPARE IMMEDIATE AND BRANCH RELATIVE has an 8-bit immediate field. |
| 1347 | If the immediate we've been given does not fit that range, we'll |
| 1348 | fall back to separate compare and branch instructions using the |
| 1349 | larger comparison range afforded by COMPARE IMMEDIATE. */ |
| 1350 | if (type == TCG_TYPE_I32) { |
| 1351 | if (is_unsigned) { |
| 1352 | opc = RIE_CLIJ; |
| 1353 | in_range = (uint32_t)c2 == (uint8_t)c2; |
| 1354 | } else { |
| 1355 | opc = RIE_CIJ; |
| 1356 | in_range = (int32_t)c2 == (int8_t)c2; |
| 1357 | } |
| 1358 | } else { |
| 1359 | if (is_unsigned) { |
| 1360 | opc = RIE_CLGIJ; |
| 1361 | in_range = (uint64_t)c2 == (uint8_t)c2; |
| 1362 | } else { |
| 1363 | opc = RIE_CGIJ; |
| 1364 | in_range = (int64_t)c2 == (int8_t)c2; |
| 1365 | } |
| 1366 | } |
| 1367 | if (in_range) { |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1368 | tgen_compare_imm_branch(s, opc, cc, r1, c2, l); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | } |
| 1372 | |
Richard Henderson | 65839b5 | 2016-12-06 22:00:57 -0500 | [diff] [blame] | 1373 | cc = tgen_cmp(s, type, c, r1, c2, c2const, false); |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1374 | tgen_branch(s, cc, l); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
Richard Henderson | 2be7d76 | 2020-10-28 15:29:04 -0700 | [diff] [blame] | 1377 | static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1378 | { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1379 | ptrdiff_t off = tcg_pcrel_diff(s, dest) >> 1; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1380 | if (off == (int32_t)off) { |
| 1381 | tcg_out_insn(s, RIL, BRASL, TCG_REG_R14, off); |
| 1382 | } else { |
Richard Henderson | 8c081b1 | 2014-04-25 10:18:59 -0400 | [diff] [blame] | 1383 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_TMP0, (uintptr_t)dest); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1384 | tcg_out_insn(s, RR, BASR, TCG_REG_R14, TCG_TMP0); |
| 1385 | } |
| 1386 | } |
| 1387 | |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1388 | static void tcg_out_qemu_ld_direct(TCGContext *s, MemOp opc, TCGReg data, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1389 | TCGReg base, TCGReg index, int disp) |
| 1390 | { |
Aurelien Jarno | 3c8691f | 2015-07-30 22:13:26 +0200 | [diff] [blame] | 1391 | switch (opc & (MO_SSIZE | MO_BSWAP)) { |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1392 | case MO_UB: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1393 | tcg_out_insn(s, RXY, LLGC, data, base, index, disp); |
| 1394 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1395 | case MO_SB: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1396 | tcg_out_insn(s, RXY, LGB, data, base, index, disp); |
| 1397 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1398 | |
| 1399 | case MO_UW | MO_BSWAP: |
| 1400 | /* swapped unsigned halfword load with upper bits zeroed */ |
| 1401 | tcg_out_insn(s, RXY, LRVH, data, base, index, disp); |
| 1402 | tgen_ext16u(s, TCG_TYPE_I64, data, data); |
| 1403 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1404 | case MO_UW: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1405 | tcg_out_insn(s, RXY, LLGH, data, base, index, disp); |
| 1406 | break; |
| 1407 | |
| 1408 | case MO_SW | MO_BSWAP: |
| 1409 | /* swapped sign-extended halfword load */ |
| 1410 | tcg_out_insn(s, RXY, LRVH, data, base, index, disp); |
| 1411 | tgen_ext16s(s, TCG_TYPE_I64, data, data); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1412 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1413 | case MO_SW: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1414 | tcg_out_insn(s, RXY, LGH, data, base, index, disp); |
| 1415 | break; |
| 1416 | |
| 1417 | case MO_UL | MO_BSWAP: |
| 1418 | /* swapped unsigned int load with upper bits zeroed */ |
| 1419 | tcg_out_insn(s, RXY, LRV, data, base, index, disp); |
| 1420 | tgen_ext32u(s, data, data); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1421 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1422 | case MO_UL: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1423 | tcg_out_insn(s, RXY, LLGF, data, base, index, disp); |
| 1424 | break; |
| 1425 | |
| 1426 | case MO_SL | MO_BSWAP: |
| 1427 | /* swapped sign-extended int load */ |
| 1428 | tcg_out_insn(s, RXY, LRV, data, base, index, disp); |
| 1429 | tgen_ext32s(s, data, data); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1430 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1431 | case MO_SL: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1432 | tcg_out_insn(s, RXY, LGF, data, base, index, disp); |
| 1433 | break; |
| 1434 | |
| 1435 | case MO_Q | MO_BSWAP: |
| 1436 | tcg_out_insn(s, RXY, LRVG, data, base, index, disp); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1437 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1438 | case MO_Q: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1439 | tcg_out_insn(s, RXY, LG, data, base, index, disp); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1440 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1441 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1442 | default: |
| 1443 | tcg_abort(); |
| 1444 | } |
| 1445 | } |
| 1446 | |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1447 | static void tcg_out_qemu_st_direct(TCGContext *s, MemOp opc, TCGReg data, |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1448 | TCGReg base, TCGReg index, int disp) |
| 1449 | { |
Aurelien Jarno | 3c8691f | 2015-07-30 22:13:26 +0200 | [diff] [blame] | 1450 | switch (opc & (MO_SIZE | MO_BSWAP)) { |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1451 | case MO_UB: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1452 | if (disp >= 0 && disp < 0x1000) { |
| 1453 | tcg_out_insn(s, RX, STC, data, base, index, disp); |
| 1454 | } else { |
| 1455 | tcg_out_insn(s, RXY, STCY, data, base, index, disp); |
| 1456 | } |
| 1457 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1458 | |
| 1459 | case MO_UW | MO_BSWAP: |
| 1460 | tcg_out_insn(s, RXY, STRVH, data, base, index, disp); |
| 1461 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1462 | case MO_UW: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1463 | if (disp >= 0 && disp < 0x1000) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1464 | tcg_out_insn(s, RX, STH, data, base, index, disp); |
| 1465 | } else { |
| 1466 | tcg_out_insn(s, RXY, STHY, data, base, index, disp); |
| 1467 | } |
| 1468 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1469 | |
| 1470 | case MO_UL | MO_BSWAP: |
| 1471 | tcg_out_insn(s, RXY, STRV, data, base, index, disp); |
| 1472 | break; |
Richard Henderson | a5a04f2 | 2014-03-23 13:15:50 -0700 | [diff] [blame] | 1473 | case MO_UL: |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1474 | if (disp >= 0 && disp < 0x1000) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1475 | tcg_out_insn(s, RX, ST, data, base, index, disp); |
| 1476 | } else { |
| 1477 | tcg_out_insn(s, RXY, STY, data, base, index, disp); |
| 1478 | } |
| 1479 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1480 | |
| 1481 | case MO_Q | MO_BSWAP: |
| 1482 | tcg_out_insn(s, RXY, STRVG, data, base, index, disp); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1483 | break; |
Richard Henderson | b8dd88b | 2014-03-23 13:24:53 -0700 | [diff] [blame] | 1484 | case MO_Q: |
| 1485 | tcg_out_insn(s, RXY, STG, data, base, index, disp); |
| 1486 | break; |
| 1487 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1488 | default: |
| 1489 | tcg_abort(); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | #if defined(CONFIG_SOFTMMU) |
Paolo Bonzini | 139c183 | 2020-02-04 12:41:01 +0100 | [diff] [blame] | 1494 | #include "../tcg-ldst.c.inc" |
Richard Henderson | 659ef5c | 2017-07-30 12:30:41 -0700 | [diff] [blame] | 1495 | |
Richard Henderson | 269bd5d | 2019-03-22 22:03:39 -0700 | [diff] [blame] | 1496 | /* We're expecting to use a 20-bit negative offset on the tlb memory ops. */ |
| 1497 | QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); |
| 1498 | QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 19)); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1499 | |
| 1500 | /* Load and compare a TLB entry, leaving the flags set. Loads the TLB |
| 1501 | addend into R2. Returns a register with the santitized guest address. */ |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1502 | static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, MemOp opc, |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1503 | int mem_index, bool is_ld) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1504 | { |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 1505 | unsigned s_bits = opc & MO_SIZE; |
| 1506 | unsigned a_bits = get_alignment_bits(opc); |
| 1507 | unsigned s_mask = (1 << s_bits) - 1; |
| 1508 | unsigned a_mask = (1 << a_bits) - 1; |
Richard Henderson | 269bd5d | 2019-03-22 22:03:39 -0700 | [diff] [blame] | 1509 | int fast_off = TLB_MASK_TABLE_OFS(mem_index); |
| 1510 | int mask_off = fast_off + offsetof(CPUTLBDescFast, mask); |
| 1511 | int table_off = fast_off + offsetof(CPUTLBDescFast, table); |
Richard Henderson | a5e3981 | 2015-07-23 13:32:35 -0700 | [diff] [blame] | 1512 | int ofs, a_off; |
| 1513 | uint64_t tlb_mask; |
| 1514 | |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1515 | tcg_out_sh64(s, RSY_SRLG, TCG_REG_R2, addr_reg, TCG_REG_NONE, |
| 1516 | TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS); |
| 1517 | tcg_out_insn(s, RXY, NG, TCG_REG_R2, TCG_AREG0, TCG_REG_NONE, mask_off); |
| 1518 | tcg_out_insn(s, RXY, AG, TCG_REG_R2, TCG_AREG0, TCG_REG_NONE, table_off); |
| 1519 | |
Richard Henderson | a5e3981 | 2015-07-23 13:32:35 -0700 | [diff] [blame] | 1520 | /* For aligned accesses, we check the first byte and include the alignment |
| 1521 | bits within the address. For unaligned access, we check that we don't |
| 1522 | cross pages using the address of the last byte of the access. */ |
Richard Henderson | 85aa808 | 2016-07-14 12:43:06 -0700 | [diff] [blame] | 1523 | a_off = (a_bits >= s_bits ? 0 : s_mask - a_mask); |
| 1524 | tlb_mask = (uint64_t)TARGET_PAGE_MASK | a_mask; |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1525 | if ((s390_facilities & FACILITY_GEN_INST_EXT) && a_off == 0) { |
| 1526 | tgen_andi_risbg(s, TCG_REG_R3, addr_reg, tlb_mask); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1527 | } else { |
Richard Henderson | a5e3981 | 2015-07-23 13:32:35 -0700 | [diff] [blame] | 1528 | tcg_out_insn(s, RX, LA, TCG_REG_R3, addr_reg, TCG_REG_NONE, a_off); |
Richard Henderson | 547ec12 | 2014-03-23 19:35:44 -0400 | [diff] [blame] | 1529 | tgen_andi(s, TCG_TYPE_TL, TCG_REG_R3, tlb_mask); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1532 | if (is_ld) { |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1533 | ofs = offsetof(CPUTLBEntry, addr_read); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1534 | } else { |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1535 | ofs = offsetof(CPUTLBEntry, addr_write); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1536 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1537 | if (TARGET_LONG_BITS == 32) { |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1538 | tcg_out_insn(s, RX, C, TCG_REG_R3, TCG_REG_R2, TCG_REG_NONE, ofs); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1539 | } else { |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1540 | tcg_out_insn(s, RXY, CG, TCG_REG_R3, TCG_REG_R2, TCG_REG_NONE, ofs); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Richard Henderson | 4f47e33 | 2018-12-26 15:41:21 +1100 | [diff] [blame] | 1543 | tcg_out_insn(s, RXY, LG, TCG_REG_R2, TCG_REG_R2, TCG_REG_NONE, |
| 1544 | offsetof(CPUTLBEntry, addend)); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1545 | |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1546 | if (TARGET_LONG_BITS == 32) { |
| 1547 | tgen_ext32u(s, TCG_REG_R3, addr_reg); |
| 1548 | return TCG_REG_R3; |
| 1549 | } |
| 1550 | return addr_reg; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1553 | static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi, |
| 1554 | TCGReg data, TCGReg addr, |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1555 | tcg_insn_unit *raddr, tcg_insn_unit *label_ptr) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1556 | { |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1557 | TCGLabelQemuLdst *label = new_ldst_label(s); |
| 1558 | |
| 1559 | label->is_ld = is_ld; |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1560 | label->oi = oi; |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1561 | label->datalo_reg = data; |
| 1562 | label->addrlo_reg = addr; |
Richard Henderson | e5e2e4c | 2020-11-05 15:46:44 -0800 | [diff] [blame] | 1563 | label->raddr = tcg_splitwx_to_rx(raddr); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1564 | label->label_ptr[0] = label_ptr; |
| 1565 | } |
| 1566 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1567 | static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1568 | { |
| 1569 | TCGReg addr_reg = lb->addrlo_reg; |
| 1570 | TCGReg data_reg = lb->datalo_reg; |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1571 | TCGMemOpIdx oi = lb->oi; |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1572 | MemOp opc = get_memop(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1573 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1574 | if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL, |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1575 | (intptr_t)tcg_splitwx_to_rx(s->code_ptr), 2)) { |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1576 | return false; |
| 1577 | } |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1578 | |
| 1579 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); |
| 1580 | if (TARGET_LONG_BITS == 64) { |
| 1581 | tcg_out_mov(s, TCG_TYPE_I64, TCG_REG_R3, addr_reg); |
| 1582 | } |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1583 | tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_R4, oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1584 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R5, (uintptr_t)lb->raddr); |
Richard Henderson | 2b7ec66 | 2015-05-29 09:16:51 -0700 | [diff] [blame] | 1585 | tcg_out_call(s, qemu_ld_helpers[opc & (MO_BSWAP | MO_SSIZE)]); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1586 | tcg_out_mov(s, TCG_TYPE_I64, data_reg, TCG_REG_R2); |
| 1587 | |
| 1588 | tgen_gotoi(s, S390_CC_ALWAYS, lb->raddr); |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1589 | return true; |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1592 | static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1593 | { |
| 1594 | TCGReg addr_reg = lb->addrlo_reg; |
| 1595 | TCGReg data_reg = lb->datalo_reg; |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1596 | TCGMemOpIdx oi = lb->oi; |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1597 | MemOp opc = get_memop(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1598 | |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1599 | if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL, |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1600 | (intptr_t)tcg_splitwx_to_rx(s->code_ptr), 2)) { |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1601 | return false; |
| 1602 | } |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1603 | |
| 1604 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); |
| 1605 | if (TARGET_LONG_BITS == 64) { |
| 1606 | tcg_out_mov(s, TCG_TYPE_I64, TCG_REG_R3, addr_reg); |
| 1607 | } |
| 1608 | switch (opc & MO_SIZE) { |
| 1609 | case MO_UB: |
| 1610 | tgen_ext8u(s, TCG_TYPE_I64, TCG_REG_R4, data_reg); |
| 1611 | break; |
| 1612 | case MO_UW: |
| 1613 | tgen_ext16u(s, TCG_TYPE_I64, TCG_REG_R4, data_reg); |
| 1614 | break; |
| 1615 | case MO_UL: |
| 1616 | tgen_ext32u(s, TCG_REG_R4, data_reg); |
| 1617 | break; |
| 1618 | case MO_Q: |
| 1619 | tcg_out_mov(s, TCG_TYPE_I64, TCG_REG_R4, data_reg); |
| 1620 | break; |
| 1621 | default: |
| 1622 | tcg_abort(); |
| 1623 | } |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1624 | tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_R5, oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1625 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R6, (uintptr_t)lb->raddr); |
Richard Henderson | 2b7ec66 | 2015-05-29 09:16:51 -0700 | [diff] [blame] | 1626 | tcg_out_call(s, qemu_st_helpers[opc & (MO_BSWAP | MO_SIZE)]); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1627 | |
| 1628 | tgen_gotoi(s, S390_CC_ALWAYS, lb->raddr); |
Richard Henderson | aeee05f | 2019-04-21 14:51:00 -0700 | [diff] [blame] | 1629 | return true; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1630 | } |
| 1631 | #else |
| 1632 | static void tcg_prepare_user_ldst(TCGContext *s, TCGReg *addr_reg, |
| 1633 | TCGReg *index_reg, tcg_target_long *disp) |
| 1634 | { |
| 1635 | if (TARGET_LONG_BITS == 32) { |
| 1636 | tgen_ext32u(s, TCG_TMP0, *addr_reg); |
| 1637 | *addr_reg = TCG_TMP0; |
| 1638 | } |
Laurent Vivier | b76f21a | 2015-08-24 14:53:54 +0200 | [diff] [blame] | 1639 | if (guest_base < 0x80000) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1640 | *index_reg = TCG_REG_NONE; |
Laurent Vivier | b76f21a | 2015-08-24 14:53:54 +0200 | [diff] [blame] | 1641 | *disp = guest_base; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1642 | } else { |
| 1643 | *index_reg = TCG_GUEST_BASE_REG; |
| 1644 | *disp = 0; |
| 1645 | } |
| 1646 | } |
| 1647 | #endif /* CONFIG_SOFTMMU */ |
| 1648 | |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 1649 | static void tcg_out_qemu_ld(TCGContext* s, TCGReg data_reg, TCGReg addr_reg, |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 1650 | TCGMemOpIdx oi) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1651 | { |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1652 | MemOp opc = get_memop(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1653 | #ifdef CONFIG_SOFTMMU |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 1654 | unsigned mem_index = get_mmuidx(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1655 | tcg_insn_unit *label_ptr; |
| 1656 | TCGReg base_reg; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1657 | |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1658 | base_reg = tcg_out_tlb_read(s, addr_reg, opc, mem_index, 1); |
| 1659 | |
Aurelien Jarno | cd3b29b | 2015-06-16 07:11:41 +0200 | [diff] [blame] | 1660 | tcg_out16(s, RI_BRC | (S390_CC_NE << 4)); |
| 1661 | label_ptr = s->code_ptr; |
| 1662 | s->code_ptr += 1; |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1663 | |
| 1664 | tcg_out_qemu_ld_direct(s, opc, data_reg, base_reg, TCG_REG_R2, 0); |
| 1665 | |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1666 | add_qemu_ldst_label(s, 1, oi, data_reg, addr_reg, s->code_ptr, label_ptr); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1667 | #else |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 1668 | TCGReg index_reg; |
| 1669 | tcg_target_long disp; |
| 1670 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1671 | tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp); |
| 1672 | tcg_out_qemu_ld_direct(s, opc, data_reg, addr_reg, index_reg, disp); |
| 1673 | #endif |
| 1674 | } |
| 1675 | |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 1676 | static void tcg_out_qemu_st(TCGContext* s, TCGReg data_reg, TCGReg addr_reg, |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 1677 | TCGMemOpIdx oi) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1678 | { |
Tony Nguyen | 14776ab | 2019-08-24 04:10:58 +1000 | [diff] [blame] | 1679 | MemOp opc = get_memop(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1680 | #ifdef CONFIG_SOFTMMU |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 1681 | unsigned mem_index = get_mmuidx(oi); |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1682 | tcg_insn_unit *label_ptr; |
| 1683 | TCGReg base_reg; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1684 | |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1685 | base_reg = tcg_out_tlb_read(s, addr_reg, opc, mem_index, 0); |
| 1686 | |
Aurelien Jarno | cd3b29b | 2015-06-16 07:11:41 +0200 | [diff] [blame] | 1687 | tcg_out16(s, RI_BRC | (S390_CC_NE << 4)); |
| 1688 | label_ptr = s->code_ptr; |
| 1689 | s->code_ptr += 1; |
Richard Henderson | fb59641 | 2014-03-23 14:26:15 -0700 | [diff] [blame] | 1690 | |
| 1691 | tcg_out_qemu_st_direct(s, opc, data_reg, base_reg, TCG_REG_R2, 0); |
| 1692 | |
Richard Henderson | 3972ef6 | 2015-05-13 09:10:33 -0700 | [diff] [blame] | 1693 | add_qemu_ldst_label(s, 0, oi, data_reg, addr_reg, s->code_ptr, label_ptr); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1694 | #else |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 1695 | TCGReg index_reg; |
| 1696 | tcg_target_long disp; |
| 1697 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1698 | tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp); |
| 1699 | tcg_out_qemu_st_direct(s, opc, data_reg, addr_reg, index_reg, disp); |
| 1700 | #endif |
| 1701 | } |
| 1702 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1703 | # define OP_32_64(x) \ |
| 1704 | case glue(glue(INDEX_op_,x),_i32): \ |
| 1705 | case glue(glue(INDEX_op_,x),_i64) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1706 | |
Richard Henderson | a975160 | 2010-03-19 11:12:29 -0700 | [diff] [blame] | 1707 | static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 1708 | const TCGArg *args, const int *const_args) |
| 1709 | { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1710 | S390Opcode op, op2; |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1711 | TCGArg a0, a1, a2; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1712 | |
| 1713 | switch (opc) { |
| 1714 | case INDEX_op_exit_tb: |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 1715 | /* Reuse the zeroing that exists for goto_ptr. */ |
| 1716 | a0 = args[0]; |
| 1717 | if (a0 == 0) { |
Richard Henderson | 8b5c2b6 | 2020-10-28 14:48:55 -0700 | [diff] [blame] | 1718 | tgen_gotoi(s, S390_CC_ALWAYS, tcg_code_gen_epilogue); |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 1719 | } else { |
| 1720 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, a0); |
| 1721 | tgen_gotoi(s, S390_CC_ALWAYS, tb_ret_addr); |
| 1722 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1723 | break; |
| 1724 | |
| 1725 | case INDEX_op_goto_tb: |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1726 | a0 = args[0]; |
Sergey Fedorov | f309101 | 2016-04-10 23:35:45 +0300 | [diff] [blame] | 1727 | if (s->tb_jmp_insn_offset) { |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1728 | /* |
| 1729 | * branch displacement must be aligned for atomic patching; |
Sergey Fedorov | ed3d51e | 2016-04-22 19:08:48 +0300 | [diff] [blame] | 1730 | * see if we need to add extra nop before branch |
| 1731 | */ |
| 1732 | if (!QEMU_PTR_IS_ALIGNED(s->code_ptr + 1, 4)) { |
| 1733 | tcg_out16(s, NOP); |
| 1734 | } |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1735 | tcg_debug_assert(!USE_REG_TB); |
Richard Henderson | a10c64e | 2014-05-14 17:14:51 -0400 | [diff] [blame] | 1736 | tcg_out16(s, RIL_BRCL | (S390_CC_ALWAYS << 4)); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1737 | s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); |
Richard Henderson | a10c64e | 2014-05-14 17:14:51 -0400 | [diff] [blame] | 1738 | s->code_ptr += 2; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1739 | } else { |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1740 | /* load address stored at s->tb_jmp_target_addr + a0 */ |
| 1741 | tcg_out_ld_abs(s, TCG_TYPE_PTR, TCG_REG_TB, |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1742 | tcg_splitwx_to_rx(s->tb_jmp_target_addr + a0)); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1743 | /* and go there */ |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1744 | tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_TB); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1745 | } |
Richard Henderson | 9f75462 | 2018-06-14 19:57:03 -1000 | [diff] [blame] | 1746 | set_jmp_reset_offset(s, a0); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1747 | |
| 1748 | /* For the unlinked path of goto_tb, we need to reset |
| 1749 | TCG_REG_TB to the beginning of this TB. */ |
| 1750 | if (USE_REG_TB) { |
| 1751 | int ofs = -tcg_current_code_size(s); |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 1752 | /* All TB are restricted to 64KiB by unwind info. */ |
| 1753 | tcg_debug_assert(ofs == sextract64(ofs, 0, 20)); |
| 1754 | tcg_out_insn(s, RXY, LAY, TCG_REG_TB, |
| 1755 | TCG_REG_TB, TCG_REG_NONE, ofs); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1756 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1757 | break; |
| 1758 | |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 1759 | case INDEX_op_goto_ptr: |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 1760 | a0 = args[0]; |
| 1761 | if (USE_REG_TB) { |
| 1762 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, a0); |
| 1763 | } |
| 1764 | tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, a0); |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 1765 | break; |
| 1766 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1767 | OP_32_64(ld8u): |
| 1768 | /* ??? LLC (RXY format) is only present with the extended-immediate |
| 1769 | facility, whereas LLGC is always present. */ |
| 1770 | tcg_out_mem(s, 0, RXY_LLGC, args[0], args[1], TCG_REG_NONE, args[2]); |
| 1771 | break; |
| 1772 | |
| 1773 | OP_32_64(ld8s): |
| 1774 | /* ??? LB is no smaller than LGB, so no point to using it. */ |
| 1775 | tcg_out_mem(s, 0, RXY_LGB, args[0], args[1], TCG_REG_NONE, args[2]); |
| 1776 | break; |
| 1777 | |
| 1778 | OP_32_64(ld16u): |
| 1779 | /* ??? LLH (RXY format) is only present with the extended-immediate |
| 1780 | facility, whereas LLGH is always present. */ |
| 1781 | tcg_out_mem(s, 0, RXY_LLGH, args[0], args[1], TCG_REG_NONE, args[2]); |
| 1782 | break; |
| 1783 | |
| 1784 | case INDEX_op_ld16s_i32: |
| 1785 | tcg_out_mem(s, RX_LH, RXY_LHY, args[0], args[1], TCG_REG_NONE, args[2]); |
| 1786 | break; |
| 1787 | |
| 1788 | case INDEX_op_ld_i32: |
| 1789 | tcg_out_ld(s, TCG_TYPE_I32, args[0], args[1], args[2]); |
| 1790 | break; |
| 1791 | |
| 1792 | OP_32_64(st8): |
| 1793 | tcg_out_mem(s, RX_STC, RXY_STCY, args[0], args[1], |
| 1794 | TCG_REG_NONE, args[2]); |
| 1795 | break; |
| 1796 | |
| 1797 | OP_32_64(st16): |
| 1798 | tcg_out_mem(s, RX_STH, RXY_STHY, args[0], args[1], |
| 1799 | TCG_REG_NONE, args[2]); |
| 1800 | break; |
| 1801 | |
| 1802 | case INDEX_op_st_i32: |
| 1803 | tcg_out_st(s, TCG_TYPE_I32, args[0], args[1], args[2]); |
| 1804 | break; |
| 1805 | |
| 1806 | case INDEX_op_add_i32: |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1807 | a0 = args[0], a1 = args[1], a2 = (int32_t)args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1808 | if (const_args[2]) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1809 | do_addi_32: |
| 1810 | if (a0 == a1) { |
| 1811 | if (a2 == (int16_t)a2) { |
| 1812 | tcg_out_insn(s, RI, AHI, a0, a2); |
| 1813 | break; |
| 1814 | } |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 1815 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1816 | tcg_out_insn(s, RIL, AFI, a0, a2); |
| 1817 | break; |
| 1818 | } |
| 1819 | } |
| 1820 | tcg_out_mem(s, RX_LA, RXY_LAY, a0, a1, TCG_REG_NONE, a2); |
| 1821 | } else if (a0 == a1) { |
| 1822 | tcg_out_insn(s, RR, AR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1823 | } else { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1824 | tcg_out_insn(s, RX, LA, a0, a1, a2, 0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1825 | } |
| 1826 | break; |
| 1827 | case INDEX_op_sub_i32: |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1828 | a0 = args[0], a1 = args[1], a2 = (int32_t)args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1829 | if (const_args[2]) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 1830 | a2 = -a2; |
| 1831 | goto do_addi_32; |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1832 | } else if (a0 == a1) { |
| 1833 | tcg_out_insn(s, RR, SR, a0, a2); |
| 1834 | } else { |
| 1835 | tcg_out_insn(s, RRF, SRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1836 | } |
| 1837 | break; |
| 1838 | |
| 1839 | case INDEX_op_and_i32: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1840 | a0 = args[0], a1 = args[1], a2 = (uint32_t)args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1841 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1842 | tcg_out_mov(s, TCG_TYPE_I32, a0, a1); |
| 1843 | tgen_andi(s, TCG_TYPE_I32, a0, a2); |
| 1844 | } else if (a0 == a1) { |
| 1845 | tcg_out_insn(s, RR, NR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1846 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1847 | tcg_out_insn(s, RRF, NRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1848 | } |
| 1849 | break; |
| 1850 | case INDEX_op_or_i32: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1851 | a0 = args[0], a1 = args[1], a2 = (uint32_t)args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1852 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1853 | tcg_out_mov(s, TCG_TYPE_I32, a0, a1); |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 1854 | tgen_ori(s, TCG_TYPE_I32, a0, a2); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1855 | } else if (a0 == a1) { |
| 1856 | tcg_out_insn(s, RR, OR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1857 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1858 | tcg_out_insn(s, RRF, ORK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1859 | } |
| 1860 | break; |
| 1861 | case INDEX_op_xor_i32: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1862 | a0 = args[0], a1 = args[1], a2 = (uint32_t)args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1863 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1864 | tcg_out_mov(s, TCG_TYPE_I32, a0, a1); |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 1865 | tgen_xori(s, TCG_TYPE_I32, a0, a2); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1866 | } else if (a0 == a1) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1867 | tcg_out_insn(s, RR, XR, args[0], args[2]); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1868 | } else { |
| 1869 | tcg_out_insn(s, RRF, XRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1870 | } |
| 1871 | break; |
| 1872 | |
| 1873 | case INDEX_op_neg_i32: |
| 1874 | tcg_out_insn(s, RR, LCR, args[0], args[1]); |
| 1875 | break; |
| 1876 | |
| 1877 | case INDEX_op_mul_i32: |
| 1878 | if (const_args[2]) { |
| 1879 | if ((int32_t)args[2] == (int16_t)args[2]) { |
| 1880 | tcg_out_insn(s, RI, MHI, args[0], args[2]); |
| 1881 | } else { |
| 1882 | tcg_out_insn(s, RIL, MSFI, args[0], args[2]); |
| 1883 | } |
| 1884 | } else { |
| 1885 | tcg_out_insn(s, RRE, MSR, args[0], args[2]); |
| 1886 | } |
| 1887 | break; |
| 1888 | |
| 1889 | case INDEX_op_div2_i32: |
| 1890 | tcg_out_insn(s, RR, DR, TCG_REG_R2, args[4]); |
| 1891 | break; |
| 1892 | case INDEX_op_divu2_i32: |
| 1893 | tcg_out_insn(s, RRE, DLR, TCG_REG_R2, args[4]); |
| 1894 | break; |
| 1895 | |
| 1896 | case INDEX_op_shl_i32: |
| 1897 | op = RS_SLL; |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1898 | op2 = RSY_SLLK; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1899 | do_shift32: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1900 | a0 = args[0], a1 = args[1], a2 = (int32_t)args[2]; |
| 1901 | if (a0 == a1) { |
| 1902 | if (const_args[2]) { |
| 1903 | tcg_out_sh32(s, op, a0, TCG_REG_NONE, a2); |
| 1904 | } else { |
| 1905 | tcg_out_sh32(s, op, a0, a2, 0); |
| 1906 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1907 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1908 | /* Using tcg_out_sh64 here for the format; it is a 32-bit shift. */ |
| 1909 | if (const_args[2]) { |
| 1910 | tcg_out_sh64(s, op2, a0, a1, TCG_REG_NONE, a2); |
| 1911 | } else { |
| 1912 | tcg_out_sh64(s, op2, a0, a1, a2, 0); |
| 1913 | } |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1914 | } |
| 1915 | break; |
| 1916 | case INDEX_op_shr_i32: |
| 1917 | op = RS_SRL; |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1918 | op2 = RSY_SRLK; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1919 | goto do_shift32; |
| 1920 | case INDEX_op_sar_i32: |
| 1921 | op = RS_SRA; |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 1922 | op2 = RSY_SRAK; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1923 | goto do_shift32; |
| 1924 | |
| 1925 | case INDEX_op_rotl_i32: |
| 1926 | /* ??? Using tcg_out_sh64 here for the format; it is a 32-bit rol. */ |
| 1927 | if (const_args[2]) { |
| 1928 | tcg_out_sh64(s, RSY_RLL, args[0], args[1], TCG_REG_NONE, args[2]); |
| 1929 | } else { |
| 1930 | tcg_out_sh64(s, RSY_RLL, args[0], args[1], args[2], 0); |
| 1931 | } |
| 1932 | break; |
| 1933 | case INDEX_op_rotr_i32: |
| 1934 | if (const_args[2]) { |
| 1935 | tcg_out_sh64(s, RSY_RLL, args[0], args[1], |
| 1936 | TCG_REG_NONE, (32 - args[2]) & 31); |
| 1937 | } else { |
| 1938 | tcg_out_insn(s, RR, LCR, TCG_TMP0, args[2]); |
| 1939 | tcg_out_sh64(s, RSY_RLL, args[0], args[1], TCG_TMP0, 0); |
| 1940 | } |
| 1941 | break; |
| 1942 | |
| 1943 | case INDEX_op_ext8s_i32: |
| 1944 | tgen_ext8s(s, TCG_TYPE_I32, args[0], args[1]); |
| 1945 | break; |
| 1946 | case INDEX_op_ext16s_i32: |
| 1947 | tgen_ext16s(s, TCG_TYPE_I32, args[0], args[1]); |
| 1948 | break; |
| 1949 | case INDEX_op_ext8u_i32: |
| 1950 | tgen_ext8u(s, TCG_TYPE_I32, args[0], args[1]); |
| 1951 | break; |
| 1952 | case INDEX_op_ext16u_i32: |
| 1953 | tgen_ext16u(s, TCG_TYPE_I32, args[0], args[1]); |
| 1954 | break; |
| 1955 | |
| 1956 | OP_32_64(bswap16): |
| 1957 | /* The TCG bswap definition requires bits 0-47 already be zero. |
| 1958 | Thus we don't need the G-type insns to implement bswap16_i64. */ |
| 1959 | tcg_out_insn(s, RRE, LRVR, args[0], args[1]); |
| 1960 | tcg_out_sh32(s, RS_SRL, args[0], TCG_REG_NONE, 16); |
| 1961 | break; |
| 1962 | OP_32_64(bswap32): |
| 1963 | tcg_out_insn(s, RRE, LRVR, args[0], args[1]); |
| 1964 | break; |
| 1965 | |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 1966 | case INDEX_op_add2_i32: |
Richard Henderson | ad19b35 | 2014-03-31 03:16:37 -0400 | [diff] [blame] | 1967 | if (const_args[4]) { |
| 1968 | tcg_out_insn(s, RIL, ALFI, args[0], args[4]); |
| 1969 | } else { |
| 1970 | tcg_out_insn(s, RR, ALR, args[0], args[4]); |
| 1971 | } |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 1972 | tcg_out_insn(s, RRE, ALCR, args[1], args[5]); |
| 1973 | break; |
| 1974 | case INDEX_op_sub2_i32: |
Richard Henderson | ad19b35 | 2014-03-31 03:16:37 -0400 | [diff] [blame] | 1975 | if (const_args[4]) { |
| 1976 | tcg_out_insn(s, RIL, SLFI, args[0], args[4]); |
| 1977 | } else { |
| 1978 | tcg_out_insn(s, RR, SLR, args[0], args[4]); |
| 1979 | } |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 1980 | tcg_out_insn(s, RRE, SLBR, args[1], args[5]); |
| 1981 | break; |
| 1982 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1983 | case INDEX_op_br: |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1984 | tgen_branch(s, S390_CC_ALWAYS, arg_label(args[0])); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1985 | break; |
| 1986 | |
| 1987 | case INDEX_op_brcond_i32: |
| 1988 | tgen_brcond(s, TCG_TYPE_I32, args[2], args[0], |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 1989 | args[1], const_args[1], arg_label(args[3])); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1990 | break; |
| 1991 | case INDEX_op_setcond_i32: |
| 1992 | tgen_setcond(s, TCG_TYPE_I32, args[3], args[0], args[1], |
| 1993 | args[2], const_args[2]); |
| 1994 | break; |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1995 | case INDEX_op_movcond_i32: |
| 1996 | tgen_movcond(s, TCG_TYPE_I32, args[5], args[0], args[1], |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 1997 | args[2], const_args[2], args[3], const_args[3]); |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 1998 | break; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 1999 | |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 2000 | case INDEX_op_qemu_ld_i32: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2001 | /* ??? Technically we can use a non-extending instruction. */ |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 2002 | case INDEX_op_qemu_ld_i64: |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 2003 | tcg_out_qemu_ld(s, args[0], args[1], args[2]); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2004 | break; |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 2005 | case INDEX_op_qemu_st_i32: |
| 2006 | case INDEX_op_qemu_st_i64: |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 2007 | tcg_out_qemu_st(s, args[0], args[1], args[2]); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2008 | break; |
| 2009 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2010 | case INDEX_op_ld16s_i64: |
| 2011 | tcg_out_mem(s, 0, RXY_LGH, args[0], args[1], TCG_REG_NONE, args[2]); |
| 2012 | break; |
| 2013 | case INDEX_op_ld32u_i64: |
| 2014 | tcg_out_mem(s, 0, RXY_LLGF, args[0], args[1], TCG_REG_NONE, args[2]); |
| 2015 | break; |
| 2016 | case INDEX_op_ld32s_i64: |
| 2017 | tcg_out_mem(s, 0, RXY_LGF, args[0], args[1], TCG_REG_NONE, args[2]); |
| 2018 | break; |
| 2019 | case INDEX_op_ld_i64: |
| 2020 | tcg_out_ld(s, TCG_TYPE_I64, args[0], args[1], args[2]); |
| 2021 | break; |
| 2022 | |
| 2023 | case INDEX_op_st32_i64: |
| 2024 | tcg_out_st(s, TCG_TYPE_I32, args[0], args[1], args[2]); |
| 2025 | break; |
| 2026 | case INDEX_op_st_i64: |
| 2027 | tcg_out_st(s, TCG_TYPE_I64, args[0], args[1], args[2]); |
| 2028 | break; |
| 2029 | |
| 2030 | case INDEX_op_add_i64: |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2031 | a0 = args[0], a1 = args[1], a2 = args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2032 | if (const_args[2]) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2033 | do_addi_64: |
| 2034 | if (a0 == a1) { |
| 2035 | if (a2 == (int16_t)a2) { |
| 2036 | tcg_out_insn(s, RI, AGHI, a0, a2); |
| 2037 | break; |
| 2038 | } |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 2039 | if (s390_facilities & FACILITY_EXT_IMM) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2040 | if (a2 == (int32_t)a2) { |
| 2041 | tcg_out_insn(s, RIL, AGFI, a0, a2); |
| 2042 | break; |
| 2043 | } else if (a2 == (uint32_t)a2) { |
| 2044 | tcg_out_insn(s, RIL, ALGFI, a0, a2); |
| 2045 | break; |
| 2046 | } else if (-a2 == (uint32_t)-a2) { |
| 2047 | tcg_out_insn(s, RIL, SLGFI, a0, -a2); |
| 2048 | break; |
| 2049 | } |
| 2050 | } |
| 2051 | } |
| 2052 | tcg_out_mem(s, RX_LA, RXY_LAY, a0, a1, TCG_REG_NONE, a2); |
| 2053 | } else if (a0 == a1) { |
| 2054 | tcg_out_insn(s, RRE, AGR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2055 | } else { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2056 | tcg_out_insn(s, RX, LA, a0, a1, a2, 0); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2057 | } |
| 2058 | break; |
| 2059 | case INDEX_op_sub_i64: |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2060 | a0 = args[0], a1 = args[1], a2 = args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2061 | if (const_args[2]) { |
Richard Henderson | 0db921e | 2013-03-27 14:23:26 -0400 | [diff] [blame] | 2062 | a2 = -a2; |
| 2063 | goto do_addi_64; |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2064 | } else if (a0 == a1) { |
| 2065 | tcg_out_insn(s, RRE, SGR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2066 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2067 | tcg_out_insn(s, RRF, SGRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2068 | } |
| 2069 | break; |
| 2070 | |
| 2071 | case INDEX_op_and_i64: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2072 | a0 = args[0], a1 = args[1], a2 = args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2073 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2074 | tcg_out_mov(s, TCG_TYPE_I64, a0, a1); |
Richard Henderson | 07ff798 | 2013-03-27 11:47:54 -0400 | [diff] [blame] | 2075 | tgen_andi(s, TCG_TYPE_I64, args[0], args[2]); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2076 | } else if (a0 == a1) { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2077 | tcg_out_insn(s, RRE, NGR, args[0], args[2]); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2078 | } else { |
| 2079 | tcg_out_insn(s, RRF, NGRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2080 | } |
| 2081 | break; |
| 2082 | case INDEX_op_or_i64: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2083 | a0 = args[0], a1 = args[1], a2 = args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2084 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2085 | tcg_out_mov(s, TCG_TYPE_I64, a0, a1); |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 2086 | tgen_ori(s, TCG_TYPE_I64, a0, a2); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2087 | } else if (a0 == a1) { |
| 2088 | tcg_out_insn(s, RRE, OGR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2089 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2090 | tcg_out_insn(s, RRF, OGRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2091 | } |
| 2092 | break; |
| 2093 | case INDEX_op_xor_i64: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2094 | a0 = args[0], a1 = args[1], a2 = args[2]; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2095 | if (const_args[2]) { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2096 | tcg_out_mov(s, TCG_TYPE_I64, a0, a1); |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 2097 | tgen_xori(s, TCG_TYPE_I64, a0, a2); |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2098 | } else if (a0 == a1) { |
| 2099 | tcg_out_insn(s, RRE, XGR, a0, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2100 | } else { |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2101 | tcg_out_insn(s, RRF, XGRK, a0, a1, a2); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2102 | } |
| 2103 | break; |
| 2104 | |
| 2105 | case INDEX_op_neg_i64: |
| 2106 | tcg_out_insn(s, RRE, LCGR, args[0], args[1]); |
| 2107 | break; |
| 2108 | case INDEX_op_bswap64_i64: |
| 2109 | tcg_out_insn(s, RRE, LRVGR, args[0], args[1]); |
| 2110 | break; |
| 2111 | |
| 2112 | case INDEX_op_mul_i64: |
| 2113 | if (const_args[2]) { |
| 2114 | if (args[2] == (int16_t)args[2]) { |
| 2115 | tcg_out_insn(s, RI, MGHI, args[0], args[2]); |
| 2116 | } else { |
| 2117 | tcg_out_insn(s, RIL, MSGFI, args[0], args[2]); |
| 2118 | } |
| 2119 | } else { |
| 2120 | tcg_out_insn(s, RRE, MSGR, args[0], args[2]); |
| 2121 | } |
| 2122 | break; |
| 2123 | |
| 2124 | case INDEX_op_div2_i64: |
| 2125 | /* ??? We get an unnecessary sign-extension of the dividend |
| 2126 | into R3 with this definition, but as we do in fact always |
| 2127 | produce both quotient and remainder using INDEX_op_div_i64 |
| 2128 | instead requires jumping through even more hoops. */ |
| 2129 | tcg_out_insn(s, RRE, DSGR, TCG_REG_R2, args[4]); |
| 2130 | break; |
| 2131 | case INDEX_op_divu2_i64: |
| 2132 | tcg_out_insn(s, RRE, DLGR, TCG_REG_R2, args[4]); |
| 2133 | break; |
Richard Henderson | 36017dc | 2013-03-26 16:50:29 -0400 | [diff] [blame] | 2134 | case INDEX_op_mulu2_i64: |
| 2135 | tcg_out_insn(s, RRE, MLGR, TCG_REG_R2, args[3]); |
| 2136 | break; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2137 | |
| 2138 | case INDEX_op_shl_i64: |
| 2139 | op = RSY_SLLG; |
| 2140 | do_shift64: |
| 2141 | if (const_args[2]) { |
| 2142 | tcg_out_sh64(s, op, args[0], args[1], TCG_REG_NONE, args[2]); |
| 2143 | } else { |
| 2144 | tcg_out_sh64(s, op, args[0], args[1], args[2], 0); |
| 2145 | } |
| 2146 | break; |
| 2147 | case INDEX_op_shr_i64: |
| 2148 | op = RSY_SRLG; |
| 2149 | goto do_shift64; |
| 2150 | case INDEX_op_sar_i64: |
| 2151 | op = RSY_SRAG; |
| 2152 | goto do_shift64; |
| 2153 | |
| 2154 | case INDEX_op_rotl_i64: |
| 2155 | if (const_args[2]) { |
| 2156 | tcg_out_sh64(s, RSY_RLLG, args[0], args[1], |
| 2157 | TCG_REG_NONE, args[2]); |
| 2158 | } else { |
| 2159 | tcg_out_sh64(s, RSY_RLLG, args[0], args[1], args[2], 0); |
| 2160 | } |
| 2161 | break; |
| 2162 | case INDEX_op_rotr_i64: |
| 2163 | if (const_args[2]) { |
| 2164 | tcg_out_sh64(s, RSY_RLLG, args[0], args[1], |
| 2165 | TCG_REG_NONE, (64 - args[2]) & 63); |
| 2166 | } else { |
| 2167 | /* We can use the smaller 32-bit negate because only the |
| 2168 | low 6 bits are examined for the rotate. */ |
| 2169 | tcg_out_insn(s, RR, LCR, TCG_TMP0, args[2]); |
| 2170 | tcg_out_sh64(s, RSY_RLLG, args[0], args[1], TCG_TMP0, 0); |
| 2171 | } |
| 2172 | break; |
| 2173 | |
| 2174 | case INDEX_op_ext8s_i64: |
| 2175 | tgen_ext8s(s, TCG_TYPE_I64, args[0], args[1]); |
| 2176 | break; |
| 2177 | case INDEX_op_ext16s_i64: |
| 2178 | tgen_ext16s(s, TCG_TYPE_I64, args[0], args[1]); |
| 2179 | break; |
Aurelien Jarno | 4f2331e | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 2180 | case INDEX_op_ext_i32_i64: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2181 | case INDEX_op_ext32s_i64: |
| 2182 | tgen_ext32s(s, args[0], args[1]); |
| 2183 | break; |
| 2184 | case INDEX_op_ext8u_i64: |
| 2185 | tgen_ext8u(s, TCG_TYPE_I64, args[0], args[1]); |
| 2186 | break; |
| 2187 | case INDEX_op_ext16u_i64: |
| 2188 | tgen_ext16u(s, TCG_TYPE_I64, args[0], args[1]); |
| 2189 | break; |
Aurelien Jarno | 4f2331e | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 2190 | case INDEX_op_extu_i32_i64: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2191 | case INDEX_op_ext32u_i64: |
| 2192 | tgen_ext32u(s, args[0], args[1]); |
| 2193 | break; |
| 2194 | |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 2195 | case INDEX_op_add2_i64: |
Richard Henderson | ad19b35 | 2014-03-31 03:16:37 -0400 | [diff] [blame] | 2196 | if (const_args[4]) { |
| 2197 | if ((int64_t)args[4] >= 0) { |
| 2198 | tcg_out_insn(s, RIL, ALGFI, args[0], args[4]); |
| 2199 | } else { |
| 2200 | tcg_out_insn(s, RIL, SLGFI, args[0], -args[4]); |
| 2201 | } |
| 2202 | } else { |
| 2203 | tcg_out_insn(s, RRE, ALGR, args[0], args[4]); |
| 2204 | } |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 2205 | tcg_out_insn(s, RRE, ALCGR, args[1], args[5]); |
| 2206 | break; |
| 2207 | case INDEX_op_sub2_i64: |
Richard Henderson | ad19b35 | 2014-03-31 03:16:37 -0400 | [diff] [blame] | 2208 | if (const_args[4]) { |
| 2209 | if ((int64_t)args[4] >= 0) { |
| 2210 | tcg_out_insn(s, RIL, SLGFI, args[0], args[4]); |
| 2211 | } else { |
| 2212 | tcg_out_insn(s, RIL, ALGFI, args[0], -args[4]); |
| 2213 | } |
| 2214 | } else { |
| 2215 | tcg_out_insn(s, RRE, SLGR, args[0], args[4]); |
| 2216 | } |
Richard Henderson | 3790b91 | 2013-03-26 16:41:45 -0400 | [diff] [blame] | 2217 | tcg_out_insn(s, RRE, SLBGR, args[1], args[5]); |
| 2218 | break; |
| 2219 | |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2220 | case INDEX_op_brcond_i64: |
| 2221 | tgen_brcond(s, TCG_TYPE_I64, args[2], args[0], |
Richard Henderson | bec1631 | 2015-02-13 13:39:54 -0800 | [diff] [blame] | 2222 | args[1], const_args[1], arg_label(args[3])); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2223 | break; |
| 2224 | case INDEX_op_setcond_i64: |
| 2225 | tgen_setcond(s, TCG_TYPE_I64, args[3], args[0], args[1], |
| 2226 | args[2], const_args[2]); |
| 2227 | break; |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 2228 | case INDEX_op_movcond_i64: |
| 2229 | tgen_movcond(s, TCG_TYPE_I64, args[5], args[0], args[1], |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 2230 | args[2], const_args[2], args[3], const_args[3]); |
Richard Henderson | 96a9f09 | 2013-03-26 17:28:52 -0400 | [diff] [blame] | 2231 | break; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2232 | |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 2233 | OP_32_64(deposit): |
Richard Henderson | 752b1be | 2016-10-17 17:00:46 -0700 | [diff] [blame] | 2234 | a0 = args[0], a1 = args[1], a2 = args[2]; |
| 2235 | if (const_args[1]) { |
| 2236 | tgen_deposit(s, a0, a2, args[3], args[4], 1); |
| 2237 | } else { |
| 2238 | /* Since we can't support "0Z" as a constraint, we allow a1 in |
| 2239 | any register. Fix things up as if a matching constraint. */ |
| 2240 | if (a0 != a1) { |
| 2241 | TCGType type = (opc == INDEX_op_deposit_i64); |
| 2242 | if (a0 == a2) { |
| 2243 | tcg_out_mov(s, type, TCG_TMP0, a2); |
| 2244 | a2 = TCG_TMP0; |
| 2245 | } |
| 2246 | tcg_out_mov(s, type, a0, a1); |
| 2247 | } |
| 2248 | tgen_deposit(s, a0, a2, args[3], args[4], 0); |
| 2249 | } |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 2250 | break; |
Richard Henderson | 752b1be | 2016-10-17 17:00:46 -0700 | [diff] [blame] | 2251 | |
Richard Henderson | b0bf5fe | 2016-10-14 14:26:40 -0500 | [diff] [blame] | 2252 | OP_32_64(extract): |
| 2253 | tgen_extract(s, args[0], args[1], args[2], args[3]); |
| 2254 | break; |
Richard Henderson | d5690ea | 2013-03-27 09:30:58 -0400 | [diff] [blame] | 2255 | |
Richard Henderson | ce41106 | 2016-11-16 16:10:37 +0100 | [diff] [blame] | 2256 | case INDEX_op_clz_i64: |
| 2257 | tgen_clz(s, args[0], args[1], args[2], const_args[2]); |
| 2258 | break; |
| 2259 | |
Pranith Kumar | c9314d6 | 2016-07-14 16:20:20 -0400 | [diff] [blame] | 2260 | case INDEX_op_mb: |
| 2261 | /* The host memory model is quite strong, we simply need to |
| 2262 | serialize the instruction stream. */ |
| 2263 | if (args[0] & TCG_MO_ST_LD) { |
| 2264 | tcg_out_insn(s, RR, BCR, |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 2265 | s390_facilities & FACILITY_FAST_BCR_SER ? 14 : 15, 0); |
Pranith Kumar | c9314d6 | 2016-07-14 16:20:20 -0400 | [diff] [blame] | 2266 | } |
| 2267 | break; |
| 2268 | |
Richard Henderson | 96d0ee7 | 2014-04-25 15:19:33 -0400 | [diff] [blame] | 2269 | case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */ |
| 2270 | case INDEX_op_mov_i64: |
Richard Henderson | 96d0ee7 | 2014-04-25 15:19:33 -0400 | [diff] [blame] | 2271 | case INDEX_op_call: /* Always emitted via tcg_out_call. */ |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2272 | default: |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2273 | tcg_abort(); |
| 2274 | } |
| 2275 | } |
| 2276 | |
Richard Henderson | f69d277 | 2016-11-18 09:31:40 +0100 | [diff] [blame] | 2277 | static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) |
| 2278 | { |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2279 | static const TCGTargetOpDef r = { .args_ct_str = { "r" } }; |
| 2280 | static const TCGTargetOpDef r_r = { .args_ct_str = { "r", "r" } }; |
| 2281 | static const TCGTargetOpDef r_L = { .args_ct_str = { "r", "L" } }; |
| 2282 | static const TCGTargetOpDef L_L = { .args_ct_str = { "L", "L" } }; |
Richard Henderson | 07952d9 | 2017-06-16 14:45:59 -0700 | [diff] [blame] | 2283 | static const TCGTargetOpDef r_ri = { .args_ct_str = { "r", "ri" } }; |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2284 | static const TCGTargetOpDef r_r_ri = { .args_ct_str = { "r", "r", "ri" } }; |
| 2285 | static const TCGTargetOpDef r_0_ri = { .args_ct_str = { "r", "0", "ri" } }; |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 2286 | static const TCGTargetOpDef r_0_rI = { .args_ct_str = { "r", "0", "rI" } }; |
| 2287 | static const TCGTargetOpDef r_0_rJ = { .args_ct_str = { "r", "0", "rJ" } }; |
Richard Henderson | ba18b07 | 2017-06-16 14:59:55 -0700 | [diff] [blame] | 2288 | static const TCGTargetOpDef a2_r |
| 2289 | = { .args_ct_str = { "r", "r", "0", "1", "r", "r" } }; |
| 2290 | static const TCGTargetOpDef a2_ri |
| 2291 | = { .args_ct_str = { "r", "r", "0", "1", "ri", "r" } }; |
| 2292 | static const TCGTargetOpDef a2_rA |
| 2293 | = { .args_ct_str = { "r", "r", "0", "1", "rA", "r" } }; |
Richard Henderson | f69d277 | 2016-11-18 09:31:40 +0100 | [diff] [blame] | 2294 | |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2295 | switch (op) { |
| 2296 | case INDEX_op_goto_ptr: |
| 2297 | return &r; |
| 2298 | |
| 2299 | case INDEX_op_ld8u_i32: |
| 2300 | case INDEX_op_ld8u_i64: |
| 2301 | case INDEX_op_ld8s_i32: |
| 2302 | case INDEX_op_ld8s_i64: |
| 2303 | case INDEX_op_ld16u_i32: |
| 2304 | case INDEX_op_ld16u_i64: |
| 2305 | case INDEX_op_ld16s_i32: |
| 2306 | case INDEX_op_ld16s_i64: |
| 2307 | case INDEX_op_ld_i32: |
| 2308 | case INDEX_op_ld32u_i64: |
| 2309 | case INDEX_op_ld32s_i64: |
| 2310 | case INDEX_op_ld_i64: |
| 2311 | case INDEX_op_st8_i32: |
| 2312 | case INDEX_op_st8_i64: |
| 2313 | case INDEX_op_st16_i32: |
| 2314 | case INDEX_op_st16_i64: |
| 2315 | case INDEX_op_st_i32: |
| 2316 | case INDEX_op_st32_i64: |
| 2317 | case INDEX_op_st_i64: |
| 2318 | return &r_r; |
| 2319 | |
| 2320 | case INDEX_op_add_i32: |
| 2321 | case INDEX_op_add_i64: |
| 2322 | return &r_r_ri; |
| 2323 | case INDEX_op_sub_i32: |
| 2324 | case INDEX_op_sub_i64: |
Richard Henderson | bdcd5d1 | 2017-07-25 18:59:13 -0400 | [diff] [blame] | 2325 | case INDEX_op_and_i32: |
| 2326 | case INDEX_op_and_i64: |
Richard Henderson | 4046d9c | 2017-07-25 19:21:36 -0400 | [diff] [blame] | 2327 | case INDEX_op_or_i32: |
| 2328 | case INDEX_op_or_i64: |
Richard Henderson | 5bf67a9 | 2017-07-25 19:42:51 -0400 | [diff] [blame] | 2329 | case INDEX_op_xor_i32: |
| 2330 | case INDEX_op_xor_i64: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2331 | return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 2332 | |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2333 | case INDEX_op_mul_i32: |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 2334 | /* If we have the general-instruction-extensions, then we have |
| 2335 | MULTIPLY SINGLE IMMEDIATE with a signed 32-bit, otherwise we |
| 2336 | have only MULTIPLY HALFWORD IMMEDIATE, with a signed 16-bit. */ |
| 2337 | return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_ri : &r_0_rI); |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2338 | case INDEX_op_mul_i64: |
Richard Henderson | a8f0269 | 2017-06-16 14:52:32 -0700 | [diff] [blame] | 2339 | return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_rJ : &r_0_rI); |
| 2340 | |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2341 | case INDEX_op_shl_i32: |
| 2342 | case INDEX_op_shr_i32: |
| 2343 | case INDEX_op_sar_i32: |
Richard Henderson | c209713 | 2017-06-16 13:43:17 -0700 | [diff] [blame] | 2344 | return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2345 | |
| 2346 | case INDEX_op_shl_i64: |
| 2347 | case INDEX_op_shr_i64: |
| 2348 | case INDEX_op_sar_i64: |
| 2349 | return &r_r_ri; |
| 2350 | |
| 2351 | case INDEX_op_rotl_i32: |
| 2352 | case INDEX_op_rotl_i64: |
| 2353 | case INDEX_op_rotr_i32: |
| 2354 | case INDEX_op_rotr_i64: |
| 2355 | return &r_r_ri; |
| 2356 | |
| 2357 | case INDEX_op_brcond_i32: |
| 2358 | case INDEX_op_brcond_i64: |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 2359 | return &r_ri; |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2360 | |
| 2361 | case INDEX_op_bswap16_i32: |
| 2362 | case INDEX_op_bswap16_i64: |
| 2363 | case INDEX_op_bswap32_i32: |
| 2364 | case INDEX_op_bswap32_i64: |
| 2365 | case INDEX_op_bswap64_i64: |
| 2366 | case INDEX_op_neg_i32: |
| 2367 | case INDEX_op_neg_i64: |
| 2368 | case INDEX_op_ext8s_i32: |
| 2369 | case INDEX_op_ext8s_i64: |
| 2370 | case INDEX_op_ext8u_i32: |
| 2371 | case INDEX_op_ext8u_i64: |
| 2372 | case INDEX_op_ext16s_i32: |
| 2373 | case INDEX_op_ext16s_i64: |
| 2374 | case INDEX_op_ext16u_i32: |
| 2375 | case INDEX_op_ext16u_i64: |
| 2376 | case INDEX_op_ext32s_i64: |
| 2377 | case INDEX_op_ext32u_i64: |
| 2378 | case INDEX_op_ext_i32_i64: |
| 2379 | case INDEX_op_extu_i32_i64: |
| 2380 | case INDEX_op_extract_i32: |
| 2381 | case INDEX_op_extract_i64: |
| 2382 | return &r_r; |
| 2383 | |
| 2384 | case INDEX_op_clz_i64: |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 2385 | case INDEX_op_setcond_i32: |
| 2386 | case INDEX_op_setcond_i64: |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2387 | return &r_r_ri; |
| 2388 | |
| 2389 | case INDEX_op_qemu_ld_i32: |
| 2390 | case INDEX_op_qemu_ld_i64: |
| 2391 | return &r_L; |
| 2392 | case INDEX_op_qemu_st_i64: |
| 2393 | case INDEX_op_qemu_st_i32: |
| 2394 | return &L_L; |
| 2395 | |
| 2396 | case INDEX_op_deposit_i32: |
| 2397 | case INDEX_op_deposit_i64: |
| 2398 | { |
| 2399 | static const TCGTargetOpDef dep |
| 2400 | = { .args_ct_str = { "r", "rZ", "r" } }; |
| 2401 | return &dep; |
Richard Henderson | f69d277 | 2016-11-18 09:31:40 +0100 | [diff] [blame] | 2402 | } |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2403 | case INDEX_op_movcond_i32: |
| 2404 | case INDEX_op_movcond_i64: |
| 2405 | { |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 2406 | static const TCGTargetOpDef movc |
| 2407 | = { .args_ct_str = { "r", "r", "ri", "r", "0" } }; |
Richard Henderson | 7af525a | 2017-06-16 15:33:28 -0700 | [diff] [blame] | 2408 | static const TCGTargetOpDef movc_l |
Richard Henderson | a534bb1 | 2017-07-25 20:10:29 -0400 | [diff] [blame] | 2409 | = { .args_ct_str = { "r", "r", "ri", "rI", "0" } }; |
| 2410 | return (s390_facilities & FACILITY_LOAD_ON_COND2 ? &movc_l : &movc); |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2411 | } |
| 2412 | case INDEX_op_div2_i32: |
| 2413 | case INDEX_op_div2_i64: |
| 2414 | case INDEX_op_divu2_i32: |
| 2415 | case INDEX_op_divu2_i64: |
| 2416 | { |
| 2417 | static const TCGTargetOpDef div2 |
| 2418 | = { .args_ct_str = { "b", "a", "0", "1", "r" } }; |
| 2419 | return &div2; |
| 2420 | } |
| 2421 | case INDEX_op_mulu2_i64: |
| 2422 | { |
| 2423 | static const TCGTargetOpDef mul2 |
| 2424 | = { .args_ct_str = { "b", "a", "0", "r" } }; |
| 2425 | return &mul2; |
| 2426 | } |
Richard Henderson | ba18b07 | 2017-06-16 14:59:55 -0700 | [diff] [blame] | 2427 | |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2428 | case INDEX_op_add2_i32: |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2429 | case INDEX_op_sub2_i32: |
Richard Henderson | ba18b07 | 2017-06-16 14:59:55 -0700 | [diff] [blame] | 2430 | return (s390_facilities & FACILITY_EXT_IMM ? &a2_ri : &a2_r); |
| 2431 | case INDEX_op_add2_i64: |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2432 | case INDEX_op_sub2_i64: |
Richard Henderson | ba18b07 | 2017-06-16 14:59:55 -0700 | [diff] [blame] | 2433 | return (s390_facilities & FACILITY_EXT_IMM ? &a2_rA : &a2_r); |
Richard Henderson | 9b5500b | 2017-06-16 12:44:18 -0700 | [diff] [blame] | 2434 | |
| 2435 | default: |
| 2436 | break; |
Richard Henderson | f69d277 | 2016-11-18 09:31:40 +0100 | [diff] [blame] | 2437 | } |
| 2438 | return NULL; |
| 2439 | } |
| 2440 | |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 2441 | static void query_s390_facilities(void) |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2442 | { |
Richard Henderson | c9baa30 | 2013-06-07 07:43:33 -0700 | [diff] [blame] | 2443 | unsigned long hwcap = qemu_getauxval(AT_HWCAP); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2444 | |
Richard Henderson | c9baa30 | 2013-06-07 07:43:33 -0700 | [diff] [blame] | 2445 | /* Is STORE FACILITY LIST EXTENDED available? Honestly, I believe this |
| 2446 | is present on all 64-bit systems, but let's check for it anyway. */ |
| 2447 | if (hwcap & HWCAP_S390_STFLE) { |
| 2448 | register int r0 __asm__("0"); |
| 2449 | register void *r1 __asm__("1"); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2450 | |
Richard Henderson | c9baa30 | 2013-06-07 07:43:33 -0700 | [diff] [blame] | 2451 | /* stfle 0(%r1) */ |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 2452 | r1 = &s390_facilities; |
Richard Henderson | c9baa30 | 2013-06-07 07:43:33 -0700 | [diff] [blame] | 2453 | asm volatile(".word 0xb2b0,0x1000" |
| 2454 | : "=r"(r0) : "0"(0), "r"(r1) : "memory", "cc"); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2455 | } |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Richard Henderson | e4d58b4 | 2010-06-02 17:26:56 -0700 | [diff] [blame] | 2458 | static void tcg_target_init(TCGContext *s) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2459 | { |
Richard Henderson | b2c98d9 | 2016-10-17 11:24:38 -0400 | [diff] [blame] | 2460 | query_s390_facilities(); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2461 | |
Richard Henderson | f46934d | 2017-09-11 12:44:30 -0700 | [diff] [blame] | 2462 | tcg_target_available_regs[TCG_TYPE_I32] = 0xffff; |
| 2463 | tcg_target_available_regs[TCG_TYPE_I64] = 0xffff; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2464 | |
Richard Henderson | ccb1bb6 | 2017-09-11 11:25:55 -0700 | [diff] [blame] | 2465 | tcg_target_call_clobber_regs = 0; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2466 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R0); |
| 2467 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R1); |
| 2468 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R2); |
| 2469 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R3); |
| 2470 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R4); |
| 2471 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R5); |
Richard Henderson | f24efee | 2014-03-23 13:36:00 -0700 | [diff] [blame] | 2472 | /* The r6 register is technically call-saved, but it's also a parameter |
| 2473 | register, so it can get killed by setup for the qemu_st helper. */ |
| 2474 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R6); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2475 | /* The return register can be considered call-clobbered. */ |
| 2476 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R14); |
| 2477 | |
Richard Henderson | ccb1bb6 | 2017-09-11 11:25:55 -0700 | [diff] [blame] | 2478 | s->reserved_regs = 0; |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2479 | tcg_regset_set_reg(s->reserved_regs, TCG_TMP0); |
| 2480 | /* XXX many insns can't be used with R0, so we better avoid it for now */ |
| 2481 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0); |
| 2482 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 2483 | if (USE_REG_TB) { |
| 2484 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_TB); |
| 2485 | } |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2488 | #define FRAME_SIZE ((int)(TCG_TARGET_CALL_STACK_OFFSET \ |
| 2489 | + TCG_STATIC_CALL_ARGS_SIZE \ |
| 2490 | + CPU_TEMP_BUF_NLONGS * sizeof(long))) |
| 2491 | |
Richard Henderson | e4d58b4 | 2010-06-02 17:26:56 -0700 | [diff] [blame] | 2492 | static void tcg_target_qemu_prologue(TCGContext *s) |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2493 | { |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2494 | /* stmg %r6,%r15,48(%r15) (save registers) */ |
| 2495 | tcg_out_insn(s, RXY, STMG, TCG_REG_R6, TCG_REG_R15, TCG_REG_R15, 48); |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2496 | |
Richard Henderson | a4924e8 | 2013-03-25 20:54:30 -0700 | [diff] [blame] | 2497 | /* aghi %r15,-frame_size */ |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2498 | tcg_out_insn(s, RI, AGHI, TCG_REG_R15, -FRAME_SIZE); |
Richard Henderson | a4924e8 | 2013-03-25 20:54:30 -0700 | [diff] [blame] | 2499 | |
| 2500 | tcg_set_frame(s, TCG_REG_CALL_STACK, |
| 2501 | TCG_STATIC_CALL_ARGS_SIZE + TCG_TARGET_CALL_STACK_OFFSET, |
| 2502 | CPU_TEMP_BUF_NLONGS * sizeof(long)); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2503 | |
Laurent Vivier | 090d0bf | 2015-08-28 12:23:41 +0200 | [diff] [blame] | 2504 | #ifndef CONFIG_SOFTMMU |
Laurent Vivier | b76f21a | 2015-08-24 14:53:54 +0200 | [diff] [blame] | 2505 | if (guest_base >= 0x80000) { |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 2506 | tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2507 | tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); |
| 2508 | } |
Laurent Vivier | 090d0bf | 2015-08-28 12:23:41 +0200 | [diff] [blame] | 2509 | #endif |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2510 | |
Blue Swirl | cea5f9a | 2011-05-15 16:03:25 +0000 | [diff] [blame] | 2511 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); |
Richard Henderson | 829e137 | 2017-07-25 11:53:50 -0700 | [diff] [blame] | 2512 | if (USE_REG_TB) { |
| 2513 | tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, |
| 2514 | tcg_target_call_iarg_regs[1]); |
| 2515 | } |
| 2516 | |
Blue Swirl | cea5f9a | 2011-05-15 16:03:25 +0000 | [diff] [blame] | 2517 | /* br %r3 (go to TB) */ |
| 2518 | tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, tcg_target_call_iarg_regs[1]); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2519 | |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 2520 | /* |
| 2521 | * Return path for goto_ptr. Set return value to 0, a-la exit_tb, |
| 2522 | * and fall through to the rest of the epilogue. |
| 2523 | */ |
Richard Henderson | c8bc116 | 2020-11-05 15:41:38 -0800 | [diff] [blame] | 2524 | tcg_code_gen_epilogue = tcg_splitwx_to_rx(s->code_ptr); |
Richard Henderson | 4664448 | 2017-04-26 18:40:59 -0400 | [diff] [blame] | 2525 | tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, 0); |
| 2526 | |
| 2527 | /* TB epilogue */ |
Richard Henderson | 79dae4d | 2020-11-04 20:56:16 -0800 | [diff] [blame] | 2528 | tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2529 | |
Richard Henderson | a4924e8 | 2013-03-25 20:54:30 -0700 | [diff] [blame] | 2530 | /* lmg %r6,%r15,fs+48(%r15) (restore registers) */ |
| 2531 | tcg_out_insn(s, RXY, LMG, TCG_REG_R6, TCG_REG_R15, TCG_REG_R15, |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2532 | FRAME_SIZE + 48); |
Richard Henderson | 48bb375 | 2010-06-28 19:15:37 -0700 | [diff] [blame] | 2533 | |
| 2534 | /* br %r14 (return) */ |
| 2535 | tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_R14); |
Alexander Graf | 2827822 | 2009-12-05 12:44:23 +0100 | [diff] [blame] | 2536 | } |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2537 | |
Richard Henderson | 28eef8a | 2017-07-31 19:16:02 -0700 | [diff] [blame] | 2538 | static void tcg_out_nop_fill(tcg_insn_unit *p, int count) |
| 2539 | { |
| 2540 | memset(p, 0x07, count * sizeof(tcg_insn_unit)); |
| 2541 | } |
| 2542 | |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2543 | typedef struct { |
Richard Henderson | d2e16f2 | 2014-05-15 12:49:42 -0700 | [diff] [blame] | 2544 | DebugFrameHeader h; |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2545 | uint8_t fde_def_cfa[4]; |
| 2546 | uint8_t fde_reg_ofs[18]; |
| 2547 | } DebugFrame; |
| 2548 | |
| 2549 | /* We're expecting a 2 byte uleb128 encoded value. */ |
| 2550 | QEMU_BUILD_BUG_ON(FRAME_SIZE >= (1 << 14)); |
| 2551 | |
| 2552 | #define ELF_HOST_MACHINE EM_S390 |
| 2553 | |
Richard Henderson | d2e16f2 | 2014-05-15 12:49:42 -0700 | [diff] [blame] | 2554 | static const DebugFrame debug_frame = { |
| 2555 | .h.cie.len = sizeof(DebugFrameCIE)-4, /* length after .len member */ |
| 2556 | .h.cie.id = -1, |
| 2557 | .h.cie.version = 1, |
| 2558 | .h.cie.code_align = 1, |
| 2559 | .h.cie.data_align = 8, /* sleb128 8 */ |
| 2560 | .h.cie.return_column = TCG_REG_R14, |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2561 | |
| 2562 | /* Total FDE size does not include the "len" member. */ |
Richard Henderson | d2e16f2 | 2014-05-15 12:49:42 -0700 | [diff] [blame] | 2563 | .h.fde.len = sizeof(DebugFrame) - offsetof(DebugFrame, h.fde.cie_offset), |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2564 | |
| 2565 | .fde_def_cfa = { |
| 2566 | 12, TCG_REG_CALL_STACK, /* DW_CFA_def_cfa %r15, ... */ |
| 2567 | (FRAME_SIZE & 0x7f) | 0x80, /* ... uleb128 FRAME_SIZE */ |
| 2568 | (FRAME_SIZE >> 7) |
| 2569 | }, |
| 2570 | .fde_reg_ofs = { |
| 2571 | 0x86, 6, /* DW_CFA_offset, %r6, 48 */ |
| 2572 | 0x87, 7, /* DW_CFA_offset, %r7, 56 */ |
| 2573 | 0x88, 8, /* DW_CFA_offset, %r8, 64 */ |
| 2574 | 0x89, 9, /* DW_CFA_offset, %r92, 72 */ |
| 2575 | 0x8a, 10, /* DW_CFA_offset, %r10, 80 */ |
| 2576 | 0x8b, 11, /* DW_CFA_offset, %r11, 88 */ |
| 2577 | 0x8c, 12, /* DW_CFA_offset, %r12, 96 */ |
| 2578 | 0x8d, 13, /* DW_CFA_offset, %r13, 104 */ |
| 2579 | 0x8e, 14, /* DW_CFA_offset, %r14, 112 */ |
| 2580 | } |
| 2581 | }; |
| 2582 | |
Richard Henderson | 755bf9e | 2020-10-29 09:17:30 -0700 | [diff] [blame] | 2583 | void tcg_register_jit(const void *buf, size_t buf_size) |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2584 | { |
Richard Henderson | f167dc3 | 2014-03-23 21:04:40 -0400 | [diff] [blame] | 2585 | tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); |
| 2586 | } |