diff options
| author | Shaked Flur | 2017-10-01 12:02:07 +0100 |
|---|---|---|
| committer | Shaked Flur | 2017-10-01 12:02:07 +0100 |
| commit | fcf8270b4f46b4cd92534807292694bfd6d14457 (patch) | |
| tree | f0482263087eba34e84082cd67d9e31c488ce959 /risc-v | |
| parent | 9f58a1bbaadd0a679413a8cb424acfb6255f8eca (diff) | |
fixed JALR: do the register write first to allow po-later reads
Diffstat (limited to 'risc-v')
| -rw-r--r-- | risc-v/riscv.sail | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/risc-v/riscv.sail b/risc-v/riscv.sail index 8658ae96..f36dba57 100644 --- a/risc-v/riscv.sail +++ b/risc-v/riscv.sail @@ -24,11 +24,12 @@ union ast member ((bit[21]), regno) JAL function clause decode ((bit[20]) imm : (regno) rd : 0b1101111) = Some (JAL(imm[19] : imm[7..0] : imm[8] : imm[18..13] : imm[12..9] : 0b0, rd)) -function clause execute (JAL(imm, rd)) = - let (bit[64]) offset = EXTS(imm) in { - nextPC := PC + offset; - wGPR(rd, PC + 4); - } +function clause execute (JAL(imm, rd)) = { + (bit[64]) pc := PC; + wGPR(rd, pc + 4); + (bit[64]) offset := EXTS(imm); + nextPC := pc + offset; +} (********************************************************************) union ast member((bit[12]), regno, regno) JALR @@ -36,11 +37,12 @@ union ast member((bit[12]), regno, regno) JALR function clause decode ((bit[12]) imm : (regno) rs1 : 0b000 : (regno) rd : 0b1100111) = Some(JALR(imm, rs1, rd)) -function clause execute (JALR(imm, rs1, rd)) = - let (bit[64]) newPC = rGPR(rs1) + EXTS(imm) in { - nextPC := newPC[63..1] : 0b0; - wGPR(rd, PC + 4); - } +function clause execute (JALR(imm, rs1, rd)) = { + (* write rd before anything else to prevent unintended strength *) + wGPR(rd, PC + 4); + (bit[64]) newPC := rGPR(rs1) + EXTS(imm); + nextPC := newPC[63..1] : 0b0; +} (********************************************************************) union ast member ((bit[13]), regno, regno, bop) BTYPE |
