Line 98... |
Line 98... |
`define ADD_IX 8'h61
|
`define ADD_IX 8'h61
|
`define ADD_IY 8'h71
|
`define ADD_IY 8'h71
|
`define ADD_ABS 8'h6D
|
`define ADD_ABS 8'h6D
|
`define ADD_ABSX 8'h7D
|
`define ADD_ABSX 8'h7D
|
`define ADD_RIND 8'h72
|
`define ADD_RIND 8'h72
|
|
`define ADD_DSP 8'h63
|
|
|
`define SUB_IMM8 8'hE5
|
`define SUB_IMM8 8'hE5
|
`define SUB_IMM16 8'hF9
|
`define SUB_IMM16 8'hF9
|
`define SUB_IMM32 8'hE9
|
`define SUB_IMM32 8'hE9
|
`define SUB_ZPX 8'hF5
|
`define SUB_ZPX 8'hF5
|
`define SUB_IX 8'hE1
|
`define SUB_IX 8'hE1
|
`define SUB_IY 8'hF1
|
`define SUB_IY 8'hF1
|
`define SUB_ABS 8'hED
|
`define SUB_ABS 8'hED
|
`define SUB_ABSX 8'hFD
|
`define SUB_ABSX 8'hFD
|
`define SUB_RIND 8'hF2
|
`define SUB_RIND 8'hF2
|
|
`define SUB_DSP 8'hE3
|
|
|
// CMP = SUB r0,....
|
// CMP = SUB r0,....
|
|
|
`define ADC_IMM 8'h69
|
`define ADC_IMM 8'h69
|
`define ADC_ZP 8'h65
|
`define ADC_ZP 8'h65
|
Line 161... |
Line 163... |
`define AND_ABS 8'h2D
|
`define AND_ABS 8'h2D
|
`define AND_ABSX 8'h3D
|
`define AND_ABSX 8'h3D
|
`define AND_ABSY 8'h39
|
`define AND_ABSY 8'h39
|
`define AND_RIND 8'h32
|
`define AND_RIND 8'h32
|
`define AND_I 8'h32
|
`define AND_I 8'h32
|
|
`define AND_DSP 8'h23
|
|
|
`define OR_IMM8 8'h05
|
`define OR_IMM8 8'h05
|
`define OR_IMM16 8'h19
|
`define OR_IMM16 8'h19
|
`define OR_IMM32 8'h09
|
`define OR_IMM32 8'h09
|
`define OR_ZPX 8'h15
|
`define OR_ZPX 8'h15
|
`define OR_IX 8'h01
|
`define OR_IX 8'h01
|
`define OR_IY 8'h11
|
`define OR_IY 8'h11
|
`define OR_ABS 8'h0D
|
`define OR_ABS 8'h0D
|
`define OR_ABSX 8'h1D
|
`define OR_ABSX 8'h1D
|
`define OR_RIND 8'h12
|
`define OR_RIND 8'h12
|
|
`define OR_DSP 8'h03
|
|
|
`define ORA_IMM 8'h09
|
`define ORA_IMM 8'h09
|
`define ORA_ZP 8'h05
|
`define ORA_ZP 8'h05
|
`define ORA_ZPX 8'h15
|
`define ORA_ZPX 8'h15
|
`define ORA_IX 8'h01
|
`define ORA_IX 8'h01
|
Line 195... |
Line 199... |
`define EOR_ABS 8'h4D
|
`define EOR_ABS 8'h4D
|
`define EOR_ABSX 8'h5D
|
`define EOR_ABSX 8'h5D
|
`define EOR_ABSY 8'h59
|
`define EOR_ABSY 8'h59
|
`define EOR_RIND 8'h52
|
`define EOR_RIND 8'h52
|
`define EOR_I 8'h52
|
`define EOR_I 8'h52
|
|
`define EOR_DSP 8'h43
|
|
|
// LD is OR rt,r0,....
|
// LD is OR rt,r0,....
|
|
|
`define ST_ZPX 8'h95
|
`define ST_ZPX 8'h95
|
`define ST_IX 8'h81
|
`define ST_IX 8'h81
|
`define ST_IY 8'h91
|
`define ST_IY 8'h91
|
`define ST_ABS 8'h8D
|
`define ST_ABS 8'h8D
|
`define ST_ABSX 8'h9D
|
`define ST_ABSX 8'h9D
|
`define ST_RIND 8'h92
|
`define ST_RIND 8'h92
|
|
`define ST_DSP 8'h83
|
|
|
`define ORB_ZPX 8'hB5
|
`define ORB_ZPX 8'hB5
|
`define ORB_IX 8'hA1
|
`define ORB_IX 8'hA1
|
`define ORB_IY 8'hB1
|
`define ORB_IY 8'hB1
|
`define ORB_ABS 8'hAD
|
`define ORB_ABS 8'hAD
|
Line 374... |
Line 380... |
`define BAZ 8'hC1
|
`define BAZ 8'hC1
|
`define BXZ 8'hD1
|
`define BXZ 8'hD1
|
`define BEQ_RR 8'hE2
|
`define BEQ_RR 8'hE2
|
`define INT0 8'hDC
|
`define INT0 8'hDC
|
`define INT1 8'hDD
|
`define INT1 8'hDD
|
|
`define SUB_SP 8'h4B
|
|
`define MVP 8'h44
|
|
`define MVN 8'h54
|
|
|
`define NOTHING 4'd0
|
`define NOTHING 4'd0
|
`define SR_70 4'd1
|
`define SR_70 4'd1
|
`define SR_310 4'd2
|
`define SR_310 4'd2
|
`define BYTE_70 4'd3
|
`define BYTE_70 4'd3
|
Line 390... |
Line 399... |
`define WORD_311 4'd10
|
`define WORD_311 4'd10
|
`define IA_310 4'd11
|
`define IA_310 4'd11
|
`define IA_70 4'd12
|
`define IA_70 4'd12
|
`define IA_158 4'd13
|
`define IA_158 4'd13
|
`define BYTE_71 4'd14
|
`define BYTE_71 4'd14
|
|
`define WORD_312 4'd15
|
|
|
module icachemem(wclk, wr, adr, dat, rclk, pc, insn);
|
module icachemem(wclk, wr, adr, dat, rclk, pc, insn);
|
input wclk;
|
input wclk;
|
input wr;
|
input wr;
|
input [33:0] adr;
|
input [33:0] adr;
|
Line 744... |
Line 754... |
parameter BYTE_CALC = 7'd104;
|
parameter BYTE_CALC = 7'd104;
|
parameter BUS_ERROR = 7'd105;
|
parameter BUS_ERROR = 7'd105;
|
parameter INSN_BUS_ERROR = 7'd106;
|
parameter INSN_BUS_ERROR = 7'd106;
|
parameter LOAD_MAC1 = 7'd107;
|
parameter LOAD_MAC1 = 7'd107;
|
parameter LOAD_MAC2 = 7'd108;
|
parameter LOAD_MAC2 = 7'd108;
|
|
parameter MVN1 = 7'd109;
|
|
parameter MVN2 = 7'd110;
|
|
parameter MVN3 = 7'd111;
|
|
parameter MVP1 = 7'd112;
|
|
parameter MVP2 = 7'd113;
|
|
|
input rst_md; // reset mode, 1=emulation mode, 0=native mode
|
input rst_md; // reset mode, 1=emulation mode, 0=native mode
|
input rst_i;
|
input rst_i;
|
input clk_i;
|
input clk_i;
|
input nmi_i;
|
input nmi_i;
|
Line 797... |
Line 812... |
wire [7:0] sp_dec = sp - 8'd1;
|
wire [7:0] sp_dec = sp - 8'd1;
|
wire [7:0] sp_inc = sp + 8'd1;
|
wire [7:0] sp_inc = sp + 8'd1;
|
wire [31:0] isp_dec = isp - 32'd1;
|
wire [31:0] isp_dec = isp - 32'd1;
|
wire [31:0] isp_inc = isp + 32'd1;
|
wire [31:0] isp_inc = isp + 32'd1;
|
reg [31:0] pc;
|
reg [31:0] pc;
|
|
reg [31:0] opc;
|
wire [31:0] pcp1 = pc + 32'd1;
|
wire [31:0] pcp1 = pc + 32'd1;
|
wire [31:0] pcp2 = pc + 32'd2;
|
wire [31:0] pcp2 = pc + 32'd2;
|
wire [31:0] pcp3 = pc + 32'd3;
|
wire [31:0] pcp3 = pc + 32'd3;
|
wire [31:0] pcp4 = pc + 32'd4;
|
wire [31:0] pcp4 = pc + 32'd4;
|
wire [31:0] pcp8 = pc + 32'd8;
|
wire [31:0] pcp8 = pc + 32'd8;
|
Line 874... |
Line 890... |
reg [1:0] wadr2LSB;
|
reg [1:0] wadr2LSB;
|
reg [31:0] wdat;
|
reg [31:0] wdat;
|
wire [31:0] rdat;
|
wire [31:0] rdat;
|
reg [3:0] load_what;
|
reg [3:0] load_what;
|
reg [3:0] store_what;
|
reg [3:0] store_what;
|
|
reg [31:0] derr_address;
|
reg imiss;
|
reg imiss;
|
reg dmiss;
|
reg dmiss;
|
reg icacheOn,dcacheOn;
|
reg icacheOn,dcacheOn;
|
wire unCachedData = radr[31:20]==12'hFFD || !dcacheOn; // I/O area is uncached
|
wire unCachedData = radr[31:20]==12'hFFD || !dcacheOn; // I/O area is uncached
|
wire unCachedInsn = pc[31:13]==19'h0 || !icacheOn; // The lowest 8kB is uncached.
|
wire unCachedInsn = pc[31:13]==19'h0 || !icacheOn; // The lowest 8kB is uncached.
|
Line 905... |
Line 922... |
wire isOrb = ir[7:0]==`ORB_ZPX || ir[7:0]==`ORB_IX || ir[7:0]==`ORB_IY || ir[7:0]==`ORB_ABS || ir[7:0]==`ORB_ABSX;
|
wire isOrb = ir[7:0]==`ORB_ZPX || ir[7:0]==`ORB_IX || ir[7:0]==`ORB_IY || ir[7:0]==`ORB_ABS || ir[7:0]==`ORB_ABSX;
|
wire isStb = ir[7:0]==`STB_ZPX || ir[7:0]==`STB_ABS || ir[7:0]==`STB_ABSX;
|
wire isStb = ir[7:0]==`STB_ZPX || ir[7:0]==`STB_ABS || ir[7:0]==`STB_ABSX;
|
wire isRTI = ir[7:0]==`RTI;
|
wire isRTI = ir[7:0]==`RTI;
|
wire isRTL = ir[7:0]==`RTL;
|
wire isRTL = ir[7:0]==`RTL;
|
wire isRTS = ir[7:0]==`RTS;
|
wire isRTS = ir[7:0]==`RTS;
|
|
wire isMove = ir[7:0]==`MVP || ir[7:0]==`MVN;
|
wire ld_muldiv = state==DECODE && ir[7:0]==`RR;
|
wire ld_muldiv = state==DECODE && ir[7:0]==`RR;
|
wire md_done;
|
wire md_done;
|
wire clk;
|
wire clk;
|
reg isIY;
|
reg isIY;
|
|
|
Line 1291... |
Line 1309... |
|
|
BUS_ERROR:
|
BUS_ERROR:
|
begin
|
begin
|
radr <= isp_dec;
|
radr <= isp_dec;
|
wadr <= isp_dec;
|
wadr <= isp_dec;
|
wdat <= pc;
|
wdat <= opc;
|
|
if (em | isOrb | isStb)
|
|
derr_address <= adr_o[31:0];
|
|
else
|
|
derr_address <= adr_o[33:2];
|
cyc_o <= 1'b1;
|
cyc_o <= 1'b1;
|
stb_o <= 1'b1;
|
stb_o <= 1'b1;
|
we_o <= 1'b1;
|
we_o <= 1'b1;
|
sel_o <= 4'hF;
|
sel_o <= 4'hF;
|
adr_o <= {isp_dec,2'b00};
|
adr_o <= {isp_dec,2'b00};
|
dat_o <= pc;
|
dat_o <= opc;
|
vect <= {vbr[31:9],9'd508,2'b00};
|
vect <= {vbr[31:9],9'd508,2'b00};
|
state <= IRQ1;
|
state <= IRQ1;
|
end
|
end
|
INSN_BUS_ERROR:
|
INSN_BUS_ERROR:
|
begin
|
begin
|
radr <= isp_dec;
|
radr <= isp_dec;
|
wadr <= isp_dec;
|
wadr <= isp_dec;
|
wdat <= pc;
|
wdat <= opc;
|
cyc_o <= 1'b1;
|
cyc_o <= 1'b1;
|
stb_o <= 1'b1;
|
stb_o <= 1'b1;
|
we_o <= 1'b1;
|
we_o <= 1'b1;
|
sel_o <= 4'hF;
|
sel_o <= 4'hF;
|
adr_o <= {isp_dec,2'b00};
|
adr_o <= {isp_dec,2'b00};
|
dat_o <= pc;
|
dat_o <= opc;
|
vect <= {vbr[31:9],9'd509,2'b00};
|
vect <= {vbr[31:9],9'd509,2'b00};
|
state <= IRQ1;
|
state <= IRQ1;
|
end
|
end
|
|
|
|
MVN1:
|
|
begin
|
|
radr <= x;
|
|
x <= x + 32'd1;
|
|
retstate <= MVN2;
|
|
load_what <= `WORD_312;
|
|
state <= LOAD_MAC1;
|
|
end
|
|
MVN2:
|
|
begin
|
|
wadr <= y;
|
|
wdat <= b;
|
|
y <= y + 32'd1;
|
|
acc <= acc - 32'd1;
|
|
state <= STORE1;
|
|
end
|
|
MVN3:
|
|
begin
|
|
state <= IFETCH;
|
|
if (acc==32'hFFFFFFFF)
|
|
pc <= pc + 32'd1;
|
|
end
|
|
MVP1:
|
|
begin
|
|
radr <= x;
|
|
x <= x - 32'd1;
|
|
retstate <= MVP2;
|
|
load_what <= `WORD_312;
|
|
state <= LOAD_MAC1;
|
|
end
|
|
MVP2:
|
|
begin
|
|
wadr <= y;
|
|
wdat <= b;
|
|
y <= y - 32'd1;
|
|
acc <= acc - 32'd1;
|
|
state <= STORE1;
|
|
end
|
|
|
endcase
|
endcase
|
|
|
`include "cache_controller.v"
|
`include "cache_controller.v"
|
|
|
end
|
end
|