-
Notifications
You must be signed in to change notification settings - Fork 1
Basic arch path #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bitglitcher
wants to merge
5
commits into
main
Choose a base branch
from
basic-arch-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4de0fe
Update directions.
bitglitcher 61f24ed
Add simple draft bash file to setup environment variables.
bitglitcher 0cf0633
Add simple Wishbone B4 compatible sram module.
bitglitcher 7acb9ea
Add simple draft structure for the RV32I Core.
bitglitcher 2b19857
Basic running simulation.
bitglitcher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,3 +53,4 @@ dkms.conf | |
|
|
||
| #Iverilog Simulation Files | ||
| *.vcd | ||
| *a.out | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,67 @@ | ||
| `include "core.pkg" | ||
|
|
||
| module core | ||
| ( | ||
| input clk, | ||
| input rst | ||
| ); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| ( | ||
| //Clock is shared with WB4 BUS | ||
| input logic clk, | ||
| input logic rst, | ||
|
|
||
|
|
||
| //Wishbone signals | ||
| output logic [31:0] addr_o, | ||
| input logic [31:0] dat_i, | ||
| output logic [31:0] dat_o, | ||
|
|
||
| input logic ack_i, | ||
| input logic err_i, | ||
| output logic cyc_o, | ||
| output logic stb_o, | ||
| output logic we_o | ||
|
|
||
| ); | ||
|
|
||
| typedef enum logic [1:0] { FETCH, EXECUTE } exec_state_t; | ||
|
|
||
| exec_state_t current_state = FETCH; | ||
|
|
||
| logic [64:0] IR = 0; | ||
|
|
||
| wire [6:0] funct7 = IR[31:25]; | ||
| wire [4:0] rs2 = IR[24:20]; | ||
| wire [4:0] rs1 = IR[19:15]; | ||
| wire [2:0] funct3 = IR[14:12]; | ||
| wire [4:0] rd = IR[11:7]; | ||
| wire [6:0] opcode = IR[6:0]; | ||
|
|
||
| wire [11:0] imm = IR[31:20]; | ||
|
|
||
| wire [6:0] imm_11_5 = IR[31:25]; | ||
| wire [4:0] imm_4_0 = IR[11:7]; | ||
|
|
||
| wire [19:0] imm_31_12 = IR[31:12]; | ||
|
|
||
| //Main state machine for the instruction execution cycle. | ||
| always@(posedge clk) | ||
| begin | ||
| case (current_state) | ||
| FETCH:; | ||
| //TODO: Implement Fetch From Wishbone 4 interface. Synchronous Mode. | ||
| //Illustration 4-2: WISHBONE Classic synchronous cycle terminated burst | ||
| //https://cdn.opencores.org/downloads/wbspec_b4.pdf | ||
| //Page: 66 | ||
|
|
||
| EXECUTE:; | ||
| //TODO: Implement ALU Execution | ||
|
|
||
| //TODO: Implement Memory Write | ||
|
|
||
| //TODO: Implement Memory Reads | ||
|
|
||
| //TODO: Implement Branch Instructions | ||
|
|
||
| //NOTES: The state machine can have nested states to accommodate wishbone BUS logic. | ||
|
|
||
| default:; | ||
| endcase | ||
| end | ||
|
|
||
|
|
||
| endmodule | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| /* ------------------------------------------------------------------------- */ | ||
|
|
||
|
|
||
| //TODO: Will need to redo defaults. | ||
| // `include "defaults/defaults.sv" | ||
|
|
||
|
|
||
| /* ------------------------------------------------------------------------- */ | ||
|
|
||
|
|
||
| /* | ||
| * Module: Internal SRAM With Wishbone BUS | ||
| * | ||
| * Parameters: | ||
| * num_words: Number of words in the memory (default = 4096). | ||
| * | ||
| */ | ||
| module wb4_sram #( | ||
| parameter num_words = 4096 | ||
| ) ( | ||
| input logic clk, | ||
| input logic rst, | ||
|
|
||
| // Wishbone signals | ||
| input logic [31:0] addr_i, | ||
| input logic [31:0] dat_i, | ||
| output logic [31:0] dat_o, | ||
|
|
||
| output logic ack_o, | ||
| output logic err_o, | ||
| input logic cyc_i, | ||
| input logic stb_i, | ||
| input logic we_i | ||
| ); | ||
| reg [31:0] memory [0:(num_words - 1)]; | ||
|
|
||
| // For address calculation | ||
| localparam ADDR_WIDTH = $clog2(num_words); | ||
| wire [ADDR_WIDTH-1:0] word_addr; | ||
| wire addr_valid; | ||
|
|
||
| initial begin | ||
| $readmemh("../firmware/crt0.hex", memory); | ||
| end | ||
|
|
||
| assign word_addr = addr_i[ADDR_WIDTH+1:2]; // Byte to word address | ||
| assign addr_valid = (addr_i[31:ADDR_WIDTH+2] == 0); // Check upper bits are 0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alignment check missing: |
||
|
|
||
| always @(posedge clk) begin | ||
| if (rst) | ||
| begin | ||
| ack_o <= 1'b0; | ||
| err_o <= 1'b0; | ||
| dat_o <= 32'b0; | ||
| end | ||
| else | ||
| begin | ||
| if (cyc_i && stb_i) begin | ||
| if (addr_valid) begin | ||
| if (we_i) | ||
| begin | ||
| memory[word_addr] <= dat_i; | ||
| end | ||
| else | ||
| begin | ||
| dat_o <= memory[word_addr]; | ||
| end | ||
| ack_o <= 1'b1; | ||
| err_o <= 1'b0; | ||
| end | ||
| else | ||
| begin | ||
| ack_o <= 1'b0; | ||
| err_o <= 1'b1; | ||
| end | ||
| end | ||
| else | ||
| begin | ||
| ack_o <= 1'b0; | ||
| err_o <= 1'b0; | ||
| end | ||
| end | ||
| end | ||
| endmodule | ||
|
|
||
| /* ------------------------------------------------------------------------- */ | ||
|
|
||
|
|
||
| /* End of file. */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
|
|
||
| all: | ||
| riscv64-unknown-elf-as -march=rv64i -mabi=lp64 crt0.s -o crt0.o | ||
| riscv64-unknown-elf-ld -Ttext=0x0 -o crt0.elf crt0.o | ||
| riscv64-unknown-elf-objdump -d crt0.elf | ||
| riscv64-unknown-elf-objcopy -O verilog --verilog-data-width=4 crt0.elf crt0.hex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| .section .text | ||
| .globl _start | ||
|
|
||
| _start: | ||
| addi x1, x0, 5 # x1 = 5 | ||
| addi x2, x0, 3 # x2 = 3 | ||
| add x3, x1, x2 # x3 = 8 | ||
| sd x3, 0(x0) # mem[0] = 8 | ||
| li x4, 4 # x4 = 4 | ||
| loop: | ||
| addi x4, x4, -1 # x4-- | ||
| bnez x4, loop # branch until x4 == 0 | ||
| ebreak # done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| export CORE_REPO_PATH=$(pwd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,16 @@ | ||
|
|
||
| TOPFILE ?= $(CORE_REPO_PATH)/sim/top.sv | ||
| DSFILE ?= $(CORE_REPO_PATH)/design/core.sv | ||
| TBFILE ?= $(CORE_REPO_PATH)/testbench/tb.sv | ||
|
|
||
| all: | ||
| iverilog \ | ||
| -g 2012 \ | ||
| -g relative-include \ | ||
| -c $(CORE_REPO_PATH)/sim/top.filelist \ | ||
| $(TOPFILE); | ||
| ./a.out; | ||
|
|
||
| core: | ||
| iverilog \ | ||
| -g 2012 \ | ||
| -g relative-include \ | ||
| -c $(CORE_REPO_PATH)/design/core.filelist \ | ||
| $(DSFILE); | ||
| ./a.out; | ||
| ############# | ||
|
|
||
| tb: | ||
| iverilog \ | ||
| -g 2012 \ | ||
| -g relative-include \ | ||
| -c $(CORE_REPO_PATH)/testbench/tb.filelist \ | ||
| $(TBFILE); | ||
| ./a.out; | ||
| DESIGN = ../design | ||
| TESTBENCH = ../testbench | ||
| RTL_FILES = $(DESIGN)/wb4_sram.sv $(DESIGN)/core.sv | ||
|
|
||
| SOC_TEST_BENCH = $(RTL_FILES) $(TESTBENCH)/tb.sv | ||
|
|
||
| all: $(SOC_TEST_BENCH) | ||
| iverilog $(SOC_TEST_BENCH) -g2012 | ||
|
|
||
| clean: | ||
| rm -rf *.out *.vcd *.log; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
rd. Let's make naming more explicit about instr type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually should we even be concerned about decoding here instead of the decoder module?