Path: blob/master/tools/arch/loongarch/include/asm/inst.h
29289 views
/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2020-2022 Loongson Technology Corporation Limited3*/4#ifndef _ASM_INST_H5#define _ASM_INST_H67#include <linux/bitops.h>89#define LOONGARCH_INSN_NOP 0x034000001011enum reg0i15_op {12break_op = 0x54,13};1415enum reg0i26_op {16b_op = 0x14,17bl_op = 0x15,18};1920enum reg1i21_op {21beqz_op = 0x10,22bnez_op = 0x11,23bceqz_op = 0x12, /* bits[9:8] = 0x00 */24bcnez_op = 0x12, /* bits[9:8] = 0x01 */25};2627enum reg2_op {28ertn_op = 0x1920e,29};3031enum reg2i12_op {32addid_op = 0x0b,33andi_op = 0x0d,34ldd_op = 0xa3,35std_op = 0xa7,36};3738enum reg2i14_op {39ldptrd_op = 0x26,40stptrd_op = 0x27,41};4243enum reg2i16_op {44jirl_op = 0x13,45beq_op = 0x16,46bne_op = 0x17,47blt_op = 0x18,48bge_op = 0x19,49bltu_op = 0x1a,50bgeu_op = 0x1b,51};5253enum reg3_op {54amswapw_op = 0x70c0,55};5657struct reg0i15_format {58unsigned int immediate : 15;59unsigned int opcode : 17;60};6162struct reg0i26_format {63unsigned int immediate_h : 10;64unsigned int immediate_l : 16;65unsigned int opcode : 6;66};6768struct reg1i21_format {69unsigned int immediate_h : 5;70unsigned int rj : 5;71unsigned int immediate_l : 16;72unsigned int opcode : 6;73};7475struct reg2_format {76unsigned int rd : 5;77unsigned int rj : 5;78unsigned int opcode : 22;79};8081struct reg2i12_format {82unsigned int rd : 5;83unsigned int rj : 5;84unsigned int immediate : 12;85unsigned int opcode : 10;86};8788struct reg2i14_format {89unsigned int rd : 5;90unsigned int rj : 5;91unsigned int immediate : 14;92unsigned int opcode : 8;93};9495struct reg2i16_format {96unsigned int rd : 5;97unsigned int rj : 5;98unsigned int immediate : 16;99unsigned int opcode : 6;100};101102struct reg3_format {103unsigned int rd : 5;104unsigned int rj : 5;105unsigned int rk : 5;106unsigned int opcode : 17;107};108109union loongarch_instruction {110unsigned int word;111struct reg0i15_format reg0i15_format;112struct reg0i26_format reg0i26_format;113struct reg1i21_format reg1i21_format;114struct reg2_format reg2_format;115struct reg2i12_format reg2i12_format;116struct reg2i14_format reg2i14_format;117struct reg2i16_format reg2i16_format;118struct reg3_format reg3_format;119};120121#define LOONGARCH_INSN_SIZE sizeof(union loongarch_instruction)122123enum loongarch_gpr {124LOONGARCH_GPR_ZERO = 0,125LOONGARCH_GPR_RA = 1,126LOONGARCH_GPR_TP = 2,127LOONGARCH_GPR_SP = 3,128LOONGARCH_GPR_A0 = 4, /* Reused as V0 for return value */129LOONGARCH_GPR_A1, /* Reused as V1 for return value */130LOONGARCH_GPR_A2,131LOONGARCH_GPR_A3,132LOONGARCH_GPR_A4,133LOONGARCH_GPR_A5,134LOONGARCH_GPR_A6,135LOONGARCH_GPR_A7,136LOONGARCH_GPR_T0 = 12,137LOONGARCH_GPR_T1,138LOONGARCH_GPR_T2,139LOONGARCH_GPR_T3,140LOONGARCH_GPR_T4,141LOONGARCH_GPR_T5,142LOONGARCH_GPR_T6,143LOONGARCH_GPR_T7,144LOONGARCH_GPR_T8,145LOONGARCH_GPR_FP = 22,146LOONGARCH_GPR_S0 = 23,147LOONGARCH_GPR_S1,148LOONGARCH_GPR_S2,149LOONGARCH_GPR_S3,150LOONGARCH_GPR_S4,151LOONGARCH_GPR_S5,152LOONGARCH_GPR_S6,153LOONGARCH_GPR_S7,154LOONGARCH_GPR_S8,155LOONGARCH_GPR_MAX156};157158#define DEF_EMIT_REG2I16_FORMAT(NAME, OP) \159static inline void emit_##NAME(union loongarch_instruction *insn, \160enum loongarch_gpr rj, \161enum loongarch_gpr rd, \162int offset) \163{ \164insn->reg2i16_format.opcode = OP; \165insn->reg2i16_format.immediate = offset; \166insn->reg2i16_format.rj = rj; \167insn->reg2i16_format.rd = rd; \168}169170DEF_EMIT_REG2I16_FORMAT(jirl, jirl_op)171172#endif /* _ASM_INST_H */173174175