From efd0269b55e2db03f5c12d6f47b00b0c2a57ff66 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Thu, 3 Sep 2020 20:22:41 +0200 Subject: rename stack_machine to stack_machine_old (prepare for redesign of the machine) --- Makefile | 13 +- design/stack_machine.v | 356 --------------------- design/stack_machine_old.v | 356 +++++++++++++++++++++ tests/stack_machine_add/instructions.s.tcl | 20 -- tests/stack_machine_add/test.v | 1 - tests/stack_machine_add/words_to_verify.mem | 9 - tests/stack_machine_cond_jump/instructions.s.tcl | 45 --- tests/stack_machine_cond_jump/test.v | 1 - tests/stack_machine_cond_jump/words_to_verify.mem | 9 - tests/stack_machine_div/instructions.s.tcl | 23 -- tests/stack_machine_div/test.v | 1 - tests/stack_machine_div/words_to_verify.mem | 12 - tests/stack_machine_jump/instructions.s.tcl | 22 -- tests/stack_machine_jump/test.v | 1 - tests/stack_machine_jump/words_to_verify.mem | 2 - tests/stack_machine_load_store/instructions.s.tcl | 109 ------- tests/stack_machine_load_store/test.v | 1 - tests/stack_machine_load_store/words_to_verify.mem | 12 - tests/stack_machine_mul/instructions.s.tcl | 42 --- tests/stack_machine_mul/test.v | 1 - tests/stack_machine_mul/words_to_verify.mem | 19 -- .../instructions.s.tcl | 32 -- .../test.v | 1 - .../words_to_verify.mem | 1 - tests/stack_machine_old_add/instructions.s.tcl | 20 ++ tests/stack_machine_old_add/test.v | 1 + tests/stack_machine_old_add/words_to_verify.mem | 9 + .../stack_machine_old_cond_jump/instructions.s.tcl | 45 +++ tests/stack_machine_old_cond_jump/test.v | 1 + .../words_to_verify.mem | 9 + tests/stack_machine_old_div/instructions.s.tcl | 23 ++ tests/stack_machine_old_div/test.v | 1 + tests/stack_machine_old_div/words_to_verify.mem | 12 + tests/stack_machine_old_jump/instructions.s.tcl | 22 ++ tests/stack_machine_old_jump/test.v | 1 + tests/stack_machine_old_jump/words_to_verify.mem | 2 + .../instructions.s.tcl | 109 +++++++ tests/stack_machine_old_load_store/test.v | 1 + .../words_to_verify.mem | 12 + tests/stack_machine_old_mul/instructions.s.tcl | 42 +++ tests/stack_machine_old_mul/test.v | 1 + tests/stack_machine_old_mul/words_to_verify.mem | 19 ++ .../instructions.s.tcl | 32 ++ .../test.v | 1 + .../words_to_verify.mem | 1 + tests/stack_machine_old_store/instructions.s.tcl | 29 ++ tests/stack_machine_old_store/test.v | 140 ++++++++ tests/stack_machine_old_store/words_to_verify.mem | 3 + tests/stack_machine_old_sub/instructions.s.tcl | 21 ++ tests/stack_machine_old_sub/test.v | 1 + tests/stack_machine_old_sub/words_to_verify.mem | 9 + tests/stack_machine_old_swap/instructions.s.tcl | 15 + tests/stack_machine_old_swap/test.v | 1 + tests/stack_machine_old_swap/words_to_verify.mem | 5 + tests/stack_machine_old_tee/instructions.s.tcl | 15 + tests/stack_machine_old_tee/test.v | 1 + tests/stack_machine_old_tee/words_to_verify.mem | 5 + tests/stack_machine_store/instructions.s.tcl | 29 -- tests/stack_machine_store/test.v | 140 -------- tests/stack_machine_store/words_to_verify.mem | 3 - tests/stack_machine_sub/instructions.s.tcl | 21 -- tests/stack_machine_sub/test.v | 1 - tests/stack_machine_sub/words_to_verify.mem | 9 - tests/stack_machine_swap/instructions.s.tcl | 15 - tests/stack_machine_swap/test.v | 1 - tests/stack_machine_swap/words_to_verify.mem | 5 - tests/stack_machine_tee/instructions.s.tcl | 15 - tests/stack_machine_tee/test.v | 1 - tests/stack_machine_tee/words_to_verify.mem | 5 - 69 files changed, 972 insertions(+), 971 deletions(-) delete mode 100644 design/stack_machine.v create mode 100644 design/stack_machine_old.v delete mode 100755 tests/stack_machine_add/instructions.s.tcl delete mode 120000 tests/stack_machine_add/test.v delete mode 100644 tests/stack_machine_add/words_to_verify.mem delete mode 100755 tests/stack_machine_cond_jump/instructions.s.tcl delete mode 120000 tests/stack_machine_cond_jump/test.v delete mode 100644 tests/stack_machine_cond_jump/words_to_verify.mem delete mode 100755 tests/stack_machine_div/instructions.s.tcl delete mode 120000 tests/stack_machine_div/test.v delete mode 100644 tests/stack_machine_div/words_to_verify.mem delete mode 100755 tests/stack_machine_jump/instructions.s.tcl delete mode 120000 tests/stack_machine_jump/test.v delete mode 100644 tests/stack_machine_jump/words_to_verify.mem delete mode 100755 tests/stack_machine_load_store/instructions.s.tcl delete mode 120000 tests/stack_machine_load_store/test.v delete mode 100644 tests/stack_machine_load_store/words_to_verify.mem delete mode 100755 tests/stack_machine_mul/instructions.s.tcl delete mode 120000 tests/stack_machine_mul/test.v delete mode 100644 tests/stack_machine_mul/words_to_verify.mem delete mode 100755 tests/stack_machine_multiinstructions_load_store/instructions.s.tcl delete mode 120000 tests/stack_machine_multiinstructions_load_store/test.v delete mode 120000 tests/stack_machine_multiinstructions_load_store/words_to_verify.mem create mode 100755 tests/stack_machine_old_add/instructions.s.tcl create mode 120000 tests/stack_machine_old_add/test.v create mode 100644 tests/stack_machine_old_add/words_to_verify.mem create mode 100755 tests/stack_machine_old_cond_jump/instructions.s.tcl create mode 120000 tests/stack_machine_old_cond_jump/test.v create mode 100644 tests/stack_machine_old_cond_jump/words_to_verify.mem create mode 100755 tests/stack_machine_old_div/instructions.s.tcl create mode 120000 tests/stack_machine_old_div/test.v create mode 100644 tests/stack_machine_old_div/words_to_verify.mem create mode 100755 tests/stack_machine_old_jump/instructions.s.tcl create mode 120000 tests/stack_machine_old_jump/test.v create mode 100644 tests/stack_machine_old_jump/words_to_verify.mem create mode 100755 tests/stack_machine_old_load_store/instructions.s.tcl create mode 120000 tests/stack_machine_old_load_store/test.v create mode 100644 tests/stack_machine_old_load_store/words_to_verify.mem create mode 100755 tests/stack_machine_old_mul/instructions.s.tcl create mode 120000 tests/stack_machine_old_mul/test.v create mode 100644 tests/stack_machine_old_mul/words_to_verify.mem create mode 100755 tests/stack_machine_old_multiinstructions_load_store/instructions.s.tcl create mode 120000 tests/stack_machine_old_multiinstructions_load_store/test.v create mode 120000 tests/stack_machine_old_multiinstructions_load_store/words_to_verify.mem create mode 100755 tests/stack_machine_old_store/instructions.s.tcl create mode 100644 tests/stack_machine_old_store/test.v create mode 100644 tests/stack_machine_old_store/words_to_verify.mem create mode 100755 tests/stack_machine_old_sub/instructions.s.tcl create mode 120000 tests/stack_machine_old_sub/test.v create mode 100644 tests/stack_machine_old_sub/words_to_verify.mem create mode 100755 tests/stack_machine_old_swap/instructions.s.tcl create mode 120000 tests/stack_machine_old_swap/test.v create mode 100644 tests/stack_machine_old_swap/words_to_verify.mem create mode 100755 tests/stack_machine_old_tee/instructions.s.tcl create mode 120000 tests/stack_machine_old_tee/test.v create mode 100644 tests/stack_machine_old_tee/words_to_verify.mem delete mode 100755 tests/stack_machine_store/instructions.s.tcl delete mode 100644 tests/stack_machine_store/test.v delete mode 100644 tests/stack_machine_store/words_to_verify.mem delete mode 100755 tests/stack_machine_sub/instructions.s.tcl delete mode 120000 tests/stack_machine_sub/test.v delete mode 100644 tests/stack_machine_sub/words_to_verify.mem delete mode 100755 tests/stack_machine_swap/instructions.s.tcl delete mode 120000 tests/stack_machine_swap/test.v delete mode 100644 tests/stack_machine_swap/words_to_verify.mem delete mode 100755 tests/stack_machine_tee/instructions.s.tcl delete mode 120000 tests/stack_machine_tee/test.v delete mode 100644 tests/stack_machine_tee/words_to_verify.mem diff --git a/Makefile b/Makefile index f0b42de..2ebc598 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ MACROASM_FLAGS := -Iinclude/ -E # It made sense to just list all of those in this variable # and then prepend stack_machine_ to each element -STACK_MACHINE_TESTS := \ +STACK_MACHINE_OLD_TESTS := \ store \ load_store \ multiinstructions_load_store \ @@ -41,7 +41,7 @@ TESTS := \ sram_slave \ embedded_bram_slave \ soc_simple_display \ - $(addprefix stack_machine_,$(STACK_MACHINE_TESTS)) + $(addprefix stack_machine_old_,$(STACK_MACHINE_OLD_TESTS)) # For each of these Makefile will attempt to generate VGAdump.ppm # and compare it to VGAdump_expected.ppm inside that test's directory @@ -141,10 +141,11 @@ tests/vga/test.vvp : tests/vga/test.v design/vga.v models/vga_display.v \ include/messages.vh $(IV) $(IVFLAGS) -s vga_test $^ -o $@ -tests/stack_machine_%/test.vvp : tests/stack_machine_%/words_to_verify.mem \ - tests/stack_machine_%/instructions.mem \ - tests/stack_machine_%/test.v models/slave.v \ - design/stack_machine.v design/div.v include/messages.vh +tests/stack_machine_old_%/test.vvp : \ + tests/stack_machine_old_%/words_to_verify.mem \ + tests/stack_machine_old_%/instructions.mem \ + tests/stack_machine_old_%/test.v models/slave.v \ + design/stack_machine_old.v design/div.v include/messages.vh $(IV) $(IVFLAGS) -s stack_machine_test \ -DINSTRUCTIONS_COUNT=$(call FILE_LINES,$(filter %ions.mem,$^)) \ -DWORDS_TO_VERIFY_COUNT=$(call FILE_LINES,$<) \ diff --git a/design/stack_machine.v b/design/stack_machine.v deleted file mode 100644 index d466cc8..0000000 --- a/design/stack_machine.v +++ /dev/null @@ -1,356 +0,0 @@ -`default_nettype none - -module stack_machine - ( - input wire ACK_I, - input wire CLK_I, - output reg [19:0] ADR_O, - input wire [15:0] DAT_I, - output reg [15:0] DAT_O, - input wire RST_I, - output reg STB_O, - output reg CYC_O, - output reg WE_O, - input wire STALL_I, - - /* non-wishbone */ - output wire finished - ); - - reg [19:0] pc; - reg [19:0] sp; - - reg [15:0] instr; - - reg [31:0] r0; - reg [31:0] r1; - reg [31:0] im; - - parameter STEP_START = 0; - parameter STEP_LOADING_INSTRUCTION = 1; - parameter STEP_PARSING_INSTRUCTION = 2; - parameter STEP_LOAD_OR_STORE = 3; - parameter STEP_PERFORM_OPERATION = 4; - reg [2:0] step; - - reg [15:0] DAT_I_latched; - reg [15:0] instruction_latched; - reg instruction_just_received; - wire [15:0] instruction; - assign instruction = instruction_just_received ? - DAT_I_latched : instruction_latched; - - /* Results of instruction parsing */ - wire shift_immediate; /* only if modify_immediate is true */ - assign shift_immediate = instruction[11]; - - /* only if shift_immediate is true */ - wire [10:0] immediate_bits_to_shift; - assign immediate_bits_to_shift = instruction[10:0]; - - /* only if shift_immediate is false */ - wire set_immediate; - assign set_immediate = instruction[10]; - - /* only if (set_immediate && !shift_immediate) is true */ - wire [31:0] immediate_value_to_set; - assign immediate_value_to_set = {{22{instruction[9]}}, instruction[9:0]}; - - /* only if (!set_immediate && !shift_immediate) is true */ - wire add_immediate; - assign add_immediate = instruction[9]; - - /* only if (add_immediate && !set_immediate && !shift_immediate) is true */ - wire [9:0] immediate_value_to_add; - assign immediate_value_to_add = instruction[8:0]; - - - wire [31:0] new_im; - assign new_im = shift_immediate ? {im[20:0], immediate_bits_to_shift} : - set_immediate ? immediate_value_to_set : - add_immediate ? im + immediate_value_to_add : im; - - - wire shift_regs; - assign shift_regs = instruction[12]; - - - wire load_or_store; - assign load_or_store = instruction[15]; - - wire [19:0] addr_to_use; /* only if load_or_store is true */ - /* The implementation is currently unable to make non-aligned accesses */ - assign addr_to_use = new_im / 2 + (immediate_addressing ? 0 : sp); - - wire load; /* only if load_or_store is true */ - assign load = instruction[14]; - - wire store; /* only if load_or_store is true */ - assign store = !load; - - wire immediate_addressing; /* only if load_or_store is true */ - assign immediate_addressing = instruction[13]; - wire sp_addressing; /* only if load_or_store is true */ - assign sp_addressing = !immediate_addressing; - - wire load_or_store_r0; /* only if load_or_store is true */ - assign load_or_store_r0 = instruction[12]; - - wire load_or_store_r1; /* only if load_or_store is true */ - assign load_or_store_r1 = !load_or_store_r0; - - - /* only if load_or_store is false */ - wire cond_jump; - assign cond_jump = instruction[14:13] == 2'b11; - - /* only if load_or_store is false */ - wire jump; - assign jump = instruction[14:13] == 2'b10; - - /* only if load_or_store is false */ - wire exchange_r1_im; - assign exchange_r1_im = instruction[14:13] == 2'b01; - - /* only if load_or_store is false */ - wire immediate_modification; - assign immediate_modification - = instruction[14:13] == 0 && - (shift_immediate || set_immediate || add_immediate); - - wire extended_instruction; /* only if load_or_store is false */ - assign extended_instruction = instruction[14:13] == 0 && ! shift_immediate && - !set_immediate && !add_immediate; - - /* only if (!load_or_store && extended_instruction) is true */ - wire [8:0] extended_instruction_bits; - assign extended_instruction_bits = instruction[8:0]; - - /* extended instructions */ - parameter INSTR_TEE = 9'd7; - parameter INSTR_MUL = 9'd6; - parameter INSTR_DIV = 9'd5; - parameter INSTR_SUB = 9'd4; - parameter INSTR_ADD = 9'd3; - parameter INSTR_SET_SP = 9'd2; - parameter INSTR_HALT = 9'd1; - parameter INSTR_NOP = 9'd0; - - /* module for division */ - wire [31:0] div_quotient; - wire [31:0] div_remainder; - wire div_done; - - div - #( - .WIDTH(32) - ) div - ( - .clock(CLK_I), - .start(step == STEP_PARSING_INSTRUCTION), - .dividend(r0), - .divisor(r1), - - .quotient(div_quotient), - .remainder(div_remainder), - .done(div_done) - ); - - assign finished = !load_or_store && extended_instruction && - extended_instruction_bits == INSTR_HALT; - - - reg [15:0] second_word_to_store; - - /* - * Variables necessary to know where we are when transferring - * a sequence of words through wishbone - */ - reg first_command_sent; - reg first_ack_received; - - /* Informs us, that DAT_I_latched should be moved to r0 or r1 */ - reg load_half_of_r0; - reg load_half_of_r1; - -`ifdef SIMULATION - /* - * RST should still be used when powering up, even in benches; - * this is just to avoid undefined values - */ - initial begin - ADR_O <= 0; - STB_O <= 0; - CYC_O <= 0; - WE_O <= 0; - - r0 <= 0; - r1 <= 0; - im <= 0; - pc <= 0; - sp <= 20'h40000; - step <= STEP_START; - instruction_latched <= 0; - instruction_just_received <= 0; - end -`endif - - always @ (posedge CLK_I) begin - DAT_I_latched <= DAT_I; - - /* - * Later part of this always block sets them to 1 under certain - * conditions, which takes precedence over this assignment - */ - load_half_of_r0 <= 0; - load_half_of_r1 <= 0; - instruction_just_received <= 0; - - if (RST_I) begin - STB_O <= 0; - CYC_O <= 0; - - pc <= 0; - sp <= 20'h40000; - step <= STEP_START; - end else begin - case (step) - STEP_START : begin - ADR_O <= pc; - STB_O <= 1; - CYC_O <= 1; - WE_O <= 0; - step <= STEP_LOADING_INSTRUCTION; - pc <= pc + 1; - end - STEP_LOADING_INSTRUCTION : begin - if (!STALL_I) - STB_O <= 0; - - if (ACK_I) begin - instruction_just_received <= 1; - step <= STEP_PARSING_INSTRUCTION; - CYC_O <= 0; - end - end // case: STEP_LOADING_INSTRUCTION - STEP_PARSING_INSTRUCTION : begin - im <= new_im; - instruction_latched <= instruction; - - first_command_sent <= 0; - first_ack_received <= 0; - - if (shift_regs) - {r0, r1} <= {r1, r0}; /* magic! */ - - if (load_or_store) begin - CYC_O <= 1; - STB_O <= 1; - WE_O <= store; - ADR_O <= addr_to_use; - - /* Even if not a store, setting these won't break anything */ - DAT_O <= load_or_store_r0 ? r0[15:0] : r1[15:0]; - second_word_to_store <= load_or_store_r0 ? - r0[31:16] : r1[31:16]; - - if (load_or_store_r0) - sp <= sp + (load ? 2 : -2); - - step <= STEP_LOAD_OR_STORE; - end else begin // if (load_or_store) - if (immediate_modification) begin - step <= STEP_START; - end else if (exchange_r1_im || extended_instruction) begin - step <= STEP_PERFORM_OPERATION; - end else if (jump) begin - pc <= new_im / 2; - step <= STEP_START; - end else if (cond_jump) begin - if (r1 != 0) - pc <= new_im / 2; - - step <= STEP_START; - end else begin -`ifdef SIMULATION - $display("operation not implemented yet"); -`endif - step <= STEP_START; - end - end // else: !if(load_or_store) - end // case: STEP_PARSING_INSTRUCTION - STEP_LOAD_OR_STORE : begin - if (!STALL_I) begin - ADR_O <= ADR_O + 1; - - DAT_O <= second_word_to_store; - - if (!first_command_sent) - first_command_sent <= 1; - else - STB_O <= 0; - end // if (!STALL_I) - - if (ACK_I) begin - if (load) begin - if (load_or_store_r0) - load_half_of_r0 <= 1; - else - load_half_of_r1 <= 1; - end - - if (!first_ack_received) - first_ack_received <= 1; - else - step <= STEP_START; - end // if (ACK_I) - end // case: STEP_LOAD_OR_STORE - STEP_PERFORM_OPERATION : begin - step <= STEP_START; /* unless overwritten in case block below */ - - if (extended_instruction) begin - case (extended_instruction_bits) - INSTR_NOP : - ; - INSTR_HALT : - step <= step; /* stay in this step forever */ - INSTR_SET_SP : - sp <= im / 2; - INSTR_ADD : - r0 <= r0 + r1; - INSTR_SUB : - r0 <= r0 - r1; - INSTR_DIV : begin - {r0, r1} <= {div_quotient, div_remainder}; - if (!div_done) - step <= step; - end - INSTR_MUL : - r0 <= r0 * r1; - INSTR_TEE : - r1 <= r0; - default : begin -`ifdef SIMULATION - $display("operation not implemented yet"); -`endif - end - endcase // case (extended_instruction_bits) - end else if (exchange_r1_im) begin - {r1, im} <= {im, r1}; - end else begin -`ifdef SIMULATION - $display("operation not implemented yet"); -`endif - end - end // case: STEP_PERFORM_OPERATION - endcase // case (step) - end // else: !if(RST_I) - - if (load_half_of_r0) - r0 <= {DAT_I_latched, r0[31:16]}; - - if (load_half_of_r1) - r1 <= {DAT_I_latched, r1[31:16]}; - end // always @ (posedge CLK_I) - -endmodule // stack_machine diff --git a/design/stack_machine_old.v b/design/stack_machine_old.v new file mode 100644 index 0000000..d466cc8 --- /dev/null +++ b/design/stack_machine_old.v @@ -0,0 +1,356 @@ +`default_nettype none + +module stack_machine + ( + input wire ACK_I, + input wire CLK_I, + output reg [19:0] ADR_O, + input wire [15:0] DAT_I, + output reg [15:0] DAT_O, + input wire RST_I, + output reg STB_O, + output reg CYC_O, + output reg WE_O, + input wire STALL_I, + + /* non-wishbone */ + output wire finished + ); + + reg [19:0] pc; + reg [19:0] sp; + + reg [15:0] instr; + + reg [31:0] r0; + reg [31:0] r1; + reg [31:0] im; + + parameter STEP_START = 0; + parameter STEP_LOADING_INSTRUCTION = 1; + parameter STEP_PARSING_INSTRUCTION = 2; + parameter STEP_LOAD_OR_STORE = 3; + parameter STEP_PERFORM_OPERATION = 4; + reg [2:0] step; + + reg [15:0] DAT_I_latched; + reg [15:0] instruction_latched; + reg instruction_just_received; + wire [15:0] instruction; + assign instruction = instruction_just_received ? + DAT_I_latched : instruction_latched; + + /* Results of instruction parsing */ + wire shift_immediate; /* only if modify_immediate is true */ + assign shift_immediate = instruction[11]; + + /* only if shift_immediate is true */ + wire [10:0] immediate_bits_to_shift; + assign immediate_bits_to_shift = instruction[10:0]; + + /* only if shift_immediate is false */ + wire set_immediate; + assign set_immediate = instruction[10]; + + /* only if (set_immediate && !shift_immediate) is true */ + wire [31:0] immediate_value_to_set; + assign immediate_value_to_set = {{22{instruction[9]}}, instruction[9:0]}; + + /* only if (!set_immediate && !shift_immediate) is true */ + wire add_immediate; + assign add_immediate = instruction[9]; + + /* only if (add_immediate && !set_immediate && !shift_immediate) is true */ + wire [9:0] immediate_value_to_add; + assign immediate_value_to_add = instruction[8:0]; + + + wire [31:0] new_im; + assign new_im = shift_immediate ? {im[20:0], immediate_bits_to_shift} : + set_immediate ? immediate_value_to_set : + add_immediate ? im + immediate_value_to_add : im; + + + wire shift_regs; + assign shift_regs = instruction[12]; + + + wire load_or_store; + assign load_or_store = instruction[15]; + + wire [19:0] addr_to_use; /* only if load_or_store is true */ + /* The implementation is currently unable to make non-aligned accesses */ + assign addr_to_use = new_im / 2 + (immediate_addressing ? 0 : sp); + + wire load; /* only if load_or_store is true */ + assign load = instruction[14]; + + wire store; /* only if load_or_store is true */ + assign store = !load; + + wire immediate_addressing; /* only if load_or_store is true */ + assign immediate_addressing = instruction[13]; + wire sp_addressing; /* only if load_or_store is true */ + assign sp_addressing = !immediate_addressing; + + wire load_or_store_r0; /* only if load_or_store is true */ + assign load_or_store_r0 = instruction[12]; + + wire load_or_store_r1; /* only if load_or_store is true */ + assign load_or_store_r1 = !load_or_store_r0; + + + /* only if load_or_store is false */ + wire cond_jump; + assign cond_jump = instruction[14:13] == 2'b11; + + /* only if load_or_store is false */ + wire jump; + assign jump = instruction[14:13] == 2'b10; + + /* only if load_or_store is false */ + wire exchange_r1_im; + assign exchange_r1_im = instruction[14:13] == 2'b01; + + /* only if load_or_store is false */ + wire immediate_modification; + assign immediate_modification + = instruction[14:13] == 0 && + (shift_immediate || set_immediate || add_immediate); + + wire extended_instruction; /* only if load_or_store is false */ + assign extended_instruction = instruction[14:13] == 0 && ! shift_immediate && + !set_immediate && !add_immediate; + + /* only if (!load_or_store && extended_instruction) is true */ + wire [8:0] extended_instruction_bits; + assign extended_instruction_bits = instruction[8:0]; + + /* extended instructions */ + parameter INSTR_TEE = 9'd7; + parameter INSTR_MUL = 9'd6; + parameter INSTR_DIV = 9'd5; + parameter INSTR_SUB = 9'd4; + parameter INSTR_ADD = 9'd3; + parameter INSTR_SET_SP = 9'd2; + parameter INSTR_HALT = 9'd1; + parameter INSTR_NOP = 9'd0; + + /* module for division */ + wire [31:0] div_quotient; + wire [31:0] div_remainder; + wire div_done; + + div + #( + .WIDTH(32) + ) div + ( + .clock(CLK_I), + .start(step == STEP_PARSING_INSTRUCTION), + .dividend(r0), + .divisor(r1), + + .quotient(div_quotient), + .remainder(div_remainder), + .done(div_done) + ); + + assign finished = !load_or_store && extended_instruction && + extended_instruction_bits == INSTR_HALT; + + + reg [15:0] second_word_to_store; + + /* + * Variables necessary to know where we are when transferring + * a sequence of words through wishbone + */ + reg first_command_sent; + reg first_ack_received; + + /* Informs us, that DAT_I_latched should be moved to r0 or r1 */ + reg load_half_of_r0; + reg load_half_of_r1; + +`ifdef SIMULATION + /* + * RST should still be used when powering up, even in benches; + * this is just to avoid undefined values + */ + initial begin + ADR_O <= 0; + STB_O <= 0; + CYC_O <= 0; + WE_O <= 0; + + r0 <= 0; + r1 <= 0; + im <= 0; + pc <= 0; + sp <= 20'h40000; + step <= STEP_START; + instruction_latched <= 0; + instruction_just_received <= 0; + end +`endif + + always @ (posedge CLK_I) begin + DAT_I_latched <= DAT_I; + + /* + * Later part of this always block sets them to 1 under certain + * conditions, which takes precedence over this assignment + */ + load_half_of_r0 <= 0; + load_half_of_r1 <= 0; + instruction_just_received <= 0; + + if (RST_I) begin + STB_O <= 0; + CYC_O <= 0; + + pc <= 0; + sp <= 20'h40000; + step <= STEP_START; + end else begin + case (step) + STEP_START : begin + ADR_O <= pc; + STB_O <= 1; + CYC_O <= 1; + WE_O <= 0; + step <= STEP_LOADING_INSTRUCTION; + pc <= pc + 1; + end + STEP_LOADING_INSTRUCTION : begin + if (!STALL_I) + STB_O <= 0; + + if (ACK_I) begin + instruction_just_received <= 1; + step <= STEP_PARSING_INSTRUCTION; + CYC_O <= 0; + end + end // case: STEP_LOADING_INSTRUCTION + STEP_PARSING_INSTRUCTION : begin + im <= new_im; + instruction_latched <= instruction; + + first_command_sent <= 0; + first_ack_received <= 0; + + if (shift_regs) + {r0, r1} <= {r1, r0}; /* magic! */ + + if (load_or_store) begin + CYC_O <= 1; + STB_O <= 1; + WE_O <= store; + ADR_O <= addr_to_use; + + /* Even if not a store, setting these won't break anything */ + DAT_O <= load_or_store_r0 ? r0[15:0] : r1[15:0]; + second_word_to_store <= load_or_store_r0 ? + r0[31:16] : r1[31:16]; + + if (load_or_store_r0) + sp <= sp + (load ? 2 : -2); + + step <= STEP_LOAD_OR_STORE; + end else begin // if (load_or_store) + if (immediate_modification) begin + step <= STEP_START; + end else if (exchange_r1_im || extended_instruction) begin + step <= STEP_PERFORM_OPERATION; + end else if (jump) begin + pc <= new_im / 2; + step <= STEP_START; + end else if (cond_jump) begin + if (r1 != 0) + pc <= new_im / 2; + + step <= STEP_START; + end else begin +`ifdef SIMULATION + $display("operation not implemented yet"); +`endif + step <= STEP_START; + end + end // else: !if(load_or_store) + end // case: STEP_PARSING_INSTRUCTION + STEP_LOAD_OR_STORE : begin + if (!STALL_I) begin + ADR_O <= ADR_O + 1; + + DAT_O <= second_word_to_store; + + if (!first_command_sent) + first_command_sent <= 1; + else + STB_O <= 0; + end // if (!STALL_I) + + if (ACK_I) begin + if (load) begin + if (load_or_store_r0) + load_half_of_r0 <= 1; + else + load_half_of_r1 <= 1; + end + + if (!first_ack_received) + first_ack_received <= 1; + else + step <= STEP_START; + end // if (ACK_I) + end // case: STEP_LOAD_OR_STORE + STEP_PERFORM_OPERATION : begin + step <= STEP_START; /* unless overwritten in case block below */ + + if (extended_instruction) begin + case (extended_instruction_bits) + INSTR_NOP : + ; + INSTR_HALT : + step <= step; /* stay in this step forever */ + INSTR_SET_SP : + sp <= im / 2; + INSTR_ADD : + r0 <= r0 + r1; + INSTR_SUB : + r0 <= r0 - r1; + INSTR_DIV : begin + {r0, r1} <= {div_quotient, div_remainder}; + if (!div_done) + step <= step; + end + INSTR_MUL : + r0 <= r0 * r1; + INSTR_TEE : + r1 <= r0; + default : begin +`ifdef SIMULATION + $display("operation not implemented yet"); +`endif + end + endcase // case (extended_instruction_bits) + end else if (exchange_r1_im) begin + {r1, im} <= {im, r1}; + end else begin +`ifdef SIMULATION + $display("operation not implemented yet"); +`endif + end + end // case: STEP_PERFORM_OPERATION + endcase // case (step) + end // else: !if(RST_I) + + if (load_half_of_r0) + r0 <= {DAT_I_latched, r0[31:16]}; + + if (load_half_of_r1) + r1 <= {DAT_I_latched, r1[31:16]}; + end // always @ (posedge CLK_I) + +endmodule // stack_machine diff --git a/tests/stack_machine_add/instructions.s.tcl b/tests/stack_machine_add/instructions.s.tcl deleted file mode 100755 index c3cfe4d..0000000 --- a/tests/stack_machine_add/instructions.s.tcl +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### store 2 values to memory, load them back, add them and store the result - -set_sp h7FFFC -const 12345678 -store@ h1EEE0 -const 40302010 -store@ h1EEE4 - -load@ h1EEE0 -stack down -load@ h1EEE4 -# adding 40302010 to 12345678 should yield 52647688 -add -stack up -store@ h1EEE8 -halt diff --git a/tests/stack_machine_add/test.v b/tests/stack_machine_add/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_add/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_add/words_to_verify.mem b/tests/stack_machine_add/words_to_verify.mem deleted file mode 100644 index db077bc..0000000 --- a/tests/stack_machine_add/words_to_verify.mem +++ /dev/null @@ -1,9 +0,0 @@ -// address value - 1EEE0 614E // 12345678 in hex is BC614E - 1EEE2 BC - - 1EEE4 F5BA // 40302010 in hex is 266F5BA - 1EEE6 266 - - 1EEE8 5708 // 52647688 in hex is 3235708 - 1EEEA 323 diff --git a/tests/stack_machine_cond_jump/instructions.s.tcl b/tests/stack_machine_cond_jump/instructions.s.tcl deleted file mode 100755 index 467a719..0000000 --- a/tests/stack_machine_cond_jump/instructions.s.tcl +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -## also look at stack_machine_jump test - -## we're going to write numbers from 0 to 7 to addresses h400 - h41C - -# this will translate to 3 16-bit instructions -set_sp h7FFFC - -## set up the counter -# each of those 2 will translate to 1 16-bit instruction -const 0 -stack down - -## this is the point we later jump to, address 10 - -tee -## compute address: counter * 4 + h400 -stack down -const 4 -mul -const h400 -add -stack up -## load computed address to im -exchange_im -## save value of counter at address pointed by im -swap -store -swap -## increase counter by 1 -const 1 -add -## compare value of counter to 8 -tee -stack down -const 8 -sub -stack up -## loop if counter != 8 -cond_jump 10 - -halt diff --git a/tests/stack_machine_cond_jump/test.v b/tests/stack_machine_cond_jump/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_cond_jump/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_cond_jump/words_to_verify.mem b/tests/stack_machine_cond_jump/words_to_verify.mem deleted file mode 100644 index 4b77b8a..0000000 --- a/tests/stack_machine_cond_jump/words_to_verify.mem +++ /dev/null @@ -1,9 +0,0 @@ -// address value - 00400 0 // verify the first number written - 00402 0 - - 00408 2 // verify a number in the middle - 0040A 0 - - 0041C 7 // verify the last number - 0041E 0 diff --git a/tests/stack_machine_div/instructions.s.tcl b/tests/stack_machine_div/instructions.s.tcl deleted file mode 100755 index e2d55dc..0000000 --- a/tests/stack_machine_div/instructions.s.tcl +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### store 2 values to memory, load them back, divide one by another and store -### the result (both quotient and remainder); this is analogous to addition -### and substraction tests - -set_sp h7FFFC -const 777681520 -store@ h1EEE0 -const 3721 -store@ h1EEE4 - -load@ h1EEE0 -stack down -load@ h1EEE4 -# dividing 777681520 by 3721 should yield 208997 r 3683 -div -store@ h1EEE8 -stack up -store@ h1EEEC -halt diff --git a/tests/stack_machine_div/test.v b/tests/stack_machine_div/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_div/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_div/words_to_verify.mem b/tests/stack_machine_div/words_to_verify.mem deleted file mode 100644 index 8543226..0000000 --- a/tests/stack_machine_div/words_to_verify.mem +++ /dev/null @@ -1,12 +0,0 @@ -// address value - 1EEE0 7A70 // 777681520 in hex is 2E5A7A70 - 1EEE2 2E5A - - 1EEE4 E89 // 3721 in hex is E89 - 1EEE6 0 - - 1EEE8 E63 // 3683 in hex is E63 - 1EEEA 0 - - 1EEEC 3065 // 208997 in hex is 33065 - 1EEEE 3 diff --git a/tests/stack_machine_jump/instructions.s.tcl b/tests/stack_machine_jump/instructions.s.tcl deleted file mode 100755 index f681fc9..0000000 --- a/tests/stack_machine_jump/instructions.s.tcl +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -## Let there be 2 pieces of code - each one storing a different value in memory -## and halting afterwards. Jump instruction should cause the second piece of -## code to execute instead of the first. We'll verify that by checking, which -## value got written. - -## Ufortunately, our assembly currently doesn't compute label addresses for us. - -# Each of those 4 instructions should get encoded into 1 16-bit word, so they -# will take 8 bytes total. Hence jump to address 8 is needed to skip them. -jump 8 -const h12 -store@ h00100 -halt - -# address 8 here -const h34 -store@ h00100 -halt diff --git a/tests/stack_machine_jump/test.v b/tests/stack_machine_jump/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_jump/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_jump/words_to_verify.mem b/tests/stack_machine_jump/words_to_verify.mem deleted file mode 100644 index 4fded2b..0000000 --- a/tests/stack_machine_jump/words_to_verify.mem +++ /dev/null @@ -1,2 +0,0 @@ -// address value - 00100 34 diff --git a/tests/stack_machine_load_store/instructions.s.tcl b/tests/stack_machine_load_store/instructions.s.tcl deleted file mode 100755 index 13cabcb..0000000 --- a/tests/stack_machine_load_store/instructions.s.tcl +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### another simple test - set stack to h7FFFC, store 4 numbers on stack (only 2 -### will really get written to memory, other 2 will remain in r0 and r1), -### then pop all the numbers and write them to h57574 - - -## set sp to h7FFFC (actually, lowest bit is assumed 0 and not stored there) -# 7777 FFFF F -# bits 19:11 of h7FFFC are 0111 1111 1 -_immediate im=b011111111 -# FFf FFFF CCCC -# bits 10:0 of h7FFFC are 111 1111 1100 -_immediate im<<=b11111111100 - -_extended_instruction set_sp - -## get value h01010202 into r1 -# 0000 1111 00 -# bits 31:22 of h01010202 are 0000 0001 00 -_immediate im<<=b0000000100 -# 00 1111 0000 2 -# bits 21:11 of h01010202 are 00 0001 0000 0 -_immediate im<<=b00000100000 -# 222 0000 2222 -# bits 10:0 of h01010202 are 010 0000 0010 -_exchange_im im<<=b01000000010 - -## get value h03030404 into r1 -stack down -# 0000 3333 00 -# bits 31:22 of h03030404 are 0000 0011 00 -_immediate im<<=b0000001100 -# 00 3333 0000 4 -# bits 21:11 of h03030404 are 00 0011 0000 0 -_immediate im<<=b00001100000 -# 444 0000 4444 -# bits 10:0 of h03030404 are 100 0000 0100 -_exchange_im im<<=b10000000100 - -## get value h05050606 into r1 -stack down -# 0000 5555 00 -# bits 31:22 of h05050606 are 0000 0101 00 -_immediate im<<=b0000010100 -# 00 5555 0000 6 -# bits 21:11 of h05050606 are 00 0101 0000 0 -_immediate im<<=b00010100000 -# 666 0000 6666 -# bits 10:0 of h05050606 are 110 0000 0110 -_exchange_im im<<=b11000000110 - -## get value h07070808 into r1 -stack down -# 0000 7777 00 -# bits 31:22 of h07070808 are 0000 0111 00 -_immediate im<<=b0000011100 -# 00 7777 0000 8 -# bits 21:11 of h07070808 are 00 0111 0000 1 -_immediate im<<=b00011100001 -# 888 0000 8888 -# bits 10:0 of h07070808 are 000 0000 1000 -_exchange_im im<<=b00000001000 - -## get address h57574 into im and write r1 to that address -# 5555 7777 5 -# bits 19:11 of h57574 are 0101 0111 0 -_immediate im=b010101110 -# 555 7777 4444 -# bits 10:0 of h57574 are 101 0111 0100 -store im<<=b10101110100 - -# get r0 to r1 -stack up - -## get address h57578 into im and write r1 to that address -# 5555 7777 5 -# bits 19:11 of h57578 are 0101 0111 0 -_immediate im=b010101110 -# 555 7777 8888 -# bits 10:0 of h57578 are 101 0111 1000 -store im<<=b10101111000 - -# get r0 to r1 -stack up - -## get address h5757C into im and write r1 to that address -# 5555 7777 5 -# bits 19:11 of h5757C are 0101 0111 0 -_immediate im=b010101110 -# 555 7777 CCCC -# bits 10:0 of h5757C are 101 0111 1100 -store im<<=b10101111100 - -# get r0 to r1 -stack up - -## get address h57580 into im and write r1 to that address -# 5555 7777 5 -# bits 19:11 of h57580 are 0101 0111 0 -_immediate im=b010101110 -# 555 8888 0000 -# bits 10:0 of h57580 are 101 1000 0000 -store im<<=b10110000000 - -## finish test -halt diff --git a/tests/stack_machine_load_store/test.v b/tests/stack_machine_load_store/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_load_store/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_load_store/words_to_verify.mem b/tests/stack_machine_load_store/words_to_verify.mem deleted file mode 100644 index 349b213..0000000 --- a/tests/stack_machine_load_store/words_to_verify.mem +++ /dev/null @@ -1,12 +0,0 @@ -// address value - 57574 0808 - 57576 0707 - - 57578 0606 - 5757A 0505 - - 5757C 0404 - 5757E 0303 - - 57580 0202 - 57582 0101 diff --git a/tests/stack_machine_mul/instructions.s.tcl b/tests/stack_machine_mul/instructions.s.tcl deleted file mode 100755 index 8473aef..0000000 --- a/tests/stack_machine_mul/instructions.s.tcl +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### store 4 values to memory; load 2 of them back, multiply them and store the -### result; load another 2, multiply them and store the result; -### this is similar to addition and substraction tests - -set_sp h7FFFC - -## store first 2 factors -const 483091365 -store@ h1EEE0 -const 74683203 -store@ h1EEE4 - -## store other 2 factors -const 8436 -store@ h1EEEC -const -14020 -store@ h1EEF0 - -## perform the first multiplication -load@ h1EEE0 -stack down -load@ h1EEE4 -# multiplying 483091365 by 74683203 should yield 36078810479842095 -# if we take lowest 32 bits of 36078810479842095 we get 2861683503 -mul -stack up -store@ h1EEE8 - -## perform the second multiplication -load@ h1EEEC -stack down -load@ h1EEF0 -# multiplying 8436 by -14020 should yield -118272720 (which fits in 32 bits) -mul -stack up -store@ h1EEF4 - -halt diff --git a/tests/stack_machine_mul/test.v b/tests/stack_machine_mul/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_mul/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_mul/words_to_verify.mem b/tests/stack_machine_mul/words_to_verify.mem deleted file mode 100644 index 3095d6e..0000000 --- a/tests/stack_machine_mul/words_to_verify.mem +++ /dev/null @@ -1,19 +0,0 @@ -// address value - 1EEE0 63A5 // 483091365 in hex is 1CCB63A5 - 1EEE2 1CCB - - 1EEE4 9343 // 74683203 in hex is 4739343 - 1EEE6 473 - - 1EEE8 D32F // 2861683503 in hex is AA91D32F - 1EEEA AA91 - - - 1EEEC 20F4 // 8436 in hex is 20F4 - 1EEEE 0 - - 1EEF0 C93C // -14020 in hex is FFFFC93C - 1EEF2 FFFF - - 1EEF4 4D30 // -118272720 in hex is F8F34D30 - 1EEF6 F8F3 diff --git a/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl b/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl deleted file mode 100755 index 58792d3..0000000 --- a/tests/stack_machine_multiinstructions_load_store/instructions.s.tcl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### do the same as in stack_machine_2 test, but use higher level instructions - -## set sp to h7FFFC -set_sp h7FFFC -## get value h01010202 into r1 -const h01010202 -## get value h03030404 into r1 -stack down -const h03030404 -## get value h05050606 into r1 -stack down -const h05050606 -## get value h07070808 into r1 -stack down -const h07070808 -## write r1 to address h57574 -store@ h57574 -stack up -## write r1 to address h57578 -store@ h57578 -stack up -## write r1 to address h5757C -store@ h5757C -stack up -## write r1 to address h57580 -store@ h57580 -## finish test -halt diff --git a/tests/stack_machine_multiinstructions_load_store/test.v b/tests/stack_machine_multiinstructions_load_store/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_multiinstructions_load_store/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem b/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem deleted file mode 120000 index b2e490b..0000000 --- a/tests/stack_machine_multiinstructions_load_store/words_to_verify.mem +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_load_store/words_to_verify.mem \ No newline at end of file diff --git a/tests/stack_machine_old_add/instructions.s.tcl b/tests/stack_machine_old_add/instructions.s.tcl new file mode 100755 index 0000000..c3cfe4d --- /dev/null +++ b/tests/stack_machine_old_add/instructions.s.tcl @@ -0,0 +1,20 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 2 values to memory, load them back, add them and store the result + +set_sp h7FFFC +const 12345678 +store@ h1EEE0 +const 40302010 +store@ h1EEE4 + +load@ h1EEE0 +stack down +load@ h1EEE4 +# adding 40302010 to 12345678 should yield 52647688 +add +stack up +store@ h1EEE8 +halt diff --git a/tests/stack_machine_old_add/test.v b/tests/stack_machine_old_add/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_add/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_add/words_to_verify.mem b/tests/stack_machine_old_add/words_to_verify.mem new file mode 100644 index 0000000..db077bc --- /dev/null +++ b/tests/stack_machine_old_add/words_to_verify.mem @@ -0,0 +1,9 @@ +// address value + 1EEE0 614E // 12345678 in hex is BC614E + 1EEE2 BC + + 1EEE4 F5BA // 40302010 in hex is 266F5BA + 1EEE6 266 + + 1EEE8 5708 // 52647688 in hex is 3235708 + 1EEEA 323 diff --git a/tests/stack_machine_old_cond_jump/instructions.s.tcl b/tests/stack_machine_old_cond_jump/instructions.s.tcl new file mode 100755 index 0000000..467a719 --- /dev/null +++ b/tests/stack_machine_old_cond_jump/instructions.s.tcl @@ -0,0 +1,45 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +## also look at stack_machine_jump test + +## we're going to write numbers from 0 to 7 to addresses h400 - h41C + +# this will translate to 3 16-bit instructions +set_sp h7FFFC + +## set up the counter +# each of those 2 will translate to 1 16-bit instruction +const 0 +stack down + +## this is the point we later jump to, address 10 + +tee +## compute address: counter * 4 + h400 +stack down +const 4 +mul +const h400 +add +stack up +## load computed address to im +exchange_im +## save value of counter at address pointed by im +swap +store +swap +## increase counter by 1 +const 1 +add +## compare value of counter to 8 +tee +stack down +const 8 +sub +stack up +## loop if counter != 8 +cond_jump 10 + +halt diff --git a/tests/stack_machine_old_cond_jump/test.v b/tests/stack_machine_old_cond_jump/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_cond_jump/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_cond_jump/words_to_verify.mem b/tests/stack_machine_old_cond_jump/words_to_verify.mem new file mode 100644 index 0000000..4b77b8a --- /dev/null +++ b/tests/stack_machine_old_cond_jump/words_to_verify.mem @@ -0,0 +1,9 @@ +// address value + 00400 0 // verify the first number written + 00402 0 + + 00408 2 // verify a number in the middle + 0040A 0 + + 0041C 7 // verify the last number + 0041E 0 diff --git a/tests/stack_machine_old_div/instructions.s.tcl b/tests/stack_machine_old_div/instructions.s.tcl new file mode 100755 index 0000000..e2d55dc --- /dev/null +++ b/tests/stack_machine_old_div/instructions.s.tcl @@ -0,0 +1,23 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 2 values to memory, load them back, divide one by another and store +### the result (both quotient and remainder); this is analogous to addition +### and substraction tests + +set_sp h7FFFC +const 777681520 +store@ h1EEE0 +const 3721 +store@ h1EEE4 + +load@ h1EEE0 +stack down +load@ h1EEE4 +# dividing 777681520 by 3721 should yield 208997 r 3683 +div +store@ h1EEE8 +stack up +store@ h1EEEC +halt diff --git a/tests/stack_machine_old_div/test.v b/tests/stack_machine_old_div/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_div/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_div/words_to_verify.mem b/tests/stack_machine_old_div/words_to_verify.mem new file mode 100644 index 0000000..8543226 --- /dev/null +++ b/tests/stack_machine_old_div/words_to_verify.mem @@ -0,0 +1,12 @@ +// address value + 1EEE0 7A70 // 777681520 in hex is 2E5A7A70 + 1EEE2 2E5A + + 1EEE4 E89 // 3721 in hex is E89 + 1EEE6 0 + + 1EEE8 E63 // 3683 in hex is E63 + 1EEEA 0 + + 1EEEC 3065 // 208997 in hex is 33065 + 1EEEE 3 diff --git a/tests/stack_machine_old_jump/instructions.s.tcl b/tests/stack_machine_old_jump/instructions.s.tcl new file mode 100755 index 0000000..f681fc9 --- /dev/null +++ b/tests/stack_machine_old_jump/instructions.s.tcl @@ -0,0 +1,22 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +## Let there be 2 pieces of code - each one storing a different value in memory +## and halting afterwards. Jump instruction should cause the second piece of +## code to execute instead of the first. We'll verify that by checking, which +## value got written. + +## Ufortunately, our assembly currently doesn't compute label addresses for us. + +# Each of those 4 instructions should get encoded into 1 16-bit word, so they +# will take 8 bytes total. Hence jump to address 8 is needed to skip them. +jump 8 +const h12 +store@ h00100 +halt + +# address 8 here +const h34 +store@ h00100 +halt diff --git a/tests/stack_machine_old_jump/test.v b/tests/stack_machine_old_jump/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_jump/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_jump/words_to_verify.mem b/tests/stack_machine_old_jump/words_to_verify.mem new file mode 100644 index 0000000..4fded2b --- /dev/null +++ b/tests/stack_machine_old_jump/words_to_verify.mem @@ -0,0 +1,2 @@ +// address value + 00100 34 diff --git a/tests/stack_machine_old_load_store/instructions.s.tcl b/tests/stack_machine_old_load_store/instructions.s.tcl new file mode 100755 index 0000000..13cabcb --- /dev/null +++ b/tests/stack_machine_old_load_store/instructions.s.tcl @@ -0,0 +1,109 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### another simple test - set stack to h7FFFC, store 4 numbers on stack (only 2 +### will really get written to memory, other 2 will remain in r0 and r1), +### then pop all the numbers and write them to h57574 + + +## set sp to h7FFFC (actually, lowest bit is assumed 0 and not stored there) +# 7777 FFFF F +# bits 19:11 of h7FFFC are 0111 1111 1 +_immediate im=b011111111 +# FFf FFFF CCCC +# bits 10:0 of h7FFFC are 111 1111 1100 +_immediate im<<=b11111111100 + +_extended_instruction set_sp + +## get value h01010202 into r1 +# 0000 1111 00 +# bits 31:22 of h01010202 are 0000 0001 00 +_immediate im<<=b0000000100 +# 00 1111 0000 2 +# bits 21:11 of h01010202 are 00 0001 0000 0 +_immediate im<<=b00000100000 +# 222 0000 2222 +# bits 10:0 of h01010202 are 010 0000 0010 +_exchange_im im<<=b01000000010 + +## get value h03030404 into r1 +stack down +# 0000 3333 00 +# bits 31:22 of h03030404 are 0000 0011 00 +_immediate im<<=b0000001100 +# 00 3333 0000 4 +# bits 21:11 of h03030404 are 00 0011 0000 0 +_immediate im<<=b00001100000 +# 444 0000 4444 +# bits 10:0 of h03030404 are 100 0000 0100 +_exchange_im im<<=b10000000100 + +## get value h05050606 into r1 +stack down +# 0000 5555 00 +# bits 31:22 of h05050606 are 0000 0101 00 +_immediate im<<=b0000010100 +# 00 5555 0000 6 +# bits 21:11 of h05050606 are 00 0101 0000 0 +_immediate im<<=b00010100000 +# 666 0000 6666 +# bits 10:0 of h05050606 are 110 0000 0110 +_exchange_im im<<=b11000000110 + +## get value h07070808 into r1 +stack down +# 0000 7777 00 +# bits 31:22 of h07070808 are 0000 0111 00 +_immediate im<<=b0000011100 +# 00 7777 0000 8 +# bits 21:11 of h07070808 are 00 0111 0000 1 +_immediate im<<=b00011100001 +# 888 0000 8888 +# bits 10:0 of h07070808 are 000 0000 1000 +_exchange_im im<<=b00000001000 + +## get address h57574 into im and write r1 to that address +# 5555 7777 5 +# bits 19:11 of h57574 are 0101 0111 0 +_immediate im=b010101110 +# 555 7777 4444 +# bits 10:0 of h57574 are 101 0111 0100 +store im<<=b10101110100 + +# get r0 to r1 +stack up + +## get address h57578 into im and write r1 to that address +# 5555 7777 5 +# bits 19:11 of h57578 are 0101 0111 0 +_immediate im=b010101110 +# 555 7777 8888 +# bits 10:0 of h57578 are 101 0111 1000 +store im<<=b10101111000 + +# get r0 to r1 +stack up + +## get address h5757C into im and write r1 to that address +# 5555 7777 5 +# bits 19:11 of h5757C are 0101 0111 0 +_immediate im=b010101110 +# 555 7777 CCCC +# bits 10:0 of h5757C are 101 0111 1100 +store im<<=b10101111100 + +# get r0 to r1 +stack up + +## get address h57580 into im and write r1 to that address +# 5555 7777 5 +# bits 19:11 of h57580 are 0101 0111 0 +_immediate im=b010101110 +# 555 8888 0000 +# bits 10:0 of h57580 are 101 1000 0000 +store im<<=b10110000000 + +## finish test +halt diff --git a/tests/stack_machine_old_load_store/test.v b/tests/stack_machine_old_load_store/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_load_store/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_load_store/words_to_verify.mem b/tests/stack_machine_old_load_store/words_to_verify.mem new file mode 100644 index 0000000..349b213 --- /dev/null +++ b/tests/stack_machine_old_load_store/words_to_verify.mem @@ -0,0 +1,12 @@ +// address value + 57574 0808 + 57576 0707 + + 57578 0606 + 5757A 0505 + + 5757C 0404 + 5757E 0303 + + 57580 0202 + 57582 0101 diff --git a/tests/stack_machine_old_mul/instructions.s.tcl b/tests/stack_machine_old_mul/instructions.s.tcl new file mode 100755 index 0000000..8473aef --- /dev/null +++ b/tests/stack_machine_old_mul/instructions.s.tcl @@ -0,0 +1,42 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 4 values to memory; load 2 of them back, multiply them and store the +### result; load another 2, multiply them and store the result; +### this is similar to addition and substraction tests + +set_sp h7FFFC + +## store first 2 factors +const 483091365 +store@ h1EEE0 +const 74683203 +store@ h1EEE4 + +## store other 2 factors +const 8436 +store@ h1EEEC +const -14020 +store@ h1EEF0 + +## perform the first multiplication +load@ h1EEE0 +stack down +load@ h1EEE4 +# multiplying 483091365 by 74683203 should yield 36078810479842095 +# if we take lowest 32 bits of 36078810479842095 we get 2861683503 +mul +stack up +store@ h1EEE8 + +## perform the second multiplication +load@ h1EEEC +stack down +load@ h1EEF0 +# multiplying 8436 by -14020 should yield -118272720 (which fits in 32 bits) +mul +stack up +store@ h1EEF4 + +halt diff --git a/tests/stack_machine_old_mul/test.v b/tests/stack_machine_old_mul/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_mul/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_mul/words_to_verify.mem b/tests/stack_machine_old_mul/words_to_verify.mem new file mode 100644 index 0000000..3095d6e --- /dev/null +++ b/tests/stack_machine_old_mul/words_to_verify.mem @@ -0,0 +1,19 @@ +// address value + 1EEE0 63A5 // 483091365 in hex is 1CCB63A5 + 1EEE2 1CCB + + 1EEE4 9343 // 74683203 in hex is 4739343 + 1EEE6 473 + + 1EEE8 D32F // 2861683503 in hex is AA91D32F + 1EEEA AA91 + + + 1EEEC 20F4 // 8436 in hex is 20F4 + 1EEEE 0 + + 1EEF0 C93C // -14020 in hex is FFFFC93C + 1EEF2 FFFF + + 1EEF4 4D30 // -118272720 in hex is F8F34D30 + 1EEF6 F8F3 diff --git a/tests/stack_machine_old_multiinstructions_load_store/instructions.s.tcl b/tests/stack_machine_old_multiinstructions_load_store/instructions.s.tcl new file mode 100755 index 0000000..58792d3 --- /dev/null +++ b/tests/stack_machine_old_multiinstructions_load_store/instructions.s.tcl @@ -0,0 +1,32 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### do the same as in stack_machine_2 test, but use higher level instructions + +## set sp to h7FFFC +set_sp h7FFFC +## get value h01010202 into r1 +const h01010202 +## get value h03030404 into r1 +stack down +const h03030404 +## get value h05050606 into r1 +stack down +const h05050606 +## get value h07070808 into r1 +stack down +const h07070808 +## write r1 to address h57574 +store@ h57574 +stack up +## write r1 to address h57578 +store@ h57578 +stack up +## write r1 to address h5757C +store@ h5757C +stack up +## write r1 to address h57580 +store@ h57580 +## finish test +halt diff --git a/tests/stack_machine_old_multiinstructions_load_store/test.v b/tests/stack_machine_old_multiinstructions_load_store/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_multiinstructions_load_store/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_multiinstructions_load_store/words_to_verify.mem b/tests/stack_machine_old_multiinstructions_load_store/words_to_verify.mem new file mode 120000 index 0000000..e82687e --- /dev/null +++ b/tests/stack_machine_old_multiinstructions_load_store/words_to_verify.mem @@ -0,0 +1 @@ +../stack_machine_old_load_store/words_to_verify.mem \ No newline at end of file diff --git a/tests/stack_machine_old_store/instructions.s.tcl b/tests/stack_machine_old_store/instructions.s.tcl new file mode 100755 index 0000000..ddc3a8e --- /dev/null +++ b/tests/stack_machine_old_store/instructions.s.tcl @@ -0,0 +1,29 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### simple test - write value hDEADBEEF to address h3ABCD + +## get value hDEADBEEF into r1 + +# DDDD EEEE AA +# bits 31:22 of hDEADBEEF are 1101 1110 10 +_immediate im<<=b1101111010 +# AA DDDD BBBB E +# bits 21:11 of hDEADBEEF are 10 1101 1011 1 +_immediate im<<=b10110110111 +# EEE EEEE FFFF +# bits 10:0 of hDEADBEEF are 110 1110 1111 +_exchange_im im<<=b11011101111 + +## get address h7579A into im + +# 7777 5555 7 +# bits 19:11 of h7579A are 0111 0101 0 +_immediate im=b011101010 +# 777 9999 AAAA +# bits 10:0 of h7579A are 111 1001 1010 +store im<<=b11110011010 + +## finish test +halt diff --git a/tests/stack_machine_old_store/test.v b/tests/stack_machine_old_store/test.v new file mode 100644 index 0000000..7e7429f --- /dev/null +++ b/tests/stack_machine_old_store/test.v @@ -0,0 +1,140 @@ +`default_nettype none + +`include "messages.vh" + +`ifndef SIMULATION + `error_SIMULATION_not_defined +; /* Cause syntax error */ +`endif + +`ifndef INSTRUCTIONS_COUNT + `error_INSTRUCTIONS_COUNT_must_be_defined +; /* Cause syntax error */ +`endif + +`ifndef WORDS_TO_VERIFY_COUNT + `error_WORDS_TO_VERIFY_COUNT_must_be_defined +; /* Cause syntax error */ +`endif + +module stack_machine_test(); + wire M_ACK_I; + wire M_CLK_I; + wire [19:0] M_ADR_O; + wire [15:0] M_DAT_I; + wire [15:0] M_DAT_O; + wire M_RST_I; + wire M_STB_O; + wire M_CYC_O; + wire M_WE_O; + wire M_STALL_I; + + wire S_ACK_O; + wire S_CLK_I; + wire [17:0] S_ADR_I; + wire [15:0] S_DAT_I; + wire [15:0] S_DAT_O; + wire S_RST_I; + wire S_STB_I; + wire S_WE_I; + wire S_STALL_O; + + /* Non-wishbone */ + wire M_finished; + + stack_machine stack_machine + ( + .ACK_I(M_ACK_I), + .CLK_I(M_CLK_I), + .ADR_O(M_ADR_O), + .DAT_I(M_DAT_I), + .DAT_O(M_DAT_O), + .RST_I(M_RST_I), + .STB_O(M_STB_O), + .CYC_O(M_CYC_O), + .WE_O(M_WE_O), + .STALL_I(M_STALL_I), + + .finished(M_finished) + ); + + memory_slave_model + #( + .SLAVE_NR(0), + .WRITABLE(1), + .WORDS_TO_INITIALIZE(`INSTRUCTIONS_COUNT), + .INITIAL_CONTENTS_FILE("instructions.mem") + ) slave + ( + .ACK_O(S_ACK_O), + .CLK_I(S_CLK_I), + .ADR_I(S_ADR_I), + .DAT_I(S_DAT_I), + .DAT_O(S_DAT_O), + .RST_I(S_RST_I), + .STB_I(S_STB_I), + .WE_I(S_WE_I), + .STALL_O(S_STALL_O) + ); + + reg CLK; + reg RST; + + assign M_ACK_I = S_ACK_O; + assign M_CLK_I = CLK; + assign M_DAT_I = S_DAT_O; + assign M_RST_I = RST; + assign M_STALL_I = S_STALL_O; + + assign S_CLK_I = CLK; + assign S_ADR_I = M_ADR_O[17:0]; /* Ignore 2 topmost bits */ + assign S_DAT_I = M_DAT_O; + assign S_RST_I = RST; + assign S_STB_I = M_STB_O && M_CYC_O; + assign S_WE_I = M_WE_O; + + integer i, j; + reg [17:0] address; + reg [15:0] expected_value; + + reg [19:0] words_to_verify[`WORDS_TO_VERIFY_COUNT * 2 - 1 : 0]; + + initial begin + CLK <= 0; + RST <= 1; + + for (i = 0; i < 3500; i++) begin + #1; + + CLK <= ~CLK; + + if (CLK) + RST <= 0; + + if (M_finished) begin + $readmemh("words_to_verify.mem", words_to_verify, + 0, `WORDS_TO_VERIFY_COUNT * 2 - 1); + + for (j = 0; j < `WORDS_TO_VERIFY_COUNT; j++) begin + /* + * Byte-grained addresses are used in CPU, and we also use + * them in tclasm opcodes and in files with words for + * verification. Slaves and wishbone address 16-bit words, not + * single bytes. We need to drop the lowest bit here. + */ + address = words_to_verify[2 * j][19:1]; + expected_value = words_to_verify[2 * j + 1]; + if (slave.memory[address] !== expected_value) begin + `MSG(("error: expected h%x at h%x, but got h%x", + expected_value, address, slave.memory[address])); + end + end + + $finish; + end // if (M_finished) + end // for (i = 0; i < 3500; i++) + + $display("error: cpu hasn't finished its operations in 1750 ticks"); + $finish; + end // initial begin +endmodule // stack_machine_test diff --git a/tests/stack_machine_old_store/words_to_verify.mem b/tests/stack_machine_old_store/words_to_verify.mem new file mode 100644 index 0000000..9056a1b --- /dev/null +++ b/tests/stack_machine_old_store/words_to_verify.mem @@ -0,0 +1,3 @@ +// address value + 7579A BEEF + 7579C DEAD diff --git a/tests/stack_machine_old_sub/instructions.s.tcl b/tests/stack_machine_old_sub/instructions.s.tcl new file mode 100755 index 0000000..3f8fb48 --- /dev/null +++ b/tests/stack_machine_old_sub/instructions.s.tcl @@ -0,0 +1,21 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +### store 2 values to memory, load them back, substract them and store the +### result; this is analogous to addition test + +set_sp h7FFFC +const 68996288 +store@ h1EEE0 +const 540904416 +store@ h1EEE4 + +load@ h1EEE0 +stack down +load@ h1EEE4 +# substracting 540904416 from 68996288 should yield -471908128 +sub +stack up +store@ h1EEE8 +halt diff --git a/tests/stack_machine_old_sub/test.v b/tests/stack_machine_old_sub/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_sub/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_sub/words_to_verify.mem b/tests/stack_machine_old_sub/words_to_verify.mem new file mode 100644 index 0000000..cc666fa --- /dev/null +++ b/tests/stack_machine_old_sub/words_to_verify.mem @@ -0,0 +1,9 @@ +// address value + 1EEE0 CCC0 // 68996288 in hex is 41CCCC0 + 1EEE2 41C + + 1EEE4 8BE0 // 540904416 in hex is 203D8BE0 + 1EEE6 203D + + 1EEE8 40E0 // -471908128 in hex is E3DF40E0 + 1EEEA E3DF diff --git a/tests/stack_machine_old_swap/instructions.s.tcl b/tests/stack_machine_old_swap/instructions.s.tcl new file mode 100755 index 0000000..c17314e --- /dev/null +++ b/tests/stack_machine_old_swap/instructions.s.tcl @@ -0,0 +1,15 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +set_sp h7FFFC +const h00AD00DE +stack down +const h00EF00BE +swap +## Because values were swapped, h00AD00DE should get written, first, at lower +## address (h100) and h00EF00BE should be written next (at h104) +store@ h00100 +stack down +store@ h00104 +halt diff --git a/tests/stack_machine_old_swap/test.v b/tests/stack_machine_old_swap/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_swap/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_swap/words_to_verify.mem b/tests/stack_machine_old_swap/words_to_verify.mem new file mode 100644 index 0000000..669219d --- /dev/null +++ b/tests/stack_machine_old_swap/words_to_verify.mem @@ -0,0 +1,5 @@ +// address value + 00100 DE + 00102 AD + 00104 BE + 00106 EF diff --git a/tests/stack_machine_old_tee/instructions.s.tcl b/tests/stack_machine_old_tee/instructions.s.tcl new file mode 100755 index 0000000..e75b564 --- /dev/null +++ b/tests/stack_machine_old_tee/instructions.s.tcl @@ -0,0 +1,15 @@ +#!/usr/bin/env tclsh + +source tclasm.tcl + +set_sp h7FFFC +const hABCDEF +stack down +const hA98765 +tee +## hA98765 should now be replaced with hABCDEF - we should have +## two hABCDEF's on stack - let's store them for verification +store@ h00100 +stack up +store@ h00104 +halt diff --git a/tests/stack_machine_old_tee/test.v b/tests/stack_machine_old_tee/test.v new file mode 120000 index 0000000..f0c3cf9 --- /dev/null +++ b/tests/stack_machine_old_tee/test.v @@ -0,0 +1 @@ +../stack_machine_old_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_old_tee/words_to_verify.mem b/tests/stack_machine_old_tee/words_to_verify.mem new file mode 100644 index 0000000..961f9dc --- /dev/null +++ b/tests/stack_machine_old_tee/words_to_verify.mem @@ -0,0 +1,5 @@ +// address value + 00100 CDEF + 00102 AB + 00104 CDEF + 00106 AB diff --git a/tests/stack_machine_store/instructions.s.tcl b/tests/stack_machine_store/instructions.s.tcl deleted file mode 100755 index ddc3a8e..0000000 --- a/tests/stack_machine_store/instructions.s.tcl +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### simple test - write value hDEADBEEF to address h3ABCD - -## get value hDEADBEEF into r1 - -# DDDD EEEE AA -# bits 31:22 of hDEADBEEF are 1101 1110 10 -_immediate im<<=b1101111010 -# AA DDDD BBBB E -# bits 21:11 of hDEADBEEF are 10 1101 1011 1 -_immediate im<<=b10110110111 -# EEE EEEE FFFF -# bits 10:0 of hDEADBEEF are 110 1110 1111 -_exchange_im im<<=b11011101111 - -## get address h7579A into im - -# 7777 5555 7 -# bits 19:11 of h7579A are 0111 0101 0 -_immediate im=b011101010 -# 777 9999 AAAA -# bits 10:0 of h7579A are 111 1001 1010 -store im<<=b11110011010 - -## finish test -halt diff --git a/tests/stack_machine_store/test.v b/tests/stack_machine_store/test.v deleted file mode 100644 index 7e7429f..0000000 --- a/tests/stack_machine_store/test.v +++ /dev/null @@ -1,140 +0,0 @@ -`default_nettype none - -`include "messages.vh" - -`ifndef SIMULATION - `error_SIMULATION_not_defined -; /* Cause syntax error */ -`endif - -`ifndef INSTRUCTIONS_COUNT - `error_INSTRUCTIONS_COUNT_must_be_defined -; /* Cause syntax error */ -`endif - -`ifndef WORDS_TO_VERIFY_COUNT - `error_WORDS_TO_VERIFY_COUNT_must_be_defined -; /* Cause syntax error */ -`endif - -module stack_machine_test(); - wire M_ACK_I; - wire M_CLK_I; - wire [19:0] M_ADR_O; - wire [15:0] M_DAT_I; - wire [15:0] M_DAT_O; - wire M_RST_I; - wire M_STB_O; - wire M_CYC_O; - wire M_WE_O; - wire M_STALL_I; - - wire S_ACK_O; - wire S_CLK_I; - wire [17:0] S_ADR_I; - wire [15:0] S_DAT_I; - wire [15:0] S_DAT_O; - wire S_RST_I; - wire S_STB_I; - wire S_WE_I; - wire S_STALL_O; - - /* Non-wishbone */ - wire M_finished; - - stack_machine stack_machine - ( - .ACK_I(M_ACK_I), - .CLK_I(M_CLK_I), - .ADR_O(M_ADR_O), - .DAT_I(M_DAT_I), - .DAT_O(M_DAT_O), - .RST_I(M_RST_I), - .STB_O(M_STB_O), - .CYC_O(M_CYC_O), - .WE_O(M_WE_O), - .STALL_I(M_STALL_I), - - .finished(M_finished) - ); - - memory_slave_model - #( - .SLAVE_NR(0), - .WRITABLE(1), - .WORDS_TO_INITIALIZE(`INSTRUCTIONS_COUNT), - .INITIAL_CONTENTS_FILE("instructions.mem") - ) slave - ( - .ACK_O(S_ACK_O), - .CLK_I(S_CLK_I), - .ADR_I(S_ADR_I), - .DAT_I(S_DAT_I), - .DAT_O(S_DAT_O), - .RST_I(S_RST_I), - .STB_I(S_STB_I), - .WE_I(S_WE_I), - .STALL_O(S_STALL_O) - ); - - reg CLK; - reg RST; - - assign M_ACK_I = S_ACK_O; - assign M_CLK_I = CLK; - assign M_DAT_I = S_DAT_O; - assign M_RST_I = RST; - assign M_STALL_I = S_STALL_O; - - assign S_CLK_I = CLK; - assign S_ADR_I = M_ADR_O[17:0]; /* Ignore 2 topmost bits */ - assign S_DAT_I = M_DAT_O; - assign S_RST_I = RST; - assign S_STB_I = M_STB_O && M_CYC_O; - assign S_WE_I = M_WE_O; - - integer i, j; - reg [17:0] address; - reg [15:0] expected_value; - - reg [19:0] words_to_verify[`WORDS_TO_VERIFY_COUNT * 2 - 1 : 0]; - - initial begin - CLK <= 0; - RST <= 1; - - for (i = 0; i < 3500; i++) begin - #1; - - CLK <= ~CLK; - - if (CLK) - RST <= 0; - - if (M_finished) begin - $readmemh("words_to_verify.mem", words_to_verify, - 0, `WORDS_TO_VERIFY_COUNT * 2 - 1); - - for (j = 0; j < `WORDS_TO_VERIFY_COUNT; j++) begin - /* - * Byte-grained addresses are used in CPU, and we also use - * them in tclasm opcodes and in files with words for - * verification. Slaves and wishbone address 16-bit words, not - * single bytes. We need to drop the lowest bit here. - */ - address = words_to_verify[2 * j][19:1]; - expected_value = words_to_verify[2 * j + 1]; - if (slave.memory[address] !== expected_value) begin - `MSG(("error: expected h%x at h%x, but got h%x", - expected_value, address, slave.memory[address])); - end - end - - $finish; - end // if (M_finished) - end // for (i = 0; i < 3500; i++) - - $display("error: cpu hasn't finished its operations in 1750 ticks"); - $finish; - end // initial begin -endmodule // stack_machine_test diff --git a/tests/stack_machine_store/words_to_verify.mem b/tests/stack_machine_store/words_to_verify.mem deleted file mode 100644 index 9056a1b..0000000 --- a/tests/stack_machine_store/words_to_verify.mem +++ /dev/null @@ -1,3 +0,0 @@ -// address value - 7579A BEEF - 7579C DEAD diff --git a/tests/stack_machine_sub/instructions.s.tcl b/tests/stack_machine_sub/instructions.s.tcl deleted file mode 100755 index 3f8fb48..0000000 --- a/tests/stack_machine_sub/instructions.s.tcl +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -### store 2 values to memory, load them back, substract them and store the -### result; this is analogous to addition test - -set_sp h7FFFC -const 68996288 -store@ h1EEE0 -const 540904416 -store@ h1EEE4 - -load@ h1EEE0 -stack down -load@ h1EEE4 -# substracting 540904416 from 68996288 should yield -471908128 -sub -stack up -store@ h1EEE8 -halt diff --git a/tests/stack_machine_sub/test.v b/tests/stack_machine_sub/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_sub/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_sub/words_to_verify.mem b/tests/stack_machine_sub/words_to_verify.mem deleted file mode 100644 index cc666fa..0000000 --- a/tests/stack_machine_sub/words_to_verify.mem +++ /dev/null @@ -1,9 +0,0 @@ -// address value - 1EEE0 CCC0 // 68996288 in hex is 41CCCC0 - 1EEE2 41C - - 1EEE4 8BE0 // 540904416 in hex is 203D8BE0 - 1EEE6 203D - - 1EEE8 40E0 // -471908128 in hex is E3DF40E0 - 1EEEA E3DF diff --git a/tests/stack_machine_swap/instructions.s.tcl b/tests/stack_machine_swap/instructions.s.tcl deleted file mode 100755 index c17314e..0000000 --- a/tests/stack_machine_swap/instructions.s.tcl +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -set_sp h7FFFC -const h00AD00DE -stack down -const h00EF00BE -swap -## Because values were swapped, h00AD00DE should get written, first, at lower -## address (h100) and h00EF00BE should be written next (at h104) -store@ h00100 -stack down -store@ h00104 -halt diff --git a/tests/stack_machine_swap/test.v b/tests/stack_machine_swap/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_swap/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_swap/words_to_verify.mem b/tests/stack_machine_swap/words_to_verify.mem deleted file mode 100644 index 669219d..0000000 --- a/tests/stack_machine_swap/words_to_verify.mem +++ /dev/null @@ -1,5 +0,0 @@ -// address value - 00100 DE - 00102 AD - 00104 BE - 00106 EF diff --git a/tests/stack_machine_tee/instructions.s.tcl b/tests/stack_machine_tee/instructions.s.tcl deleted file mode 100755 index e75b564..0000000 --- a/tests/stack_machine_tee/instructions.s.tcl +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env tclsh - -source tclasm.tcl - -set_sp h7FFFC -const hABCDEF -stack down -const hA98765 -tee -## hA98765 should now be replaced with hABCDEF - we should have -## two hABCDEF's on stack - let's store them for verification -store@ h00100 -stack up -store@ h00104 -halt diff --git a/tests/stack_machine_tee/test.v b/tests/stack_machine_tee/test.v deleted file mode 120000 index f5b6a59..0000000 --- a/tests/stack_machine_tee/test.v +++ /dev/null @@ -1 +0,0 @@ -../stack_machine_store/test.v \ No newline at end of file diff --git a/tests/stack_machine_tee/words_to_verify.mem b/tests/stack_machine_tee/words_to_verify.mem deleted file mode 100644 index 961f9dc..0000000 --- a/tests/stack_machine_tee/words_to_verify.mem +++ /dev/null @@ -1,5 +0,0 @@ -// address value - 00100 CDEF - 00102 AB - 00104 CDEF - 00106 AB -- cgit v1.2.3