Skip to content

Commit

Permalink
Fix verbose print of instrs that omit low imm bits
Browse files Browse the repository at this point in the history
Modify `unscatter` so it works for instructions that do not encode
the lowest bits of the immediate value provided to them.
This issue has been hidden because many instructions have been encoded
using the lower immediate bits rather than upper immediate bits
(e.g. `imm[19:0]` rather than `imm[31:12]` for `lui`),
and others (which do omit lower immediate bits) are not included
in disassembly output (e.g. `c_lui` with empty `rv_c_disass`).

See also:
CTSRD-CHERI#41
  • Loading branch information
elliotb-lowrisc committed May 3, 2024
1 parent 09fa1c6 commit 101988c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/InstrCodec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ subst :: Mapping -> BitList -> BitList
subst m bs = unscatter [(bi, bs !! si) | (bi, si) <- m]

-- Join a scattered bit-string, complain if gaps or overlapping
unscatter :: [(Int, a)] -> [a]
unscatter = join 0
unscatter :: [(Int, Bool)] -> BitList
unscatter m = zeros ++ join lsb m
where
lsb = minimum [j | (j, _) <- m]
zeros = take lsb $ repeat False
join _ [] = []
join i m =
case [x | (j, x) <- m, i == j] of
Expand Down

0 comments on commit 101988c

Please sign in to comment.