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;
36 Multiplier multiplier(
37 .clk(clk), .Nrst(Nrst),
38 .start(mult_start), .acc0(mult_acc0), .in0(mult_in0),
39 .in1(mult_in1), .done(mult_done), .result(mult_result));
42 .clk(clk), .Nrst(Nrst),
43 .in0(alu_in0), .in1(alu_in1), .cpsr(cpsr), .op(alu_op),
44 .setflags(alu_setflags), .shifter_carry(carry),
45 .result(alu_result), .cpsr_out(alu_outcpsr), .set(alu_set));
49 `DECODE_ALU_MULT, /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
50 // `DECODE_ALU_MUL_LONG, /* Multiply long */
51 `DECODE_ALU_MRS, /* MRS (Transfer PSR to register) */
52 `DECODE_ALU_MSR, /* MSR (Transfer register to PSR) */
53 `DECODE_ALU_MSR_FLAGS, /* MSR (Transfer register or immediate to PSR, flag bits only) */
54 `DECODE_ALU_SWP, /* Atomic swap */
55 `DECODE_ALU_BX, /* Branch */
56 `DECODE_ALU_HDATA_REG, /* Halfword transfer - register offset */
57 `DECODE_ALU_HDATA_IMM, /* Halfword transfer - immediate offset */
58 `DECODE_ALU, /* ALU */
59 `DECODE_LDRSTR_UNDEFINED, /* Undefined. I hate ARM */
60 `DECODE_LDRSTR, /* Single data transfer */
61 `DECODE_LDMSTM, /* Block data transfer */
62 `DECODE_BRANCH, /* Branch */
63 `DECODE_LDCSTC, /* Coprocessor data transfer */
64 `DECODE_CDP, /* Coprocessor data op */
65 `DECODE_MRCMCR, /* Coprocessor register transfer */
66 `DECODE_SWI: /* SWI */
68 default: /* X everything else out */
75 input Nrst, /* XXX not used yet */
83 output reg [31:0] result);
86 reg [31:0] multiplicand;
97 bitfield <= {2'b00, bitfield[31:2]};
98 multiplicand <= {multiplicand[29:0], 2'b00};
100 (bitfield[0] ? multiplicand : 0) +
101 (bitfield[1] ? {multiplicand[30:0], 1'b0} : 0);
102 if (bitfield == 0) begin
110 /* XXX is the interface correct? */
113 input Nrst, /* XXX not used yet */
122 output reg [31:0] result,
123 output reg [31:0] cpsr_out,
127 wire flag_n, flag_z, flag_c, flag_v, setres;
128 wire [32:0] sum, diff, rdiff;
130 assign sum = {1'b0, in0} + {1'b0, in1};
131 assign diff = {1'b0, in0} - {1'b0, in1};
132 assign rdiff = {1'b0, in1} + {1'b0, in0};
134 /* TODO XXX flag_v not set correctly */
138 flag_c = cpsr[`CPSR_C];
139 flag_v = cpsr[`CPSR_V];
143 flag_c = shifter_carry;
148 flag_c = shifter_carry;
152 {flag_c, res} = diff;
156 {flag_c, res} = rdiff;
164 {flag_c, res} = sum + {32'b0, cpsr[`CPSR_C]};
168 {flag_c, res} = diff - {32'b0, (~cpsr[`CPSR_C])};
172 {flag_c, res} = rdiff - {32'b0, (~cpsr[`CPSR_C])};
177 flag_c = shifter_carry;
182 flag_c = shifter_carry;
186 {flag_c, res} = diff;
195 flag_c = shifter_carry;
200 flag_c = shifter_carry;
205 flag_c = shifter_carry;
210 flag_c = shifter_carry;
221 always @(posedge clk) begin
223 cpsr_out <= setflags ? {flag_n, flag_z, flag_c, flag_v, cpsr[27:0]} : cpsr;