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

Question of a machine-level trap handler described in aia spec(5.2.2) #96

Open
ZeyueShen opened this issue Sep 24, 2024 · 2 comments
Open

Comments

@ZeyueShen
Copy link

image
As shown in this figure, when the condition: if (mstatus.mpie == 1) is met in the above pseudo-code, the interrupt service program will be entered, but there is such a scenario:
a.set mie.mtie = 1 in M mode,
b.set mtimecmp = 0 ,which making mip.stip = 1 in M mode
c.Execute mret to change the privilege mode from M mode to S mode
At this point, an interrupt will cause a trap, but since mstatus.mie = 0, after the trap occurs, mstatus.mpie will also be equal to 0. This means that the condition mpie == 1 will never be met, thus rendering the interrupt unhandled. This scenario puzzles me greatly.

@jhauser-us
Copy link
Collaborator

@ZeyueShen, your question makes me realize that the AIA document should mention that software must be sure that mstatus.MPIE = 1 before executing an MRET to change to another privilege mode.

If we assume mstatus.MPIE = 1 before your step c, there is no problem. The MRET copies MPIE to MIE, and sets MPIE = 1. When the interrupt trap occurs, it then copies MIE to MPIE, and sets MIE = 0. Thus, MPIE is restored to 1 at the start of the trap handler.

@ZeyueShen
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants