ibex icon indicating copy to clipboard operation
ibex copied to clipboard

DRET treated as normal instruction in M-mode

Open udinator opened this issue 7 years ago • 7 comments

Screenshot from 2019-08-28 16-50-42 While executing this code in M-mode and with no external debug/irq stimulus applied, the log shows ibex executing a dret and then jumping to PC=0x00000000, and the instruction at this address raises an illegal instruction exception, causing a jump to our vectored trap handler at 0x8001c000. Screenshot from 2019-08-28 16-51-38 In the waveform, we see that ibex recognizes the dret instruction, raising dret_insn_dec, but then when the core jumps to FLUSH state it executes the instruction as normal, and sets the next pc to PC_DRET, the value stored in the dpc CSR, or 0x00000000. However according to the debug spec, executing dret while not in Debug Mode should cause an illegal instruction exception (Debug Spec, chapter 4.6), which does not seem to be the case in this situation.

udinator avatar Aug 29 '19 00:08 udinator

That may be the case for RISCY too, is it @bluewww ?

davideschiavone avatar Aug 29 '19 08:08 davideschiavone

Thanks for reporting this issue @udinator . I will need to fix the controller to generate the illegal instruction exception when encountering DRET without being in debug mode.

vogelpi avatar Aug 29 '19 08:08 vogelpi

@davideschiavone indeed ri5cy also doesnt raise an exception in m-mode.

bluewww avatar Aug 29 '19 10:08 bluewww

@udinator can you confirm that this is fixed now? (And are there tests for it?) (Reopening to get DV confirmation.)

imphil avatar Aug 29 '19 14:08 imphil

Confirming that the fix submitted by @vogelpi fixed this issue. DRET instructions are now properly treated as illegal instructions and cause an immediate jump to the vectored trap handler. @imphil: I do have tests for this in my testbench, and will have a PR out in the near future.

udinator avatar Aug 29 '19 16:08 udinator

Thanks a lot!

imphil avatar Aug 29 '19 16:08 imphil

No problem!

udinator avatar Aug 29 '19 16:08 udinator