Skip to content

Commit 4d62b5e

Browse files
implement jal
1 parent 073d8d5 commit 4d62b5e

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

documentation/Modules/Hart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Currently only the `LW` instruction uses stage 2, since in stage 1 `LW` requests
3939
- [ ] SB
4040
- [ ] SH
4141
- [x] SW
42-
- [ ] JAL
42+
- [x] JAL
4343
- [ ] JALR
4444
- [ ] BEQ
4545
- [ ] BNE

src/main/scala/RISCV/Decoder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Decoder(val width: Int = 32) extends Module {
4242
is(0b1110011.U) { format := InstructionFormat.S; } // ecall, ebreak, sret, mret, wfi, sfence.vma | the format for these is not within the standard formats but we can basically achieve the same thing with S type and then using the immediate, rs2, and rs1 to differentiate the calls. Also technically sret, mret, and wfi come from the privelleged spec but we'll just include them here.
4343
is(0b0000011.U) { format := InstructionFormat.I; } // lb, lh, lw, lbu, lhu
4444
is(0b0100011.U) { format := InstructionFormat.S; } // sb, sh, sw
45-
is(0b1101111.U) { format := InstructionFormat.U; } // jal
45+
is(0b1101111.U) { format := InstructionFormat.J; } // jal
4646
is(0b1100111.U) { format := InstructionFormat.I; } // jalr
4747
is(0b1100011.U) { format := InstructionFormat.B; } // beq, bne, blt, bge, bltu, bgeu
4848
}

src/main/scala/RISCV/Main.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ class Main() extends Module {
430430

431431
printf("[AND] Rs1: %d Rs2: %d Rd: %d\n", decoder.io.rs1, decoder.io.rs2, decoder.io.rd);
432432
}
433+
434+
// JAL
435+
is("b1101111".U) {
436+
registers.io.write_address := decoder.io.rd;
437+
registers.io.write_enable := true.B;
438+
registers.io.in := program_pointer + 1.U;
439+
440+
program_pointer := (program_pointer.zext + decoder.io.immediate.asSInt).asUInt;
441+
stage := 0.U;
442+
443+
printf("[JAL] Rd: %d Immediate: %b\n", decoder.io.rd, decoder.io.immediate);
444+
}
433445
}
434446
}
435447

src/test/scala/RISCV/MainSpec.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,23 @@ class MainSpec extends AnyFreeSpec with Matchers with ChiselSim {
1515
dut.clock.step(1);
1616

1717
dut.io.debug_write.poke(true.B);
18-
dut.io.debug_write_data.poke("b0000000_00001_00000_010_01000_0100011".U(32.W));
18+
dut.io.debug_write_data.poke("b00000000001000000000_00001_1101111".U(32.W));
1919
dut.io.debug_write_addressess.poke(1.U);
2020

2121
dut.clock.step(1);
2222

2323
dut.io.debug_write.poke(true.B);
24-
dut.io.debug_write_data.poke("b000000001000_00000_010_00010_0000011".U(32.W));
24+
dut.io.debug_write_data.poke("b000000000110_00000_000_00010_0010011".U(32.W));
2525
dut.io.debug_write_addressess.poke(2.U);
2626

2727
dut.clock.step(1);
2828

2929
dut.io.debug_write.poke(true.B);
30-
dut.io.debug_write_data.poke("b0100000_00001_00001_101_00010_0010011".U(32.W));
30+
dut.io.debug_write_data.poke("b000000000111_00000_000_00010_0010011".U(32.W));
3131
dut.io.debug_write_addressess.poke(3.U);
3232

3333
dut.clock.step(1);
3434

35-
dut.io.debug_write.poke(true.B);
36-
dut.io.debug_write_data.poke("b0000000_00001_00010_011_00010_0110011".U(32.W));
37-
dut.io.debug_write_addressess.poke(4.U);
38-
39-
dut.clock.step(1);
40-
4135
dut.io.debug_write.poke(false.B);
4236
dut.io.execute.poke(true.B);
4337

@@ -52,8 +46,6 @@ class MainSpec extends AnyFreeSpec with Matchers with ChiselSim {
5246
dut.clock.step(1);
5347
dut.clock.step(1);
5448
dut.clock.step(1);
55-
dut.clock.step(1);
56-
dut.clock.step(1);
5749
}
5850
}
5951
}

0 commit comments

Comments
 (0)