4 * Copyright (c) 2015 Chen Gang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
23 #include "disas/disas.h"
25 #include "exec/cpu_ldst.h"
26 #include "opcode_tilegx.h"
28 #define FMT64X "%016" PRIx64
30 static TCGv_ptr cpu_env;
32 static TCGv cpu_regs[TILEGX_R_COUNT];
34 static const char * const reg_names[64] = {
35 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
36 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
37 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
38 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
39 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
40 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
41 "r48", "r49", "r50", "r51", "bp", "tp", "sp", "lr",
42 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn2", "zero"
45 /* Modified registers are cached in temporaries until the end of the bundle. */
51 #define MAX_WRITEBACK 4
53 /* This is the state at translation time. */
55 uint64_t pc; /* Current pc */
57 TCGv zero; /* For zero register */
59 DisasContextTemp wb[MAX_WRITEBACK];
65 TCGCond cond; /* branch condition */
66 TCGv dest; /* branch destination */
67 TCGv val1; /* value to be compared against zero, for cond */
68 } jmp; /* Jump object, only once in each TB block */
71 #include "exec/gen-icount.h"
73 /* Differentiate the various pipe encodings. */
79 /* Remerge the base opcode and extension fields for switching.
80 The X opcode fields are 3 bits; Y0/Y1 opcode fields are 4 bits;
81 Y2 opcode field is 2 bits. */
82 #define OE(OP, EXT, XY) (TY_##XY + OP * 4 + EXT * 64)
84 /* Similar, but for Y2 only. */
85 #define OEY2(OP, MODE) (OP + MODE * 4)
87 /* Similar, but make sure opcode names match up. */
88 #define OE_RR_X0(E) OE(RRR_0_OPCODE_X0, E##_UNARY_OPCODE_X0, X0)
89 #define OE_RR_X1(E) OE(RRR_0_OPCODE_X1, E##_UNARY_OPCODE_X1, X1)
90 #define OE_RR_Y0(E) OE(RRR_1_OPCODE_Y0, E##_UNARY_OPCODE_Y0, Y0)
91 #define OE_RR_Y1(E) OE(RRR_1_OPCODE_Y1, E##_UNARY_OPCODE_Y1, Y1)
92 #define OE_RRR(E,N,XY) OE(RRR_##N##_OPCODE_##XY, E##_RRR_##N##_OPCODE_##XY, XY)
93 #define OE_IM(E,XY) OE(IMM8_OPCODE_##XY, E##_IMM8_OPCODE_##XY, XY)
94 #define OE_SH(E,XY) OE(SHIFT_OPCODE_##XY, E##_SHIFT_OPCODE_##XY, XY)
97 static void gen_exception(DisasContext *dc, TileExcp num)
101 tcg_gen_movi_tl(cpu_pc, dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
103 tmp = tcg_const_i32(num);
104 gen_helper_exception(cpu_env, tmp);
105 tcg_temp_free_i32(tmp);
109 static bool check_gr(DisasContext *dc, uint8_t reg)
111 if (likely(reg < TILEGX_R_COUNT)) {
121 gen_exception(dc, TILEGX_EXCP_REG_IDN_ACCESS);
127 gen_exception(dc, TILEGX_EXCP_REG_UDN_ACCESS);
130 g_assert_not_reached();
135 static TCGv load_zero(DisasContext *dc)
137 if (TCGV_IS_UNUSED_I64(dc->zero)) {
138 dc->zero = tcg_const_i64(0);
143 static TCGv load_gr(DisasContext *dc, unsigned reg)
145 if (check_gr(dc, reg)) {
146 return cpu_regs[reg];
148 return load_zero(dc);
151 static TCGv dest_gr(DisasContext *dc, unsigned reg)
155 /* Skip the result, mark the exception if necessary, and continue */
160 return dc->wb[n].val = tcg_temp_new_i64();
163 static void gen_saturate_op(TCGv tdest, TCGv tsrca, TCGv tsrcb,
164 void (*operate)(TCGv, TCGv, TCGv))
166 TCGv t0 = tcg_temp_new();
168 tcg_gen_ext32s_tl(tdest, tsrca);
169 tcg_gen_ext32s_tl(t0, tsrcb);
170 operate(tdest, tdest, t0);
172 tcg_gen_movi_tl(t0, 0x7fffffff);
173 tcg_gen_movcond_tl(TCG_COND_GT, tdest, tdest, t0, t0, tdest);
174 tcg_gen_movi_tl(t0, -0x80000000LL);
175 tcg_gen_movcond_tl(TCG_COND_LT, tdest, tdest, t0, t0, tdest);
180 /* Shift the 128-bit value TSRCA:TSRCD right by the number of bytes
181 specified by the bottom 3 bits of TSRCB, and set TDEST to the
182 low 64 bits of the resulting value. */
183 static void gen_dblalign(TCGv tdest, TCGv tsrcd, TCGv tsrca, TCGv tsrcb)
185 TCGv t0 = tcg_temp_new();
187 tcg_gen_andi_tl(t0, tsrcb, 7);
188 tcg_gen_shli_tl(t0, t0, 3);
189 tcg_gen_shr_tl(tdest, tsrcd, t0);
191 /* We want to do "t0 = tsrca << (64 - t0)". Two's complement
192 arithmetic on a 6-bit field tells us that 64 - t0 is equal
193 to (t0 ^ 63) + 1. So we can do the shift in two parts,
194 neither of which will be an invalid shift by 64. */
195 tcg_gen_xori_tl(t0, t0, 63);
196 tcg_gen_shl_tl(t0, tsrca, t0);
197 tcg_gen_shli_tl(t0, t0, 1);
198 tcg_gen_or_tl(tdest, tdest, t0);
203 /* Similarly, except that the 128-bit value is TSRCA:TSRCB, and the
204 right shift is an immediate. */
205 static void gen_dblaligni(TCGv tdest, TCGv tsrca, TCGv tsrcb, int shr)
207 TCGv t0 = tcg_temp_new();
209 tcg_gen_shri_tl(t0, tsrcb, shr);
210 tcg_gen_shli_tl(tdest, tsrca, 64 - shr);
211 tcg_gen_or_tl(tdest, tdest, t0);
216 static TileExcp gen_st_opcode(DisasContext *dc, unsigned dest, unsigned srca,
217 unsigned srcb, TCGMemOp memop, const char *name)
220 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
223 tcg_gen_qemu_st_tl(load_gr(dc, srcb), load_gr(dc, srca),
226 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", name,
227 reg_names[srca], reg_names[srcb]);
228 return TILEGX_EXCP_NONE;
231 static TileExcp gen_st_add_opcode(DisasContext *dc, unsigned srca, unsigned srcb,
232 int imm, TCGMemOp memop, const char *name)
234 TCGv tsrca = load_gr(dc, srca);
235 TCGv tsrcb = load_gr(dc, srcb);
237 tcg_gen_qemu_st_tl(tsrcb, tsrca, dc->mmuidx, memop);
238 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
240 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %d", name,
241 reg_names[srca], reg_names[srcb], imm);
242 return TILEGX_EXCP_NONE;
245 static TileExcp gen_rr_opcode(DisasContext *dc, unsigned opext,
246 unsigned dest, unsigned srca)
249 const char *mnemonic;
252 /* Eliminate nops before doing anything else. */
267 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
269 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s", mnemonic);
270 return TILEGX_EXCP_NONE;
273 tdest = dest_gr(dc, dest);
274 tsrca = load_gr(dc, srca);
277 case OE_RR_X0(CNTLZ):
278 case OE_RR_Y0(CNTLZ):
279 gen_helper_cntlz(tdest, tsrca);
282 case OE_RR_X0(CNTTZ):
283 case OE_RR_Y0(CNTTZ):
284 gen_helper_cnttz(tdest, tsrca);
287 case OE_RR_X1(DRAIN):
288 case OE_RR_X1(DTLBPR):
290 case OE_RR_X1(FLUSHWB):
291 case OE_RR_X1(FLUSH):
292 case OE_RR_X0(FSINGLE_PACK1):
293 case OE_RR_Y0(FSINGLE_PACK1):
299 case OE_RR_X1(JALRP):
300 case OE_RR_Y1(JALRP):
307 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
332 case OE_RR_X1(LDNT1S):
336 case OE_RR_X1(LDNT1U):
340 case OE_RR_X1(LDNT2S):
344 case OE_RR_X1(LDNT2U):
348 case OE_RR_X1(LDNT4S):
352 case OE_RR_X1(LDNT4U):
364 tcg_gen_qemu_ld_tl(tdest, tsrca, dc->mmuidx, memop);
367 tcg_gen_andi_tl(tdest, tsrca, ~7);
368 tcg_gen_qemu_ld_tl(tdest, tdest, dc->mmuidx, MO_TEQ);
375 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
378 gen_helper_pcnt(tdest, tsrca);
381 case OE_RR_X0(REVBITS):
382 case OE_RR_Y0(REVBITS):
383 gen_helper_revbits(tdest, tsrca);
384 mnemonic = "revbits";
386 case OE_RR_X0(REVBYTES):
387 case OE_RR_Y0(REVBYTES):
388 tcg_gen_bswap64_tl(tdest, tsrca);
389 mnemonic = "revbytes";
391 case OE_RR_X1(SWINT0):
392 case OE_RR_X1(SWINT1):
393 case OE_RR_X1(SWINT2):
394 case OE_RR_X1(SWINT3):
395 case OE_RR_X0(TBLIDXB0):
396 case OE_RR_Y0(TBLIDXB0):
397 case OE_RR_X0(TBLIDXB1):
398 case OE_RR_Y0(TBLIDXB1):
399 case OE_RR_X0(TBLIDXB2):
400 case OE_RR_Y0(TBLIDXB2):
401 case OE_RR_X0(TBLIDXB3):
402 case OE_RR_Y0(TBLIDXB3):
405 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
408 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", mnemonic,
409 reg_names[dest], reg_names[srca]);
410 return TILEGX_EXCP_NONE;
413 static TileExcp gen_rrr_opcode(DisasContext *dc, unsigned opext,
414 unsigned dest, unsigned srca, unsigned srcb)
416 TCGv tdest = dest_gr(dc, dest);
417 TCGv tsrca = load_gr(dc, srca);
418 TCGv tsrcb = load_gr(dc, srcb);
419 const char *mnemonic;
422 case OE_RRR(ADDXSC, 0, X0):
423 case OE_RRR(ADDXSC, 0, X1):
424 gen_saturate_op(tdest, tsrca, tsrcb, tcg_gen_add_tl);
427 case OE_RRR(ADDX, 0, X0):
428 case OE_RRR(ADDX, 0, X1):
429 case OE_RRR(ADDX, 0, Y0):
430 case OE_RRR(ADDX, 0, Y1):
431 tcg_gen_add_tl(tdest, tsrca, tsrcb);
432 tcg_gen_ext32s_tl(tdest, tdest);
435 case OE_RRR(ADD, 0, X0):
436 case OE_RRR(ADD, 0, X1):
437 case OE_RRR(ADD, 0, Y0):
438 case OE_RRR(ADD, 0, Y1):
439 tcg_gen_add_tl(tdest, tsrca, tsrcb);
442 case OE_RRR(AND, 0, X0):
443 case OE_RRR(AND, 0, X1):
444 case OE_RRR(AND, 5, Y0):
445 case OE_RRR(AND, 5, Y1):
446 tcg_gen_and_tl(tdest, tsrca, tsrcb);
449 case OE_RRR(CMOVEQZ, 0, X0):
450 case OE_RRR(CMOVEQZ, 4, Y0):
451 case OE_RRR(CMOVNEZ, 0, X0):
452 case OE_RRR(CMOVNEZ, 4, Y0):
453 case OE_RRR(CMPEQ, 0, X0):
454 case OE_RRR(CMPEQ, 0, X1):
455 case OE_RRR(CMPEQ, 3, Y0):
456 case OE_RRR(CMPEQ, 3, Y1):
457 case OE_RRR(CMPEXCH4, 0, X1):
458 case OE_RRR(CMPEXCH, 0, X1):
459 case OE_RRR(CMPLES, 0, X0):
460 case OE_RRR(CMPLES, 0, X1):
461 case OE_RRR(CMPLES, 2, Y0):
462 case OE_RRR(CMPLES, 2, Y1):
463 case OE_RRR(CMPLEU, 0, X0):
464 case OE_RRR(CMPLEU, 0, X1):
465 case OE_RRR(CMPLEU, 2, Y0):
466 case OE_RRR(CMPLEU, 2, Y1):
467 case OE_RRR(CMPLTS, 0, X0):
468 case OE_RRR(CMPLTS, 0, X1):
469 case OE_RRR(CMPLTS, 2, Y0):
470 case OE_RRR(CMPLTS, 2, Y1):
471 case OE_RRR(CMPLTU, 0, X0):
472 case OE_RRR(CMPLTU, 0, X1):
473 case OE_RRR(CMPLTU, 2, Y0):
474 case OE_RRR(CMPLTU, 2, Y1):
475 case OE_RRR(CMPNE, 0, X0):
476 case OE_RRR(CMPNE, 0, X1):
477 case OE_RRR(CMPNE, 3, Y0):
478 case OE_RRR(CMPNE, 3, Y1):
479 case OE_RRR(CMULAF, 0, X0):
480 case OE_RRR(CMULA, 0, X0):
481 case OE_RRR(CMULFR, 0, X0):
482 case OE_RRR(CMULF, 0, X0):
483 case OE_RRR(CMULHR, 0, X0):
484 case OE_RRR(CMULH, 0, X0):
485 case OE_RRR(CMUL, 0, X0):
486 case OE_RRR(CRC32_32, 0, X0):
487 case OE_RRR(CRC32_8, 0, X0):
488 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
489 case OE_RRR(DBLALIGN2, 0, X0):
490 case OE_RRR(DBLALIGN2, 0, X1):
491 gen_dblaligni(tdest, tsrca, tsrcb, 16);
492 mnemonic = "dblalign2";
494 case OE_RRR(DBLALIGN4, 0, X0):
495 case OE_RRR(DBLALIGN4, 0, X1):
496 gen_dblaligni(tdest, tsrca, tsrcb, 32);
497 mnemonic = "dblalign4";
499 case OE_RRR(DBLALIGN6, 0, X0):
500 case OE_RRR(DBLALIGN6, 0, X1):
501 gen_dblaligni(tdest, tsrca, tsrcb, 48);
502 mnemonic = "dblalign6";
504 case OE_RRR(DBLALIGN, 0, X0):
505 gen_dblalign(tdest, load_gr(dc, dest), tsrca, tsrcb);
506 mnemonic = "dblalign";
508 case OE_RRR(EXCH4, 0, X1):
509 case OE_RRR(EXCH, 0, X1):
510 case OE_RRR(FDOUBLE_ADDSUB, 0, X0):
511 case OE_RRR(FDOUBLE_ADD_FLAGS, 0, X0):
512 case OE_RRR(FDOUBLE_MUL_FLAGS, 0, X0):
513 case OE_RRR(FDOUBLE_PACK1, 0, X0):
514 case OE_RRR(FDOUBLE_PACK2, 0, X0):
515 case OE_RRR(FDOUBLE_SUB_FLAGS, 0, X0):
516 case OE_RRR(FDOUBLE_UNPACK_MAX, 0, X0):
517 case OE_RRR(FDOUBLE_UNPACK_MIN, 0, X0):
518 case OE_RRR(FETCHADD4, 0, X1):
519 case OE_RRR(FETCHADDGEZ4, 0, X1):
520 case OE_RRR(FETCHADDGEZ, 0, X1):
521 case OE_RRR(FETCHADD, 0, X1):
522 case OE_RRR(FETCHAND4, 0, X1):
523 case OE_RRR(FETCHAND, 0, X1):
524 case OE_RRR(FETCHOR4, 0, X1):
525 case OE_RRR(FETCHOR, 0, X1):
526 case OE_RRR(FSINGLE_ADD1, 0, X0):
527 case OE_RRR(FSINGLE_ADDSUB2, 0, X0):
528 case OE_RRR(FSINGLE_MUL1, 0, X0):
529 case OE_RRR(FSINGLE_MUL2, 0, X0):
530 case OE_RRR(FSINGLE_PACK2, 0, X0):
531 case OE_RRR(FSINGLE_SUB1, 0, X0):
532 case OE_RRR(MNZ, 0, X0):
533 case OE_RRR(MNZ, 0, X1):
534 case OE_RRR(MNZ, 4, Y0):
535 case OE_RRR(MNZ, 4, Y1):
536 case OE_RRR(MULAX, 0, X0):
537 case OE_RRR(MULAX, 3, Y0):
538 case OE_RRR(MULA_HS_HS, 0, X0):
539 case OE_RRR(MULA_HS_HS, 9, Y0):
540 case OE_RRR(MULA_HS_HU, 0, X0):
541 case OE_RRR(MULA_HS_LS, 0, X0):
542 case OE_RRR(MULA_HS_LU, 0, X0):
543 case OE_RRR(MULA_HU_HU, 0, X0):
544 case OE_RRR(MULA_HU_HU, 9, Y0):
545 case OE_RRR(MULA_HU_LS, 0, X0):
546 case OE_RRR(MULA_HU_LU, 0, X0):
547 case OE_RRR(MULA_LS_LS, 0, X0):
548 case OE_RRR(MULA_LS_LS, 9, Y0):
549 case OE_RRR(MULA_LS_LU, 0, X0):
550 case OE_RRR(MULA_LU_LU, 0, X0):
551 case OE_RRR(MULA_LU_LU, 9, Y0):
552 case OE_RRR(MULX, 0, X0):
553 case OE_RRR(MULX, 3, Y0):
554 case OE_RRR(MUL_HS_HS, 0, X0):
555 case OE_RRR(MUL_HS_HS, 8, Y0):
556 case OE_RRR(MUL_HS_HU, 0, X0):
557 case OE_RRR(MUL_HS_LS, 0, X0):
558 case OE_RRR(MUL_HS_LU, 0, X0):
559 case OE_RRR(MUL_HU_HU, 0, X0):
560 case OE_RRR(MUL_HU_HU, 8, Y0):
561 case OE_RRR(MUL_HU_LS, 0, X0):
562 case OE_RRR(MUL_HU_LU, 0, X0):
563 case OE_RRR(MUL_LS_LS, 0, X0):
564 case OE_RRR(MUL_LS_LS, 8, Y0):
565 case OE_RRR(MUL_LS_LU, 0, X0):
566 case OE_RRR(MUL_LU_LU, 0, X0):
567 case OE_RRR(MUL_LU_LU, 8, Y0):
568 case OE_RRR(MZ, 0, X0):
569 case OE_RRR(MZ, 0, X1):
570 case OE_RRR(MZ, 4, Y0):
571 case OE_RRR(MZ, 4, Y1):
572 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
573 case OE_RRR(NOR, 0, X0):
574 case OE_RRR(NOR, 0, X1):
575 case OE_RRR(NOR, 5, Y0):
576 case OE_RRR(NOR, 5, Y1):
577 tcg_gen_nor_tl(tdest, tsrca, tsrcb);
580 case OE_RRR(OR, 0, X0):
581 case OE_RRR(OR, 0, X1):
582 case OE_RRR(OR, 5, Y0):
583 case OE_RRR(OR, 5, Y1):
584 tcg_gen_or_tl(tdest, tsrca, tsrcb);
587 case OE_RRR(ROTL, 0, X0):
588 case OE_RRR(ROTL, 0, X1):
589 case OE_RRR(ROTL, 6, Y0):
590 case OE_RRR(ROTL, 6, Y1):
591 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
592 case OE_RRR(SHL1ADDX, 0, X0):
593 case OE_RRR(SHL1ADDX, 0, X1):
594 case OE_RRR(SHL1ADDX, 7, Y0):
595 case OE_RRR(SHL1ADDX, 7, Y1):
596 tcg_gen_shli_tl(tdest, tsrca, 1);
597 tcg_gen_add_tl(tdest, tdest, tsrcb);
598 tcg_gen_ext32s_tl(tdest, tdest);
599 mnemonic = "shl1addx";
601 case OE_RRR(SHL1ADD, 0, X0):
602 case OE_RRR(SHL1ADD, 0, X1):
603 case OE_RRR(SHL1ADD, 1, Y0):
604 case OE_RRR(SHL1ADD, 1, Y1):
605 tcg_gen_shli_tl(tdest, tsrca, 1);
606 tcg_gen_add_tl(tdest, tdest, tsrcb);
607 mnemonic = "shl1add";
609 case OE_RRR(SHL2ADDX, 0, X0):
610 case OE_RRR(SHL2ADDX, 0, X1):
611 case OE_RRR(SHL2ADDX, 7, Y0):
612 case OE_RRR(SHL2ADDX, 7, Y1):
613 tcg_gen_shli_tl(tdest, tsrca, 2);
614 tcg_gen_add_tl(tdest, tdest, tsrcb);
615 tcg_gen_ext32s_tl(tdest, tdest);
616 mnemonic = "shl2addx";
618 case OE_RRR(SHL2ADD, 0, X0):
619 case OE_RRR(SHL2ADD, 0, X1):
620 case OE_RRR(SHL2ADD, 1, Y0):
621 case OE_RRR(SHL2ADD, 1, Y1):
622 tcg_gen_shli_tl(tdest, tsrca, 2);
623 tcg_gen_add_tl(tdest, tdest, tsrcb);
624 mnemonic = "shl2add";
626 case OE_RRR(SHL3ADDX, 0, X0):
627 case OE_RRR(SHL3ADDX, 0, X1):
628 case OE_RRR(SHL3ADDX, 7, Y0):
629 case OE_RRR(SHL3ADDX, 7, Y1):
630 tcg_gen_shli_tl(tdest, tsrca, 3);
631 tcg_gen_add_tl(tdest, tdest, tsrcb);
632 tcg_gen_ext32s_tl(tdest, tdest);
633 mnemonic = "shl3addx";
635 case OE_RRR(SHL3ADD, 0, X0):
636 case OE_RRR(SHL3ADD, 0, X1):
637 case OE_RRR(SHL3ADD, 1, Y0):
638 case OE_RRR(SHL3ADD, 1, Y1):
639 tcg_gen_shli_tl(tdest, tsrca, 3);
640 tcg_gen_add_tl(tdest, tdest, tsrcb);
641 mnemonic = "shl3add";
643 case OE_RRR(SHLX, 0, X0):
644 case OE_RRR(SHLX, 0, X1):
645 case OE_RRR(SHL, 0, X0):
646 case OE_RRR(SHL, 0, X1):
647 case OE_RRR(SHL, 6, Y0):
648 case OE_RRR(SHL, 6, Y1):
649 case OE_RRR(SHRS, 0, X0):
650 case OE_RRR(SHRS, 0, X1):
651 case OE_RRR(SHRS, 6, Y0):
652 case OE_RRR(SHRS, 6, Y1):
653 case OE_RRR(SHRUX, 0, X0):
654 case OE_RRR(SHRUX, 0, X1):
655 case OE_RRR(SHRU, 0, X0):
656 case OE_RRR(SHRU, 0, X1):
657 case OE_RRR(SHRU, 6, Y0):
658 case OE_RRR(SHRU, 6, Y1):
659 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
660 case OE_RRR(SHUFFLEBYTES, 0, X0):
661 gen_helper_shufflebytes(tdest, load_gr(dc, dest), tsrca, tsrca);
662 mnemonic = "shufflebytes";
664 case OE_RRR(SUBXSC, 0, X0):
665 case OE_RRR(SUBXSC, 0, X1):
666 gen_saturate_op(tdest, tsrca, tsrcb, tcg_gen_sub_tl);
669 case OE_RRR(SUBX, 0, X0):
670 case OE_RRR(SUBX, 0, X1):
671 case OE_RRR(SUBX, 0, Y0):
672 case OE_RRR(SUBX, 0, Y1):
673 tcg_gen_sub_tl(tdest, tsrca, tsrcb);
674 tcg_gen_ext32s_tl(tdest, tdest);
677 case OE_RRR(SUB, 0, X0):
678 case OE_RRR(SUB, 0, X1):
679 case OE_RRR(SUB, 0, Y0):
680 case OE_RRR(SUB, 0, Y1):
681 tcg_gen_sub_tl(tdest, tsrca, tsrcb);
684 case OE_RRR(V1ADDUC, 0, X0):
685 case OE_RRR(V1ADDUC, 0, X1):
686 case OE_RRR(V1ADD, 0, X0):
687 case OE_RRR(V1ADD, 0, X1):
688 case OE_RRR(V1ADIFFU, 0, X0):
689 case OE_RRR(V1AVGU, 0, X0):
690 case OE_RRR(V1CMPEQ, 0, X0):
691 case OE_RRR(V1CMPEQ, 0, X1):
692 case OE_RRR(V1CMPLES, 0, X0):
693 case OE_RRR(V1CMPLES, 0, X1):
694 case OE_RRR(V1CMPLEU, 0, X0):
695 case OE_RRR(V1CMPLEU, 0, X1):
696 case OE_RRR(V1CMPLTS, 0, X0):
697 case OE_RRR(V1CMPLTS, 0, X1):
698 case OE_RRR(V1CMPLTU, 0, X0):
699 case OE_RRR(V1CMPLTU, 0, X1):
700 case OE_RRR(V1CMPNE, 0, X0):
701 case OE_RRR(V1CMPNE, 0, X1):
702 case OE_RRR(V1DDOTPUA, 0, X0):
703 case OE_RRR(V1DDOTPUSA, 0, X0):
704 case OE_RRR(V1DDOTPUS, 0, X0):
705 case OE_RRR(V1DDOTPU, 0, X0):
706 case OE_RRR(V1DOTPA, 0, X0):
707 case OE_RRR(V1DOTPUA, 0, X0):
708 case OE_RRR(V1DOTPUSA, 0, X0):
709 case OE_RRR(V1DOTPUS, 0, X0):
710 case OE_RRR(V1DOTPU, 0, X0):
711 case OE_RRR(V1DOTP, 0, X0):
712 case OE_RRR(V1INT_H, 0, X0):
713 case OE_RRR(V1INT_H, 0, X1):
714 case OE_RRR(V1INT_L, 0, X0):
715 case OE_RRR(V1INT_L, 0, X1):
716 case OE_RRR(V1MAXU, 0, X0):
717 case OE_RRR(V1MAXU, 0, X1):
718 case OE_RRR(V1MINU, 0, X0):
719 case OE_RRR(V1MINU, 0, X1):
720 case OE_RRR(V1MNZ, 0, X0):
721 case OE_RRR(V1MNZ, 0, X1):
722 case OE_RRR(V1MULTU, 0, X0):
723 case OE_RRR(V1MULUS, 0, X0):
724 case OE_RRR(V1MULU, 0, X0):
725 case OE_RRR(V1MZ, 0, X0):
726 case OE_RRR(V1MZ, 0, X1):
727 case OE_RRR(V1SADAU, 0, X0):
728 case OE_RRR(V1SADU, 0, X0):
729 case OE_RRR(V1SHL, 0, X0):
730 case OE_RRR(V1SHL, 0, X1):
731 case OE_RRR(V1SHRS, 0, X0):
732 case OE_RRR(V1SHRS, 0, X1):
733 case OE_RRR(V1SHRU, 0, X0):
734 case OE_RRR(V1SHRU, 0, X1):
735 case OE_RRR(V1SUBUC, 0, X0):
736 case OE_RRR(V1SUBUC, 0, X1):
737 case OE_RRR(V1SUB, 0, X0):
738 case OE_RRR(V1SUB, 0, X1):
739 case OE_RRR(V2ADDSC, 0, X0):
740 case OE_RRR(V2ADDSC, 0, X1):
741 case OE_RRR(V2ADD, 0, X0):
742 case OE_RRR(V2ADD, 0, X1):
743 case OE_RRR(V2ADIFFS, 0, X0):
744 case OE_RRR(V2AVGS, 0, X0):
745 case OE_RRR(V2CMPEQ, 0, X0):
746 case OE_RRR(V2CMPEQ, 0, X1):
747 case OE_RRR(V2CMPLES, 0, X0):
748 case OE_RRR(V2CMPLES, 0, X1):
749 case OE_RRR(V2CMPLEU, 0, X0):
750 case OE_RRR(V2CMPLEU, 0, X1):
751 case OE_RRR(V2CMPLTS, 0, X0):
752 case OE_RRR(V2CMPLTS, 0, X1):
753 case OE_RRR(V2CMPLTU, 0, X0):
754 case OE_RRR(V2CMPLTU, 0, X1):
755 case OE_RRR(V2CMPNE, 0, X0):
756 case OE_RRR(V2CMPNE, 0, X1):
757 case OE_RRR(V2DOTPA, 0, X0):
758 case OE_RRR(V2DOTP, 0, X0):
759 case OE_RRR(V2INT_H, 0, X0):
760 case OE_RRR(V2INT_H, 0, X1):
761 case OE_RRR(V2INT_L, 0, X0):
762 case OE_RRR(V2INT_L, 0, X1):
763 case OE_RRR(V2MAXS, 0, X0):
764 case OE_RRR(V2MAXS, 0, X1):
765 case OE_RRR(V2MINS, 0, X0):
766 case OE_RRR(V2MINS, 0, X1):
767 case OE_RRR(V2MNZ, 0, X0):
768 case OE_RRR(V2MNZ, 0, X1):
769 case OE_RRR(V2MULFSC, 0, X0):
770 case OE_RRR(V2MULS, 0, X0):
771 case OE_RRR(V2MULTS, 0, X0):
772 case OE_RRR(V2MZ, 0, X0):
773 case OE_RRR(V2MZ, 0, X1):
774 case OE_RRR(V2PACKH, 0, X0):
775 case OE_RRR(V2PACKH, 0, X1):
776 case OE_RRR(V2PACKL, 0, X0):
777 case OE_RRR(V2PACKL, 0, X1):
778 case OE_RRR(V2PACKUC, 0, X0):
779 case OE_RRR(V2PACKUC, 0, X1):
780 case OE_RRR(V2SADAS, 0, X0):
781 case OE_RRR(V2SADAU, 0, X0):
782 case OE_RRR(V2SADS, 0, X0):
783 case OE_RRR(V2SADU, 0, X0):
784 case OE_RRR(V2SHLSC, 0, X0):
785 case OE_RRR(V2SHLSC, 0, X1):
786 case OE_RRR(V2SHL, 0, X0):
787 case OE_RRR(V2SHL, 0, X1):
788 case OE_RRR(V2SHRS, 0, X0):
789 case OE_RRR(V2SHRS, 0, X1):
790 case OE_RRR(V2SHRU, 0, X0):
791 case OE_RRR(V2SHRU, 0, X1):
792 case OE_RRR(V2SUBSC, 0, X0):
793 case OE_RRR(V2SUBSC, 0, X1):
794 case OE_RRR(V2SUB, 0, X0):
795 case OE_RRR(V2SUB, 0, X1):
796 case OE_RRR(V4ADDSC, 0, X0):
797 case OE_RRR(V4ADDSC, 0, X1):
798 case OE_RRR(V4ADD, 0, X0):
799 case OE_RRR(V4ADD, 0, X1):
800 case OE_RRR(V4INT_H, 0, X0):
801 case OE_RRR(V4INT_H, 0, X1):
802 case OE_RRR(V4INT_L, 0, X0):
803 case OE_RRR(V4INT_L, 0, X1):
804 case OE_RRR(V4PACKSC, 0, X0):
805 case OE_RRR(V4PACKSC, 0, X1):
806 case OE_RRR(V4SHLSC, 0, X0):
807 case OE_RRR(V4SHLSC, 0, X1):
808 case OE_RRR(V4SHL, 0, X0):
809 case OE_RRR(V4SHL, 0, X1):
810 case OE_RRR(V4SHRS, 0, X0):
811 case OE_RRR(V4SHRS, 0, X1):
812 case OE_RRR(V4SHRU, 0, X0):
813 case OE_RRR(V4SHRU, 0, X1):
814 case OE_RRR(V4SUBSC, 0, X0):
815 case OE_RRR(V4SUBSC, 0, X1):
816 case OE_RRR(V4SUB, 0, X0):
817 case OE_RRR(V4SUB, 0, X1):
818 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
819 case OE_RRR(XOR, 0, X0):
820 case OE_RRR(XOR, 0, X1):
821 case OE_RRR(XOR, 5, Y0):
822 case OE_RRR(XOR, 5, Y1):
823 tcg_gen_xor_tl(tdest, tsrca, tsrcb);
827 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
830 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %s", mnemonic,
831 reg_names[dest], reg_names[srca], reg_names[srcb]);
832 return TILEGX_EXCP_NONE;
835 static TileExcp gen_rri_opcode(DisasContext *dc, unsigned opext,
836 unsigned dest, unsigned srca, int imm)
838 TCGv tdest = dest_gr(dc, dest);
839 TCGv tsrca = load_gr(dc, srca);
840 const char *mnemonic;
844 case OE(ADDI_OPCODE_Y0, 0, Y0):
845 case OE(ADDI_OPCODE_Y1, 0, Y1):
846 case OE_IM(ADDI, X0):
847 case OE_IM(ADDI, X1):
848 tcg_gen_addi_tl(tdest, tsrca, imm);
851 case OE(ADDXI_OPCODE_Y0, 0, Y0):
852 case OE(ADDXI_OPCODE_Y1, 0, Y1):
853 case OE_IM(ADDXI, X0):
854 case OE_IM(ADDXI, X1):
855 tcg_gen_addi_tl(tdest, tsrca, imm);
856 tcg_gen_ext32s_tl(tdest, tdest);
859 case OE(ANDI_OPCODE_Y0, 0, Y0):
860 case OE(ANDI_OPCODE_Y1, 0, Y1):
861 case OE_IM(ANDI, X0):
862 case OE_IM(ANDI, X1):
863 tcg_gen_andi_tl(tdest, tsrca, imm);
866 case OE_IM(CMPEQI, X0):
867 case OE_IM(CMPEQI, X1):
868 case OE_IM(CMPLTSI, X0):
869 case OE_IM(CMPLTSI, X1):
870 case OE_IM(CMPLTUI, X0):
871 case OE_IM(CMPLTUI, X1):
872 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
873 case OE_IM(LD1S_ADD, X1):
875 mnemonic = "ld1s_add";
877 case OE_IM(LD1U_ADD, X1):
879 mnemonic = "ld1u_add";
881 case OE_IM(LD2S_ADD, X1):
883 mnemonic = "ld2s_add";
885 case OE_IM(LD2U_ADD, X1):
887 mnemonic = "ld2u_add";
889 case OE_IM(LD4S_ADD, X1):
891 mnemonic = "ld4s_add";
893 case OE_IM(LD4U_ADD, X1):
895 mnemonic = "ld4u_add";
897 case OE_IM(LDNT1S_ADD, X1):
899 mnemonic = "ldnt1s_add";
901 case OE_IM(LDNT1U_ADD, X1):
903 mnemonic = "ldnt1u_add";
905 case OE_IM(LDNT2S_ADD, X1):
907 mnemonic = "ldnt2s_add";
909 case OE_IM(LDNT2U_ADD, X1):
911 mnemonic = "ldnt2u_add";
913 case OE_IM(LDNT4S_ADD, X1):
915 mnemonic = "ldnt4s_add";
917 case OE_IM(LDNT4U_ADD, X1):
919 mnemonic = "ldnt4u_add";
921 case OE_IM(LDNT_ADD, X1):
923 mnemonic = "ldnt_add";
925 case OE_IM(LD_ADD, X1):
927 mnemonic = "ldnt_add";
929 tcg_gen_qemu_ld_tl(tdest, tsrca, dc->mmuidx, memop);
930 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
932 case OE_IM(LDNA_ADD, X1):
933 tcg_gen_andi_tl(tdest, tsrca, ~7);
934 tcg_gen_qemu_ld_tl(tdest, tdest, dc->mmuidx, MO_TEQ);
935 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
936 mnemonic = "ldna_add";
938 case OE_IM(MFSPR, X1):
939 case OE_IM(MTSPR, X1):
940 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
943 tcg_gen_ori_tl(tdest, tsrca, imm);
946 case OE_IM(V1ADDI, X0):
947 case OE_IM(V1ADDI, X1):
948 case OE_IM(V1CMPEQI, X0):
949 case OE_IM(V1CMPEQI, X1):
950 case OE_IM(V1CMPLTSI, X0):
951 case OE_IM(V1CMPLTSI, X1):
952 case OE_IM(V1CMPLTUI, X0):
953 case OE_IM(V1CMPLTUI, X1):
954 case OE_IM(V1MAXUI, X0):
955 case OE_IM(V1MAXUI, X1):
956 case OE_IM(V1MINUI, X0):
957 case OE_IM(V1MINUI, X1):
958 case OE_IM(V2ADDI, X0):
959 case OE_IM(V2ADDI, X1):
960 case OE_IM(V2CMPEQI, X0):
961 case OE_IM(V2CMPEQI, X1):
962 case OE_IM(V2CMPLTSI, X0):
963 case OE_IM(V2CMPLTSI, X1):
964 case OE_IM(V2CMPLTUI, X0):
965 case OE_IM(V2CMPLTUI, X1):
966 case OE_IM(V2MAXSI, X0):
967 case OE_IM(V2MAXSI, X1):
968 case OE_IM(V2MINSI, X0):
969 case OE_IM(V2MINSI, X1):
970 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
971 case OE_IM(XORI, X0):
972 case OE_IM(XORI, X1):
973 tcg_gen_xori_tl(tdest, tsrca, imm);
977 case OE_SH(ROTLI, X0):
978 case OE_SH(ROTLI, X1):
979 case OE_SH(ROTLI, Y0):
980 case OE_SH(ROTLI, Y1):
981 case OE_SH(SHLI, X0):
982 case OE_SH(SHLI, X1):
983 case OE_SH(SHLI, Y0):
984 case OE_SH(SHLI, Y1):
985 case OE_SH(SHLXI, X0):
986 case OE_SH(SHLXI, X1):
987 case OE_SH(SHRSI, X0):
988 case OE_SH(SHRSI, X1):
989 case OE_SH(SHRSI, Y0):
990 case OE_SH(SHRSI, Y1):
991 case OE_SH(SHRUI, X0):
992 case OE_SH(SHRUI, X1):
993 case OE_SH(SHRUI, Y0):
994 case OE_SH(SHRUI, Y1):
995 case OE_SH(SHRUXI, X0):
996 case OE_SH(SHRUXI, X1):
997 case OE_SH(V1SHLI, X0):
998 case OE_SH(V1SHLI, X1):
999 case OE_SH(V1SHRSI, X0):
1000 case OE_SH(V1SHRSI, X1):
1001 case OE_SH(V1SHRUI, X0):
1002 case OE_SH(V1SHRUI, X1):
1003 case OE_SH(V2SHLI, X0):
1004 case OE_SH(V2SHLI, X1):
1005 case OE_SH(V2SHRSI, X0):
1006 case OE_SH(V2SHRSI, X1):
1007 case OE_SH(V2SHRUI, X0):
1008 case OE_SH(V2SHRUI, X1):
1009 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1011 case OE(ADDLI_OPCODE_X0, 0, X0):
1012 case OE(ADDLI_OPCODE_X1, 0, X1):
1013 tcg_gen_addi_tl(tdest, tsrca, imm);
1016 case OE(ADDXLI_OPCODE_X0, 0, X0):
1017 case OE(ADDXLI_OPCODE_X1, 0, X1):
1018 tcg_gen_addi_tl(tdest, tsrca, imm);
1019 tcg_gen_ext32s_tl(tdest, tdest);
1020 mnemonic = "addxli";
1022 case OE(CMPEQI_OPCODE_Y0, 0, Y0):
1023 case OE(CMPEQI_OPCODE_Y1, 0, Y1):
1024 case OE(CMPLTSI_OPCODE_Y0, 0, Y0):
1025 case OE(CMPLTSI_OPCODE_Y1, 0, Y1):
1026 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1027 case OE(SHL16INSLI_OPCODE_X0, 0, X0):
1028 case OE(SHL16INSLI_OPCODE_X1, 0, X1):
1029 tcg_gen_shli_tl(tdest, tsrca, 16);
1030 tcg_gen_ori_tl(tdest, tdest, imm & 0xffff);
1031 mnemonic = "shl16insli";
1035 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1038 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %d", mnemonic,
1039 reg_names[dest], reg_names[srca], imm);
1040 return TILEGX_EXCP_NONE;
1043 static TileExcp gen_bf_opcode_x0(DisasContext *dc, unsigned ext,
1044 unsigned dest, unsigned srca,
1045 unsigned bfs, unsigned bfe)
1047 const char *mnemonic;
1050 case BFEXTU_BF_OPCODE_X0:
1051 case BFEXTS_BF_OPCODE_X0:
1052 case BFINS_BF_OPCODE_X0:
1053 case MM_BF_OPCODE_X0:
1055 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1058 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %u, %u", mnemonic,
1059 reg_names[dest], reg_names[srca], bfs, bfe);
1060 return TILEGX_EXCP_NONE;
1063 static TileExcp gen_branch_opcode_x1(DisasContext *dc, unsigned ext,
1064 unsigned srca, int off)
1066 target_ulong tgt = dc->pc + off * TILEGX_BUNDLE_SIZE_IN_BYTES;
1067 const char *mnemonic;
1070 case BEQZT_BRANCH_OPCODE_X1:
1071 case BEQZ_BRANCH_OPCODE_X1:
1072 case BNEZT_BRANCH_OPCODE_X1:
1073 case BNEZ_BRANCH_OPCODE_X1:
1074 case BLBC_BRANCH_OPCODE_X1:
1075 case BGEZT_BRANCH_OPCODE_X1:
1076 case BGEZ_BRANCH_OPCODE_X1:
1077 case BGTZT_BRANCH_OPCODE_X1:
1078 case BGTZ_BRANCH_OPCODE_X1:
1079 case BLBCT_BRANCH_OPCODE_X1:
1080 case BLBST_BRANCH_OPCODE_X1:
1081 case BLBS_BRANCH_OPCODE_X1:
1082 case BLEZT_BRANCH_OPCODE_X1:
1083 case BLEZ_BRANCH_OPCODE_X1:
1084 case BLTZT_BRANCH_OPCODE_X1:
1085 case BLTZ_BRANCH_OPCODE_X1:
1087 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1090 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1091 qemu_log("%s %s, " TARGET_FMT_lx " <%s>",
1092 mnemonic, reg_names[srca], tgt, lookup_symbol(tgt));
1094 return TILEGX_EXCP_NONE;
1097 static TileExcp gen_jump_opcode_x1(DisasContext *dc, unsigned ext,
1100 target_ulong tgt = dc->pc + off * TILEGX_BUNDLE_SIZE_IN_BYTES;
1101 const char *mnemonic;
1104 case JAL_JUMP_OPCODE_X1:
1105 case J_JUMP_OPCODE_X1:
1107 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1110 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1111 qemu_log("%s " TARGET_FMT_lx " <%s>",
1112 mnemonic, tgt, lookup_symbol(tgt));
1114 return TILEGX_EXCP_NONE;
1117 static TileExcp decode_y0(DisasContext *dc, tilegx_bundle_bits bundle)
1119 unsigned opc = get_Opcode_Y0(bundle);
1120 unsigned ext = get_RRROpcodeExtension_Y0(bundle);
1121 unsigned dest = get_Dest_Y0(bundle);
1122 unsigned srca = get_SrcA_Y0(bundle);
1127 case RRR_1_OPCODE_Y0:
1128 if (ext == UNARY_RRR_1_OPCODE_Y0) {
1129 ext = get_UnaryOpcodeExtension_Y0(bundle);
1130 return gen_rr_opcode(dc, OE(opc, ext, Y0), dest, srca);
1133 case RRR_0_OPCODE_Y0:
1134 case RRR_2_OPCODE_Y0:
1135 case RRR_3_OPCODE_Y0:
1136 case RRR_4_OPCODE_Y0:
1137 case RRR_5_OPCODE_Y0:
1138 case RRR_6_OPCODE_Y0:
1139 case RRR_7_OPCODE_Y0:
1140 case RRR_8_OPCODE_Y0:
1141 case RRR_9_OPCODE_Y0:
1142 srcb = get_SrcB_Y0(bundle);
1143 return gen_rrr_opcode(dc, OE(opc, ext, Y0), dest, srca, srcb);
1145 case SHIFT_OPCODE_Y0:
1146 ext = get_ShiftOpcodeExtension_Y0(bundle);
1147 imm = get_ShAmt_Y0(bundle);
1148 return gen_rri_opcode(dc, OE(opc, ext, Y0), dest, srca, imm);
1150 case ADDI_OPCODE_Y0:
1151 case ADDXI_OPCODE_Y0:
1152 case ANDI_OPCODE_Y0:
1153 case CMPEQI_OPCODE_Y0:
1154 case CMPLTSI_OPCODE_Y0:
1155 imm = (int8_t)get_Imm8_Y0(bundle);
1156 return gen_rri_opcode(dc, OE(opc, 0, Y0), dest, srca, imm);
1159 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1163 static TileExcp decode_y1(DisasContext *dc, tilegx_bundle_bits bundle)
1165 unsigned opc = get_Opcode_Y1(bundle);
1166 unsigned ext = get_RRROpcodeExtension_Y1(bundle);
1167 unsigned dest = get_Dest_Y1(bundle);
1168 unsigned srca = get_SrcA_Y1(bundle);
1172 switch (get_Opcode_Y1(bundle)) {
1173 case RRR_1_OPCODE_Y1:
1174 if (ext == UNARY_RRR_1_OPCODE_Y0) {
1175 ext = get_UnaryOpcodeExtension_Y1(bundle);
1176 return gen_rr_opcode(dc, OE(opc, ext, Y1), dest, srca);
1179 case RRR_0_OPCODE_Y1:
1180 case RRR_2_OPCODE_Y1:
1181 case RRR_3_OPCODE_Y1:
1182 case RRR_4_OPCODE_Y1:
1183 case RRR_5_OPCODE_Y1:
1184 case RRR_6_OPCODE_Y1:
1185 case RRR_7_OPCODE_Y1:
1186 srcb = get_SrcB_Y1(bundle);
1187 return gen_rrr_opcode(dc, OE(opc, ext, Y1), dest, srca, srcb);
1189 case SHIFT_OPCODE_Y1:
1190 ext = get_ShiftOpcodeExtension_Y1(bundle);
1191 imm = get_ShAmt_Y1(bundle);
1192 return gen_rri_opcode(dc, OE(opc, ext, Y1), dest, srca, imm);
1194 case ADDI_OPCODE_Y1:
1195 case ADDXI_OPCODE_Y1:
1196 case ANDI_OPCODE_Y1:
1197 case CMPEQI_OPCODE_Y1:
1198 case CMPLTSI_OPCODE_Y1:
1199 imm = (int8_t)get_Imm8_Y1(bundle);
1200 return gen_rri_opcode(dc, OE(opc, 0, Y1), dest, srca, imm);
1203 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1207 static TileExcp decode_y2(DisasContext *dc, tilegx_bundle_bits bundle)
1209 unsigned mode = get_Mode(bundle);
1210 unsigned opc = get_Opcode_Y2(bundle);
1211 unsigned srca = get_SrcA_Y2(bundle);
1212 unsigned srcbdest = get_SrcBDest_Y2(bundle);
1213 const char *mnemonic;
1216 switch (OEY2(opc, mode)) {
1217 case OEY2(LD1S_OPCODE_Y2, MODE_OPCODE_YA2):
1221 case OEY2(LD1U_OPCODE_Y2, MODE_OPCODE_YA2):
1225 case OEY2(LD2S_OPCODE_Y2, MODE_OPCODE_YA2):
1229 case OEY2(LD2U_OPCODE_Y2, MODE_OPCODE_YA2):
1233 case OEY2(LD4S_OPCODE_Y2, MODE_OPCODE_YB2):
1237 case OEY2(LD4U_OPCODE_Y2, MODE_OPCODE_YB2):
1241 case OEY2(LD_OPCODE_Y2, MODE_OPCODE_YB2):
1245 tcg_gen_qemu_ld_tl(dest_gr(dc, srcbdest), load_gr(dc, srca),
1247 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", mnemonic,
1248 reg_names[srcbdest], reg_names[srca]);
1249 return TILEGX_EXCP_NONE;
1251 case OEY2(ST1_OPCODE_Y2, MODE_OPCODE_YC2):
1252 return gen_st_opcode(dc, 0, srca, srcbdest, MO_UB, "st1");
1253 case OEY2(ST2_OPCODE_Y2, MODE_OPCODE_YC2):
1254 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEUW, "st2");
1255 case OEY2(ST4_OPCODE_Y2, MODE_OPCODE_YC2):
1256 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEUL, "st4");
1257 case OEY2(ST_OPCODE_Y2, MODE_OPCODE_YC2):
1258 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEQ, "st");
1261 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1265 static TileExcp decode_x0(DisasContext *dc, tilegx_bundle_bits bundle)
1267 unsigned opc = get_Opcode_X0(bundle);
1268 unsigned dest = get_Dest_X0(bundle);
1269 unsigned srca = get_SrcA_X0(bundle);
1270 unsigned ext, srcb, bfs, bfe;
1274 case RRR_0_OPCODE_X0:
1275 ext = get_RRROpcodeExtension_X0(bundle);
1276 if (ext == UNARY_RRR_0_OPCODE_X0) {
1277 ext = get_UnaryOpcodeExtension_X0(bundle);
1278 return gen_rr_opcode(dc, OE(opc, ext, X0), dest, srca);
1280 srcb = get_SrcB_X0(bundle);
1281 return gen_rrr_opcode(dc, OE(opc, ext, X0), dest, srca, srcb);
1283 case SHIFT_OPCODE_X0:
1284 ext = get_ShiftOpcodeExtension_X0(bundle);
1285 imm = get_ShAmt_X0(bundle);
1286 return gen_rri_opcode(dc, OE(opc, ext, X0), dest, srca, imm);
1288 case IMM8_OPCODE_X0:
1289 ext = get_Imm8OpcodeExtension_X0(bundle);
1290 imm = (int8_t)get_Imm8_X0(bundle);
1291 return gen_rri_opcode(dc, OE(opc, ext, X0), dest, srca, imm);
1294 ext = get_BFOpcodeExtension_X0(bundle);
1295 bfs = get_BFStart_X0(bundle);
1296 bfe = get_BFEnd_X0(bundle);
1297 return gen_bf_opcode_x0(dc, ext, dest, srca, bfs, bfe);
1299 case ADDLI_OPCODE_X0:
1300 case SHL16INSLI_OPCODE_X0:
1301 case ADDXLI_OPCODE_X0:
1302 imm = (int16_t)get_Imm16_X0(bundle);
1303 return gen_rri_opcode(dc, OE(opc, 0, X0), dest, srca, imm);
1306 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1310 static TileExcp decode_x1(DisasContext *dc, tilegx_bundle_bits bundle)
1312 unsigned opc = get_Opcode_X1(bundle);
1313 unsigned dest = get_Dest_X1(bundle);
1314 unsigned srca = get_SrcA_X1(bundle);
1319 case RRR_0_OPCODE_X1:
1320 ext = get_RRROpcodeExtension_X1(bundle);
1321 srcb = get_SrcB_X1(bundle);
1323 case UNARY_RRR_0_OPCODE_X1:
1324 ext = get_UnaryOpcodeExtension_X1(bundle);
1325 return gen_rr_opcode(dc, OE(opc, ext, X1), dest, srca);
1326 case ST1_RRR_0_OPCODE_X1:
1327 return gen_st_opcode(dc, dest, srca, srcb, MO_UB, "st1");
1328 case ST2_RRR_0_OPCODE_X1:
1329 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUW, "st2");
1330 case ST4_RRR_0_OPCODE_X1:
1331 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUL, "st4");
1332 case STNT1_RRR_0_OPCODE_X1:
1333 return gen_st_opcode(dc, dest, srca, srcb, MO_UB, "stnt1");
1334 case STNT2_RRR_0_OPCODE_X1:
1335 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUW, "stnt2");
1336 case STNT4_RRR_0_OPCODE_X1:
1337 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUL, "stnt4");
1338 case STNT_RRR_0_OPCODE_X1:
1339 return gen_st_opcode(dc, dest, srca, srcb, MO_TEQ, "stnt");
1340 case ST_RRR_0_OPCODE_X1:
1341 return gen_st_opcode(dc, dest, srca, srcb, MO_TEQ, "st");
1343 return gen_rrr_opcode(dc, OE(opc, ext, X1), dest, srca, srcb);
1345 case SHIFT_OPCODE_X1:
1346 ext = get_ShiftOpcodeExtension_X1(bundle);
1347 imm = get_ShAmt_X1(bundle);
1348 return gen_rri_opcode(dc, OE(opc, ext, X1), dest, srca, imm);
1350 case IMM8_OPCODE_X1:
1351 ext = get_Imm8OpcodeExtension_X1(bundle);
1352 imm = (int8_t)get_Dest_Imm8_X1(bundle);
1353 srcb = get_SrcB_X1(bundle);
1355 case ST1_ADD_IMM8_OPCODE_X1:
1356 return gen_st_add_opcode(dc, srca, srcb, imm, MO_UB, "st1_add");
1357 case ST2_ADD_IMM8_OPCODE_X1:
1358 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUW, "st2_add");
1359 case ST4_ADD_IMM8_OPCODE_X1:
1360 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUL, "st4_add");
1361 case STNT1_ADD_IMM8_OPCODE_X1:
1362 return gen_st_add_opcode(dc, srca, srcb, imm, MO_UB, "stnt1_add");
1363 case STNT2_ADD_IMM8_OPCODE_X1:
1364 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUW, "stnt2_add");
1365 case STNT4_ADD_IMM8_OPCODE_X1:
1366 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUL, "stnt4_add");
1367 case STNT_ADD_IMM8_OPCODE_X1:
1368 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEQ, "stnt_add");
1369 case ST_ADD_IMM8_OPCODE_X1:
1370 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEQ, "st_add");
1372 imm = (int8_t)get_Imm8_X1(bundle);
1373 return gen_rri_opcode(dc, OE(opc, ext, X1), dest, srca, imm);
1375 case BRANCH_OPCODE_X1:
1376 ext = get_BrType_X1(bundle);
1377 imm = sextract32(get_BrOff_X1(bundle), 0, 17);
1378 return gen_branch_opcode_x1(dc, ext, srca, imm);
1380 case JUMP_OPCODE_X1:
1381 ext = get_JumpOpcodeExtension_X1(bundle);
1382 imm = sextract32(get_JumpOff_X1(bundle), 0, 27);
1383 return gen_jump_opcode_x1(dc, ext, imm);
1385 case ADDLI_OPCODE_X1:
1386 case SHL16INSLI_OPCODE_X1:
1387 case ADDXLI_OPCODE_X1:
1388 imm = (int16_t)get_Imm16_X1(bundle);
1389 return gen_rri_opcode(dc, OE(opc, 0, X1), dest, srca, imm);
1392 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1396 static void notice_excp(DisasContext *dc, uint64_t bundle,
1397 const char *type, TileExcp excp)
1399 if (likely(excp == TILEGX_EXCP_NONE)) {
1402 gen_exception(dc, excp);
1403 if (excp == TILEGX_EXCP_OPCODE_UNIMPLEMENTED) {
1404 qemu_log_mask(LOG_UNIMP, "UNIMP %s, [" FMT64X "]\n", type, bundle);
1408 static void translate_one_bundle(DisasContext *dc, uint64_t bundle)
1412 for (i = 0; i < ARRAY_SIZE(dc->wb); i++) {
1413 DisasContextTemp *wb = &dc->wb[i];
1414 wb->reg = TILEGX_R_NOREG;
1415 TCGV_UNUSED_I64(wb->val);
1419 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
1420 tcg_gen_debug_insn_start(dc->pc);
1423 qemu_log_mask(CPU_LOG_TB_IN_ASM, " %" PRIx64 ": { ", dc->pc);
1424 if (get_Mode(bundle)) {
1425 notice_excp(dc, bundle, "y0", decode_y0(dc, bundle));
1426 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
1427 notice_excp(dc, bundle, "y1", decode_y1(dc, bundle));
1428 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
1429 notice_excp(dc, bundle, "y2", decode_y2(dc, bundle));
1431 notice_excp(dc, bundle, "x0", decode_x0(dc, bundle));
1432 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
1433 notice_excp(dc, bundle, "x1", decode_x1(dc, bundle));
1435 qemu_log_mask(CPU_LOG_TB_IN_ASM, " }\n");
1437 for (i = dc->num_wb - 1; i >= 0; --i) {
1438 DisasContextTemp *wb = &dc->wb[i];
1439 if (wb->reg < TILEGX_R_COUNT) {
1440 tcg_gen_mov_i64(cpu_regs[wb->reg], wb->val);
1442 tcg_temp_free_i64(wb->val);
1445 if (dc->jmp.cond != TCG_COND_NEVER) {
1446 if (dc->jmp.cond == TCG_COND_ALWAYS) {
1447 tcg_gen_mov_i64(cpu_pc, dc->jmp.dest);
1449 TCGv next = tcg_const_i64(dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
1450 tcg_gen_movcond_i64(dc->jmp.cond, cpu_pc,
1451 dc->jmp.val1, load_zero(dc),
1452 dc->jmp.dest, next);
1453 tcg_temp_free_i64(dc->jmp.val1);
1454 tcg_temp_free_i64(next);
1456 tcg_temp_free_i64(dc->jmp.dest);
1462 static inline void gen_intermediate_code_internal(TileGXCPU *cpu,
1463 TranslationBlock *tb,
1467 DisasContext *dc = &ctx;
1468 CPUState *cs = CPU(cpu);
1469 CPUTLGState *env = &cpu->env;
1470 uint64_t pc_start = tb->pc;
1471 uint64_t next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
1474 int max_insns = tb->cflags & CF_COUNT_MASK;
1478 dc->exit_tb = false;
1479 dc->jmp.cond = TCG_COND_NEVER;
1480 TCGV_UNUSED_I64(dc->jmp.dest);
1481 TCGV_UNUSED_I64(dc->jmp.val1);
1482 TCGV_UNUSED_I64(dc->zero);
1484 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1485 qemu_log("IN: %s\n", lookup_symbol(pc_start));
1488 max_insns = CF_COUNT_MASK;
1490 if (cs->singlestep_enabled || singlestep) {
1497 j = tcg_op_buf_count();
1501 tcg_ctx.gen_opc_instr_start[lj++] = 0;
1504 tcg_ctx.gen_opc_pc[lj] = dc->pc;
1505 tcg_ctx.gen_opc_instr_start[lj] = 1;
1506 tcg_ctx.gen_opc_icount[lj] = num_insns;
1508 translate_one_bundle(dc, cpu_ldq_data(env, dc->pc));
1511 /* PC updated and EXIT_TB/GOTO_TB/exception emitted. */
1514 dc->pc += TILEGX_BUNDLE_SIZE_IN_BYTES;
1515 if (++num_insns >= max_insns
1516 || dc->pc >= next_page_start
1517 || tcg_op_buf_full()) {
1518 /* Ending the TB due to TB size or page boundary. Set PC. */
1519 tcg_gen_movi_tl(cpu_pc, dc->pc);
1525 gen_tb_end(tb, num_insns);
1527 j = tcg_op_buf_count();
1530 tcg_ctx.gen_opc_instr_start[lj++] = 0;
1533 tb->size = dc->pc - pc_start;
1534 tb->icount = num_insns;
1537 qemu_log_mask(CPU_LOG_TB_IN_ASM, "\n");
1540 void gen_intermediate_code(CPUTLGState *env, struct TranslationBlock *tb)
1542 gen_intermediate_code_internal(tilegx_env_get_cpu(env), tb, false);
1545 void gen_intermediate_code_pc(CPUTLGState *env, struct TranslationBlock *tb)
1547 gen_intermediate_code_internal(tilegx_env_get_cpu(env), tb, true);
1550 void restore_state_to_opc(CPUTLGState *env, TranslationBlock *tb, int pc_pos)
1552 env->pc = tcg_ctx.gen_opc_pc[pc_pos];
1555 void tilegx_tcg_init(void)
1559 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
1560 cpu_pc = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUTLGState, pc), "pc");
1561 for (i = 0; i < TILEGX_R_COUNT; i++) {
1562 cpu_regs[i] = tcg_global_mem_new_i64(TCG_AREG0,
1563 offsetof(CPUTLGState, regs[i]),