Added HLT instruction, made testbench count total clock cycles and write memdump and fixed reset timing

This commit is contained in:
(Tim) Efthimis Kritikos 2023-02-10 18:20:28 +00:00
parent cd918302cc
commit fc4ecdb8d2
4 changed files with 36 additions and 8 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
*.swp *.swp
cpu/boot_code.bin cpu/boot_code.bin
cpu/boot_code.txt cpu/boot_code.txt
cpu/memdump.txt

View File

@ -5,3 +5,4 @@ ADD AX,#0xDEAD
ADD CX,#0xBEEF ADD CX,#0xBEEF
ADD CX,#0x4111 ADD CX,#0x4111
ADD AX,#0x2200 ADD AX,#0x2200
HLT

View File

@ -33,6 +33,7 @@ reg [1:0] out_sel;
always @(negedge reset) begin always @(negedge reset) begin
if (reset==0) begin if (reset==0) begin
@(posedge clock); @(posedge clock);
state=`PROC_HALT_STATE;
ProgCount=0;//TODO: Reset Vector ProgCount=0;//TODO: Reset Vector
EXCEPTION=0; EXCEPTION=0;
HALT=0; HALT=0;
@ -41,8 +42,8 @@ always @(negedge reset) begin
reg_read_read=1; reg_read_read=1;
unaligned_access=0; unaligned_access=0;
ALU_OUT=1; ALU_OUT=1;
@(posedge reset)
@(negedge clock); @(negedge clock);
@(posedge clock);
state=`PROC_IF_STATE_ENTRY; state=`PROC_IF_STATE_ENTRY;
end end
end end
@ -128,8 +129,8 @@ end
always @(posedge clock) begin always @(posedge clock) begin
case(state) case(state)
`PROC_HALT_STATE: `PROC_HALT_STATE:begin
HALT=1; end
`PROC_IF_STATE_ENTRY:begin `PROC_IF_STATE_ENTRY:begin
EXCEPTION=0; EXCEPTION=0;
external_address_bus <= ProgCount; external_address_bus <= ProgCount;
@ -228,6 +229,21 @@ always @(posedge clock) begin
`invalid_instruction `invalid_instruction
end end
end end
6'b111101 : begin
/*HLT, CMC, TEST, NOT, NEG, MUL, IMUL, .... */
case (CIR[9:8])
2'b00:begin
/* HLT*/
unaligned_access=~unaligned_access;
HALT=1;
state=`PROC_HALT_STATE;
end
default:begin
`invalid_instruction;
end
endcase
end
default:begin default:begin
`invalid_instruction `invalid_instruction
end end

View File

@ -16,21 +16,31 @@ rom bootrom(address_bus,data_bus,rd,romcs);
clock_gen #(.FREQ(1000)) u1(clk_enable, clock); clock_gen #(.FREQ(1000)) u1(clk_enable, clock);
assign romcs=0; assign romcs=0;
integer cycles=0;
initial begin initial begin
$dumpfile("test.lx2"); $dumpfile("test.lx2");
$dumpvars(0,p); $dumpvars(0,p);
reset = 0;
clk_enable <= 1; clk_enable <= 1;
#($random%500) #($random%500)
reset = 0;
#(`CPU_SPEED) #(`CPU_SPEED)
reset = 1; reset = 1;
#(`CPU_SPEED*55)
//$writememh("register_dump.txt", registers);
#50 $finish;
end end
always @(posedge HALT) begin
$display("Processor halted.\nCycles run for: %d",cycles);
$writememh("memdump.txt", bootrom.memory);
#(`CPU_SPEED) //Just for the waveform
$finish;
end
always @(posedge clock)begin
if(reset==1)
cycles=cycles+1;
end
endmodule endmodule