Skip to content

Commit 56a761e

Browse files
elliotb-lowriscPeterRugg
authored andcommitted
Add RVC HINT/RES/NSE encs & rework disassembly
Add explicit HINT, Reserved, and NSE compressed instruction encodings from the spec. This allows Templates to more easily specify these special encodings and enables more accurate disassembly. Note that some encodings overlap. Add new instruction disassembly pretty printer functions for special cases where the operands are uninteresting or ambiguous. Rework the disassembly to account for overlapping encodings. Use XLEN, when available, and carful ordering to distinguish overlapping encodings from each other. Present both encodings when encodings overlap and XLEN is not available. Integrate new disassembly so that XLEN will be passed through when known (currently only for RVFI V2 packets). Minor errors may remain. Caution only goes so far when there are so many fiddly changes required.
1 parent 6663d5f commit 56a761e

File tree

4 files changed

+399
-173
lines changed

4 files changed

+399
-173
lines changed

Diff for: src/QuickCheckVEngine/RVFI_DII/RVFI.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ instance Show RVFI_Packet where
420420
(rvfi_insn tok)
421421
(privString (rvfi_mode tok))
422422
(xlenString (rvfi_ixl tok))
423-
(rv_pretty (MkInstruction (toInteger (rvfi_insn tok)))) -- Inst
423+
(rv_pretty (MkInstruction (toInteger (rvfi_insn tok))) (rvfi_ixl tok)) -- Inst
424424

425425
-- | Return 'True' for halt 'RVFI_Packet's
426426
rvfiIsHalt :: RVFI_Packet -> Bool

Diff for: src/RISCV/Helpers.hs

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module RISCV.Helpers (
8585
, prettyCSS
8686
, prettyCSS_F
8787
, prettyCIW
88+
, prettyCIW_reg
8889
, prettyCL
8990
, prettyCL_F
9091
, prettyCS
@@ -94,6 +95,9 @@ module RISCV.Helpers (
9495
, prettyCB_sig
9596
, prettyCB_reg
9697
, prettyCJ
98+
, prettyIgnr1
99+
, prettyIgnr2
100+
, prettyIgnr3
97101
-- * Others
98102
, reg
99103
, int
@@ -406,6 +410,9 @@ prettyCSS_F instr imm rs2 =
406410
-- | CIW-type 'Wide-Immediate' compressed instruction pretty printer
407411
prettyCIW instr imm rd' =
408412
concat [instr, " ", reg' rd', ", ", int imm]
413+
-- | CIW-type (register-only variant)
414+
prettyCIW_reg instr rd' =
415+
concat [instr, " ", reg' rd']
409416

410417
-- | CL-type 'Load' compressed instruction pretty printer
411418
prettyCL instr imm rd' rs1' =
@@ -439,6 +446,15 @@ prettyCB_reg instr rs1' =
439446
prettyCJ instr imm =
440447
concat [instr, " ", int $ toSigned 12 imm]
441448

449+
-- | Operand-swallowing instruction pretty printers.
450+
-- | Useful for special cases, such as reserved or overlapping encodings.
451+
prettyIgnr1 :: String -> Integer -> String
452+
prettyIgnr1 instr _ = instr
453+
prettyIgnr2 :: String -> Integer -> Integer -> String
454+
prettyIgnr2 instr _ _ = instr
455+
prettyIgnr3 :: String -> Integer -> Integer -> Integer-> String
456+
prettyIgnr3 instr _ _ _ = instr
457+
442458
type ExtractedRegs = ( Bool -- ^ is_bypass
443459
, Maybe Integer -- ^ rs2
444460
, Maybe Integer -- ^ rs1

Diff for: src/RISCV/InstInspect.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ import RISCV.Helpers
7474
import Text.Printf
7575

7676
-- | RISC-V instruction pretty printer
77-
rv_pretty :: Instruction -> String
78-
rv_pretty instr = case decode 32 instr instList of
77+
rv_pretty :: Instruction -> Maybe XLen-> String
78+
rv_pretty instr ixl = case decode 32 instr instList of
7979
Nothing -> "Unknown instruction"
8080
Just i -> i
8181
where instList = rv32_i_disass ++ rv64_i_disass
@@ -86,10 +86,10 @@ rv_pretty instr = case decode 32 instr instList of
8686
++ rv32_zicsr_disass
8787
++ rv32_zifencei_disass
8888
++ rv32_xcheri_disass
89-
++ rv_c_disass
89+
++ rv_c_disass ixl
9090

9191
instance Show Instruction where
92-
show i@(MkInstruction v) = printf ".4byte 0x%08x # %s" v (rv_pretty i)
92+
show i@(MkInstruction v) = printf ".4byte 0x%08x # %s" v (rv_pretty i Nothing)
9393

9494
rv_extract :: Instruction -> ExtractedRegs
9595
rv_extract instr = case decode 32 instr extractList of

0 commit comments

Comments
 (0)