Skip to content

Commit 4e59e5a

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Add some instruction opcodes and formats
According to the "Table of Instruction Encoding" in LoongArch Reference Manual [1], add some instruction opcodes and formats which are used in the BPF JIT for LoongArch. [1] https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#table-of-instruction-encoding Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 8a34228 commit 4e59e5a

File tree

1 file changed

+174
-5
lines changed
  • arch/loongarch/include/asm

1 file changed

+174
-5
lines changed

arch/loongarch/include/asm/inst.h

Lines changed: 174 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <linux/types.h>
99
#include <asm/asm.h>
1010

11+
#define INSN_BREAK 0x002a0000
12+
1113
#define ADDR_IMMMASK_LU52ID 0xFFF0000000000000
1214
#define ADDR_IMMMASK_LU32ID 0x000FFFFF00000000
1315
#define ADDR_IMMMASK_ADDU16ID 0x00000000FFFF0000
@@ -18,20 +20,51 @@
1820

1921
#define ADDR_IMM(addr, INSN) ((addr & ADDR_IMMMASK_##INSN) >> ADDR_IMMSHIFT_##INSN)
2022

23+
enum reg0i26_op {
24+
b_op = 0x14,
25+
bl_op = 0x15,
26+
};
27+
2128
enum reg1i20_op {
2229
lu12iw_op = 0x0a,
2330
lu32id_op = 0x0b,
31+
pcaddu12i_op = 0x0e,
32+
pcaddu18i_op = 0x0f,
2433
};
2534

2635
enum reg1i21_op {
2736
beqz_op = 0x10,
2837
bnez_op = 0x11,
2938
};
3039

40+
enum reg2_op {
41+
revb2h_op = 0x0c,
42+
revb4h_op = 0x0d,
43+
revb2w_op = 0x0e,
44+
revbd_op = 0x0f,
45+
revh2w_op = 0x10,
46+
revhd_op = 0x11,
47+
};
48+
49+
enum reg2i5_op {
50+
slliw_op = 0x81,
51+
srliw_op = 0x89,
52+
sraiw_op = 0x91,
53+
};
54+
55+
enum reg2i6_op {
56+
sllid_op = 0x41,
57+
srlid_op = 0x45,
58+
sraid_op = 0x49,
59+
};
60+
3161
enum reg2i12_op {
3262
addiw_op = 0x0a,
3363
addid_op = 0x0b,
3464
lu52id_op = 0x0c,
65+
andi_op = 0x0d,
66+
ori_op = 0x0e,
67+
xori_op = 0x0f,
3568
ldb_op = 0xa0,
3669
ldh_op = 0xa1,
3770
ldw_op = 0xa2,
@@ -40,6 +73,20 @@ enum reg2i12_op {
4073
sth_op = 0xa5,
4174
stw_op = 0xa6,
4275
std_op = 0xa7,
76+
ldbu_op = 0xa8,
77+
ldhu_op = 0xa9,
78+
ldwu_op = 0xaa,
79+
};
80+
81+
enum reg2i14_op {
82+
llw_op = 0x20,
83+
scw_op = 0x21,
84+
lld_op = 0x22,
85+
scd_op = 0x23,
86+
ldptrw_op = 0x24,
87+
stptrw_op = 0x25,
88+
ldptrd_op = 0x26,
89+
stptrd_op = 0x27,
4390
};
4491

4592
enum reg2i16_op {
@@ -52,6 +99,71 @@ enum reg2i16_op {
5299
bgeu_op = 0x1b,
53100
};
54101

102+
enum reg2bstrd_op {
103+
bstrinsd_op = 0x2,
104+
bstrpickd_op = 0x3,
105+
};
106+
107+
enum reg3_op {
108+
addw_op = 0x20,
109+
addd_op = 0x21,
110+
subw_op = 0x22,
111+
subd_op = 0x23,
112+
nor_op = 0x28,
113+
and_op = 0x29,
114+
or_op = 0x2a,
115+
xor_op = 0x2b,
116+
orn_op = 0x2c,
117+
andn_op = 0x2d,
118+
sllw_op = 0x2e,
119+
srlw_op = 0x2f,
120+
sraw_op = 0x30,
121+
slld_op = 0x31,
122+
srld_op = 0x32,
123+
srad_op = 0x33,
124+
mulw_op = 0x38,
125+
mulhw_op = 0x39,
126+
mulhwu_op = 0x3a,
127+
muld_op = 0x3b,
128+
mulhd_op = 0x3c,
129+
mulhdu_op = 0x3d,
130+
divw_op = 0x40,
131+
modw_op = 0x41,
132+
divwu_op = 0x42,
133+
modwu_op = 0x43,
134+
divd_op = 0x44,
135+
modd_op = 0x45,
136+
divdu_op = 0x46,
137+
moddu_op = 0x47,
138+
ldxb_op = 0x7000,
139+
ldxh_op = 0x7008,
140+
ldxw_op = 0x7010,
141+
ldxd_op = 0x7018,
142+
stxb_op = 0x7020,
143+
stxh_op = 0x7028,
144+
stxw_op = 0x7030,
145+
stxd_op = 0x7038,
146+
ldxbu_op = 0x7040,
147+
ldxhu_op = 0x7048,
148+
ldxwu_op = 0x7050,
149+
amswapw_op = 0x70c0,
150+
amswapd_op = 0x70c1,
151+
amaddw_op = 0x70c2,
152+
amaddd_op = 0x70c3,
153+
amandw_op = 0x70c4,
154+
amandd_op = 0x70c5,
155+
amorw_op = 0x70c6,
156+
amord_op = 0x70c7,
157+
amxorw_op = 0x70c8,
158+
amxord_op = 0x70c9,
159+
};
160+
161+
enum reg3sa2_op {
162+
alslw_op = 0x02,
163+
alslwu_op = 0x03,
164+
alsld_op = 0x16,
165+
};
166+
55167
struct reg0i26_format {
56168
unsigned int immediate_h : 10;
57169
unsigned int immediate_l : 16;
@@ -71,27 +183,84 @@ struct reg1i21_format {
71183
unsigned int opcode : 6;
72184
};
73185

186+
struct reg2_format {
187+
unsigned int rd : 5;
188+
unsigned int rj : 5;
189+
unsigned int opcode : 22;
190+
};
191+
192+
struct reg2i5_format {
193+
unsigned int rd : 5;
194+
unsigned int rj : 5;
195+
unsigned int immediate : 5;
196+
unsigned int opcode : 17;
197+
};
198+
199+
struct reg2i6_format {
200+
unsigned int rd : 5;
201+
unsigned int rj : 5;
202+
unsigned int immediate : 6;
203+
unsigned int opcode : 16;
204+
};
205+
74206
struct reg2i12_format {
75207
unsigned int rd : 5;
76208
unsigned int rj : 5;
77209
unsigned int immediate : 12;
78210
unsigned int opcode : 10;
79211
};
80212

213+
struct reg2i14_format {
214+
unsigned int rd : 5;
215+
unsigned int rj : 5;
216+
unsigned int immediate : 14;
217+
unsigned int opcode : 8;
218+
};
219+
81220
struct reg2i16_format {
82221
unsigned int rd : 5;
83222
unsigned int rj : 5;
84223
unsigned int immediate : 16;
85224
unsigned int opcode : 6;
86225
};
87226

227+
struct reg2bstrd_format {
228+
unsigned int rd : 5;
229+
unsigned int rj : 5;
230+
unsigned int lsbd : 6;
231+
unsigned int msbd : 6;
232+
unsigned int opcode : 10;
233+
};
234+
235+
struct reg3_format {
236+
unsigned int rd : 5;
237+
unsigned int rj : 5;
238+
unsigned int rk : 5;
239+
unsigned int opcode : 17;
240+
};
241+
242+
struct reg3sa2_format {
243+
unsigned int rd : 5;
244+
unsigned int rj : 5;
245+
unsigned int rk : 5;
246+
unsigned int immediate : 2;
247+
unsigned int opcode : 15;
248+
};
249+
88250
union loongarch_instruction {
89251
unsigned int word;
90-
struct reg0i26_format reg0i26_format;
91-
struct reg1i20_format reg1i20_format;
92-
struct reg1i21_format reg1i21_format;
93-
struct reg2i12_format reg2i12_format;
94-
struct reg2i16_format reg2i16_format;
252+
struct reg0i26_format reg0i26_format;
253+
struct reg1i20_format reg1i20_format;
254+
struct reg1i21_format reg1i21_format;
255+
struct reg2_format reg2_format;
256+
struct reg2i5_format reg2i5_format;
257+
struct reg2i6_format reg2i6_format;
258+
struct reg2i12_format reg2i12_format;
259+
struct reg2i14_format reg2i14_format;
260+
struct reg2i16_format reg2i16_format;
261+
struct reg2bstrd_format reg2bstrd_format;
262+
struct reg3_format reg3_format;
263+
struct reg3sa2_format reg3sa2_format;
95264
};
96265

97266
#define LOONGARCH_INSN_SIZE sizeof(union loongarch_instruction)

0 commit comments

Comments
 (0)