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

Fix evaluating final blocks on fatal #4980

Open
dominiksalvet opened this issue Mar 14, 2024 · 2 comments
Open

Fix evaluating final blocks on fatal #4980

dominiksalvet opened this issue Mar 14, 2024 · 2 comments
Labels
status: ready Issue is ready for someone to fix; then goes to 'status: assigned'

Comments

@dominiksalvet
Copy link

Hello,
I am using Verilator 4.038 2020-07-11 rev v4.036-114-g0cd4a57ad from Ubuntu 22.04 repos and wondered how I should evaluate final blocks on a $fatal call (or assertion fail) since this is something SV standard (IEEE 1800-2012) requires (if I understand it correctly). The standard says:

  1. Calling $fatal results in an implicit call to $finish.
  2. A final procedure executes when simulation ends due to an explicit or implicit call to $finish.

Currently, Verilator throws an abort exception, which is not easy/intended to catch and call Vtb->final() (and maybe one more VCD dump) manually. I also saw that there are extern void vl_fatal(const char* filename, int linenum, const char* hier, const char* msg) (and similar for finish and stop) functions in the verilated.h file installed on my system, which is to-be-overrided by a programmer but it seems a bit cumbersome to do so since Verilator might do something I can miss in these routines.

Hence, my question is what is the intended way to achieve compliance with the SV standard? Some examples would be very appreciated.

@dominiksalvet dominiksalvet added the new New issue not seen by maintainers label Mar 14, 2024
@wsnyder wsnyder added status: ready Issue is ready for someone to fix; then goes to 'status: assigned' and removed new New issue not seen by maintainers labels Mar 16, 2024
@wsnyder wsnyder changed the title How to evaluate final blocks on fatal? Fix evaluating final blocks on fatal Mar 16, 2024
@wsnyder
Copy link
Member

wsnyder commented Mar 16, 2024

That's an old version but this hasn't fundamentally changed in master.

You are correct that currently it does a stop and exits, this goes back to the early days of Verilator when there was no evaluation loop.

I believe the correct handling would be for $fatal to set a flag in VerilatedContext and this also sets gotFinished(), and this causes the main loop (e.g. with --main), which will then call the final blocks.

Perhpas you'd be willing to work on a pull to do this?

@dominiksalvet
Copy link
Author

Well, the solution sounds good to me (although I do not know what --main does). Maybe adding more context detail for the reason of gotFinished() would be appropriate also by calling another function later e.g. (if not already present).

I am sorry but I am very busy finishing my studies, so no PR is possible from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready Issue is ready for someone to fix; then goes to 'status: assigned'
Projects
None yet
Development

No branches or pull requests

2 participants