3 input Nrst, /* XXX not used yet */
17 output reg outstall = 0,
18 output reg outbubble = 1,
19 output reg [31:0] outcpsr = 0,
20 output reg write_reg = 1'bx,
21 output reg [3:0] write_num = 4'bxxxx,
22 output reg [31:0] write_data = 32'hxxxxxxxx
26 reg [31:0] mult_acc0, mult_in0, mult_in1;
28 wire [31:0] mult_result;
30 reg [31:0] alu_in0, alu_in1;
33 wire [31:0] alu_result, alu_outcpsr;
37 reg [31:0] next_outcpsr;
39 reg [3:0] next_write_num;
40 reg [31:0] next_write_data;
42 Multiplier multiplier(
43 .clk(clk), .Nrst(Nrst),
44 .start(mult_start), .acc0(mult_acc0), .in0(mult_in0),
45 .in1(mult_in1), .done(mult_done), .result(mult_result));
48 .clk(clk), .Nrst(Nrst),
49 .in0(alu_in0), .in1(alu_in1), .cpsr(cpsr), .op(alu_op),
50 .setflags(alu_setflags), .shifter_carry(carry),
51 .result(alu_result), .cpsr_out(alu_outcpsr), .setres(alu_setres));
57 outbubble <= next_outbubble;
58 outcpsr <= next_outcpsr;
59 write_reg <= next_write_reg;
60 write_num <= next_write_num;
61 write_data <= next_write_data;
67 prevstall <= outstall;
72 next_outbubble = inbubble;
75 next_write_num = 4'hx;
76 next_write_data = 32'hxxxxxxxx;
79 mult_acc0 = 32'hxxxxxxxx;
80 mult_in0 = 32'hxxxxxxxx;
81 mult_in1 = 32'hxxxxxxxx;
83 alu_in0 = 32'hxxxxxxxx;
84 alu_in1 = 32'hxxxxxxxx;
85 alu_op = 4'hx; /* hax! */
89 `DECODE_ALU_MULT: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
91 if (!prevstall && !inbubble)
94 mult_acc0 = insn[21] /* A */ ? op0 /* Rn */ : 32'h0;
95 mult_in0 = op1 /* Rm */;
96 mult_in1 = op2 /* Rs */;
97 $display("New MUL instruction");
99 outstall = stall | ((!prevstall | !mult_done) && !inbubble);
100 next_outbubble = inbubble | !mult_done | !prevstall;
101 next_outcpsr = insn[20] /* S */ ? {mult_result[31] /* N */, mult_result == 0 /* Z */, 1'b0 /* C */, cpsr[28] /* V */, cpsr[27:0]} : cpsr;
103 next_write_num = insn[19:16] /* Rd -- why the fuck isn't this the same place as ALU */;
104 next_write_data = mult_result;
106 // `DECODE_ALU_MUL_LONG, /* Multiply long */
107 `DECODE_ALU_MRS, /* MRS (Transfer PSR to register) */
108 `DECODE_ALU_MSR, /* MSR (Transfer register to PSR) */
109 `DECODE_ALU_MSR_FLAGS, /* MSR (Transfer register or immediate to PSR, flag bits only) */
110 `DECODE_ALU_SWP, /* Atomic swap */
111 `DECODE_ALU_BX, /* Branch */
112 `DECODE_ALU_HDATA_REG, /* Halfword transfer - register offset */
113 `DECODE_ALU_HDATA_IMM: /* Halfword transfer - immediate offset */
115 `DECODE_ALU: /* ALU */
119 alu_op = insn[24:21];
120 alu_setflags = insn[20] /* I */;
122 if (alu_setres) begin
124 next_write_num = insn[15:12] /* Rd */;
125 next_write_data = alu_result;
128 next_outcpsr = alu_outcpsr;
130 `DECODE_LDRSTR_UNDEFINED, /* Undefined. I hate ARM */
131 `DECODE_LDRSTR, /* Single data transfer */
132 `DECODE_LDMSTM, /* Block data transfer */
133 `DECODE_BRANCH, /* Branch */
134 `DECODE_LDCSTC, /* Coprocessor data transfer */
135 `DECODE_CDP, /* Coprocessor data op */
136 `DECODE_MRCMCR, /* Coprocessor register transfer */
137 `DECODE_SWI: /* SWI */
139 default: /* X everything else out */
147 input Nrst, /* XXX not used yet */
155 output reg [31:0] result);
158 reg [31:0] multiplicand;
161 always @(posedge clk)
169 bitfield <= {2'b00, bitfield[31:2]};
170 multiplicand <= {multiplicand[29:0], 2'b00};
172 (bitfield[0] ? multiplicand : 0) +
173 (bitfield[1] ? {multiplicand[30:0], 1'b0} : 0);
174 if (bitfield == 0) begin
182 /* XXX is the interface correct? */
185 input Nrst, /* XXX not used yet */
194 output reg [31:0] result,
195 output reg [31:0] cpsr_out,
199 wire flag_n, flag_z, flag_c, flag_v, setres;
200 wire [32:0] sum, diff, rdiff;
202 assign sum = {1'b0, in0} + {1'b0, in1};
203 assign diff = {1'b0, in0} - {1'b0, in1};
204 assign rdiff = {1'b0, in1} + {1'b0, in0};
206 /* TODO XXX flag_v not set correctly */
210 flag_c = cpsr[`CPSR_C];
211 flag_v = cpsr[`CPSR_V];
215 flag_c = shifter_carry;
220 flag_c = shifter_carry;
224 {flag_c, result} = diff;
228 {flag_c, result} = rdiff;
232 {flag_c, result} = sum;
236 {flag_c, result} = sum + {32'b0, cpsr[`CPSR_C]};
240 {flag_c, result} = diff - {32'b0, (~cpsr[`CPSR_C])};
244 {flag_c, result} = rdiff - {32'b0, (~cpsr[`CPSR_C])};
249 flag_c = shifter_carry;
254 flag_c = shifter_carry;
258 {flag_c, result} = diff;
262 {flag_c, result} = sum;
267 flag_c = shifter_carry;
272 flag_c = shifter_carry;
276 result = in0 & (~in1);
277 flag_c = shifter_carry;
282 flag_c = shifter_carry;
287 flag_z = (result == 0);
290 cpsr_out = setflags ? {flag_n, flag_z, flag_c, flag_v, cpsr[27:0]} : cpsr;