EEyE:
This may not be of much help, but I think the problem you are having is not in the ALU but in the CPU of your core. I think the issue is a mis-decode of the required operation, and an issue in the the evaluation order of the CI multiplexer. (You have much more experience with this core, and I haven't attempted to set up a simulation to verify my observations. Thus, your conjecture may be correct, and my analysis may be incorrect.)
You have a signal for rotate operations:
Code:
always @(posedge clk )
if( state == DECODE && RDY )
casex( IR[15:0] )
16'bxxxx_xxxx_0x10_1010, // ROL[A..D]op[A..D], ROR[A..D]op[A..D] acc
16'bxxxx_0000_0x1x_x110: // ROR, ROL a, ax, zp, zpx
rotate <= 1;
default: rotate <= 0;
endcase
You also have a signal for shift operations:
Code:
always @(posedge clk )
if( state == DECODE && RDY )
casex( IR[15:0] )
16'bxxxx_0000_0xxx_x110, // ASL, ROL, LSR, ROR a, ax, zp, zpx
16'bxxxx_xxxx_0xx0_1010: // ASL[A..D]op[A..D], ROL[A..D]op[A..D], LSR[A..D]op[A..D], ROR[A..D]op[A..D] acc
shift <= 1;
default: shift <= 0;
endcase
Clearly, the
rotate signal only deals with ROR/ROL instructions. The
shift signal appears to assert for both ROR/ROL and ASL and LSR. I think that
shift should only assert for ASL/LSR, and
rotate should only assert for ROL/ROR.
I think that the CI multiplexer is not selecting 1'b0 as the input because
shift follows the
rotate in the nested if-else represented by the trigraphs in the CI multiplexer specification:
Code:
/*
* ALU CI (carry in) mux
*/
always @*
case( state )
INDY2,
BRA1,
ABSX1 : CI = CO;
DECODE,
ABS1 : CI = 1'bx;
READ,
REG : CI = rotate ? C
: shift ? 0
: inc;
FETCH : CI = rotate ? C
: compare ? 1
: (shift | load_only) ? 0
: C;
PULL0,
RTI0,
RTI1,
RTI2,
RTS0,
RTS1,
INDY0,
INDX1 : CI = 1;
default : CI = 0;
endcase
If I'm not too far off, in the READ or REG states, I might rewrite the equation for CI as follows:
Code:
READ,
REG : CI = (rotate | shift) ? (rotate ? C : 0)
: inc;
If the execution of the instruction takes place during the fetch cycle, then the adjustment suggested above may need to be applied to the nested if-else of the FETCH state.
Hope this helps.