1 `include "ARM_Constants.v"
7 input stall, /* pipeline control */
10 input inbubble, /* stage inputs */
14 output reg outbubble, /* stage outputs */
15 output reg [31:0] outpc
21 outbubble <= inbubble;
25 `ifdef COPY_PASTA_FODDER
26 /* from page 2 of ARM7TDMIvE2.pdf */
28 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
29 // 32'b????00001???????????????1001????: /* Multiply long */
30 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
31 32'b????00010?101001111100000000????: /* MSR (Transfer register to PSR) */
32 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
33 32'b????00??????????????????????????: /* ALU */
34 32'b????00010?00????????00001001????: /* Atomic swap */
35 32'b????000100101111111111110001????: /* Branch */
36 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
37 32'b????000??1??????????00001??1????: /* Halfword transfer - register offset */
38 32'b????011????????????????????1????: /* Undefined. I hate ARM */
39 32'b????01??????????????????????????: /* Single data transfer */
40 32'b????100?????????????????????????: /* Block data transfer */
41 32'b????101?????????????????????????: /* Branch */
42 32'b????110?????????????????????????: /* Coprocessor data transfer */
43 32'b????1110???????????????????0????: /* Coprocessor data op */
44 32'b????1110???????????????????1????: /* Coprocessor register transfer */
45 32'b????1111????????????????????????: /* SWI */
46 default: /* X everything else out */
56 function [15:0] idxbit;
61 idxbit = (16'b1) << r;
64 wire [3:0] rn = insn[19:16];
65 wire [3:0] rd = insn[15:12];
66 wire [3:0] rs = insn[11:8];
67 wire [3:0] rm = insn[3:0];
68 wire [3:0] cond = insn[31:28];
70 wire [3:0] rd_mul = insn[19:16];
71 wire [3:0] rn_mul = insn[15:12];
72 wire [3:0] rs_mul = insn[11:8];
74 wire [3:0] alu_opc = insn[24:21];
76 function alu_is_logical;
80 `ALU_AND,`ALU_EOR,`ALU_TST,`ALU_TEQ,`ALU_ORR,`ALU_MOV,`ALU_BIC,`ALU_MVN: alu_is_logical = 1;
81 default: alu_is_logical = 0;
85 function alu_flags_only;
89 `ALU_TST,`ALU_TEQ,`ALU_CMP,`ALU_CMN: alu_flags_only = 1;
90 default: alu_flags_only = 0;
94 function shift_requires_carry;
98 `SHIFT_LSL: shift_requires_carry = (shift[7:2] == 0);
99 `SHIFT_LSR: shift_requires_carry = 0;
100 `SHIFT_ASR: shift_requires_carry = 0;
101 `SHIFT_ROR: shift_requires_carry = (shift[7:2] == 0);
107 32'b????000000??????????????1001????: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
109 use_cpsr = `COND_MATTERS(cond);
110 use_regs = (insn[21] /* accum */ ? idxbit(rn_mul) : 0) | idxbit(rs_mul) | idxbit(rm);
111 def_cpsr = insn[20] /* setcc */;
112 def_regs = idxbit(rd_mul);
114 // 32'b????00001???????????????1001????: /* Multiply long */
115 32'b????00010?001111????000000000000: /* MRS (Transfer PSR to register) */
117 use_cpsr = `COND_MATTERS(cond) || (insn[22] == 0) /* Source = CPSR */;
120 def_regs = idxbit(rd);
122 32'b????00010?101001111100000000????: /* MSR (Transfer register to PSR) */
124 use_cpsr = `COND_MATTERS(cond);
125 use_regs = idxbit(rm);
129 32'b????00?10?1010001111????????????: /* MSR (Transfer register or immediate to PSR, flag bits only) */
131 use_cpsr = `COND_MATTERS(cond);
132 use_regs = insn[25] ? 0 : idxbit(rm);
136 32'b????00??????????????????????????: /* ALU */
138 use_cpsr = `COND_MATTERS(cond) | (!insn[25] /* I */ && shift_requires_carry(insn[11:4]));
140 (insn[25] /* I */ ? 0 :
141 (insn[4] /* shift by reg */ ?
142 (idxbit(rs) | idxbit(rm)) :
144 (((alu_opc != `ALU_MOV) && (alu_opc != `ALU_MVN)) ? idxbit(rn) : 0);
145 def_cpsr = insn[20] /* S */ | alu_is_logical(alu_opc);
146 def_regs = alu_flags_only(alu_opc) ? 0 : idxbit(rd);
148 32'b????00010?00????????00001001????: /* Atomic swap */
150 use_cpsr = `COND_MATTERS(cond);
151 use_regs = idxbit(rn) | idxbit(rm);
153 def_regs = idxbit(rd);
155 32'b????000100101111111111110001????: /* Branch */
157 use_cpsr = `COND_MATTERS(cond);
158 use_regs = idxbit(rm);
159 def_cpsr = 0; // don't care, we'll never get there
162 32'b????000??0??????????00001??1????: /* Halfword transfer - register offset */
164 use_cpsr = `COND_MATTERS(cond);
165 use_regs = idxbit(rn) | idxbit(rm) | (insn[20] /* L */ ? 0 : idxbit(rd));
167 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
169 32'b????000??1??????????00001??1????: /* Halfword transfer - immediate offset */
171 use_cpsr = `COND_MATTERS(cond);
172 use_regs = idxbit(rn) | (insn[20] /* L */ ? 0 : idxbit(rd));
174 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
176 32'b????011????????????????????1????: /* Undefined. I hate ARM */
183 32'b????100?????????????????????????: /* Block data transfer */
185 use_cpsr = `COND_MATTERS(cond);
186 use_regs = idxbit(rn) | (insn[20] /* L */ ? 0 : insn[15:0]);
187 def_cpsr = insn[22]; /* This is a superset of all cases, anyway. */
188 def_regs = (insn[21] /* W */ ? idxbit(rn) : 0) | (insn[20] /* L */ ? insn[15:0] : 0);
190 32'b????101?????????????????????????: /* Branch */
192 use_cpsr = `COND_MATTERS(cond);
197 32'b????110?????????????????????????: /* Coprocessor data transfer */
199 use_cpsr = `COND_MATTERS(cond);
200 use_regs = idxbit(rn);
202 def_regs = insn[21] /* W */ ? idxbit(rn) : 0;
204 32'b????1110???????????????????0????: /* Coprocessor data op */
206 use_cpsr = `COND_MATTERS(cond);
211 32'b????1110???????????????????1????: /* Coprocessor register transfer */
213 use_cpsr = `COND_MATTERS(cond);
214 use_regs = insn[20] /* L */ ? 0 : idxbit(rd);
216 def_regs = insn[20] /* L */ ? idxbit(rd) : 0;
218 32'b????1111????????????????????????: /* SWI */
220 use_cpsr = `COND_MATTERS(cond);
225 default: /* X everything else out */
228 use_regs = 16'bxxxxxxxxxxxxxxxx;
230 def_regs = 16'bxxxxxxxxxxxxxxxx;