Compare commits
28 Commits
parallel_a
...
main
Author | SHA1 | Date | |
---|---|---|---|
9dddfd07c2 | |||
4beed25f84 | |||
ecba3742d3 | |||
8f7783f801 | |||
1a135b5966 | |||
a52c425024 | |||
8ae90cb4ef | |||
2c28eb4194 | |||
63d7d59580 | |||
cf85106ef9 | |||
de1ed2978b | |||
76d1c52cb2 | |||
8ec06e6ed8 | |||
5d8d652c9a | |||
b8568acb26 | |||
43e2e897f7 | |||
cfbc68221a | |||
b231133858 | |||
1533ddb4f5 | |||
bb13d09825 | |||
9c254f29fa | |||
965e127989 | |||
01c91fec99 | |||
294dfc6b47 | |||
ecf0b6bba2 | |||
50a342fe9c | |||
5eb65bce9d | |||
70a53c200c |
68
.github/workflows/build.yml
vendored
Normal file
68
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
# lint:
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@master
|
||||||
|
# - uses: chipsalliance/verible-linter-action@main
|
||||||
|
# # with:
|
||||||
|
# # paths: |
|
||||||
|
# # ./src
|
||||||
|
# # ./lib
|
||||||
|
# # ./tests
|
||||||
|
# # extra_args: "--check_syntax=true"
|
||||||
|
|
||||||
|
# enumerate-tests:
|
||||||
|
# name: Enumerate tests
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# outputs:
|
||||||
|
# matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v2
|
||||||
|
# - id: set-matrix
|
||||||
|
# run: echo "::set-output name=matrix::$(ls tests | grep test_* | jq -R -s -c 'split("\n")[:-1]')"
|
||||||
|
|
||||||
|
test:
|
||||||
|
# needs: enumerate-tests
|
||||||
|
name: Run Test `${{ matrix.test }}`
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
# test: ${{ fromJson(needs.enumerate-tests.outputs.matrix) }}
|
||||||
|
test:
|
||||||
|
- test_basic
|
||||||
|
- test_c
|
||||||
|
max-parallel: 1
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Build executables
|
||||||
|
uses: docker://runtimeverificationinc/riscv-gnu-toolchain:ubuntu-jammy-2024.04.12
|
||||||
|
with:
|
||||||
|
entrypoint: sh
|
||||||
|
args: |
|
||||||
|
-c "\
|
||||||
|
cd tests/${{ matrix.test }} && \
|
||||||
|
make obj && \
|
||||||
|
riscv64-unknown-elf-ld -melf32lriscv -T tb.ld *.o -o tb.elf && \
|
||||||
|
riscv64-unknown-elf-objcopy --target=verilog tb.elf tb.hex && \
|
||||||
|
riscv64-unknown-elf-objdump -xhdtsf tb.elf && \
|
||||||
|
echo "done" \
|
||||||
|
"
|
||||||
|
|
||||||
|
- name: Run Simulation
|
||||||
|
uses: docker://brendanhaines/iverilog:latest
|
||||||
|
with:
|
||||||
|
entrypoint: bash
|
||||||
|
args: |
|
||||||
|
-c "\
|
||||||
|
cd tests/${{ matrix.test }} && \
|
||||||
|
iverilog -g2012 -o tb.out tb.sv ../../src/*.v -Y .sv -I ../../lib && \
|
||||||
|
./tb.out | tee tb.log &&\
|
||||||
|
grep -q "ERROR" tb.log || true &&\
|
||||||
|
grep -q "SUCCESS" tb.log &&\
|
||||||
|
echo "done"
|
||||||
|
"
|
@@ -1,20 +0,0 @@
|
|||||||
image: ubuntu
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- simulate
|
|
||||||
|
|
||||||
testbench:
|
|
||||||
stage: simulate
|
|
||||||
script:
|
|
||||||
- echo "Installing dependencies..."
|
|
||||||
- apt update && apt install -y make iverilog gcc-10-riscv64-linux-gnu
|
|
||||||
- echo "Running tests..."
|
|
||||||
- make -C tests
|
|
||||||
|
|
||||||
testbench_libraries:
|
|
||||||
stage: simulate
|
|
||||||
script:
|
|
||||||
- echo "Installing dependencies..."
|
|
||||||
- apt update && apt install -y make iverilog
|
|
||||||
- echo "Running tests..."
|
|
||||||
- make -C lib/tb
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "riscv-gnu-toolchain"]
|
|
||||||
path = riscv-gnu-toolchain
|
|
||||||
url = https://github.com/riscv-collab/riscv-gnu-toolchain.git
|
|
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@@ -2,6 +2,7 @@
|
|||||||
"recommendations": [
|
"recommendations": [
|
||||||
"mshr-h.veriloghdl",
|
"mshr-h.veriloghdl",
|
||||||
"zhwu95.riscv",
|
"zhwu95.riscv",
|
||||||
"hediet.vscode-drawio"
|
"hediet.vscode-drawio",
|
||||||
|
"sunshaoce.risc-v"
|
||||||
]
|
]
|
||||||
}
|
}
|
43
README.md
43
README.md
@@ -1,25 +1,36 @@
|
|||||||

|
|
||||||
|
|
||||||
# RISC-V CPU
|
# RISC-V CPU
|
||||||
|
|
||||||
Short Term To Do:
|
Short Term To Do:
|
||||||
* add stalls for memory access
|
- [ ] add stalls for memory access
|
||||||
* use AXI for memory access (depends on AXIL memory module for test)
|
- [ ] use AXI for memory access (depends on AXIL memory module for test)
|
||||||
* add tests for non-pipelined case
|
- [ ] add tests for non-pipelined case
|
||||||
* get C working (may depend on memory stalls)
|
- [ ] get C working (may depend on memory stalls)
|
||||||
|
|
||||||
Desired features:
|
Desired features:
|
||||||
* 1- or 5-stage pipeline selectable via parameter
|
- [ ] 1- or 5-stage pipeline selectable via parameter
|
||||||
* AXI-lite Master for both instruction and data memory
|
- [ ] AXI-lite Master for both instruction and data memory
|
||||||
* 32, 64, (or 128?) bit word size
|
- [ ] 32, 64, (or 128?) bit word size
|
||||||
* floating point
|
- [ ] floating point
|
||||||
* multiplication
|
- [ ] multiplication
|
||||||
* division
|
- [ ] division
|
||||||
* instruction and data caches
|
- [ ] instruction and data caches
|
||||||
* JTAG debug probe
|
- [ ] JTAG debug probe
|
||||||
|
|
||||||
## Installation
|
## Development
|
||||||
Run `setup.sh` to install GCC
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
I'm using [act](https://github.com/nektos/act) for local testing. No special installation is required since everything gets built and tested in containers as part of the CI actions.
|
||||||
|
|
||||||
|
To run the tests, use
|
||||||
|
```bash
|
||||||
|
act push
|
||||||
|
```
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
* [AXI4 Protocol Specification](https://developer.arm.com/documentation/ihi0022/e/AMBA-AXI3-and-AXI4-Protocol-Specification?lang=en)
|
* [AXI4 Protocol Specification](https://developer.arm.com/documentation/ihi0022/e/AMBA-AXI3-and-AXI4-Protocol-Specification?lang=en)
|
||||||
|
* [JTAG Bus Description](https://web.archive.org/web/20230314233136/http://www.interfacebus.com/Design_Connector_JTAG_Bus.html)
|
||||||
|
* [1149.1-2013 - IEEE Standard for Test Access Port and Boundary-Scan Architecture](https://ieeexplore.ieee.org/document/6515989)
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
* [Icon](https://www.flaticon.com/free-icon/cpu_543275)
|
@@ -1 +0,0 @@
|
|||||||
<mxfile host="www.draw.io" modified="2021-07-04T02:03:34.409Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36" etag="gyPD3FephFzBolRvCJxz" version="14.8.4" type="device"><diagram id="K6ND4OlvUQiSsjvqaGL3" name="Page-1">7Vpbc5s4FP41ntl9iAchwPjRl2SbnWa2M9mZbR8VkA1dGXmEnNj99SuMMCAJ16kh0G384EEHSaDvfOeig0Zwsdn/wdA2eqAhJiPbCvcjuBzZ9tQH4j8THHKBa8FcsGZxmItAKXiMv2EptKR0F4c4rXXklBIeb+vCgCYJDnhNhhijL/VuK0rqT92iNdYEjwEiuvSfOORRLvVdq5R/wPE6Kp4MLHlng4rOUpBGKKQvFRG8HcEFo5TnV5v9ApMMuwKXfNxdw93TizGc8EsGPN18Q/HKWzjLP7nvEJAs/rq/sZ18mmdEdnLF8m35oYCA0V0S4mwWawTnL1HM8eMWBdndF6FzIYv4hogWEJchSqNj36yxiglZUEKZaCc0ESPm8nGYcbxvXAg4wSNohekGc3YQXeQATwIqGVXg+1Kqx/GlLKqoxi6ESFJifZq5RE1cSOBeASK0WwaxitvIhqvVyg4CIU85o//i9hGdKIhCHVJoGSD1ukLUnnSLaOhiP3Q6RBROVZLqkALHAOm0M0i9nxxShaQGjjqeAVDQmdlPNfxwKGKHbFLGI7qmCSK3pXReR7js85HSrcT1K+b8IAMh2nFaRx3vY/45Gz52ZetL5c5yL2c+Ng5FIxHLrQzKml+q98phx1YxLuWI8VkWRIUgIChN46AQ38WkeKUchmzt5zUroKI7FuAzkBYRHrE15mf6uWamMEwQj5/r79G63oFmSAFlePx8nTm1YCF+3UIcg4WYXI7TmcvRgFoijoTkAW/o8cUXKIhw77idEDgo7aqztt8SOaghd58Iv7oLeEyT4QHoDw0/AN99c9u+2bnQN8M+fbO+nWkwnA8oCQlmQzMdYNjNvLHp6Gnhu+lcaTruhaZj95rWuJrtzD7fjzLy3Yl/cX3zUViDuPztAaUcs9/7JAqo0KQkjZkoFyo8jdA2e+iK4L3s3ToJGv2ANYbQkaZ3sb7lbJ9oLF6mUh9RfMpkOp64vmdbnj/1XNeG9RlzWspJqgWkYt6iI12tUsw1op0Wc0WmaPXJJWts/5DXsf8nbgdMr/Q7x6FiaehQ6bDN2JM201SrOqn1S7U/vK5/UcFq7K8VGGr9xUW+wlaJr/tcZYvkEaG5+ZNIVLx1djWUvEXdMwGv78RFLxm+NnyZAgBOwgab1cVXhinxqOITA/DGXu3n5/elK3PHPqz9Osj0z0QqT9e0qTp8El4Zz6BimI6lUChf0JkA1hQYVS4OIBIC30RjSV3VGVyRiJm4PuTkrEV6+21Eu++SS/s40kCutoij82aJn3brrEZERR5CyRCihqOC1H+l6KfMPAeeeF5axm8INNfGC1AnmfpJ7dJwoc4DJm9r0QD0S83Jr0zNboIEtBVK/Wgqo02kfuVs4OZrN2mOagPf2UQ53tn+3WyigP5p+5j6q+nSgtE0fUL9h0E1VzBEweLcVDUIwu7OW9hmBA2bp0eCnvF76e91TqehwNJ97Q/Cwdf+wFTjnqyB/J1Rnxw/c9LdlgjulHWRgZU/YO/fbWy9lJStfIuZ4WSCWDivY2I8tWM4v4dIvE4yWxJAiQ0FnGcwxgEiM3ljE4fh0d5NSqirqXZWsAOlXKoTuzOd6NT+JByPkOipna6SNqFeiT1g5bDWZDbzvUJeuG3Qggq0nNlw7s14OLOzkxT6aR2pArsHFZRQaypZOLOJc9eOIQD1QIbbmRZEszzCnIeE8hw4vP0P</diagram></mxfile>
|
|
BIN
docs/cpu.drawio.png
Normal file
BIN
docs/cpu.drawio.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 390 KiB |
Submodule riscv-gnu-toolchain deleted from 96d9f40c9d
7
setup.sh
7
setup.sh
@@ -1,7 +0,0 @@
|
|||||||
sudo apt-get install -y autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
|
|
||||||
|
|
||||||
SCRIPT=$(realpath "$0")
|
|
||||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
|
||||||
cd $SCRIPTPATH/riscv-gnu-toolchain
|
|
||||||
./configure --prefix=$SCRIPTPATH/toolchain/riscv --enable-multilib
|
|
||||||
make
|
|
62
src/bh_cpu.v
62
src/bh_cpu.v
@@ -120,19 +120,6 @@ reg s_if_stall = 0;
|
|||||||
reg [31:0] s_if_next_pc;
|
reg [31:0] s_if_next_pc;
|
||||||
reg [31:0] s_if_inst;
|
reg [31:0] s_if_inst;
|
||||||
|
|
||||||
always @(*) begin
|
|
||||||
s_if_stall = s_id_stall;
|
|
||||||
|
|
||||||
if (s_ex_take_branch) begin
|
|
||||||
s_if_next_pc = s_ex_branch_addr;
|
|
||||||
end else begin
|
|
||||||
s_if_next_pc = r_if_pc + 4;
|
|
||||||
end
|
|
||||||
|
|
||||||
mem_inst_addr = r_if_pc;
|
|
||||||
s_if_inst = mem_inst_data;
|
|
||||||
end
|
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
reg s_id_stall;
|
reg s_id_stall;
|
||||||
reg [6:0] s_id_opcode;
|
reg [6:0] s_id_opcode;
|
||||||
@@ -177,7 +164,39 @@ localparam ALUOP_ADD = 4'b0000,
|
|||||||
ALUOP_SLT = 4'b1000,
|
ALUOP_SLT = 4'b1000,
|
||||||
ALUOP_SLTU = 4'b1001;
|
ALUOP_SLTU = 4'b1001;
|
||||||
|
|
||||||
|
// EX
|
||||||
|
reg s_ex_stall = 0;
|
||||||
|
reg [31:0] s_ex_data1, s_ex_data2;
|
||||||
|
reg [31:0] s_ex_alu_out;
|
||||||
|
reg s_ex_alu_zero;
|
||||||
|
reg s_ex_take_branch;
|
||||||
|
reg [31:0] s_ex_branch_addr;
|
||||||
|
reg [31:0] s_ex_ra;
|
||||||
|
|
||||||
|
// MEM
|
||||||
|
reg s_mem_stall = 0;
|
||||||
|
reg s_mem_bp;
|
||||||
|
reg [31:0] s_mem_load_data;
|
||||||
|
|
||||||
|
// WB
|
||||||
|
reg [31:0] s_wb_data;
|
||||||
|
reg s_wb_write;
|
||||||
|
|
||||||
|
// IF
|
||||||
|
always @(*) begin
|
||||||
|
s_if_stall = s_id_stall;
|
||||||
|
|
||||||
|
if (s_ex_take_branch) begin
|
||||||
|
s_if_next_pc = s_ex_branch_addr;
|
||||||
|
end else begin
|
||||||
|
s_if_next_pc = r_if_pc + 4;
|
||||||
|
end
|
||||||
|
|
||||||
|
mem_inst_addr = r_if_pc;
|
||||||
|
s_if_inst = mem_inst_data;
|
||||||
|
end
|
||||||
|
|
||||||
|
// ID
|
||||||
always @(*) begin
|
always @(*) begin
|
||||||
s_id_invalid = 0;
|
s_id_invalid = 0;
|
||||||
s_id_store = 0;
|
s_id_store = 0;
|
||||||
@@ -332,14 +351,6 @@ always @(*) begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
// EX
|
// EX
|
||||||
reg s_ex_stall = 0;
|
|
||||||
reg [31:0] s_ex_data1, s_ex_data2;
|
|
||||||
reg [31:0] s_ex_alu_out;
|
|
||||||
reg s_ex_alu_zero;
|
|
||||||
reg s_ex_take_branch;
|
|
||||||
reg [31:0] s_ex_branch_addr;
|
|
||||||
reg [31:0] s_ex_ra;
|
|
||||||
|
|
||||||
always @(*) begin
|
always @(*) begin
|
||||||
s_ex_stall = s_mem_stall;
|
s_ex_stall = s_mem_stall;
|
||||||
|
|
||||||
@@ -394,10 +405,6 @@ always @(*) begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
// MEM
|
// MEM
|
||||||
reg s_mem_stall = 0;
|
|
||||||
reg s_mem_bp;
|
|
||||||
reg [31:0] s_mem_load_data;
|
|
||||||
|
|
||||||
always @(*) begin
|
always @(*) begin
|
||||||
s_mem_stall = 0; // TODO: add stall logic when actually reading/writing
|
s_mem_stall = 0; // TODO: add stall logic when actually reading/writing
|
||||||
s_mem_bp = 0;
|
s_mem_bp = 0;
|
||||||
@@ -417,9 +424,6 @@ always @(*) begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
// WB
|
// WB
|
||||||
reg [31:0] s_wb_data;
|
|
||||||
reg s_wb_write;
|
|
||||||
|
|
||||||
always @(*) begin
|
always @(*) begin
|
||||||
|
|
||||||
// load instructions do not use output of alu in wb
|
// load instructions do not use output of alu in wb
|
||||||
@@ -475,6 +479,8 @@ always @(posedge clk) begin: pipeline_update
|
|||||||
end
|
end
|
||||||
|
|
||||||
end else begin
|
end else begin
|
||||||
|
// $display("%0t:\tPC=0x%h", $time, s_if_next_pc);
|
||||||
|
|
||||||
// IF
|
// IF
|
||||||
if (!s_if_stall) begin
|
if (!s_if_stall) begin
|
||||||
r_if_pc <= s_if_next_pc;
|
r_if_pc <= s_if_next_pc;
|
||||||
|
6
tests/.gitignore
vendored
6
tests/.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
*.out
|
**/*.out
|
||||||
*.vcd
|
**/*.vcd
|
||||||
*.log
|
**/*.log
|
@@ -1,18 +0,0 @@
|
|||||||
all: verify
|
|
||||||
|
|
||||||
BENCH ?= $(sort $(dir $(wildcard test_*/)))
|
|
||||||
|
|
||||||
# override bench to disable test_c
|
|
||||||
BENCH = test_basic
|
|
||||||
|
|
||||||
verify:
|
|
||||||
$(foreach dir, $(BENCH), make -C $(dir) verify;)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(foreach dir, $(BENCH), make -C $(dir) clean;)
|
|
||||||
|
|
||||||
help:
|
|
||||||
$(info BENCH options: [${BENCH}])
|
|
||||||
|
|
||||||
.SECONDARY:
|
|
||||||
.PHONY: all clean verify help
|
|
@@ -11,15 +11,15 @@ OBJ = $(notdir $(SOURCE_AS:.S=.o))
|
|||||||
OBJ += $(notdir $(SOURCE_C:.c=.o))
|
OBJ += $(notdir $(SOURCE_C:.c=.o))
|
||||||
|
|
||||||
# Software compilation
|
# Software compilation
|
||||||
CC = riscv64-linux-gnu-gcc
|
CC = riscv64-unknown-elf-gcc
|
||||||
CFLAGS = -march=rv32i -mabi=ilp32
|
CFLAGS = -march=rv32i -mabi=ilp32
|
||||||
|
|
||||||
CPPFLAGS =
|
CPPFLAGS =
|
||||||
|
|
||||||
AS = riscv64-linux-gnu-as
|
AS = riscv64-unknown-elf-as
|
||||||
ASFLAGS = -march=rv32i -mabi=ilp32
|
ASFLAGS = -march=rv32i -mabi=ilp32
|
||||||
|
|
||||||
LD = riscv64-linux-gnu-ld
|
LD = riscv64-unknown-elf-ld
|
||||||
LDFLAGS = -melf32lriscv_ilp32
|
LDFLAGS = -melf32lriscv_ilp32
|
||||||
|
|
||||||
# $(info $$TESTBENCH_V is [${TESTBENCH_V}])
|
# $(info $$TESTBENCH_V is [${TESTBENCH_V}])
|
||||||
@@ -40,7 +40,7 @@ LDFLAGS = -melf32lriscv_ilp32
|
|||||||
$(LD) $(LDFLAGS) -T $^ -o $@
|
$(LD) $(LDFLAGS) -T $^ -o $@
|
||||||
|
|
||||||
%.hex: %.elf
|
%.hex: %.elf
|
||||||
riscv64-linux-gnu-objcopy --target=verilog $< $@
|
riscv64-unknown-elf-objcopy --target=verilog $< $@
|
||||||
|
|
||||||
# Hardware compilation
|
# Hardware compilation
|
||||||
%.out: %.sv $(SOURCE_V)
|
%.out: %.sv $(SOURCE_V)
|
||||||
@@ -57,5 +57,7 @@ verify: $(LOGS)
|
|||||||
clean:
|
clean:
|
||||||
rm -rf *.vcd *.log *.out *.hex
|
rm -rf *.vcd *.log *.out *.hex
|
||||||
|
|
||||||
|
obj: $(OBJ)
|
||||||
|
|
||||||
.SECONDARY: %.log %.vcd
|
.SECONDARY: %.log %.vcd
|
||||||
.PHONY: all clean verify
|
.PHONY: all clean verify obj
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# basic_test
|
# basic_test
|
||||||
|
|
||||||
Verify basic usage of all instructions. Includes tests to ensure pipeline stalls sufficiently for correctness but does not test for unnecessary stalls.
|
Verify basic usage of all instructions. Includes tests to ensure pipeline stalls sufficiently for correctness but does not test for unnecessary/excessive stalls.
|
||||||
|
|
||||||
Currently store/load does not implement proper stalling so these operations are padded with nop
|
Currently store/load does not implement proper stalling so these operations are padded with `nop`
|
@@ -31,7 +31,7 @@ initial $readmemh("tb.hex", mem);
|
|||||||
// Instruction Memory
|
// Instruction Memory
|
||||||
wire [31:0] mem_inst_addr;
|
wire [31:0] mem_inst_addr;
|
||||||
reg [31:0] mem_inst_data;
|
reg [31:0] mem_inst_data;
|
||||||
always @(*) begin
|
always_comb begin
|
||||||
if (mem_inst_addr < MEM_LENGTH - 3) begin
|
if (mem_inst_addr < MEM_LENGTH - 3) begin
|
||||||
mem_inst_data[ 7: 0] = mem[mem_inst_addr+0];
|
mem_inst_data[ 7: 0] = mem[mem_inst_addr+0];
|
||||||
mem_inst_data[15: 8] = mem[mem_inst_addr+1];
|
mem_inst_data[15: 8] = mem[mem_inst_addr+1];
|
||||||
|
@@ -10,18 +10,18 @@ SOURCE_AS = $(wildcard *.S)
|
|||||||
OBJ = $(notdir $(SOURCE_AS:.S=.o))
|
OBJ = $(notdir $(SOURCE_AS:.S=.o))
|
||||||
OBJ += $(notdir $(SOURCE_C:.c=.o))
|
OBJ += $(notdir $(SOURCE_C:.c=.o))
|
||||||
|
|
||||||
CC = riscv64-linux-gnu-gcc
|
CC = riscv64-unknown-elf-gcc
|
||||||
CFLAGS = -march=rv32i -mabi=ilp32
|
CFLAGS = -march=rv32i -mabi=ilp32
|
||||||
# CFLAGS = -march=rv64i -mabi=lp64
|
# CFLAGS = -march=rv64i -mabi=lp64
|
||||||
# CFLAGS += -nostdlib -lgcc
|
# CFLAGS += -nostdlib -lgcc
|
||||||
|
|
||||||
CPPFLAGS =
|
CPPFLAGS =
|
||||||
|
|
||||||
AS = riscv64-linux-gnu-as
|
AS = riscv64-unknown-elf-as
|
||||||
ASFLAGS = -march=rv32i -mabi=ilp32
|
ASFLAGS = -march=rv32i -mabi=ilp32
|
||||||
# ASFLAGS = -march=rv64i -mabi=lp64
|
# ASFLAGS = -march=rv64i -mabi=lp64
|
||||||
|
|
||||||
LD = riscv64-linux-gnu-ld
|
LD = riscv64-unknown-elf-ld
|
||||||
LDFLAGS = -melf32lriscv_ilp32
|
LDFLAGS = -melf32lriscv_ilp32
|
||||||
# LDFLAGS =
|
# LDFLAGS =
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ LDFLAGS = -melf32lriscv_ilp32
|
|||||||
$(LD) $(LDFLAGS) -T $^ -o $@
|
$(LD) $(LDFLAGS) -T $^ -o $@
|
||||||
|
|
||||||
%.hex: %.elf
|
%.hex: %.elf
|
||||||
riscv64-linux-gnu-objcopy --target=verilog $< $@
|
riscv64-unknown-elf-objcopy --target=verilog $< $@
|
||||||
|
|
||||||
%.out: %.sv $(SOURCE_V)
|
%.out: %.sv $(SOURCE_V)
|
||||||
iverilog -g2012 -o $@ $^
|
iverilog -g2012 -o $@ $^
|
||||||
@@ -62,6 +62,8 @@ verify: $(LOGS)
|
|||||||
clean:
|
clean:
|
||||||
rm -rf *.vcd *.log *.out *.hex
|
rm -rf *.vcd *.log *.out *.hex
|
||||||
|
|
||||||
.SECONDARY: %.log %.vcd
|
obj: $(OBJ)
|
||||||
.PHONY: all clean verify
|
|
||||||
|
.SECONDARY: %.log %.vcd
|
||||||
|
.PHONY: all clean verify obj
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
# basic_test
|
# C test
|
||||||
|
|
||||||
Verify basic usage of all instructions. Includes tests to ensure pipeline stalls sufficiently for correctness but does not test for unnecessary stalls.
|
Verify basic ability to use C
|
||||||
|
|
||||||
Currently store/load does not implement proper stalling so these operations are padded with nop
|
Currently all C functions fail because store/load do not stall properly.
|
@@ -1,6 +1,6 @@
|
|||||||
// #include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
unsigned int addathing(unsigned int a)
|
uint32_t addathing(uint32_t a)
|
||||||
{
|
{
|
||||||
return a + 0x29;
|
return a + 0x29;
|
||||||
}
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
OUTPUT_ARCH( "riscv" )
|
OUTPUT_ARCH( "riscv" )
|
||||||
ENTRY(_start)
|
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
@@ -14,6 +13,7 @@ SECTIONS
|
|||||||
{
|
{
|
||||||
/* . = ALIGN(4); */
|
/* . = ALIGN(4); */
|
||||||
_text = .;
|
_text = .;
|
||||||
|
*(.text.startup)
|
||||||
*(.text*)
|
*(.text*)
|
||||||
*(.rodata*)
|
*(.rodata*)
|
||||||
_etext = .;
|
_etext = .;
|
||||||
|
@@ -31,7 +31,7 @@ initial $readmemh("tb.hex", mem);
|
|||||||
// Instruction Memory
|
// Instruction Memory
|
||||||
wire [31:0] mem_inst_addr;
|
wire [31:0] mem_inst_addr;
|
||||||
reg [31:0] mem_inst_data;
|
reg [31:0] mem_inst_data;
|
||||||
always @(*) begin
|
always_comb begin
|
||||||
if (mem_inst_addr < MEM_LENGTH - 3) begin
|
if (mem_inst_addr < MEM_LENGTH - 3) begin
|
||||||
mem_inst_data[ 7: 0] = mem[mem_inst_addr+0];
|
mem_inst_data[ 7: 0] = mem[mem_inst_addr+0];
|
||||||
mem_inst_data[15: 8] = mem[mem_inst_addr+1];
|
mem_inst_data[15: 8] = mem[mem_inst_addr+1];
|
||||||
|
@@ -1,17 +1,23 @@
|
|||||||
.global _start
|
.global _start
|
||||||
|
|
||||||
.global addathing
|
.section .text.startup # start vector
|
||||||
|
j _start
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
.text
|
.text
|
||||||
_start:
|
_start:
|
||||||
|
|
||||||
addi a0, zero, 0x134
|
addi a0, zero, 0x134
|
||||||
|
addi a1, zero, 0x0
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
call addathing
|
# call addathing # c compilation has sw/lw instructions. Missing stalls break execution
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
|
Reference in New Issue
Block a user