gateware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 3189205c14b6d5d170db277faea41dd8c463e6fd
parent 6a79fbf55c4090fafab8d8fb65d60ea6be6644fb
Author: Brian Swetland <swetland@frotz.net>
Date:   Tue, 29 Dec 2015 21:56:13 -0800

some support for a test infrastructure

Diffstat:
Mhdl/simram.sv | 1+
Mhdl/testbench.sv | 9++++++++-
Msrc/a16.c | 41+++++++++++++++++++----------------------
Msrc/d16.c | 3++-
Msrc/test.s | 44+++++++++++++++++++++++---------------------
Msrc/testbench.cpp | 3+--
6 files changed, 54 insertions(+), 47 deletions(-)

diff --git a/hdl/simram.sv b/hdl/simram.sv @@ -20,6 +20,7 @@ module simram( always @(posedge clk) begin if (we) begin + $display(":WRI %08x %08x", waddr, wdata); dpi_mem_write({16'd0, waddr}, {16'd0, wdata}); end if (re) begin diff --git a/hdl/testbench.sv b/hdl/testbench.sv @@ -11,7 +11,14 @@ reg [15:0]count = 16'd0; always @(posedge clk) begin count <= count + 16'd1; - if (count == 16'd256) $finish; + if (count == 16'd1000) $finish; + if (cpu0.ir == 16'hFFFF) begin + for ( integer i = 0; i < 16; i++ ) begin + $display(":REG R%0d %8X", i, cpu0.regs.R[i]); + end + $display(":END"); + $finish; + end end wire [15:0]wdata; diff --git a/src/a16.c b/src/a16.c @@ -200,10 +200,9 @@ void save(const char *fn) { enum tokens { tEOL, tCOMMA, tCOLON, tOBRACK, tCBRACK, tDOT, tHASH, tSTRING, tNUMBER, - tMOV, tAND, tORR, tXOR, tADD, tSUB, tSHR, tSHL, -// tADC, tSBC, tSR4, tSL4, tBIS, tBIC, tTBS, tMUL, - tLW, tSW, tNOP, tNOT, tMHI, - tB, tBL, tBZ, tBNZ, + tMOV, tAND, tORR, tXOR, tADD, tSUB, tMUL, tMHI, + tSLT, tSLE, tSHR, tSHL, tBIS, tBIC, tTBS, tBIT, + tLW, tSW, tNOP, tNOT, tB, tBL, tBZ, tBNZ, tR0, tR1, tR2, tR3, tR4, tR5, tR6, tR7, rR8, rR9, rR10, rR11, rR12, tR13, tR14, tR15, tSP, tLR, @@ -214,10 +213,9 @@ enum tokens { char *tnames[] = { "<EOL>", ",", ":", "[", "]", ".", "#", "<STRING>", "<NUMBER>", - "MOV", "AND", "ORR", "XOR", "ADD", "SUB", "SHR", "SHL", -// "ADC", "SBC", "SR4", "SL4", "BIS", "BIC", "TBS", "MUL", - "LW", "SW", "NOP", "NOT", "MHI", - "B", "BL", "BZ", "BNZ", + "MOV", "AND", "ORR", "XOR", "ADD", "SUB", "MUL", "MHI", + "SLT", "SLE", "SHR", "SHL", "BIS", "BIC", "TBS", "BIT", + "LW", "SW", "NOP", "NOT", "B", "BL", "BZ", "BNZ", "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", "SP", "LR", @@ -225,7 +223,7 @@ char *tnames[] = { }; #define FIRST_ALU_OP tMOV -#define LAST_ALU_OP tSHL +#define LAST_ALU_OP tBIT #define FIRST_REGISTER tR0 #define LAST_REGISTER tLR @@ -301,7 +299,8 @@ int tokenize(char *line, unsigned *tok, unsigned *num, char **str) { case '/': if (line[1] == '/') goto alldone; - + case ';': + goto alldone; case ',': str[count] = ","; num[count] = 0; @@ -486,23 +485,21 @@ void assemble_line(int n, unsigned *tok, unsigned *num, char **str) { emit(OP_ALU_RA_RA_RB | _A(to_reg(T1)) | _B(to_reg(T3)) | ALU_MOV); return; } - expect(tHASH, T3); - expect(tNUMBER, T4); - if (is_signed8(num[4])) { - emit(OP_MOV_RA_S8 | _A(to_reg(T1)) | _I8(num[4])); + expect(tNUMBER, T3); + if (is_signed8(num[3])) { + emit(OP_MOV_RA_S8 | _A(to_reg(T1)) | _I8(num[3])); return; } else { - emit(OP_MOV_RA_S8 | _A(to_reg(T1)) | _I8(num[4])); - emit(OP_MHI_RA_S8 | _A(to_reg(T1)) | _I8((num[4] >> 8))); + emit(OP_MOV_RA_S8 | _A(to_reg(T1)) | _I8(num[3])); + emit(OP_MHI_RA_S8 | _A(to_reg(T1)) | _I8((num[3] >> 8))); } return; case tMHI: expect_register(T1); expect(tCOMMA, T2); - expect(tHASH, T3); - expect(tNUMBER, T4); + expect(tNUMBER, T3); // range - emit(OP_MHI_RA_S8 | _A(to_reg(T1)) | _I8(num[4])); + emit(OP_MHI_RA_S8 | _A(to_reg(T1)) | _I8(num[3])); return; case tLW: case tSW: @@ -591,12 +588,12 @@ void assemble_line(int n, unsigned *tok, unsigned *num, char **str) { expect(T2, tCOMMA); expect_register(T3); expect(T4, tCOMMA); - if ((T5 == tHASH) && (T6 == tNUMBER)) { + if (T5 == tNUMBER) { if (T1 != T3) { die("both registers must be the same in this form"); } - if (is_signed4(num[6])) { - emit(OP_ALU_RA_RA_S4 | _A(to_reg(T1)) | _FLO(to_func(T0)) | _I4(num[6])); + if (is_signed4(num[5])) { + emit(OP_ALU_RA_RA_S4 | _A(to_reg(T1)) | _FLO(to_func(T0)) | _I4(num[5])); return; } else { // auto use R15 as scratch? diff --git a/src/d16.c b/src/d16.c @@ -31,7 +31,8 @@ const char *regname[] = { }; const char *alufunc[] = { - "MOV", "AND", "ORR", "XOR", "ADD", "SUB", "SHR", "SHL", + "MOV", "AND", "ORR", "XOR", "ADD", "SUB", "MUL", "MHI", + "SLT", "SLE", "SHR", "SHL", "BIS", "BIC", "TBS", "BIT", }; void printinst(char *buf, unsigned pc, unsigned instr, const char *fmt) { diff --git a/src/test.s b/src/test.s @@ -1,34 +1,36 @@ - mov r0, #0 - mov r1, #1 - mov r1, #7 - mov r2, #2 - mov r3, #3 - add r3, r3, #1 - mov r3, #0xFEED - add r2, r2, #1 - add r2, r2, #1 - add r2, r2, #1 - add r2, r2, #1 + mov r0, 0 + mov r1, 1 + mov r1, 7 + mul r3, r1, r1 + mov r2, 2 + mov r3, 3 + add r3, r3, 1 + mov r3, 0xFEED + add r2, r2, 1 + add r2, r2, 1 + add r2, r2, 1 + add r2, r2, 1 - mov r0, #0xE000 - mov r1, #0x1234 - mov r2, #5 + mov r0, 0xE000 + mov r1, 0x1234 + mov r2, 5 bl fill - mov r0, #0xE000 - mov r1, #0x4321; - mov r2, #5 + mov r0, 0xE000 + mov r1, 0x4321; + mov r2, 5 bl fill - mov r0, #0xE000 + mov r0, 0xE000 lw r3, [r0] mov r2, r3 - mov r0, #0xDEAD + mov r0, 0xDEAD + word 0xFFFF b . fill: // r0=addr r1=value r2=count sw r1, [r0] - add r0, r0, #1 - sub r2, r2, #1 + add r0, r0, 1 + sub r2, r2, 1 bnz r2, fill b lr diff --git a/src/testbench.cpp b/src/testbench.cpp @@ -34,7 +34,7 @@ static unsigned memory[65536]; void dpi_mem_write(int addr, int data) { - fprintf(stderr,"WR %04x = %08x\n", addr, data); + //fprintf(stderr,"WR %04x = %08x\n", addr, data); memory[addr & 0xFFFF] = data; } @@ -73,7 +73,6 @@ void loadmem(const char *fn) { memory[a++] = n; if (a == 4096) break; } - fprintf(stderr, "loaded %d words from '%s'\n", a, fn); } #ifdef TRACE