1// -*- mode:c++ -*-
2
3// Copyright (c) 2015 RISC-V Foundation
4// Copyright (c) 2017 The University of Virginia
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are

--- 29 unchanged lines hidden (view full) ---

38 0x0: decode COPCODE {
39 0x0: CIOp::c_addi4spn({{
40 imm = CIMM8<1:1> << 2 |
41 CIMM8<0:0> << 3 |
42 CIMM8<7:6> << 4 |
43 CIMM8<5:2> << 6;
44 }}, {{
45 if (machInst == 0)
46 fault = make_shared<IllegalInstFault>("zero instruction");
46 fault = make_shared<IllegalInstFault>("zero instruction",
47 machInst);
48 Rp2 = sp + imm;
49 }}, uint64_t);
50 format CompressedLoad {
51 0x1: c_fld({{
52 offset = CIMM3 << 3 | CIMM2 << 6;
53 }}, {{
54 Fp2_bits = Mem;
55 }}, {{

--- 46 unchanged lines hidden (view full) ---

102 format CIOp {
103 0x0: c_addi({{
104 imm = CIMM5;
105 if (CIMM1 > 0)
106 imm |= ~((uint64_t)0x1F);
107 }}, {{
108 if ((RC1 == 0) != (imm == 0)) {
109 if (RC1 == 0) {
109 fault = make_shared<IllegalInstFault>("source reg x0");
110 fault = make_shared<IllegalInstFault>("source reg x0",
111 machInst);
112 } else // imm == 0
111 fault = make_shared<IllegalInstFault>("immediate = 0");
113 fault = make_shared<IllegalInstFault>("immediate = 0",
114 machInst);
115 }
116 Rc1_sd = Rc1_sd + imm;
117 }});
118 0x1: c_addiw({{
119 imm = CIMM5;
120 if (CIMM1 > 0)
121 imm |= ~((uint64_t)0x1F);
122 }}, {{
123 if (RC1 == 0) {
121 fault = make_shared<IllegalInstFault>("source reg x0");
124 fault = make_shared<IllegalInstFault>("source reg x0",
125 machInst);
126 }
127 Rc1_sd = (int32_t)Rc1_sd + imm;
128 }});
129 0x2: c_li({{
130 imm = CIMM5;
131 if (CIMM1 > 0)
132 imm |= ~((uint64_t)0x1F);
133 }}, {{
134 if (RC1 == 0) {
131 fault = make_shared<IllegalInstFault>("source reg x0");
135 fault = make_shared<IllegalInstFault>("source reg x0",
136 machInst);
137 }
138 Rc1_sd = imm;
139 }});
140 0x3: decode RC1 {
141 0x2: c_addi16sp({{
142 imm = CIMM5<4:4> << 4 |
143 CIMM5<0:0> << 5 |
144 CIMM5<3:3> << 6 |
145 CIMM5<2:1> << 7;
146 if (CIMM1 > 0)
147 imm |= ~((int64_t)0x1FF);
148 }}, {{
149 if (imm == 0) {
145 fault = make_shared<IllegalInstFault>("immediate = 0");
150 fault = make_shared<IllegalInstFault>("immediate = 0",
151 machInst);
152 }
153 sp_sd = sp_sd + imm;
154 }});
155 default: c_lui({{
156 imm = CIMM5 << 12;
157 if (CIMM1 > 0)
158 imm |= ~((uint64_t)0x1FFFF);
159 }}, {{
160 if (RC1 == 0 || RC1 == 2) {
155 fault = make_shared<IllegalInstFault>("source reg x0");
161 fault = make_shared<IllegalInstFault>("source reg x0",
162 machInst);
163 }
164 if (imm == 0) {
158 fault = make_shared<IllegalInstFault>("immediate = 0");
165 fault = make_shared<IllegalInstFault>("immediate = 0",
166 machInst);
167 }
168 Rc1_sd = imm;
169 }});
170 }
171 }
172 0x4: decode CFUNCT2HIGH {
173 format CIOp {
174 0x0: c_srli({{
175 imm = CIMM5 | (CIMM1 << 5);
176 }}, {{
177 if (imm == 0) {
170 fault = make_shared<IllegalInstFault>("immediate = 0");
178 fault = make_shared<IllegalInstFault>("immediate = 0",
179 machInst);
180 }
181 Rp1 = Rp1 >> imm;
182 }}, uint64_t);
183 0x1: c_srai({{
184 imm = CIMM5 | (CIMM1 << 5);
185 }}, {{
186 if (imm == 0) {
178 fault = make_shared<IllegalInstFault>("immediate = 0");
187 fault = make_shared<IllegalInstFault>("immediate = 0",
188 machInst);
189 }
190 Rp1_sd = Rp1_sd >> imm;
191 }}, uint64_t);
192 0x2: c_andi({{
193 imm = CIMM5;
194 if (CIMM1 > 0)
195 imm |= ~((uint64_t)0x1F);
196 }}, {{

--- 54 unchanged lines hidden (view full) ---

251 }}, IsDirectControl, IsCondControl);
252 }
253 }
254 0x2: decode COPCODE {
255 0x0: CIOp::c_slli({{
256 imm = CIMM5 | (CIMM1 << 5);
257 }}, {{
258 if (imm == 0) {
249 fault = make_shared<IllegalInstFault>("immediate = 0");
259 fault = make_shared<IllegalInstFault>("immediate = 0",
260 machInst);
261 }
262 if (RC1 == 0) {
252 fault = make_shared<IllegalInstFault>("source reg x0");
263 fault = make_shared<IllegalInstFault>("source reg x0",
264 machInst);
265 }
266 Rc1 = Rc1 << imm;
267 }}, uint64_t);
268 format CompressedLoad {
269 0x1: c_fldsp({{
270 offset = CIMM5<4:3> << 3 |
271 CIMM1 << 5 |
272 CIMM5<2:0> << 6;
273 }}, {{
274 Fc1_bits = Mem;
275 }}, {{
276 EA = sp + offset;
277 }});
278 0x2: c_lwsp({{
279 offset = CIMM5<4:2> << 2 |
280 CIMM1 << 5 |
281 CIMM5<1:0> << 6;
282 }}, {{
283 if (RC1 == 0) {
272 fault = make_shared<IllegalInstFault>("source reg x0");
284 fault = make_shared<IllegalInstFault>("source reg x0",
285 machInst);
286 }
287 Rc1_sd = Mem_sw;
288 }}, {{
289 EA = sp + offset;
290 }});
291 0x3: c_ldsp({{
292 offset = CIMM5<4:3> << 3 |
293 CIMM1 << 5 |
294 CIMM5<2:0> << 6;
295 }}, {{
296 if (RC1 == 0) {
284 fault = make_shared<IllegalInstFault>("source reg x0");
297 fault = make_shared<IllegalInstFault>("source reg x0",
298 machInst);
299 }
300 Rc1_sd = Mem_sd;
301 }}, {{
302 EA = sp + offset;
303 }});
304 }
305 0x4: decode CFUNCT1 {
306 0x0: decode RC2 {
307 0x0: Jump::c_jr({{
308 if (RC1 == 0) {
295 fault = make_shared<IllegalInstFault>("source reg x0");
309 fault = make_shared<IllegalInstFault>("source reg x0",
310 machInst);
311 }
312 NPC = Rc1;
313 }}, IsIndirectControl, IsUncondControl, IsCall);
314 default: CROp::c_mv({{
315 if (RC1 == 0) {
301 fault = make_shared<IllegalInstFault>("source reg x0");
316 fault = make_shared<IllegalInstFault>("source reg x0",
317 machInst);
318 }
319 Rc1 = Rc2;
320 }});
321 }
322 0x1: decode RC1 {
323 0x0: SystemOp::c_ebreak({{
324 if (RC2 != 0) {
309 fault = make_shared<IllegalInstFault>("source reg x1");
325 fault = make_shared<IllegalInstFault>("source reg x1",
326 machInst);
327 }
311 fault = make_shared();
328 fault = make_shared<BreakpointFault>(xc->pcState());
329 }}, IsSerializeAfter, IsNonSpeculative, No_OpClass);
330 default: decode RC2 {
331 0x0: Jump::c_jalr({{
332 if (RC1 == 0) {
333 fault = make_shared<IllegalInstFault>
317 ("source reg x0");
334 ("source reg x0",
335 machInst);
336 }
337 ra = NPC;
338 NPC = Rc1;
339 }}, IsIndirectControl, IsUncondControl, IsCall);
340 default: ROp::c_add({{
341 Rc1_sd = Rc1_sd + Rc2_sd;
342 }});
343 }

--- 919 unchanged lines hidden (view full) ---

1263 FFLAGS |= FloatInvalid;
1264 } else {
1265 Fd = fmax(Fs1, Fs2);
1266 }
1267 }}, FloatCmpOp);
1268 }
1269 0x20: fcvt_s_d({{
1270 if (CONV_SGN != 1) {
1253 fault = make_shared<IllegalInstFault>("CONV_SGN != 1");
1271 fault = make_shared<IllegalInstFault>("CONV_SGN != 1",
1272 machInst);
1273 }
1274 float fd;
1275 if (issignalingnan(Fs1)) {
1276 fd = numeric_limits<float>::quiet_NaN();
1277 FFLAGS |= FloatInvalid;
1278 } else {
1279 fd = (float)Fs1;
1280 }
1281 Fd_bits = (uint64_t)reinterpret_cast<uint32_t&>(fd);
1282 }}, FloatCvtOp);
1283 0x21: fcvt_d_s({{
1284 if (CONV_SGN != 0) {
1266 fault = make_shared<IllegalInstFault>("CONV_SGN != 0");
1285 fault = make_shared<IllegalInstFault>("CONV_SGN != 0",
1286 machInst);
1287 }
1288 uint32_t temp;
1289 float fs1 = reinterpret_cast<float&>(temp = Fs1_bits);
1290
1291 if (issignalingnan(fs1)) {
1292 Fd = numeric_limits<double>::quiet_NaN();
1293 FFLAGS |= FloatInvalid;
1294 } else {
1295 Fd = (double)fs1;
1296 }
1297 }}, FloatCvtOp);
1298 0x2c: fsqrt_s({{
1299 if (RS2 != 0) {
1280 fault = make_shared<IllegalInstFault>("source reg x1");
1300 fault = make_shared<IllegalInstFault>("source reg x1",
1301 machInst);
1302 }
1303 uint32_t temp;
1304 float fs1 = reinterpret_cast<float&>(temp = Fs1_bits);
1305 float fd;
1306
1307 if (issignalingnan(Fs1_sf)) {
1308 FFLAGS |= FloatInvalid;
1309 }
1310 fd = sqrt(fs1);
1311 Fd_bits = (uint64_t)reinterpret_cast<uint32_t&>(fd);
1312 }}, FloatSqrtOp);
1313 0x2d: fsqrt_d({{
1314 if (RS2 != 0) {
1294 fault = make_shared<IllegalInstFault>("source reg x1");
1315 fault = make_shared<IllegalInstFault>("source reg x1",
1316 machInst);
1317 }
1318 Fd = sqrt(Fs1);
1319 }}, FloatSqrtOp);
1320 0x50: decode ROUND_MODE {
1321 0x0: fle_s({{
1322 uint32_t temp;
1323 float fs1 = reinterpret_cast<float&>(temp = Fs1_bits);
1324 float fs2 = reinterpret_cast<float&>(temp = Fs2_bits);

--- 382 unchanged lines hidden (view full) ---

1707 0x1c: decode FUNCT3 {
1708 format SystemOp {
1709 0x0: decode FUNCT12 {
1710 0x0: ecall({{
1711 fault = make_shared<SyscallFault>();
1712 }}, IsSerializeAfter, IsNonSpeculative, IsSyscall,
1713 No_OpClass);
1714 0x1: ebreak({{
1693 fault = make_shared();
1715 fault = make_shared<BreakpointFault>(xc->pcState());
1716 }}, IsSerializeAfter, IsNonSpeculative, No_OpClass);
1717 0x100: eret({{
1696 fault = make_shared<UnimplementedFault>("eret");
1718 fault = make_shared<UnimplementedFault>("eret",
1719 machInst);
1720 }}, No_OpClass);
1721 }
1722 }
1723 format CSROp {
1724 0x1: csrrw({{
1725 Rd = data;
1726 data = Rs1;
1727 }}, IsNonSpeculative, No_OpClass);

--- 24 unchanged lines hidden ---