diff options
| author | Brian Campbell | 2018-11-29 15:44:54 +0000 |
|---|---|---|
| committer | Brian Campbell | 2018-11-29 15:44:54 +0000 |
| commit | 8ea0e3a21975066207349b83f642b327cd72cb3f (patch) | |
| tree | c5312b6770e4f4eb24cfda835edec1871a1896c2 /riscv/riscv.sail | |
| parent | 28b05bee5f0b2b81dc1bff72b5de9cc142a2b4b9 (diff) | |
RISC-V: add checks for misaligned targets to jumps and branches
Diffstat (limited to 'riscv/riscv.sail')
| -rw-r--r-- | riscv/riscv.sail | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/riscv/riscv.sail b/riscv/riscv.sail index f50514aa..ffe862d7 100644 --- a/riscv/riscv.sail +++ b/riscv/riscv.sail @@ -46,12 +46,16 @@ but this is difficult function clause execute (RISCV_JAL(imm, rd)) = { let pc : xlenbits = PC; - X(rd) = nextPC; /* compatible with JAL and C.JAL */ - let offset : xlenbits = EXTS(imm); - nextPC = pc + offset; - true + let newPC : xlenbits = pc + EXTS(imm); + if newPC[1] & (~ (haveRVC())) then { + handle_mem_exception(newPC, E_Fetch_Addr_Align); + false + } else { + X(rd) = nextPC; /* compatible with JAL and C.JAL */ + nextPC = newPC; + true + } } - /* TODO: handle 2-byte-alignment in mappings */ mapping clause assembly = RISCV_JAL(imm, rd) <-> "jal" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_21(imm) @@ -92,8 +96,16 @@ function clause execute (BTYPE(imm, rs2, rs1, op)) = { RISCV_BLTU => rs1_val <_u rs2_val, RISCV_BGEU => rs1_val >=_u rs2_val }; - if taken then nextPC = PC + EXTS(imm); - true + let newPC = PC + EXTS(imm); + if taken then { + if newPC[1] & (~ (haveRVC())) then { + handle_mem_exception(newPC, E_Fetch_Addr_Align); + false; + } else { + nextPC = newPC; + true + } + } else true } mapping btype_mnemonic : bop <-> string = { |
