0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef __ASM_UASM_H
0013 #define __ASM_UASM_H
0014
0015 #include <linux/types.h>
0016
0017 #ifdef CONFIG_EXPORT_UASM
0018 #include <linux/export.h>
0019 #define UASM_EXPORT_SYMBOL(sym) EXPORT_SYMBOL(sym)
0020 #else
0021 #define UASM_EXPORT_SYMBOL(sym)
0022 #endif
0023
0024 #define Ip_u1u2u3(op) \
0025 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, unsigned int c)
0026
0027 #define Ip_u2u1u3(op) \
0028 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, unsigned int c)
0029
0030 #define Ip_u3u2u1(op) \
0031 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, unsigned int c)
0032
0033 #define Ip_u3u1u2(op) \
0034 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, unsigned int c)
0035
0036 #define Ip_u1u2s3(op) \
0037 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, signed int c)
0038
0039 #define Ip_u2s3u1(op) \
0040 void uasm_i##op(u32 **buf, unsigned int a, signed int b, unsigned int c)
0041
0042 #define Ip_s3s1s2(op) \
0043 void uasm_i##op(u32 **buf, int a, int b, int c)
0044
0045 #define Ip_u2u1s3(op) \
0046 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, signed int c)
0047
0048 #define Ip_u2u1msbu3(op) \
0049 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b, unsigned int c, \
0050 unsigned int d)
0051
0052 #define Ip_u1u2(op) \
0053 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b)
0054
0055 #define Ip_u2u1(op) \
0056 void uasm_i##op(u32 **buf, unsigned int a, unsigned int b)
0057
0058 #define Ip_u1s2(op) \
0059 void uasm_i##op(u32 **buf, unsigned int a, signed int b)
0060
0061 #define Ip_u1(op) void uasm_i##op(u32 **buf, unsigned int a)
0062
0063 #define Ip_0(op) void uasm_i##op(u32 **buf)
0064
0065 Ip_u2u1s3(_addiu);
0066 Ip_u3u1u2(_addu);
0067 Ip_u3u1u2(_and);
0068 Ip_u2u1u3(_andi);
0069 Ip_u1u2s3(_bbit0);
0070 Ip_u1u2s3(_bbit1);
0071 Ip_u1u2s3(_beq);
0072 Ip_u1u2s3(_beql);
0073 Ip_u1s2(_bgez);
0074 Ip_u1s2(_bgezl);
0075 Ip_u1s2(_bgtz);
0076 Ip_u1s2(_blez);
0077 Ip_u1s2(_bltz);
0078 Ip_u1s2(_bltzl);
0079 Ip_u1u2s3(_bne);
0080 Ip_u1(_break);
0081 Ip_u2s3u1(_cache);
0082 Ip_u1u2(_cfc1);
0083 Ip_u2u1(_cfcmsa);
0084 Ip_u1u2(_ctc1);
0085 Ip_u2u1(_ctcmsa);
0086 Ip_u2u1s3(_daddiu);
0087 Ip_u3u1u2(_daddu);
0088 Ip_u1u2(_ddivu);
0089 Ip_u3u1u2(_ddivu_r6);
0090 Ip_u1(_di);
0091 Ip_u2u1msbu3(_dins);
0092 Ip_u2u1msbu3(_dinsm);
0093 Ip_u2u1msbu3(_dinsu);
0094 Ip_u1u2(_divu);
0095 Ip_u3u1u2(_divu_r6);
0096 Ip_u1u2u3(_dmfc0);
0097 Ip_u3u1u2(_dmodu);
0098 Ip_u1u2u3(_dmtc0);
0099 Ip_u1u2(_dmultu);
0100 Ip_u3u1u2(_dmulu);
0101 Ip_u2u1u3(_drotr);
0102 Ip_u2u1u3(_drotr32);
0103 Ip_u2u1(_dsbh);
0104 Ip_u2u1(_dshd);
0105 Ip_u2u1u3(_dsll);
0106 Ip_u2u1u3(_dsll32);
0107 Ip_u3u2u1(_dsllv);
0108 Ip_u2u1u3(_dsra);
0109 Ip_u2u1u3(_dsra32);
0110 Ip_u3u2u1(_dsrav);
0111 Ip_u2u1u3(_dsrl);
0112 Ip_u2u1u3(_dsrl32);
0113 Ip_u3u2u1(_dsrlv);
0114 Ip_u3u1u2(_dsubu);
0115 Ip_0(_eret);
0116 Ip_u2u1msbu3(_ext);
0117 Ip_u2u1msbu3(_ins);
0118 Ip_u1(_j);
0119 Ip_u1(_jal);
0120 Ip_u2u1(_jalr);
0121 Ip_u1(_jr);
0122 Ip_u2s3u1(_lb);
0123 Ip_u2s3u1(_lbu);
0124 Ip_u2s3u1(_ld);
0125 Ip_u3u1u2(_ldx);
0126 Ip_u2s3u1(_lh);
0127 Ip_u2s3u1(_lhu);
0128 Ip_u2s3u1(_ll);
0129 Ip_u2s3u1(_lld);
0130 Ip_u1s2(_lui);
0131 Ip_u2s3u1(_lw);
0132 Ip_u2s3u1(_lwu);
0133 Ip_u3u1u2(_lwx);
0134 Ip_u1u2u3(_mfc0);
0135 Ip_u1u2u3(_mfhc0);
0136 Ip_u1(_mfhi);
0137 Ip_u1(_mflo);
0138 Ip_u3u1u2(_modu);
0139 Ip_u3u1u2(_movn);
0140 Ip_u3u1u2(_movz);
0141 Ip_u1u2u3(_mtc0);
0142 Ip_u1u2u3(_mthc0);
0143 Ip_u1(_mthi);
0144 Ip_u1(_mtlo);
0145 Ip_u3u1u2(_mul);
0146 Ip_u1u2(_multu);
0147 Ip_u3u1u2(_mulu);
0148 Ip_u3u1u2(_muhu);
0149 Ip_u3u1u2(_nor);
0150 Ip_u3u1u2(_or);
0151 Ip_u2u1u3(_ori);
0152 Ip_u2s3u1(_pref);
0153 Ip_0(_rfe);
0154 Ip_u2u1u3(_rotr);
0155 Ip_u2s3u1(_sb);
0156 Ip_u2s3u1(_sc);
0157 Ip_u2s3u1(_scd);
0158 Ip_u2s3u1(_sd);
0159 Ip_u3u1u2(_seleqz);
0160 Ip_u3u1u2(_selnez);
0161 Ip_u2s3u1(_sh);
0162 Ip_u2u1u3(_sll);
0163 Ip_u3u2u1(_sllv);
0164 Ip_s3s1s2(_slt);
0165 Ip_u2u1s3(_slti);
0166 Ip_u2u1s3(_sltiu);
0167 Ip_u3u1u2(_sltu);
0168 Ip_u2u1u3(_sra);
0169 Ip_u3u2u1(_srav);
0170 Ip_u2u1u3(_srl);
0171 Ip_u3u2u1(_srlv);
0172 Ip_u3u1u2(_subu);
0173 Ip_u2s3u1(_sw);
0174 Ip_u1(_sync);
0175 Ip_u1(_syscall);
0176 Ip_0(_tlbp);
0177 Ip_0(_tlbr);
0178 Ip_0(_tlbwi);
0179 Ip_0(_tlbwr);
0180 Ip_u1(_wait);
0181 Ip_u2u1(_wsbh);
0182 Ip_u3u1u2(_xor);
0183 Ip_u2u1u3(_xori);
0184 Ip_u2u1(_yield);
0185 Ip_u1u2(_ldpte);
0186 Ip_u2u1u3(_lddir);
0187
0188
0189 struct uasm_label {
0190 u32 *addr;
0191 int lab;
0192 };
0193
0194 void uasm_build_label(struct uasm_label **lab, u32 *addr,
0195 int lid);
0196 #ifdef CONFIG_64BIT
0197 int uasm_in_compat_space_p(long addr);
0198 #endif
0199 int uasm_rel_hi(long val);
0200 int uasm_rel_lo(long val);
0201 void UASM_i_LA_mostly(u32 **buf, unsigned int rs, long addr);
0202 void UASM_i_LA(u32 **buf, unsigned int rs, long addr);
0203
0204 #define UASM_L_LA(lb) \
0205 static inline void uasm_l##lb(struct uasm_label **lab, u32 *addr) \
0206 { \
0207 uasm_build_label(lab, addr, label##lb); \
0208 }
0209
0210
0211 #ifdef CONFIG_64BIT
0212 # define UASM_i_ADDIU(buf, rs, rt, val) uasm_i_daddiu(buf, rs, rt, val)
0213 # define UASM_i_ADDU(buf, rs, rt, rd) uasm_i_daddu(buf, rs, rt, rd)
0214 # define UASM_i_LL(buf, rs, rt, off) uasm_i_lld(buf, rs, rt, off)
0215 # define UASM_i_LW(buf, rs, rt, off) uasm_i_ld(buf, rs, rt, off)
0216 # define UASM_i_LWX(buf, rs, rt, rd) uasm_i_ldx(buf, rs, rt, rd)
0217 # define UASM_i_MFC0(buf, rt, rd...) uasm_i_dmfc0(buf, rt, rd)
0218 # define UASM_i_MTC0(buf, rt, rd...) uasm_i_dmtc0(buf, rt, rd)
0219 # define UASM_i_ROTR(buf, rs, rt, sh) uasm_i_drotr(buf, rs, rt, sh)
0220 # define UASM_i_SC(buf, rs, rt, off) uasm_i_scd(buf, rs, rt, off)
0221 # define UASM_i_SLL(buf, rs, rt, sh) uasm_i_dsll(buf, rs, rt, sh)
0222 # define UASM_i_SRA(buf, rs, rt, sh) uasm_i_dsra(buf, rs, rt, sh)
0223 # define UASM_i_SRL(buf, rs, rt, sh) uasm_i_dsrl(buf, rs, rt, sh)
0224 # define UASM_i_SRL_SAFE(buf, rs, rt, sh) uasm_i_dsrl_safe(buf, rs, rt, sh)
0225 # define UASM_i_SUBU(buf, rs, rt, rd) uasm_i_dsubu(buf, rs, rt, rd)
0226 # define UASM_i_SW(buf, rs, rt, off) uasm_i_sd(buf, rs, rt, off)
0227 #else
0228 # define UASM_i_ADDIU(buf, rs, rt, val) uasm_i_addiu(buf, rs, rt, val)
0229 # define UASM_i_ADDU(buf, rs, rt, rd) uasm_i_addu(buf, rs, rt, rd)
0230 # define UASM_i_LL(buf, rs, rt, off) uasm_i_ll(buf, rs, rt, off)
0231 # define UASM_i_LW(buf, rs, rt, off) uasm_i_lw(buf, rs, rt, off)
0232 # define UASM_i_LWX(buf, rs, rt, rd) uasm_i_lwx(buf, rs, rt, rd)
0233 # define UASM_i_MFC0(buf, rt, rd...) uasm_i_mfc0(buf, rt, rd)
0234 # define UASM_i_MTC0(buf, rt, rd...) uasm_i_mtc0(buf, rt, rd)
0235 # define UASM_i_ROTR(buf, rs, rt, sh) uasm_i_rotr(buf, rs, rt, sh)
0236 # define UASM_i_SC(buf, rs, rt, off) uasm_i_sc(buf, rs, rt, off)
0237 # define UASM_i_SLL(buf, rs, rt, sh) uasm_i_sll(buf, rs, rt, sh)
0238 # define UASM_i_SRA(buf, rs, rt, sh) uasm_i_sra(buf, rs, rt, sh)
0239 # define UASM_i_SRL(buf, rs, rt, sh) uasm_i_srl(buf, rs, rt, sh)
0240 # define UASM_i_SRL_SAFE(buf, rs, rt, sh) uasm_i_srl(buf, rs, rt, sh)
0241 # define UASM_i_SUBU(buf, rs, rt, rd) uasm_i_subu(buf, rs, rt, rd)
0242 # define UASM_i_SW(buf, rs, rt, off) uasm_i_sw(buf, rs, rt, off)
0243 #endif
0244
0245 #define uasm_i_b(buf, off) uasm_i_beq(buf, 0, 0, off)
0246 #define uasm_i_beqz(buf, rs, off) uasm_i_beq(buf, rs, 0, off)
0247 #define uasm_i_beqzl(buf, rs, off) uasm_i_beql(buf, rs, 0, off)
0248 #define uasm_i_bnez(buf, rs, off) uasm_i_bne(buf, rs, 0, off)
0249 #define uasm_i_bnezl(buf, rs, off) uasm_i_bnel(buf, rs, 0, off)
0250 #define uasm_i_ehb(buf) uasm_i_sll(buf, 0, 0, 3)
0251 #define uasm_i_move(buf, a, b) UASM_i_ADDU(buf, a, 0, b)
0252 #ifdef CONFIG_CPU_NOP_WORKAROUNDS
0253 #define uasm_i_nop(buf) uasm_i_or(buf, 1, 1, 0)
0254 #else
0255 #define uasm_i_nop(buf) uasm_i_sll(buf, 0, 0, 0)
0256 #endif
0257 #define uasm_i_ssnop(buf) uasm_i_sll(buf, 0, 0, 1)
0258
0259 static inline void uasm_i_drotr_safe(u32 **p, unsigned int a1,
0260 unsigned int a2, unsigned int a3)
0261 {
0262 if (a3 < 32)
0263 uasm_i_drotr(p, a1, a2, a3);
0264 else
0265 uasm_i_drotr32(p, a1, a2, a3 - 32);
0266 }
0267
0268 static inline void uasm_i_dsll_safe(u32 **p, unsigned int a1,
0269 unsigned int a2, unsigned int a3)
0270 {
0271 if (a3 < 32)
0272 uasm_i_dsll(p, a1, a2, a3);
0273 else
0274 uasm_i_dsll32(p, a1, a2, a3 - 32);
0275 }
0276
0277 static inline void uasm_i_dsrl_safe(u32 **p, unsigned int a1,
0278 unsigned int a2, unsigned int a3)
0279 {
0280 if (a3 < 32)
0281 uasm_i_dsrl(p, a1, a2, a3);
0282 else
0283 uasm_i_dsrl32(p, a1, a2, a3 - 32);
0284 }
0285
0286 static inline void uasm_i_dsra_safe(u32 **p, unsigned int a1,
0287 unsigned int a2, unsigned int a3)
0288 {
0289 if (a3 < 32)
0290 uasm_i_dsra(p, a1, a2, a3);
0291 else
0292 uasm_i_dsra32(p, a1, a2, a3 - 32);
0293 }
0294
0295
0296 struct uasm_reloc {
0297 u32 *addr;
0298 unsigned int type;
0299 int lab;
0300 };
0301
0302
0303 #define UASM_LABEL_INVALID 0
0304
0305 void uasm_r_mips_pc16(struct uasm_reloc **rel, u32 *addr, int lid);
0306 void uasm_resolve_relocs(struct uasm_reloc *rel, struct uasm_label *lab);
0307 void uasm_move_relocs(struct uasm_reloc *rel, u32 *first, u32 *end, long off);
0308 void uasm_move_labels(struct uasm_label *lab, u32 *first, u32 *end, long off);
0309 void uasm_copy_handler(struct uasm_reloc *rel, struct uasm_label *lab,
0310 u32 *first, u32 *end, u32 *target);
0311 int uasm_insn_has_bdelay(struct uasm_reloc *rel, u32 *addr);
0312
0313
0314 void uasm_il_b(u32 **p, struct uasm_reloc **r, int lid);
0315 void uasm_il_bbit0(u32 **p, struct uasm_reloc **r, unsigned int reg,
0316 unsigned int bit, int lid);
0317 void uasm_il_bbit1(u32 **p, struct uasm_reloc **r, unsigned int reg,
0318 unsigned int bit, int lid);
0319 void uasm_il_beq(u32 **p, struct uasm_reloc **r, unsigned int r1,
0320 unsigned int r2, int lid);
0321 void uasm_il_beqz(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0322 void uasm_il_beqzl(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0323 void uasm_il_bgezl(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0324 void uasm_il_bgez(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0325 void uasm_il_bltz(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0326 void uasm_il_bne(u32 **p, struct uasm_reloc **r, unsigned int reg1,
0327 unsigned int reg2, int lid);
0328 void uasm_il_bnez(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid);
0329
0330 #endif