9 output reg [31:0] cps_out,
19 wire [31:0] regs0, regs1, regs2, rpc;
20 wire [31:0] op1_res, new_cps;
23 wire [31:0] shift_oper;
24 wire [31:0] shift_res;
27 assign regs0 = (regsel0 == 4'b1111) ? rpc : iregs0;
28 assign regs1 = (regsel1 == 4'b1111) ? rpc : iregs1;
29 assign regs2 = iregs2; /* use regs2 for things that cannot be r15 */
31 IHATEARMSHIFT(.insn(ansn),
34 .cflag_in(cps_in[`COND_CBIT]),
36 .cflag_out(shift_cflag));
40 32'b????000000??????????????1001????: begin /* Multiply */
42 regsel0 = ansn[15:12]; /* Rn */
43 regsel1 = ansn[3:0]; /* Rm */
44 regsel2 = ansn[11:8]; /* Rs */
49 32'b????00001???????????????1001????: begin * Multiply long *
50 regsel0 = ansn[11:8]; * Rn *
51 regsel1 = ansn[3:0]; * Rm *
52 regsel2 = 4'b0; * anyus *
56 32'b????00010?001111????000000000000: begin /* MRS (Transfer PSR to register) */
60 32'b????00010?101001111100000000????: begin /* MSR (Transfer register to PSR) */
64 32'b????00?10?1010001111????????????: begin /* MSR (Transfer register or immediate to PSR, flag bits onry) */
68 32'b????00??????????????????????????: begin /* ALU */
69 rpc = inpc - (ansn[25] ? 8 : (ansn[4] ? 12 : 8));
70 regsel0 = ansn[19:16]; /* Rn */
71 regsel1 = ansn[3:0]; /* Rm */
72 regsel2 = ansn[11:8]; /* Rs for shift */
73 if(ansn[25]) begin /* the constant case */
75 op1_res = ({24'b0, ansn[7:0]} >> {ansn[11:8], 1'b0}) | ({24'b0, ansn[7:0]} << (5'b0 - {ansn[11:8], 1'b0}));
77 new_cps = {shift_cflag_out, cps_in[30:0]};
81 32'b????00010?00????????00001001????: begin /* Atomic swap */
83 regsel0 = ansn[19:16]; /* Rn */
84 regsel1 = ansn[3:0]; /* Rm */
85 regsel2 = 4'b0; /* anyus */
88 32'b????000100101111111111110001????: begin /* Branch and exchange */
90 regsel0 = ansn[3:0]; /* Rn */
93 32'b????000??0??????????00001??1????: begin /* Halfword transfer - register offset */
95 regsel0 = ansn[19:16];
101 32'b????000??1??????????00001??1????: begin /* Halfword transfer - immediate offset */
103 regsel0 = ansn[19:16];
105 op1_res = {24'b0, ansn[11:8], ansn[3:0]};
108 32'b????011????????????????????1????: begin /* Undefined. I hate ARM */
111 32'b????01??????????????????????????: begin /* Single data transfer */
113 regsel0 = ansn[19:16]; /* Rn */
114 regsel1 = ansn[3:0]; /* Rm */
116 op1_res = {20'b0, ansn[11:0]};
120 new_cps = shift_cflag_out;
123 32'b????100?????????????????????????: begin /* Block data transfer */
125 regsel0 = ansn[19:16];
126 op1_res = {16'b0, ansn[15:0]};
129 32'b????101?????????????????????????: begin /* Branch */
131 op1_res = {6{ansn[23]}, ansn[23:0], 2'b0};
134 32'b????110?????????????????????????: begin /* Coprocessor data transfer */
136 regsel0 = ansn[19:16];
137 op1_res = {24'b0, ansn[7:0]};
140 32'b????1110???????????????????0????: begin /* Coprocessor data op */
144 32'b????1110???????????????????1????: begin /* Coprocessor register transfer */
148 32'b????1111????????????????????????: begin /* SWI */
156 always @ (posedge clk) begin
157 op0 <= regs0; /* Rn - always */
158 op1 <= op1_res; /* 'operand 2' - Rm */
159 op2 <= regs2; /* thirdedge - Rs */
165 module IHATEARMSHIFT(
167 input [31:0] operand,
168 input [31:0] reg_amt,
173 wire [1:0] shift_type;
174 wire [5:0] shift_amt;
177 shift_type = insn[6:5];
179 shift_amt = {|reg_amt[7:5], reg_amt[4:0]};
182 shift_amt = {insn[11:7] == 5'b0, insn[11:7]};
186 /* might want to write our own damn shifter that does arithmetic/logical efficiently and stuff */
190 {cflag_out, res} = {cflag_in, operand} << {elanus & shift_amt[5], shift_amt[4:0]};
193 {res, cflag_out} = {operand, cflag_in} >> shift_amt;
196 {res, cflag_out} = {operand, cflag_in} >> shift_amt | (operand[31] ? ~(33'h1FFFFFFFF >> shift_amt) : 33'b0);
199 if(!elanus && shift_amt[4:0] == 5'b0) begin /* RRX x.x */
200 res = {cflag_in, operand[31:1]};
201 cflag_out = operand[0];
202 end else if(!shift_amt) begin
204 cflag_out = cflag_in;
206 res = operand >> shift_amt[4:0] | operand << (5'b0 - shift_amt[4:0]);
207 cflag_out = operand[shift_amt[4:0] - 5'b1];