diff --git a/hdl/tb/core_tb.v b/hdl/tb/core_tb.v index d60b06a..d2417d8 100644 --- a/hdl/tb/core_tb.v +++ b/hdl/tb/core_tb.v @@ -4,27 +4,31 @@ module core_tb(); initial $timeformat(-9, 2, " ns", 20); -localparam MEM_INST_LENGTH = 256; -localparam MEM_DATA_LENGTH = 256; +wire dummy_out; -localparam INST_NOP = 32'h00000013; // nop +localparam MEM_INST_LENGTH = 256; // words +localparam MEM_DATA_LENGTH = 256; // words + +localparam INST_NOP = 32'h00000013; // nop +localparam DATA_DEFAULT = 32'hdeadbeef; reg clk, reset; + +// Instruction memory reg [31:0] mem_inst [0:MEM_INST_LENGTH-1]; wire [31:0] mem_inst_addr; wire [31:0] mem_inst_idx = mem_inst_addr >> 2; wire [31:0] mem_inst_data = mem_inst_idx < MEM_INST_LENGTH ? mem_inst[mem_inst_idx] : INST_NOP; -wire dummy_out; - initial begin: mem_inst_init integer i; for (i=0; i $@ +text.hex: test.elf + riscv64-linux-gnu-objdump -s $^ | sed -n '/.text/,$$p' | tail -n+2 | sed -n '/.data/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@ + +data.hex: test.elf + riscv64-linux-gnu-objdump -s $^ | sed -n '/.data/,$$p' | tail -n+2 | sed -n '/.bss/,$$!p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@ + +clean: + rm test.elf text.hex data.hex \ No newline at end of file diff --git a/test/test.S b/test/test.S index 18716ad..67372ba 100644 --- a/test/test.S +++ b/test/test.S @@ -1,4 +1,7 @@ +# NOTE: .text .data .bss must occur in that order + .global _start + .text _start: @@ -206,8 +209,31 @@ test9: j fail test10: + # now for some memory stuff +# # sw +# la x9, someint # x9 = start of .bss +# li x10, 0x12345678 # x10 = 0x12345678 +# nop +# nop +# nop +# nop +# nop +# sw x10, 0(x9) # someint = 0x12345678 +# nop +# nop +# nop +# nop +# nop +# lw x11, 0(x9) # x11 = 0x12345678 +# nop +# nop +# nop +# nop +# nop +done: + # set registers to known values before loop addi x2, x0, 1 # x1 = 1 addi x3, x0, 1 # x1 = 1 @@ -257,4 +283,11 @@ fail: nop nop + .data +someint: + .word 0xfedcba98 + +.bss +anotherint: + .word \ No newline at end of file diff --git a/test/test.ld b/test/test.ld index 4ede032..13d874c 100644 --- a/test/test.ld +++ b/test/test.ld @@ -2,16 +2,29 @@ ENTRY(_start) MEMORY { - ROM (rx) : ORIGIN = 0x00000000, LENGTH = 1024 + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 1024 + RAM (rwx) : ORIGIN = 0x10000000, LENGTH = 512 + /* FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 512 */ } SECTIONS { .text : { + . = ALIGN(4); _text = .; *(.text*) *(.rodata*) _etext = .; + . = ALIGN(4); } > ROM + + .data : + { + . = ALIGN(4); + _data = .; + *(.data*) + _edata = .; + . = ALIGN(4); + } > RAM /*AT> FLASH*/ } \ No newline at end of file