1 `include "ARM_Constants.v"
7 input stall, /* pipeline control */
10 input inbubble, /* stage inputs */
15 output reg outbubble, /* stage outputs */
16 output reg [31:0] outpc
22 outbubble <= inbubble;
26 `ifdef COPY_PASTA_FODDER
27 /* from page 2 of ARM7TDMIvE2.pdf */
29 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
30 // 32'b????00001???????????????1001????: /* Multiply long */
31 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
32 32'b????00010?101001111100000000????: /* MSR (Transfer register to PSR) */
33 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
34 32'b????00??????????????????????????: /* ALU */
35 32'b????00010?00????????00001001????: /* Atomic swap */
36 32'b????000100101111111111110001????: /* Branch */
37 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
38 32'b????000??1??????????00001??1????: /* Halfword transfer - register offset */
39 32'b????011????????????????????1????: /* Undefined. I hate ARM */
40 32'b????01??????????????????????????: /* Single data transfer */
41 32'b????100?????????????????????????: /* Block data transfer */
42 32'b????101?????????????????????????: /* Branch */
43 32'b????110?????????????????????????: /* Coprocessor data transfer */
44 32'b????1110???????????????????0????: /* Coprocessor data op */
45 32'b????1110???????????????????1????: /* Coprocessor register transfer */
46 32'b????1111????????????????????????: /* SWI */
47 default: /* X everything else out */
57 function [15:0] idxbit;
62 idxbit = (16'b1) << r;
65 wire [3:0] rn = insn[19:16];
66 wire [3:0] rd = insn[15:12];
67 wire [3:0] rs = insn[11:8];
68 wire [3:0] rm = insn[3:0];
69 wire [3:0] cond = insn[31:28];
71 wire [3:0] rd_mul = insn[19:16];
72 wire [3:0] rn_mul = insn[15:12];
73 wire [3:0] rs_mul = insn[11:8];
75 wire [3:0] alu_opc = insn[24:21];
77 function alu_is_logical;
81 `ALU_AND,`ALU_EOR,`ALU_TST,`ALU_TEQ,`ALU_ORR,`ALU_MOV,`ALU_BIC,`ALU_MVN: alu_is_logical = 1;
82 default: alu_is_logical = 0;
86 function alu_flags_only;
90 `ALU_TST,`ALU_TEQ,`ALU_CMP,`ALU_CMN: alu_flags_only = 1;
91 default: alu_flags_only = 0;
95 function shift_requires_carry;
99 `SHIFT_LSL: shift_requires_carry = (shift[7:2] == 0);
100 `SHIFT_LSR: shift_requires_carry = 0;
101 `SHIFT_ASR: shift_requires_carry = 0;
102 `SHIFT_ROR: shift_requires_carry = (shift[7:2] == 0);
108 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
110 use_cpsr = `COND_MATTERS(cond);
111 use_regs = (insn[21] /* accum */ ? idxbit(rn_mul) : 0) | idxbit(rs_mul) | idxbit(rm);
112 def_cpsr = insn[20] /* setcc */;
113 def_regs = idxbit(rd_mul);
115 // 32'b????00001???????????????1001????: /* Multiply long */
116 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
118 use_cpsr = `COND_MATTERS(cond) || (insn[22] == 0) /* Source = CPSR */;
121 def_regs = idxbit(rd);
123 32'b????00010?101001111100000000????: /* MSR (Transfer register to PSR) */
125 use_cpsr = `COND_MATTERS(cond);
126 use_regs = idxbit(rm);
130 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
132 use_cpsr = `COND_MATTERS(cond);
133 use_regs = insn[25] ? 0 : idxbit(rm);
137 32'b????00??????????????????????????: /* ALU */
139 use_cpsr = `COND_MATTERS(cond) | (!insn[25] /* I */ && shift_requires_carry(insn[11:4]));
141 (insn[25] /* I */ ? 0 :
142 (insn[4] /* shift by reg */ ?
143 (idxbit(rs) | idxbit(rm)) :
145 (((alu_opc != `ALU_MOV) && (alu_opc != `ALU_MVN)) ? idxbit(rn) : 0);
146 def_cpsr = insn[20] /* S */ | alu_is_logical(alu_opc);
147 def_regs = alu_flags_only(alu_opc) ? 0 : idxbit(rd);
149 32'b????00010?00????????00001001????: /* Atomic swap */
151 use_cpsr = `COND_MATTERS(cond);
152 use_regs = idxbit(rn) | idxbit(rm);
154 def_regs = idxbit(rd);
156 32'b????000100101111111111110001????: /* Branch */
158 use_cpsr = `COND_MATTERS(cond);
159 use_regs = idxbit(rm);
160 def_cpsr = 0; // don't care, we'll never get there
163 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
165 use_cpsr = `COND_MATTERS(cond);
166 use_regs = idxbit(rn) | idxbit(rm) | (insn[20] /* L */ ? 0 : idxbit(rd));
168 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
170 32'b????000??1??????????00001??1????: /* Halfword transfer - immediate offset */
172 use_cpsr = `COND_MATTERS(cond);
173 use_regs = idxbit(rn) | (insn[20] /* L */ ? 0 : idxbit(rd));
175 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
177 32'b????011????????????????????1????: /* Undefined. I hate ARM */
184 32'b????100?????????????????????????: /* Block data transfer */
186 use_cpsr = `COND_MATTERS(cond);
187 use_regs = idxbit(rn) | (insn[20] /* L */ ? 0 : insn[15:0]);
188 def_cpsr = insn[22]; /* This is a superset of all cases, anyway. */
189 def_regs = (insn[21] /* W */ ? idxbit(rn) : 0) | (insn[20] /* L */ ? insn[15:0] : 0);
191 32'b????101?????????????????????????: /* Branch */
193 use_cpsr = `COND_MATTERS(cond);
198 32'b????110?????????????????????????: /* Coprocessor data transfer */
200 use_cpsr = `COND_MATTERS(cond);
201 use_regs = idxbit(rn);
203 def_regs = insn[21] /* W */ ? idxbit(rn) : 0;
205 32'b????1110???????????????????0????: /* Coprocessor data op */
207 use_cpsr = `COND_MATTERS(cond);
212 32'b????1110???????????????????1????: /* Coprocessor register transfer */
214 use_cpsr = `COND_MATTERS(cond);
215 use_regs = insn[20] /* L */ ? 0 : idxbit(rd);
217 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
219 32'b????1111????????????????????????: /* SWI */
221 use_cpsr = `COND_MATTERS(cond);
226 default: /* X everything else out */
229 use_regs = 16'bxxxxxxxxxxxxxxxx;
231 def_regs = 16'bxxxxxxxxxxxxxxxx;
235 /* Condition checking logic */
239 `COND_EQ: condition_met = cpsr[`CPSR_Z];
240 `COND_NE: condition_met = !cpsr[`CPSR_Z];
241 `COND_CS: condition_met = cpsr[`CPSR_C];
242 `COND_CC: condition_met = !cpsr[`CPSR_C];
243 `COND_MI: condition_met = cpsr[`CPSR_N];
244 `COND_PL: condition_met = !cpsr[`CPSR_N];
245 `COND_VS: condition_met = cpsr[`CPSR_V];
246 `COND_VC: condition_met = !cpsr[`CPSR_V];
247 `COND_HI: condition_met = cpsr[`CPSR_C] && !cpsr[`CPSR_Z];
248 `COND_LS: condition_met = !cpsr[`CPSR_C] || cpsr[`CPSR_Z];
249 `COND_GE: condition_met = cpsr[`CPSR_N] == cpsr[`CPSR_V];
250 `COND_LT: condition_met = cpsr[`CPSR_N] != cpsr[`CPSR_V];
251 `COND_GT: condition_met = !cpsr[`CPSR_Z] && (cpsr[`CPSR_N] == cpsr[`CPSR_V]);
252 `COND_LE: condition_met = cpsr[`CPSR_Z] || (cpsr[`CPSR_N] != cpsr[`CPSR_V]);
253 `COND_AL: condition_met = 1;
254 `COND_NV: condition_met = 0;
255 default: condition_met = 1'bx;
260 * reg [15:0] use_regs;
262 * reg [15:0] def_regs;