separate .text and .data for instruction and data memory

This commit is contained in:
Brendan Haines 2020-11-10 00:19:42 -07:00
parent 32d0a2dcaa
commit caf9a6f4f7
4 changed files with 74 additions and 10 deletions

View File

@ -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<MEM_INST_LENGTH; i=i+1) begin
mem_inst[i] = INST_NOP;
end
$readmemh("../test/test.hex", mem_inst);
$readmemh("../test/text.hex", mem_inst);
end
// Data memory
reg [31:0] mem_data [0:MEM_DATA_LENGTH-1];
wire [31:0] mem_data_waddr;
wire [31:0] mem_data_wdata;
@ -34,6 +38,14 @@ wire [31:0] mem_data_raddr;
reg [31:0] mem_data_rdata;
wire [3:0] mem_data_rmask;
initial begin: mem_data_init
integer i;
for (i=0; i<MEM_DATA_LENGTH; i=i+1) begin
mem_data[i] = DATA_DEFAULT;
end
$readmemh("../test/data.hex", mem_data);
end
initial begin
#0
clk = 0;

View File

@ -1,4 +1,4 @@
all: test.hex
all: text.hex data.hex
CC = riscv64-linux-gnu-gcc
# CFLAGS = -march=rv32i -mabi=ilp32
@ -19,5 +19,11 @@ LDFLAGS = -T test.ld
%.elf: %.o
$(LD) $(LDFLAGS) $^ -o $@
test.hex: test.elf
riscv64-linux-gnu-objdump -s $^ | sed -n '/0000/,$$p' | cut -f3-6 -d ' ' | sed -e 's/ /\n/g' | sed 's/^\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/' > $@
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

View File

@ -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

View File

@ -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*/
}