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;
68 next_outbubble = inbubble;
71 next_write_num = 4'hx;
72 next_write_data = 32'hxxxxxxxx;
74 alu_in0 = 32'hxxxxxxxx;
75 alu_in1 = 32'hxxxxxxxx;
76 alu_op = 4'hx; /* hax! */
80 `DECODE_ALU_MULT, /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
81 // `DECODE_ALU_MUL_LONG, /* Multiply long */
82 `DECODE_ALU_MRS, /* MRS (Transfer PSR to register) */
83 `DECODE_ALU_MSR, /* MSR (Transfer register to PSR) */
84 `DECODE_ALU_MSR_FLAGS, /* MSR (Transfer register or immediate to PSR, flag bits only) */
85 `DECODE_ALU_SWP, /* Atomic swap */
86 `DECODE_ALU_BX, /* Branch */
87 `DECODE_ALU_HDATA_REG, /* Halfword transfer - register offset */
88 `DECODE_ALU_HDATA_IMM: /* Halfword transfer - immediate offset */
90 `DECODE_ALU: /* ALU */
95 alu_setflags = insn[20] /* I */;
99 next_write_num = insn[15:12] /* Rd */;
100 next_write_data = alu_result;
103 next_outcpsr = alu_outcpsr;
105 `DECODE_LDRSTR_UNDEFINED, /* Undefined. I hate ARM */
106 `DECODE_LDRSTR, /* Single data transfer */
107 `DECODE_LDMSTM, /* Block data transfer */
108 `DECODE_BRANCH, /* Branch */
109 `DECODE_LDCSTC, /* Coprocessor data transfer */
110 `DECODE_CDP, /* Coprocessor data op */
111 `DECODE_MRCMCR, /* Coprocessor register transfer */
112 `DECODE_SWI: /* SWI */
114 default: /* X everything else out */
122 input Nrst, /* XXX not used yet */
130 output reg [31:0] result);
133 reg [31:0] multiplicand;
136 always @(posedge clk)
144 bitfield <= {2'b00, bitfield[31:2]};
145 multiplicand <= {multiplicand[29:0], 2'b00};
147 (bitfield[0] ? multiplicand : 0) +
148 (bitfield[1] ? {multiplicand[30:0], 1'b0} : 0);
149 if (bitfield == 0) begin
157 /* XXX is the interface correct? */
160 input Nrst, /* XXX not used yet */
169 output reg [31:0] result,
170 output reg [31:0] cpsr_out,
174 wire flag_n, flag_z, flag_c, flag_v, setres;
175 wire [32:0] sum, diff, rdiff;
177 assign sum = {1'b0, in0} + {1'b0, in1};
178 assign diff = {1'b0, in0} - {1'b0, in1};
179 assign rdiff = {1'b0, in1} + {1'b0, in0};
181 /* TODO XXX flag_v not set correctly */
185 flag_c = cpsr[`CPSR_C];
186 flag_v = cpsr[`CPSR_V];
190 flag_c = shifter_carry;
195 flag_c = shifter_carry;
199 {flag_c, result} = diff;
203 {flag_c, result} = rdiff;
207 {flag_c, result} = sum;
211 {flag_c, result} = sum + {32'b0, cpsr[`CPSR_C]};
215 {flag_c, result} = diff - {32'b0, (~cpsr[`CPSR_C])};
219 {flag_c, result} = rdiff - {32'b0, (~cpsr[`CPSR_C])};
224 flag_c = shifter_carry;
229 flag_c = shifter_carry;
233 {flag_c, result} = diff;
237 {flag_c, result} = sum;
242 flag_c = shifter_carry;
247 flag_c = shifter_carry;
251 result = in0 & (~in1);
252 flag_c = shifter_carry;
257 flag_c = shifter_carry;
262 flag_z = (result == 0);
265 cpsr_out = setflags ? {flag_n, flag_z, flag_c, flag_v, cpsr[27:0]} : cpsr;