aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-09 10:13:14 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-09 10:13:14 +0200
commit678aef68af85c04015d8c385f6d6c60ffada7fad (patch)
treea36f8af2af4a5485a186084f9ee30fcbdb0c6586
parent89c0244b8bcd98e8dd273888a0cadc43357f79fc (diff)
downloadriscv_cpu-678aef68af85c04015d8c385f6d6c60ffada7fad.tar.gz
riscv_cpu-678aef68af85c04015d8c385f6d6c60ffada7fad.zip
fixed sw bug, where we wasn't set correctly
-rw-r--r--README.md8
-rw-r--r--prog/src/prog.s18
-rw-r--r--src/memory_unit.v4
-rw-r--r--src/ram.v8
-rw-r--r--src/rom.v6
5 files changed, 30 insertions, 14 deletions
diff --git a/README.md b/README.md
index 1d81cb2..a14a584 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,14 @@ The board used in this project is a [Tang Nano 9K](https://wiki.sipeed.com/hardw
* [gtkwave](https://github.com/gtkwave/gtkwave) for viewing waveforms
* [openocd](https://openocd.org) for debugging
+## Currently Supported Instructions
+
+* R-type: add, sub, and, or, xor, sll, srl, sra, slt, sltu
+* I-type: addi, andi, ori, xori, slti, sltiu, slli, srli, srai
+* S-type: sw
+* B-type: beq
+* U-type:
+* J-type: jal, jalr
## Resources
diff --git a/prog/src/prog.s b/prog/src/prog.s
index 2759554..2b5e4c2 100644
--- a/prog/src/prog.s
+++ b/prog/src/prog.s
@@ -35,17 +35,25 @@ _start:
*/
- jal target
- addi t0, zero, 2
+# jal target
+# addi t0, zero, 2
+#0010 0000
+addi t0, zero, 0x0010
+slli t0, t0, 16
+ori t0, t0, 0x0000
+
+addi t1, zero, 0xff
+sw t1, 0(t0)
+lw t2, 0(t0)
halt_loop:
j halt_loop
-target:
- addi t0, zero, 1
- jalr zero, ra, 0
+#target:
+# addi t0, zero, 1
+# jalr zero, ra, 0
.section .data
diff --git a/src/memory_unit.v b/src/memory_unit.v
index b2d7434..6e2b457 100644
--- a/src/memory_unit.v
+++ b/src/memory_unit.v
@@ -13,7 +13,7 @@ wire [31:0] ram_read_data, rom_read_data;
ram #(.N(32), .SIZE(1024)) ram(
.clk(clk),
.rst(rst),
- .we(we_ram),
+ .we(ram_we),
.addr(addr),
.data_read(ram_read_data),
.data_write(write_data)
@@ -44,8 +44,8 @@ always @(*) begin
read_data <= 0;
end else if (addr[31:16] >= 16'h0001 && addr[31:16] <= 16'h000F) begin
read_data <= rom_read_data;
- ram_we = we;
end else if (addr[31:16] >= 16'h0010 && addr[31:16] <= 16'hFF0F) begin
+ ram_we = we;
read_data <= ram_read_data;
end else if (addr[31:16] >= 16'hFF10 && addr[31:16] <= 16'hFFFF) begin
read_data <= 0;
diff --git a/src/ram.v b/src/ram.v
index 92b14a2..9b62c77 100644
--- a/src/ram.v
+++ b/src/ram.v
@@ -7,23 +7,25 @@ module ram #(
input we,
input [log2(SIZE)-1:0] addr,
input [N-1:0] data_write,
- output reg [N-1:0] data_read
+ output [N-1:0] data_read
);
`include "include/log2.vh"
reg [8:0] memory [SIZE-1:0];
+assign data_read = { memory[addr + 3], memory[addr + 2], memory[addr + 1], memory[addr + 0] };
+
+
integer i;
always @(posedge clk or posedge rst) begin
if (rst) begin
for (i = 0; i < SIZE; i = i + 1)
memory[i] <= 0;
- end else begin
+ end else begin
if (we) begin
{ memory[addr + 3], memory[addr + 2], memory[addr + 1], memory[addr + 0] } = data_write;
end
- data_read = { memory[addr + 3], memory[addr + 2], memory[addr + 1], memory[addr + 0] };
end
end
diff --git a/src/rom.v b/src/rom.v
index a2e12cd..8a25f46 100644
--- a/src/rom.v
+++ b/src/rom.v
@@ -4,7 +4,7 @@ module rom #(
)(
input clk,
input [log2(SIZE)-1:0] addr,
- output reg [N-1:0] data_read
+ output [N-1:0] data_read
);
`include "include/log2.vh"
@@ -15,9 +15,7 @@ initial begin
$readmemh("build/rom.hex", memory, 0, SIZE-1);
end
-always @(posedge clk) begin
- data_read <= {memory[addr + 3], memory[addr + 2], memory[addr + 1], memory[addr + 0] };
-end
+assign data_read = {memory[addr + 3], memory[addr + 2], memory[addr + 1], memory[addr + 0] };