18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * A small micro-assembler. It is intentionally kept simple, does only 78c2ecf20Sopenharmony_ci * support a subset of instructions, and does not try to hide pipeline 88c2ecf20Sopenharmony_ci * effects like branch delay slots. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 2004, 2005, 2006, 2008 Thiemo Seufer 118c2ecf20Sopenharmony_ci * Copyright (C) 2005, 2007 Maciej W. Rozycki 128c2ecf20Sopenharmony_ci * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org) 138c2ecf20Sopenharmony_ci * Copyright (C) 2012, 2013 MIPS Technologies, Inc. All rights reserved. 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/kernel.h> 178c2ecf20Sopenharmony_ci#include <linux/types.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <asm/inst.h> 208c2ecf20Sopenharmony_ci#include <asm/elf.h> 218c2ecf20Sopenharmony_ci#include <asm/bugs.h> 228c2ecf20Sopenharmony_ci#include <asm/uasm.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define RS_MASK 0x1f 258c2ecf20Sopenharmony_ci#define RS_SH 21 268c2ecf20Sopenharmony_ci#define RT_MASK 0x1f 278c2ecf20Sopenharmony_ci#define RT_SH 16 288c2ecf20Sopenharmony_ci#define SCIMM_MASK 0xfffff 298c2ecf20Sopenharmony_ci#define SCIMM_SH 6 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* This macro sets the non-variable bits of an instruction. */ 328c2ecf20Sopenharmony_ci#define M(a, b, c, d, e, f) \ 338c2ecf20Sopenharmony_ci ((a) << OP_SH \ 348c2ecf20Sopenharmony_ci | (b) << RS_SH \ 358c2ecf20Sopenharmony_ci | (c) << RT_SH \ 368c2ecf20Sopenharmony_ci | (d) << RD_SH \ 378c2ecf20Sopenharmony_ci | (e) << RE_SH \ 388c2ecf20Sopenharmony_ci | (f) << FUNC_SH) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* This macro sets the non-variable bits of an R6 instruction. */ 418c2ecf20Sopenharmony_ci#define M6(a, b, c, d, e) \ 428c2ecf20Sopenharmony_ci ((a) << OP_SH \ 438c2ecf20Sopenharmony_ci | (b) << RS_SH \ 448c2ecf20Sopenharmony_ci | (c) << RT_SH \ 458c2ecf20Sopenharmony_ci | (d) << SIMM9_SH \ 468c2ecf20Sopenharmony_ci | (e) << FUNC_SH) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#include "uasm.c" 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic const struct insn insn_table[insn_invalid] = { 518c2ecf20Sopenharmony_ci [insn_addiu] = {M(addiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 528c2ecf20Sopenharmony_ci [insn_addu] = {M(spec_op, 0, 0, 0, 0, addu_op), RS | RT | RD}, 538c2ecf20Sopenharmony_ci [insn_and] = {M(spec_op, 0, 0, 0, 0, and_op), RS | RT | RD}, 548c2ecf20Sopenharmony_ci [insn_andi] = {M(andi_op, 0, 0, 0, 0, 0), RS | RT | UIMM}, 558c2ecf20Sopenharmony_ci [insn_bbit0] = {M(lwc2_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, 568c2ecf20Sopenharmony_ci [insn_bbit1] = {M(swc2_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, 578c2ecf20Sopenharmony_ci [insn_beq] = {M(beq_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, 588c2ecf20Sopenharmony_ci [insn_beql] = {M(beql_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, 598c2ecf20Sopenharmony_ci [insn_bgez] = {M(bcond_op, 0, bgez_op, 0, 0, 0), RS | BIMM}, 608c2ecf20Sopenharmony_ci [insn_bgezl] = {M(bcond_op, 0, bgezl_op, 0, 0, 0), RS | BIMM}, 618c2ecf20Sopenharmony_ci [insn_bgtz] = {M(bgtz_op, 0, 0, 0, 0, 0), RS | BIMM}, 628c2ecf20Sopenharmony_ci [insn_blez] = {M(blez_op, 0, 0, 0, 0, 0), RS | BIMM}, 638c2ecf20Sopenharmony_ci [insn_bltz] = {M(bcond_op, 0, bltz_op, 0, 0, 0), RS | BIMM}, 648c2ecf20Sopenharmony_ci [insn_bltzl] = {M(bcond_op, 0, bltzl_op, 0, 0, 0), RS | BIMM}, 658c2ecf20Sopenharmony_ci [insn_bne] = {M(bne_op, 0, 0, 0, 0, 0), RS | RT | BIMM}, 668c2ecf20Sopenharmony_ci [insn_break] = {M(spec_op, 0, 0, 0, 0, break_op), SCIMM}, 678c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 688c2ecf20Sopenharmony_ci [insn_cache] = {M(cache_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 698c2ecf20Sopenharmony_ci#else 708c2ecf20Sopenharmony_ci [insn_cache] = {M6(spec3_op, 0, 0, 0, cache6_op), RS | RT | SIMM9}, 718c2ecf20Sopenharmony_ci#endif 728c2ecf20Sopenharmony_ci [insn_cfc1] = {M(cop1_op, cfc_op, 0, 0, 0, 0), RT | RD}, 738c2ecf20Sopenharmony_ci [insn_cfcmsa] = {M(msa_op, 0, msa_cfc_op, 0, 0, msa_elm_op), RD | RE}, 748c2ecf20Sopenharmony_ci [insn_ctc1] = {M(cop1_op, ctc_op, 0, 0, 0, 0), RT | RD}, 758c2ecf20Sopenharmony_ci [insn_ctcmsa] = {M(msa_op, 0, msa_ctc_op, 0, 0, msa_elm_op), RD | RE}, 768c2ecf20Sopenharmony_ci [insn_daddiu] = {M(daddiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 778c2ecf20Sopenharmony_ci [insn_daddu] = {M(spec_op, 0, 0, 0, 0, daddu_op), RS | RT | RD}, 788c2ecf20Sopenharmony_ci [insn_ddivu] = {M(spec_op, 0, 0, 0, 0, ddivu_op), RS | RT}, 798c2ecf20Sopenharmony_ci [insn_ddivu_r6] = {M(spec_op, 0, 0, 0, ddivu_ddivu6_op, ddivu_op), 808c2ecf20Sopenharmony_ci RS | RT | RD}, 818c2ecf20Sopenharmony_ci [insn_di] = {M(cop0_op, mfmc0_op, 0, 12, 0, 0), RT}, 828c2ecf20Sopenharmony_ci [insn_dins] = {M(spec3_op, 0, 0, 0, 0, dins_op), RS | RT | RD | RE}, 838c2ecf20Sopenharmony_ci [insn_dinsm] = {M(spec3_op, 0, 0, 0, 0, dinsm_op), RS | RT | RD | RE}, 848c2ecf20Sopenharmony_ci [insn_dinsu] = {M(spec3_op, 0, 0, 0, 0, dinsu_op), RS | RT | RD | RE}, 858c2ecf20Sopenharmony_ci [insn_divu] = {M(spec_op, 0, 0, 0, 0, divu_op), RS | RT}, 868c2ecf20Sopenharmony_ci [insn_divu_r6] = {M(spec_op, 0, 0, 0, divu_divu6_op, divu_op), 878c2ecf20Sopenharmony_ci RS | RT | RD}, 888c2ecf20Sopenharmony_ci [insn_dmfc0] = {M(cop0_op, dmfc_op, 0, 0, 0, 0), RT | RD | SET}, 898c2ecf20Sopenharmony_ci [insn_dmodu] = {M(spec_op, 0, 0, 0, ddivu_dmodu_op, ddivu_op), 908c2ecf20Sopenharmony_ci RS | RT | RD}, 918c2ecf20Sopenharmony_ci [insn_dmtc0] = {M(cop0_op, dmtc_op, 0, 0, 0, 0), RT | RD | SET}, 928c2ecf20Sopenharmony_ci [insn_dmultu] = {M(spec_op, 0, 0, 0, 0, dmultu_op), RS | RT}, 938c2ecf20Sopenharmony_ci [insn_dmulu] = {M(spec_op, 0, 0, 0, dmult_dmul_op, dmultu_op), 948c2ecf20Sopenharmony_ci RS | RT | RD}, 958c2ecf20Sopenharmony_ci [insn_drotr] = {M(spec_op, 1, 0, 0, 0, dsrl_op), RT | RD | RE}, 968c2ecf20Sopenharmony_ci [insn_drotr32] = {M(spec_op, 1, 0, 0, 0, dsrl32_op), RT | RD | RE}, 978c2ecf20Sopenharmony_ci [insn_dsbh] = {M(spec3_op, 0, 0, 0, dsbh_op, dbshfl_op), RT | RD}, 988c2ecf20Sopenharmony_ci [insn_dshd] = {M(spec3_op, 0, 0, 0, dshd_op, dbshfl_op), RT | RD}, 998c2ecf20Sopenharmony_ci [insn_dsll] = {M(spec_op, 0, 0, 0, 0, dsll_op), RT | RD | RE}, 1008c2ecf20Sopenharmony_ci [insn_dsll32] = {M(spec_op, 0, 0, 0, 0, dsll32_op), RT | RD | RE}, 1018c2ecf20Sopenharmony_ci [insn_dsllv] = {M(spec_op, 0, 0, 0, 0, dsllv_op), RS | RT | RD}, 1028c2ecf20Sopenharmony_ci [insn_dsra] = {M(spec_op, 0, 0, 0, 0, dsra_op), RT | RD | RE}, 1038c2ecf20Sopenharmony_ci [insn_dsra32] = {M(spec_op, 0, 0, 0, 0, dsra32_op), RT | RD | RE}, 1048c2ecf20Sopenharmony_ci [insn_dsrav] = {M(spec_op, 0, 0, 0, 0, dsrav_op), RS | RT | RD}, 1058c2ecf20Sopenharmony_ci [insn_dsrl] = {M(spec_op, 0, 0, 0, 0, dsrl_op), RT | RD | RE}, 1068c2ecf20Sopenharmony_ci [insn_dsrl32] = {M(spec_op, 0, 0, 0, 0, dsrl32_op), RT | RD | RE}, 1078c2ecf20Sopenharmony_ci [insn_dsrlv] = {M(spec_op, 0, 0, 0, 0, dsrlv_op), RS | RT | RD}, 1088c2ecf20Sopenharmony_ci [insn_dsubu] = {M(spec_op, 0, 0, 0, 0, dsubu_op), RS | RT | RD}, 1098c2ecf20Sopenharmony_ci [insn_eret] = {M(cop0_op, cop_op, 0, 0, 0, eret_op), 0}, 1108c2ecf20Sopenharmony_ci [insn_ext] = {M(spec3_op, 0, 0, 0, 0, ext_op), RS | RT | RD | RE}, 1118c2ecf20Sopenharmony_ci [insn_ins] = {M(spec3_op, 0, 0, 0, 0, ins_op), RS | RT | RD | RE}, 1128c2ecf20Sopenharmony_ci [insn_j] = {M(j_op, 0, 0, 0, 0, 0), JIMM}, 1138c2ecf20Sopenharmony_ci [insn_jal] = {M(jal_op, 0, 0, 0, 0, 0), JIMM}, 1148c2ecf20Sopenharmony_ci [insn_jalr] = {M(spec_op, 0, 0, 0, 0, jalr_op), RS | RD}, 1158c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 1168c2ecf20Sopenharmony_ci [insn_jr] = {M(spec_op, 0, 0, 0, 0, jr_op), RS}, 1178c2ecf20Sopenharmony_ci#else 1188c2ecf20Sopenharmony_ci [insn_jr] = {M(spec_op, 0, 0, 0, 0, jalr_op), RS}, 1198c2ecf20Sopenharmony_ci#endif 1208c2ecf20Sopenharmony_ci [insn_lb] = {M(lb_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1218c2ecf20Sopenharmony_ci [insn_lbu] = {M(lbu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1228c2ecf20Sopenharmony_ci [insn_ld] = {M(ld_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1238c2ecf20Sopenharmony_ci [insn_lddir] = {M(lwc2_op, 0, 0, 0, lddir_op, mult_op), RS | RT | RD}, 1248c2ecf20Sopenharmony_ci [insn_ldpte] = {M(lwc2_op, 0, 0, 0, ldpte_op, mult_op), RS | RD}, 1258c2ecf20Sopenharmony_ci [insn_ldx] = {M(spec3_op, 0, 0, 0, ldx_op, lx_op), RS | RT | RD}, 1268c2ecf20Sopenharmony_ci [insn_lh] = {M(lh_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1278c2ecf20Sopenharmony_ci [insn_lhu] = {M(lhu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1288c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 1298c2ecf20Sopenharmony_ci [insn_ll] = {M(ll_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1308c2ecf20Sopenharmony_ci [insn_lld] = {M(lld_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1318c2ecf20Sopenharmony_ci#else 1328c2ecf20Sopenharmony_ci [insn_ll] = {M6(spec3_op, 0, 0, 0, ll6_op), RS | RT | SIMM9}, 1338c2ecf20Sopenharmony_ci [insn_lld] = {M6(spec3_op, 0, 0, 0, lld6_op), RS | RT | SIMM9}, 1348c2ecf20Sopenharmony_ci#endif 1358c2ecf20Sopenharmony_ci [insn_lui] = {M(lui_op, 0, 0, 0, 0, 0), RT | SIMM}, 1368c2ecf20Sopenharmony_ci [insn_lw] = {M(lw_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1378c2ecf20Sopenharmony_ci [insn_lwu] = {M(lwu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1388c2ecf20Sopenharmony_ci [insn_lwx] = {M(spec3_op, 0, 0, 0, lwx_op, lx_op), RS | RT | RD}, 1398c2ecf20Sopenharmony_ci [insn_mfc0] = {M(cop0_op, mfc_op, 0, 0, 0, 0), RT | RD | SET}, 1408c2ecf20Sopenharmony_ci [insn_mfhc0] = {M(cop0_op, mfhc0_op, 0, 0, 0, 0), RT | RD | SET}, 1418c2ecf20Sopenharmony_ci [insn_mfhi] = {M(spec_op, 0, 0, 0, 0, mfhi_op), RD}, 1428c2ecf20Sopenharmony_ci [insn_mflo] = {M(spec_op, 0, 0, 0, 0, mflo_op), RD}, 1438c2ecf20Sopenharmony_ci [insn_modu] = {M(spec_op, 0, 0, 0, divu_modu_op, divu_op), 1448c2ecf20Sopenharmony_ci RS | RT | RD}, 1458c2ecf20Sopenharmony_ci [insn_movn] = {M(spec_op, 0, 0, 0, 0, movn_op), RS | RT | RD}, 1468c2ecf20Sopenharmony_ci [insn_movz] = {M(spec_op, 0, 0, 0, 0, movz_op), RS | RT | RD}, 1478c2ecf20Sopenharmony_ci [insn_mtc0] = {M(cop0_op, mtc_op, 0, 0, 0, 0), RT | RD | SET}, 1488c2ecf20Sopenharmony_ci [insn_mthc0] = {M(cop0_op, mthc0_op, 0, 0, 0, 0), RT | RD | SET}, 1498c2ecf20Sopenharmony_ci [insn_mthi] = {M(spec_op, 0, 0, 0, 0, mthi_op), RS}, 1508c2ecf20Sopenharmony_ci [insn_mtlo] = {M(spec_op, 0, 0, 0, 0, mtlo_op), RS}, 1518c2ecf20Sopenharmony_ci [insn_mulu] = {M(spec_op, 0, 0, 0, multu_mulu_op, multu_op), 1528c2ecf20Sopenharmony_ci RS | RT | RD}, 1538c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 1548c2ecf20Sopenharmony_ci [insn_mul] = {M(spec2_op, 0, 0, 0, 0, mul_op), RS | RT | RD}, 1558c2ecf20Sopenharmony_ci#else 1568c2ecf20Sopenharmony_ci [insn_mul] = {M(spec_op, 0, 0, 0, mult_mul_op, mult_op), RS | RT | RD}, 1578c2ecf20Sopenharmony_ci#endif 1588c2ecf20Sopenharmony_ci [insn_multu] = {M(spec_op, 0, 0, 0, 0, multu_op), RS | RT}, 1598c2ecf20Sopenharmony_ci [insn_nor] = {M(spec_op, 0, 0, 0, 0, nor_op), RS | RT | RD}, 1608c2ecf20Sopenharmony_ci [insn_or] = {M(spec_op, 0, 0, 0, 0, or_op), RS | RT | RD}, 1618c2ecf20Sopenharmony_ci [insn_ori] = {M(ori_op, 0, 0, 0, 0, 0), RS | RT | UIMM}, 1628c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 1638c2ecf20Sopenharmony_ci [insn_pref] = {M(pref_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1648c2ecf20Sopenharmony_ci#else 1658c2ecf20Sopenharmony_ci [insn_pref] = {M6(spec3_op, 0, 0, 0, pref6_op), RS | RT | SIMM9}, 1668c2ecf20Sopenharmony_ci#endif 1678c2ecf20Sopenharmony_ci [insn_rfe] = {M(cop0_op, cop_op, 0, 0, 0, rfe_op), 0}, 1688c2ecf20Sopenharmony_ci [insn_rotr] = {M(spec_op, 1, 0, 0, 0, srl_op), RT | RD | RE}, 1698c2ecf20Sopenharmony_ci [insn_sb] = {M(sb_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1708c2ecf20Sopenharmony_ci#ifndef CONFIG_CPU_MIPSR6 1718c2ecf20Sopenharmony_ci [insn_sc] = {M(sc_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1728c2ecf20Sopenharmony_ci [insn_scd] = {M(scd_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1738c2ecf20Sopenharmony_ci#else 1748c2ecf20Sopenharmony_ci [insn_sc] = {M6(spec3_op, 0, 0, 0, sc6_op), RS | RT | SIMM9}, 1758c2ecf20Sopenharmony_ci [insn_scd] = {M6(spec3_op, 0, 0, 0, scd6_op), RS | RT | SIMM9}, 1768c2ecf20Sopenharmony_ci#endif 1778c2ecf20Sopenharmony_ci [insn_sd] = {M(sd_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1788c2ecf20Sopenharmony_ci [insn_seleqz] = {M(spec_op, 0, 0, 0, 0, seleqz_op), RS | RT | RD}, 1798c2ecf20Sopenharmony_ci [insn_selnez] = {M(spec_op, 0, 0, 0, 0, selnez_op), RS | RT | RD}, 1808c2ecf20Sopenharmony_ci [insn_sh] = {M(sh_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1818c2ecf20Sopenharmony_ci [insn_sll] = {M(spec_op, 0, 0, 0, 0, sll_op), RT | RD | RE}, 1828c2ecf20Sopenharmony_ci [insn_sllv] = {M(spec_op, 0, 0, 0, 0, sllv_op), RS | RT | RD}, 1838c2ecf20Sopenharmony_ci [insn_slt] = {M(spec_op, 0, 0, 0, 0, slt_op), RS | RT | RD}, 1848c2ecf20Sopenharmony_ci [insn_slti] = {M(slti_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1858c2ecf20Sopenharmony_ci [insn_sltiu] = {M(sltiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1868c2ecf20Sopenharmony_ci [insn_sltu] = {M(spec_op, 0, 0, 0, 0, sltu_op), RS | RT | RD}, 1878c2ecf20Sopenharmony_ci [insn_sra] = {M(spec_op, 0, 0, 0, 0, sra_op), RT | RD | RE}, 1888c2ecf20Sopenharmony_ci [insn_srav] = {M(spec_op, 0, 0, 0, 0, srav_op), RS | RT | RD}, 1898c2ecf20Sopenharmony_ci [insn_srl] = {M(spec_op, 0, 0, 0, 0, srl_op), RT | RD | RE}, 1908c2ecf20Sopenharmony_ci [insn_srlv] = {M(spec_op, 0, 0, 0, 0, srlv_op), RS | RT | RD}, 1918c2ecf20Sopenharmony_ci [insn_subu] = {M(spec_op, 0, 0, 0, 0, subu_op), RS | RT | RD}, 1928c2ecf20Sopenharmony_ci [insn_sw] = {M(sw_op, 0, 0, 0, 0, 0), RS | RT | SIMM}, 1938c2ecf20Sopenharmony_ci [insn_sync] = {M(spec_op, 0, 0, 0, 0, sync_op), RE}, 1948c2ecf20Sopenharmony_ci [insn_syscall] = {M(spec_op, 0, 0, 0, 0, syscall_op), SCIMM}, 1958c2ecf20Sopenharmony_ci [insn_tlbp] = {M(cop0_op, cop_op, 0, 0, 0, tlbp_op), 0}, 1968c2ecf20Sopenharmony_ci [insn_tlbr] = {M(cop0_op, cop_op, 0, 0, 0, tlbr_op), 0}, 1978c2ecf20Sopenharmony_ci [insn_tlbwi] = {M(cop0_op, cop_op, 0, 0, 0, tlbwi_op), 0}, 1988c2ecf20Sopenharmony_ci [insn_tlbwr] = {M(cop0_op, cop_op, 0, 0, 0, tlbwr_op), 0}, 1998c2ecf20Sopenharmony_ci [insn_wait] = {M(cop0_op, cop_op, 0, 0, 0, wait_op), SCIMM}, 2008c2ecf20Sopenharmony_ci [insn_wsbh] = {M(spec3_op, 0, 0, 0, wsbh_op, bshfl_op), RT | RD}, 2018c2ecf20Sopenharmony_ci [insn_xor] = {M(spec_op, 0, 0, 0, 0, xor_op), RS | RT | RD}, 2028c2ecf20Sopenharmony_ci [insn_xori] = {M(xori_op, 0, 0, 0, 0, 0), RS | RT | UIMM}, 2038c2ecf20Sopenharmony_ci [insn_yield] = {M(spec3_op, 0, 0, 0, 0, yield_op), RS | RD}, 2048c2ecf20Sopenharmony_ci}; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci#undef M 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic inline u32 build_bimm(s32 arg) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci WARN(arg > 0x1ffff || arg < -0x20000, 2118c2ecf20Sopenharmony_ci KERN_WARNING "Micro-assembler field overflow\n"); 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci WARN(arg & 0x3, KERN_WARNING "Invalid micro-assembler branch target\n"); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci return ((arg < 0) ? (1 << 15) : 0) | ((arg >> 2) & 0x7fff); 2168c2ecf20Sopenharmony_ci} 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_cistatic inline u32 build_jimm(u32 arg) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci WARN(arg & ~(JIMM_MASK << 2), 2218c2ecf20Sopenharmony_ci KERN_WARNING "Micro-assembler field overflow\n"); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci return (arg >> 2) & JIMM_MASK; 2248c2ecf20Sopenharmony_ci} 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci/* 2278c2ecf20Sopenharmony_ci * The order of opcode arguments is implicitly left to right, 2288c2ecf20Sopenharmony_ci * starting with RS and ending with FUNC or IMM. 2298c2ecf20Sopenharmony_ci */ 2308c2ecf20Sopenharmony_cistatic void build_insn(u32 **buf, enum opcode opc, ...) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci const struct insn *ip; 2338c2ecf20Sopenharmony_ci va_list ap; 2348c2ecf20Sopenharmony_ci u32 op; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci if (opc < 0 || opc >= insn_invalid || 2378c2ecf20Sopenharmony_ci (opc == insn_daddiu && r4k_daddiu_bug()) || 2388c2ecf20Sopenharmony_ci (insn_table[opc].match == 0 && insn_table[opc].fields == 0)) 2398c2ecf20Sopenharmony_ci panic("Unsupported Micro-assembler instruction %d", opc); 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci ip = &insn_table[opc]; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci op = ip->match; 2448c2ecf20Sopenharmony_ci va_start(ap, opc); 2458c2ecf20Sopenharmony_ci if (ip->fields & RS) 2468c2ecf20Sopenharmony_ci op |= build_rs(va_arg(ap, u32)); 2478c2ecf20Sopenharmony_ci if (ip->fields & RT) 2488c2ecf20Sopenharmony_ci op |= build_rt(va_arg(ap, u32)); 2498c2ecf20Sopenharmony_ci if (ip->fields & RD) 2508c2ecf20Sopenharmony_ci op |= build_rd(va_arg(ap, u32)); 2518c2ecf20Sopenharmony_ci if (ip->fields & RE) 2528c2ecf20Sopenharmony_ci op |= build_re(va_arg(ap, u32)); 2538c2ecf20Sopenharmony_ci if (ip->fields & SIMM) 2548c2ecf20Sopenharmony_ci op |= build_simm(va_arg(ap, s32)); 2558c2ecf20Sopenharmony_ci if (ip->fields & UIMM) 2568c2ecf20Sopenharmony_ci op |= build_uimm(va_arg(ap, u32)); 2578c2ecf20Sopenharmony_ci if (ip->fields & BIMM) 2588c2ecf20Sopenharmony_ci op |= build_bimm(va_arg(ap, s32)); 2598c2ecf20Sopenharmony_ci if (ip->fields & JIMM) 2608c2ecf20Sopenharmony_ci op |= build_jimm(va_arg(ap, u32)); 2618c2ecf20Sopenharmony_ci if (ip->fields & FUNC) 2628c2ecf20Sopenharmony_ci op |= build_func(va_arg(ap, u32)); 2638c2ecf20Sopenharmony_ci if (ip->fields & SET) 2648c2ecf20Sopenharmony_ci op |= build_set(va_arg(ap, u32)); 2658c2ecf20Sopenharmony_ci if (ip->fields & SCIMM) 2668c2ecf20Sopenharmony_ci op |= build_scimm(va_arg(ap, u32)); 2678c2ecf20Sopenharmony_ci if (ip->fields & SIMM9) 2688c2ecf20Sopenharmony_ci op |= build_scimm9(va_arg(ap, u32)); 2698c2ecf20Sopenharmony_ci va_end(ap); 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci **buf = op; 2728c2ecf20Sopenharmony_ci (*buf)++; 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_cistatic inline void 2768c2ecf20Sopenharmony_ci__resolve_relocs(struct uasm_reloc *rel, struct uasm_label *lab) 2778c2ecf20Sopenharmony_ci{ 2788c2ecf20Sopenharmony_ci long laddr = (long)lab->addr; 2798c2ecf20Sopenharmony_ci long raddr = (long)rel->addr; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci switch (rel->type) { 2828c2ecf20Sopenharmony_ci case R_MIPS_PC16: 2838c2ecf20Sopenharmony_ci *rel->addr |= build_bimm(laddr - (raddr + 4)); 2848c2ecf20Sopenharmony_ci break; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci default: 2878c2ecf20Sopenharmony_ci panic("Unsupported Micro-assembler relocation %d", 2888c2ecf20Sopenharmony_ci rel->type); 2898c2ecf20Sopenharmony_ci } 2908c2ecf20Sopenharmony_ci} 291