+
+ /* Drive the state machines and stall. */
+ always @(*)
+ begin
+ outstall = 1'b0;
+ next_lsm_state = lsm_state;
+ next_lsr_state = lsr_state;
+ next_lsrh_state = lsrh_state;
+ next_swp_state = swp_state;
+ casez(insn)
+ `DECODE_ALU_SWP: if(!inbubble) begin
+ case(swp_state)
+ `SWP_READING: begin
+ outstall = 1'b1;
+ if (!rw_wait)
+ next_swp_state = `SWP_WRITING;
+ $display("SWP: read stage");
+ end
+ `SWP_WRITING: begin
+ outstall = rw_wait;
+ if(!rw_wait)
+ next_swp_state = `SWP_READING;
+ $display("SWP: write stage");
+ end
+ default: begin
+ outstall = 1'bx;
+ next_swp_state = 2'bxx;
+ end
+ endcase
+ end
+ `DECODE_ALU_MULT: begin end
+ `DECODE_ALU_HDATA_REG,
+ `DECODE_ALU_HDATA_IMM: if(!inbubble) begin
+ case(lsrh_state)
+ `LSRH_MEMIO: begin
+ outstall = rw_wait;
+ if(insn[21] | !insn[24]) begin
+ outstall = 1'b1;
+ if(!rw_wait)
+ next_lsrh_state = `LSRH_BASEWB;
+ end
+
+ if (flush) /* special case! */ begin
+ outstall = 1'b0;
+ next_lsrh_state = `LSRH_MEMIO;
+ end
+
+ $display("ALU_LDRSTRH: rd_req %d, wr_req %d", rd_req, wr_req);
+ end
+ `LSRH_BASEWB: begin
+ outstall = 1'b1;
+ next_lsrh_state = `LSRH_WBFLUSH;
+ end
+ `LSRH_WBFLUSH: begin
+ outstall = 1'b0;
+ next_lsrh_state = `LSRH_MEMIO;
+ end
+ default: begin
+ outstall = 1'bx;
+ next_lsrh_state = 3'bxxx;
+ end
+ endcase
+ end
+ `DECODE_LDRSTR_UNDEFINED: begin end
+ `DECODE_LDRSTR: if(!inbubble) begin
+ outstall = rw_wait;
+ case(lsr_state)
+ `LSR_MEMIO: begin
+ outstall = rw_wait;
+ next_lsr_state = `LSR_MEMIO;
+ if (insn[22] /* B */ && !insn[20] /* L */) begin /* i.e., strb */
+ outstall = 1'b1;
+ if (!rw_wait)
+ next_lsr_state = `LSR_STRB_WR;
+ end else if (insn[21] /* W */ || !insn[24] /* P */) begin /* writeback needed */
+ outstall = 1'b1;
+ if (!rw_wait)
+ next_lsr_state = `LSR_BASEWB;
+ end
+
+ if (flush) begin
+ outstall = 1'b0;
+ next_lsr_state = `LSR_MEMIO;
+ end
+ $display("LDRSTR: rd_req %d, wr_req %d, raddr %08x, wait %d", rd_req, wr_req, raddr, rw_wait);
+ end
+ `LSR_STRB_WR: begin
+ outstall = 1;
+ if(insn[21] /* W */ | !insn[24] /* P */) begin
+ if(!rw_wait)
+ next_lsr_state = `LSR_BASEWB;
+ end else if (!rw_wait)
+ next_lsr_state = `LSR_WBFLUSH;
+ $display("LDRSTR: Handling STRB");
+ end
+ `LSR_BASEWB: begin
+ outstall = 1;
+ next_lsr_state = `LSR_WBFLUSH;
+ end
+ `LSR_WBFLUSH: begin
+ outstall = 0;
+ next_lsr_state = `LSR_MEMIO;
+ end
+ default: begin
+ outstall = 1'bx;
+ next_lsr_state = 4'bxxxx;
+ end
+ endcase
+ $display("LDRSTR: Decoded, bubble %d, insn %08x, lsm state %b -> %b, stall %d", inbubble, insn, lsr_state, next_lsr_state, outstall);
+ end
+ `DECODE_LDMSTM: if(!inbubble) begin
+ outstall = rw_wait;
+ case(lsm_state)
+ `LSM_SETUP: begin
+ outstall = 1'b1;
+ next_lsm_state = `LSM_MEMIO;
+ if (flush) begin
+ outstall = 1'b0;
+ next_lsm_state = `LSM_SETUP;
+ end
+ $display("LDMSTM: Round 1: base register: %08x, reg list %b", op0, op1[15:0]);
+ end
+ `LSM_MEMIO: begin
+ outstall = 1'b1;
+ if(next_regs == 16'b0) begin
+ next_lsm_state = `LSM_BASEWB;
+ end
+
+ $display("LDMSTM: Stage 2: Writing: regs %b, next_regs %b, reg %d, wr_data %08x, addr %08x", regs, next_regs, cur_reg, wr_data, busaddr);
+ end
+ `LSM_BASEWB: begin
+ outstall = 1;
+ next_lsm_state = `LSM_WBFLUSH;
+ $display("LDMSTM: Stage 3: Writing back");
+ end
+ `LSM_WBFLUSH: begin
+ outstall = 0;
+ next_lsm_state = `LSM_SETUP;
+ end
+ default: begin
+ outstall = 1'bx;
+ next_lsm_state = 4'bxxxx;
+ end
+ endcase
+ $display("LDMSTM: Decoded, bubble %d, insn %08x, lsm state %b -> %b, stall %d", inbubble, insn, lsm_state, next_lsm_state, outstall);
+ end
+ `DECODE_LDCSTC: if(!inbubble) begin
+ $display("WARNING: Unimplemented LDCSTC");
+ end
+ `DECODE_CDP: if (!inbubble) begin
+ if (cp_busy) begin
+ outstall = 1;
+ end
+ end
+ `DECODE_MRCMCR: if (!inbubble) begin
+ if (cp_busy) begin
+ outstall = 1;
+ end
+ $display("MRCMCR: ack %d, busy %d", cp_ack, cp_busy);
+ end
+ default: begin end
+ endcase
+ end