1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 4 */ 5 #ifndef _ASM_INST_H 6 #define _ASM_INST_H 7 8 #include <linux/types.h> 9 #include <asm/asm.h> 10 11 #define INSN_NOP 0x03400000 12 #define INSN_BREAK 0x002a0000 13 14 #define ADDR_IMMMASK_LU52ID 0xFFF0000000000000 15 #define ADDR_IMMMASK_LU32ID 0x000FFFFF00000000 16 #define ADDR_IMMMASK_LU12IW 0x00000000FFFFF000 17 #define ADDR_IMMMASK_ADDU16ID 0x00000000FFFF0000 18 19 #define ADDR_IMMSHIFT_LU52ID 52 20 #define ADDR_IMMSHIFT_LU32ID 32 21 #define ADDR_IMMSHIFT_LU12IW 12 22 #define ADDR_IMMSHIFT_ADDU16ID 16 23 24 #define ADDR_IMM(addr, INSN) ((addr & ADDR_IMMMASK_##INSN) >> ADDR_IMMSHIFT_##INSN) 25 26 enum reg0i26_op { 27 b_op = 0x14, 28 bl_op = 0x15, 29 }; 30 31 enum reg1i20_op { 32 lu12iw_op = 0x0a, 33 lu32id_op = 0x0b, 34 pcaddi_op = 0x0c, 35 pcaddu12i_op = 0x0e, 36 pcaddu18i_op = 0x0f, 37 }; 38 39 enum reg1i21_op { 40 beqz_op = 0x10, 41 bnez_op = 0x11, 42 bceqz_op = 0x12, /* bits[9:8] = 0x00 */ 43 bcnez_op = 0x12, /* bits[9:8] = 0x01 */ 44 }; 45 46 enum reg2_op { 47 revb2h_op = 0x0c, 48 revb4h_op = 0x0d, 49 revb2w_op = 0x0e, 50 revbd_op = 0x0f, 51 revh2w_op = 0x10, 52 revhd_op = 0x11, 53 }; 54 55 enum reg2i5_op { 56 slliw_op = 0x81, 57 srliw_op = 0x89, 58 sraiw_op = 0x91, 59 }; 60 61 enum reg2i6_op { 62 sllid_op = 0x41, 63 srlid_op = 0x45, 64 sraid_op = 0x49, 65 }; 66 67 enum reg2i12_op { 68 addiw_op = 0x0a, 69 addid_op = 0x0b, 70 lu52id_op = 0x0c, 71 andi_op = 0x0d, 72 ori_op = 0x0e, 73 xori_op = 0x0f, 74 ldb_op = 0xa0, 75 ldh_op = 0xa1, 76 ldw_op = 0xa2, 77 ldd_op = 0xa3, 78 stb_op = 0xa4, 79 sth_op = 0xa5, 80 stw_op = 0xa6, 81 std_op = 0xa7, 82 ldbu_op = 0xa8, 83 ldhu_op = 0xa9, 84 ldwu_op = 0xaa, 85 flds_op = 0xac, 86 fsts_op = 0xad, 87 fldd_op = 0xae, 88 fstd_op = 0xaf, 89 }; 90 91 enum reg2i14_op { 92 llw_op = 0x20, 93 scw_op = 0x21, 94 lld_op = 0x22, 95 scd_op = 0x23, 96 ldptrw_op = 0x24, 97 stptrw_op = 0x25, 98 ldptrd_op = 0x26, 99 stptrd_op = 0x27, 100 }; 101 102 enum reg2i16_op { 103 jirl_op = 0x13, 104 beq_op = 0x16, 105 bne_op = 0x17, 106 blt_op = 0x18, 107 bge_op = 0x19, 108 bltu_op = 0x1a, 109 bgeu_op = 0x1b, 110 }; 111 112 enum reg2bstrd_op { 113 bstrinsd_op = 0x2, 114 bstrpickd_op = 0x3, 115 }; 116 117 enum reg3_op { 118 addw_op = 0x20, 119 addd_op = 0x21, 120 subw_op = 0x22, 121 subd_op = 0x23, 122 nor_op = 0x28, 123 and_op = 0x29, 124 or_op = 0x2a, 125 xor_op = 0x2b, 126 orn_op = 0x2c, 127 andn_op = 0x2d, 128 sllw_op = 0x2e, 129 srlw_op = 0x2f, 130 sraw_op = 0x30, 131 slld_op = 0x31, 132 srld_op = 0x32, 133 srad_op = 0x33, 134 mulw_op = 0x38, 135 mulhw_op = 0x39, 136 mulhwu_op = 0x3a, 137 muld_op = 0x3b, 138 mulhd_op = 0x3c, 139 mulhdu_op = 0x3d, 140 divw_op = 0x40, 141 modw_op = 0x41, 142 divwu_op = 0x42, 143 modwu_op = 0x43, 144 divd_op = 0x44, 145 modd_op = 0x45, 146 divdu_op = 0x46, 147 moddu_op = 0x47, 148 ldxb_op = 0x7000, 149 ldxh_op = 0x7008, 150 ldxw_op = 0x7010, 151 ldxd_op = 0x7018, 152 stxb_op = 0x7020, 153 stxh_op = 0x7028, 154 stxw_op = 0x7030, 155 stxd_op = 0x7038, 156 ldxbu_op = 0x7040, 157 ldxhu_op = 0x7048, 158 ldxwu_op = 0x7050, 159 fldxs_op = 0x7060, 160 fldxd_op = 0x7068, 161 fstxs_op = 0x7070, 162 fstxd_op = 0x7078, 163 amswapw_op = 0x70c0, 164 amswapd_op = 0x70c1, 165 amaddw_op = 0x70c2, 166 amaddd_op = 0x70c3, 167 amandw_op = 0x70c4, 168 amandd_op = 0x70c5, 169 amorw_op = 0x70c6, 170 amord_op = 0x70c7, 171 amxorw_op = 0x70c8, 172 amxord_op = 0x70c9, 173 }; 174 175 enum reg3sa2_op { 176 alslw_op = 0x02, 177 alslwu_op = 0x03, 178 alsld_op = 0x16, 179 }; 180 181 struct reg0i26_format { 182 unsigned int immediate_h : 10; 183 unsigned int immediate_l : 16; 184 unsigned int opcode : 6; 185 }; 186 187 struct reg1i20_format { 188 unsigned int rd : 5; 189 unsigned int immediate : 20; 190 unsigned int opcode : 7; 191 }; 192 193 struct reg1i21_format { 194 unsigned int immediate_h : 5; 195 unsigned int rj : 5; 196 unsigned int immediate_l : 16; 197 unsigned int opcode : 6; 198 }; 199 200 struct reg2_format { 201 unsigned int rd : 5; 202 unsigned int rj : 5; 203 unsigned int opcode : 22; 204 }; 205 206 struct reg2i5_format { 207 unsigned int rd : 5; 208 unsigned int rj : 5; 209 unsigned int immediate : 5; 210 unsigned int opcode : 17; 211 }; 212 213 struct reg2i6_format { 214 unsigned int rd : 5; 215 unsigned int rj : 5; 216 unsigned int immediate : 6; 217 unsigned int opcode : 16; 218 }; 219 220 struct reg2i12_format { 221 unsigned int rd : 5; 222 unsigned int rj : 5; 223 unsigned int immediate : 12; 224 unsigned int opcode : 10; 225 }; 226 227 struct reg2i14_format { 228 unsigned int rd : 5; 229 unsigned int rj : 5; 230 unsigned int immediate : 14; 231 unsigned int opcode : 8; 232 }; 233 234 struct reg2i16_format { 235 unsigned int rd : 5; 236 unsigned int rj : 5; 237 unsigned int immediate : 16; 238 unsigned int opcode : 6; 239 }; 240 241 struct reg2bstrd_format { 242 unsigned int rd : 5; 243 unsigned int rj : 5; 244 unsigned int lsbd : 6; 245 unsigned int msbd : 6; 246 unsigned int opcode : 10; 247 }; 248 249 struct reg3_format { 250 unsigned int rd : 5; 251 unsigned int rj : 5; 252 unsigned int rk : 5; 253 unsigned int opcode : 17; 254 }; 255 256 struct reg3sa2_format { 257 unsigned int rd : 5; 258 unsigned int rj : 5; 259 unsigned int rk : 5; 260 unsigned int immediate : 2; 261 unsigned int opcode : 15; 262 }; 263 264 union loongarch_instruction { 265 unsigned int word; 266 struct reg0i26_format reg0i26_format; 267 struct reg1i20_format reg1i20_format; 268 struct reg1i21_format reg1i21_format; 269 struct reg2_format reg2_format; 270 struct reg2i5_format reg2i5_format; 271 struct reg2i6_format reg2i6_format; 272 struct reg2i12_format reg2i12_format; 273 struct reg2i14_format reg2i14_format; 274 struct reg2i16_format reg2i16_format; 275 struct reg2bstrd_format reg2bstrd_format; 276 struct reg3_format reg3_format; 277 struct reg3sa2_format reg3sa2_format; 278 }; 279 280 #define LOONGARCH_INSN_SIZE sizeof(union loongarch_instruction) 281 282 enum loongarch_gpr { 283 LOONGARCH_GPR_ZERO = 0, 284 LOONGARCH_GPR_RA = 1, 285 LOONGARCH_GPR_TP = 2, 286 LOONGARCH_GPR_SP = 3, 287 LOONGARCH_GPR_A0 = 4, /* Reused as V0 for return value */ 288 LOONGARCH_GPR_A1, /* Reused as V1 for return value */ 289 LOONGARCH_GPR_A2, 290 LOONGARCH_GPR_A3, 291 LOONGARCH_GPR_A4, 292 LOONGARCH_GPR_A5, 293 LOONGARCH_GPR_A6, 294 LOONGARCH_GPR_A7, 295 LOONGARCH_GPR_T0 = 12, 296 LOONGARCH_GPR_T1, 297 LOONGARCH_GPR_T2, 298 LOONGARCH_GPR_T3, 299 LOONGARCH_GPR_T4, 300 LOONGARCH_GPR_T5, 301 LOONGARCH_GPR_T6, 302 LOONGARCH_GPR_T7, 303 LOONGARCH_GPR_T8, 304 LOONGARCH_GPR_FP = 22, 305 LOONGARCH_GPR_S0 = 23, 306 LOONGARCH_GPR_S1, 307 LOONGARCH_GPR_S2, 308 LOONGARCH_GPR_S3, 309 LOONGARCH_GPR_S4, 310 LOONGARCH_GPR_S5, 311 LOONGARCH_GPR_S6, 312 LOONGARCH_GPR_S7, 313 LOONGARCH_GPR_S8, 314 LOONGARCH_GPR_MAX 315 }; 316 317 #define is_imm12_negative(val) is_imm_negative(val, 12) 318 319 static inline bool is_imm_negative(unsigned long val, unsigned int bit) 320 { 321 return val & (1UL << (bit - 1)); 322 } 323 324 static inline bool is_pc_ins(union loongarch_instruction *ip) 325 { 326 return ip->reg1i20_format.opcode >= pcaddi_op && 327 ip->reg1i20_format.opcode <= pcaddu18i_op; 328 } 329 330 static inline bool is_branch_ins(union loongarch_instruction *ip) 331 { 332 return ip->reg1i21_format.opcode >= beqz_op && 333 ip->reg1i21_format.opcode <= bgeu_op; 334 } 335 336 static inline bool is_ra_save_ins(union loongarch_instruction *ip) 337 { 338 /* st.d $ra, $sp, offset */ 339 return ip->reg2i12_format.opcode == std_op && 340 ip->reg2i12_format.rj == LOONGARCH_GPR_SP && 341 ip->reg2i12_format.rd == LOONGARCH_GPR_RA && 342 !is_imm12_negative(ip->reg2i12_format.immediate); 343 } 344 345 static inline bool is_stack_alloc_ins(union loongarch_instruction *ip) 346 { 347 /* addi.d $sp, $sp, -imm */ 348 return ip->reg2i12_format.opcode == addid_op && 349 ip->reg2i12_format.rj == LOONGARCH_GPR_SP && 350 ip->reg2i12_format.rd == LOONGARCH_GPR_SP && 351 is_imm12_negative(ip->reg2i12_format.immediate); 352 } 353 354 int larch_insn_read(void *addr, u32 *insnp); 355 int larch_insn_write(void *addr, u32 insn); 356 int larch_insn_patch_text(void *addr, u32 insn); 357 358 u32 larch_insn_gen_nop(void); 359 u32 larch_insn_gen_b(unsigned long pc, unsigned long dest); 360 u32 larch_insn_gen_bl(unsigned long pc, unsigned long dest); 361 362 u32 larch_insn_gen_or(enum loongarch_gpr rd, enum loongarch_gpr rj, enum loongarch_gpr rk); 363 u32 larch_insn_gen_move(enum loongarch_gpr rd, enum loongarch_gpr rj); 364 365 u32 larch_insn_gen_lu12iw(enum loongarch_gpr rd, int imm); 366 u32 larch_insn_gen_lu32id(enum loongarch_gpr rd, int imm); 367 u32 larch_insn_gen_lu52id(enum loongarch_gpr rd, enum loongarch_gpr rj, int imm); 368 u32 larch_insn_gen_jirl(enum loongarch_gpr rd, enum loongarch_gpr rj, unsigned long pc, unsigned long dest); 369 370 static inline bool signed_imm_check(long val, unsigned int bit) 371 { 372 return -(1L << (bit - 1)) <= val && val < (1L << (bit - 1)); 373 } 374 375 static inline bool unsigned_imm_check(unsigned long val, unsigned int bit) 376 { 377 return val < (1UL << bit); 378 } 379 380 #define DEF_EMIT_REG0I26_FORMAT(NAME, OP) \ 381 static inline void emit_##NAME(union loongarch_instruction *insn, \ 382 int offset) \ 383 { \ 384 unsigned int immediate_l, immediate_h; \ 385 \ 386 immediate_l = offset & 0xffff; \ 387 offset >>= 16; \ 388 immediate_h = offset & 0x3ff; \ 389 \ 390 insn->reg0i26_format.opcode = OP; \ 391 insn->reg0i26_format.immediate_l = immediate_l; \ 392 insn->reg0i26_format.immediate_h = immediate_h; \ 393 } 394 395 DEF_EMIT_REG0I26_FORMAT(b, b_op) 396 DEF_EMIT_REG0I26_FORMAT(bl, bl_op) 397 398 #define DEF_EMIT_REG1I20_FORMAT(NAME, OP) \ 399 static inline void emit_##NAME(union loongarch_instruction *insn, \ 400 enum loongarch_gpr rd, int imm) \ 401 { \ 402 insn->reg1i20_format.opcode = OP; \ 403 insn->reg1i20_format.immediate = imm; \ 404 insn->reg1i20_format.rd = rd; \ 405 } 406 407 DEF_EMIT_REG1I20_FORMAT(lu12iw, lu12iw_op) 408 DEF_EMIT_REG1I20_FORMAT(lu32id, lu32id_op) 409 DEF_EMIT_REG1I20_FORMAT(pcaddu18i, pcaddu18i_op) 410 411 #define DEF_EMIT_REG2_FORMAT(NAME, OP) \ 412 static inline void emit_##NAME(union loongarch_instruction *insn, \ 413 enum loongarch_gpr rd, \ 414 enum loongarch_gpr rj) \ 415 { \ 416 insn->reg2_format.opcode = OP; \ 417 insn->reg2_format.rd = rd; \ 418 insn->reg2_format.rj = rj; \ 419 } 420 421 DEF_EMIT_REG2_FORMAT(revb2h, revb2h_op) 422 DEF_EMIT_REG2_FORMAT(revb2w, revb2w_op) 423 DEF_EMIT_REG2_FORMAT(revbd, revbd_op) 424 425 #define DEF_EMIT_REG2I5_FORMAT(NAME, OP) \ 426 static inline void emit_##NAME(union loongarch_instruction *insn, \ 427 enum loongarch_gpr rd, \ 428 enum loongarch_gpr rj, \ 429 int imm) \ 430 { \ 431 insn->reg2i5_format.opcode = OP; \ 432 insn->reg2i5_format.immediate = imm; \ 433 insn->reg2i5_format.rd = rd; \ 434 insn->reg2i5_format.rj = rj; \ 435 } 436 437 DEF_EMIT_REG2I5_FORMAT(slliw, slliw_op) 438 DEF_EMIT_REG2I5_FORMAT(srliw, srliw_op) 439 DEF_EMIT_REG2I5_FORMAT(sraiw, sraiw_op) 440 441 #define DEF_EMIT_REG2I6_FORMAT(NAME, OP) \ 442 static inline void emit_##NAME(union loongarch_instruction *insn, \ 443 enum loongarch_gpr rd, \ 444 enum loongarch_gpr rj, \ 445 int imm) \ 446 { \ 447 insn->reg2i6_format.opcode = OP; \ 448 insn->reg2i6_format.immediate = imm; \ 449 insn->reg2i6_format.rd = rd; \ 450 insn->reg2i6_format.rj = rj; \ 451 } 452 453 DEF_EMIT_REG2I6_FORMAT(sllid, sllid_op) 454 DEF_EMIT_REG2I6_FORMAT(srlid, srlid_op) 455 DEF_EMIT_REG2I6_FORMAT(sraid, sraid_op) 456 457 #define DEF_EMIT_REG2I12_FORMAT(NAME, OP) \ 458 static inline void emit_##NAME(union loongarch_instruction *insn, \ 459 enum loongarch_gpr rd, \ 460 enum loongarch_gpr rj, \ 461 int imm) \ 462 { \ 463 insn->reg2i12_format.opcode = OP; \ 464 insn->reg2i12_format.immediate = imm; \ 465 insn->reg2i12_format.rd = rd; \ 466 insn->reg2i12_format.rj = rj; \ 467 } 468 469 DEF_EMIT_REG2I12_FORMAT(addiw, addiw_op) 470 DEF_EMIT_REG2I12_FORMAT(addid, addid_op) 471 DEF_EMIT_REG2I12_FORMAT(lu52id, lu52id_op) 472 DEF_EMIT_REG2I12_FORMAT(andi, andi_op) 473 DEF_EMIT_REG2I12_FORMAT(ori, ori_op) 474 DEF_EMIT_REG2I12_FORMAT(xori, xori_op) 475 DEF_EMIT_REG2I12_FORMAT(ldbu, ldbu_op) 476 DEF_EMIT_REG2I12_FORMAT(ldhu, ldhu_op) 477 DEF_EMIT_REG2I12_FORMAT(ldwu, ldwu_op) 478 DEF_EMIT_REG2I12_FORMAT(ldd, ldd_op) 479 DEF_EMIT_REG2I12_FORMAT(stb, stb_op) 480 DEF_EMIT_REG2I12_FORMAT(sth, sth_op) 481 DEF_EMIT_REG2I12_FORMAT(stw, stw_op) 482 DEF_EMIT_REG2I12_FORMAT(std, std_op) 483 484 #define DEF_EMIT_REG2I14_FORMAT(NAME, OP) \ 485 static inline void emit_##NAME(union loongarch_instruction *insn, \ 486 enum loongarch_gpr rd, \ 487 enum loongarch_gpr rj, \ 488 int imm) \ 489 { \ 490 insn->reg2i14_format.opcode = OP; \ 491 insn->reg2i14_format.immediate = imm; \ 492 insn->reg2i14_format.rd = rd; \ 493 insn->reg2i14_format.rj = rj; \ 494 } 495 496 DEF_EMIT_REG2I14_FORMAT(llw, llw_op) 497 DEF_EMIT_REG2I14_FORMAT(scw, scw_op) 498 DEF_EMIT_REG2I14_FORMAT(lld, lld_op) 499 DEF_EMIT_REG2I14_FORMAT(scd, scd_op) 500 DEF_EMIT_REG2I14_FORMAT(ldptrw, ldptrw_op) 501 DEF_EMIT_REG2I14_FORMAT(stptrw, stptrw_op) 502 DEF_EMIT_REG2I14_FORMAT(ldptrd, ldptrd_op) 503 DEF_EMIT_REG2I14_FORMAT(stptrd, stptrd_op) 504 505 #define DEF_EMIT_REG2I16_FORMAT(NAME, OP) \ 506 static inline void emit_##NAME(union loongarch_instruction *insn, \ 507 enum loongarch_gpr rj, \ 508 enum loongarch_gpr rd, \ 509 int offset) \ 510 { \ 511 insn->reg2i16_format.opcode = OP; \ 512 insn->reg2i16_format.immediate = offset; \ 513 insn->reg2i16_format.rj = rj; \ 514 insn->reg2i16_format.rd = rd; \ 515 } 516 517 DEF_EMIT_REG2I16_FORMAT(beq, beq_op) 518 DEF_EMIT_REG2I16_FORMAT(bne, bne_op) 519 DEF_EMIT_REG2I16_FORMAT(blt, blt_op) 520 DEF_EMIT_REG2I16_FORMAT(bge, bge_op) 521 DEF_EMIT_REG2I16_FORMAT(bltu, bltu_op) 522 DEF_EMIT_REG2I16_FORMAT(bgeu, bgeu_op) 523 DEF_EMIT_REG2I16_FORMAT(jirl, jirl_op) 524 525 #define DEF_EMIT_REG2BSTRD_FORMAT(NAME, OP) \ 526 static inline void emit_##NAME(union loongarch_instruction *insn, \ 527 enum loongarch_gpr rd, \ 528 enum loongarch_gpr rj, \ 529 int msbd, \ 530 int lsbd) \ 531 { \ 532 insn->reg2bstrd_format.opcode = OP; \ 533 insn->reg2bstrd_format.msbd = msbd; \ 534 insn->reg2bstrd_format.lsbd = lsbd; \ 535 insn->reg2bstrd_format.rj = rj; \ 536 insn->reg2bstrd_format.rd = rd; \ 537 } 538 539 DEF_EMIT_REG2BSTRD_FORMAT(bstrpickd, bstrpickd_op) 540 541 #define DEF_EMIT_REG3_FORMAT(NAME, OP) \ 542 static inline void emit_##NAME(union loongarch_instruction *insn, \ 543 enum loongarch_gpr rd, \ 544 enum loongarch_gpr rj, \ 545 enum loongarch_gpr rk) \ 546 { \ 547 insn->reg3_format.opcode = OP; \ 548 insn->reg3_format.rd = rd; \ 549 insn->reg3_format.rj = rj; \ 550 insn->reg3_format.rk = rk; \ 551 } 552 553 DEF_EMIT_REG3_FORMAT(addd, addd_op) 554 DEF_EMIT_REG3_FORMAT(subd, subd_op) 555 DEF_EMIT_REG3_FORMAT(muld, muld_op) 556 DEF_EMIT_REG3_FORMAT(divdu, divdu_op) 557 DEF_EMIT_REG3_FORMAT(moddu, moddu_op) 558 DEF_EMIT_REG3_FORMAT(and, and_op) 559 DEF_EMIT_REG3_FORMAT(or, or_op) 560 DEF_EMIT_REG3_FORMAT(xor, xor_op) 561 DEF_EMIT_REG3_FORMAT(sllw, sllw_op) 562 DEF_EMIT_REG3_FORMAT(slld, slld_op) 563 DEF_EMIT_REG3_FORMAT(srlw, srlw_op) 564 DEF_EMIT_REG3_FORMAT(srld, srld_op) 565 DEF_EMIT_REG3_FORMAT(sraw, sraw_op) 566 DEF_EMIT_REG3_FORMAT(srad, srad_op) 567 DEF_EMIT_REG3_FORMAT(ldxbu, ldxbu_op) 568 DEF_EMIT_REG3_FORMAT(ldxhu, ldxhu_op) 569 DEF_EMIT_REG3_FORMAT(ldxwu, ldxwu_op) 570 DEF_EMIT_REG3_FORMAT(ldxd, ldxd_op) 571 DEF_EMIT_REG3_FORMAT(stxb, stxb_op) 572 DEF_EMIT_REG3_FORMAT(stxh, stxh_op) 573 DEF_EMIT_REG3_FORMAT(stxw, stxw_op) 574 DEF_EMIT_REG3_FORMAT(stxd, stxd_op) 575 DEF_EMIT_REG3_FORMAT(amaddw, amaddw_op) 576 DEF_EMIT_REG3_FORMAT(amaddd, amaddd_op) 577 DEF_EMIT_REG3_FORMAT(amandw, amandw_op) 578 DEF_EMIT_REG3_FORMAT(amandd, amandd_op) 579 DEF_EMIT_REG3_FORMAT(amorw, amorw_op) 580 DEF_EMIT_REG3_FORMAT(amord, amord_op) 581 DEF_EMIT_REG3_FORMAT(amxorw, amxorw_op) 582 DEF_EMIT_REG3_FORMAT(amxord, amxord_op) 583 DEF_EMIT_REG3_FORMAT(amswapw, amswapw_op) 584 DEF_EMIT_REG3_FORMAT(amswapd, amswapd_op) 585 586 #define DEF_EMIT_REG3SA2_FORMAT(NAME, OP) \ 587 static inline void emit_##NAME(union loongarch_instruction *insn, \ 588 enum loongarch_gpr rd, \ 589 enum loongarch_gpr rj, \ 590 enum loongarch_gpr rk, \ 591 int imm) \ 592 { \ 593 insn->reg3sa2_format.opcode = OP; \ 594 insn->reg3sa2_format.immediate = imm; \ 595 insn->reg3sa2_format.rd = rd; \ 596 insn->reg3sa2_format.rj = rj; \ 597 insn->reg3sa2_format.rk = rk; \ 598 } 599 600 DEF_EMIT_REG3SA2_FORMAT(alsld, alsld_op) 601 602 struct pt_regs; 603 604 void emulate_load_store_insn(struct pt_regs *regs, void __user *addr, unsigned int *pc); 605 unsigned long unaligned_read(void __user *addr, void *value, unsigned long n, bool sign); 606 unsigned long unaligned_write(void __user *addr, unsigned long value, unsigned long n); 607 608 #endif /* _ASM_INST_H */ 609