Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instbits and extend Retired enum #412

Open
Timmmm opened this issue Feb 23, 2024 · 4 comments
Open

Remove instbits and extend Retired enum #412

Timmmm opened this issue Feb 23, 2024 · 4 comments
Labels
refactor Code clean up

Comments

@Timmmm
Copy link
Collaborator

Timmmm commented Feb 23, 2024

Currently there's a global register:

/* internal state to hold instruction bits for faulting instructions */
register instbits : xlenbits

Which is saved after fetch:

                F_Base(w) => {
                  instbits = zero_extend(w);

And used in handle_illegal():

function handle_illegal() -> unit = {
  let info = if plat_mtval_has_illegal_inst_bits ()
             then Some(instbits)
             else None();

This use of a global is unnecessary. It would be more elegant to:

  1. Remove the instbits register.
  2. Add RETIRE_ILLEGAL to the Retire enum.
  3. Change all instances of handle_illegal(); RETIRE_FAIL to just RETIRE_ILLEGAL
  4. Add instbits as a parameter to handle_illegal().
  5. Call handle_illegal(...) from step() if retired == RETIRE_ILLEGAL.
@jrtc27
Copy link
Collaborator

jrtc27 commented Feb 23, 2024

Whilst I agree that the global is ugly, I disagree that your proposal is a better fit for the architectural specification. Architecturally, illegal instruction is just another exception, and so should follow the exact same path as other exceptions.

Which I think means what you really want is that all exception cases are RETIRE_FAIL(exception_details), with the top level then being responsible for the exception handling, passing on the extra state needed, including instbits for illegal instructions.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Feb 23, 2024

Good call, that does sound better and I guess would let you treat other exceptions in the same way (I'll have to double check the code though). I don't think exception_details needs to include the instructions bits though since they are already available at the point in step() where it's handled (and they'd be a bit awkward to get in execute() since the instruction has already been decoded).

@jrtc27
Copy link
Collaborator

jrtc27 commented Feb 23, 2024

Good call, that does sound better and I guess would let you treat other exceptions in the same way (I'll have to double check the code though). I don't think exception_details needs to include the instructions bits though since they are already available at the point in step() where it's handled (and they'd be a bit awkward to get in execute() since the instruction has already been decoded).

Sorry I should have been clearer: instbits would be supplied to handle_exception to use in the case that the execute clause returned Exc_Illegal_Inst (names entirely made up, any semblance to real names is coincidental). Or, to put it another way: yes, that's what I meant, I just failed to clearly communicate it.

@martinberger
Copy link
Collaborator

martinberger commented Mar 19, 2024

I'm also in favour of extending the Retired data type.

There is another important case: Sdtrig debug triggers (https://github.com/riscv/riscv-debug-spec). One way to implement is to centralise trigger handling uniformly in step. But if you get a trigger for example of a load address, that trigger is found in the execute clause of the relevant load instruction. We don't want to handle the trigger in all relevant execute clauses, so need to pass this information back to step where it can be handled uniformly. (And where we need to handle triggers on the PC anyway.) For this purpose a RETIRE_TRIGGER(...) would be neater than yet another set of global, but non architectural registers.

Extending Retired does not require changing all the existing code that returns RETIRE_SUCCESS or RETIRE_FAIL, so it's not an intrusive change.

@Timmmm Timmmm added the refactor Code clean up label May 7, 2024
@Timmmm Timmmm changed the title Remove instbits Remove instbits and extend Retired enum Jun 24, 2024
pmundkur added a commit to pmundkur/sail-riscv that referenced this issue Feb 25, 2025
The eventual goal here is to surface wait-states of the hart
(e.g. as caused by WFI and WRS.{NTO,STO}) into the stepper,
and handle debug triggers from execution for extensions such as
Sdtrig.

The refactor makes interrupt and exception handling more
symmetrical: both are now handled in the stepper.

This also removes the model-internal global instbits register
into a stepper-local variable, which fixes riscv#412.

This refactor is based on ideas discussed in riscv#398 and riscv#412.

Co-authored-by: Tim Hutt <timothy.hutt@codasip.com>
Co-authored-by: Jessica Clarke <jrtc27@jrtc27.com>
Co-authored-by: Alasdair Armstrong <alasdair.armstrong@cl.cam.ac.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code clean up
Projects
None yet
Development

No branches or pull requests

3 participants