1 /* Copyright 2016-2024 Free Software Foundation, Inc.
2 Contributed by Dimitar Dimitrov <dimitar@dinux.eu>
4 This file is part of the PRU simulator.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
20 PRU Instruction Set Architecture
27 OP2 = (IO ? IMM8 : RS2);
29 CARRY = (((uint64_t) RS1 + (uint64_t) OP2) >> RD_WIDTH) & 1;
33 OP2 = (IO ? IMM8 : RS2);
34 RD = RS1 + OP2 + CARRY;
35 CARRY = (((uint64_t) RS1 + (uint64_t) OP2 + (uint64_t) CARRY)
40 OP2 = (IO ? IMM8 : RS2);
42 CARRY = (((uint64_t) RS1 - (uint64_t) OP2) >> RD_WIDTH) & 1;
47 OP2 = (IO ? IMM8 : RS2);
48 RD = RS1 - OP2 - !CARRY;
49 CARRY = (((uint64_t) RS1 - (uint64_t) OP2 - (uint64_t) !CARRY)
55 OP2 = (IO ? IMM8 : RS2);
57 CARRY = (((uint64_t) OP2 - (uint64_t) RS1) >> RD_WIDTH) & 1;
62 OP2 = (IO ? IMM8 : RS2);
63 RD = OP2 - RS1 - !CARRY;
64 CARRY = (((uint64_t) OP2 - (uint64_t) RS1 - (uint64_t) !CARRY)
70 OP2 = (IO ? IMM8 : RS2);
71 RD = RS1 << (OP2 & 0x1f);
75 OP2 = (IO ? IMM8 : RS2);
76 RD = RS1 >> (OP2 & 0x1f);
80 OP2 = (IO ? IMM8 : RS2);
85 OP2 = (IO ? IMM8 : RS2);
90 OP2 = (IO ? IMM8 : RS2);
99 OP2 = (IO ? IMM8 : RS2);
100 RD = RS1 < OP2 ? RS1 : OP2;
104 OP2 = (IO ? IMM8 : RS2);
105 RD = RS1 > OP2 ? RS1 : OP2;
109 OP2 = (IO ? IMM8 : RS2);
110 RD = RS1 & ~(1u << (OP2 & 0x1f));
114 OP2 = (IO ? IMM8 : RS2);
115 RD = RS1 | (1u << (OP2 & 0x1f));
119 OP2 = (IO ? IMM16 : RS2);
123 OP2 = (IO ? IMM16 : RS2);
132 pru_sim_syscall (sd, cpu);
146 OP2 = (IO ? IMM8 : RS2);
147 PC = (OP2 > RS1) ? (PC + BROFF) : (PC + 1))
150 OP2 = (IO ? IMM8 : RS2);
151 PC = (OP2 >= RS1) ? (PC + BROFF) : (PC + 1))
154 OP2 = (IO ? IMM8 : RS2);
155 PC = (OP2 < RS1) ? (PC + BROFF) : (PC + 1))
158 OP2 = (IO ? IMM8 : RS2);
159 PC = (OP2 <= RS1) ? (PC + BROFF) : (PC + 1))
162 OP2 = (IO ? IMM8 : RS2);
163 PC = (OP2 == RS1) ? (PC + BROFF) : (PC + 1))
166 OP2 = (IO ? IMM8 : RS2);
167 PC = (OP2 != RS1) ? (PC + BROFF) : (PC + 1))
170 OP2 = (IO ? IMM8 : RS2);
174 OP2 = (IO ? IMM8 : RS2);
175 PC = (RS1 & (1u << (OP2 & 0x1f))) ? (PC + BROFF) : (PC + 1))
178 OP2 = (IO ? IMM8 : RS2);
179 PC = !(RS1 & (1u << (OP2 & 0x1f))) ? (PC + BROFF) : (PC + 1))
182 pru_dmem2reg (cpu, XBBO_BASEREG + (IO ? IMM8 : RS2),
183 BURSTLEN, RD_REGN, RDB);
187 pru_reg2dmem (cpu, XBBO_BASEREG + (IO ? IMM8 : RS2),
188 BURSTLEN, RD_REGN, RDB);
192 pru_dmem2reg (cpu, CTABLE[CB] + (IO ? IMM8 : RS2),
193 BURSTLEN, RD_REGN, RDB);
197 pru_reg2dmem (cpu, CTABLE[CB] + (IO ? IMM8 : RS2),
198 BURSTLEN, RD_REGN, RDB);
202 DO_XIN (XFR_WBA, RD_REGN, RDB, XFR_LENGTH);
206 DO_XOUT (XFR_WBA, RD_REGN, RDB, XFR_LENGTH);
210 DO_XCHG (XFR_WBA, RD_REGN, RDB, XFR_LENGTH);
214 sim_io_eprintf (sd, "SXIN instruction not supported by sim\n");
218 sim_io_eprintf (sd, "SXOUT instruction not supported by sim\n");
222 sim_io_eprintf (sd, "SXCHG instruction not supported by sim\n");
226 OP2 = (IO ? IMM8 + 1 : RS2_w0);
229 PC = PC + LOOP_JMPOFFS;
234 LOOPEND = PC + LOOP_JMPOFFS;
236 LOOP_IN_PROGRESS = 1;
241 OP2 = (IO ? IMM8 + 1 : RS2_w0);
244 PC = PC + LOOP_JMPOFFS;
249 LOOPEND = PC + LOOP_JMPOFFS;
251 LOOP_IN_PROGRESS = 1;
259 OP2 = (IO ? IMM8 : RS2);
261 for (lmbd_i = RS1_WIDTH - 1; lmbd_i >= 0; lmbd_i--)
263 if (!(((RS1 >> lmbd_i) ^ OP2) & 1))
266 RD = (lmbd_i < 0) ? 32 : lmbd_i;