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

feat(trap): support atomic instructions emulation #5

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

tfx2001
Copy link
Collaborator

@tfx2001 tfx2001 commented Aug 14, 2024

Since HPM6360 does not support execute atomic load/store with SDRAM address range, we need to emulate atomic instructions execute in trap handler then the Linux kernel can runs without any modifications and user space thread also is supported.

For AMO instructions, they will trap into Store/AMO access fault exception during execution, so we can emulate it in store fault exception handler.

For lr/sc instructions, lr will trap into Load access fault during execution but sc won't, however. So we need to replace sc into an illegal instruction which I use csrrw zero, time, zero here, then it will trap into Illegal instruction exception and will be replaced back during exception handling. After replacing instructions we have to execute fence.i to make sure this data store is visible to the subsequent instruction fetch.

@tfx2001 tfx2001 force-pushed the dev/atomic-emulation branch from 87222ce to 15d2ce2 Compare August 14, 2024 17:19
@tfx2001 tfx2001 requested a review from luojia65 August 14, 2024 17:20
@tfx2001 tfx2001 force-pushed the dev/atomic-emulation branch 2 times, most recently from 28c5d94 to 47946e5 Compare August 14, 2024 17:26
Since HPM6360 dose not support execute atomic load/store with SDRAM address
range, we need to emulation atomic instructions execute in trap handler
then the Linux kernel can runs without any modifications and user space
thread also is supported.

For AMO instructions, they will trap into Store/AMO access fault exception
during execution, so we can emulate it in store fault exception handler.

For lr/sc instructions, lr will trap into Load access fault during
execution but sc won't, however. So we need to replace sc into an illegal
instruction which I use csrrw zero, time, zero here, then it will trap
into Illegal instruction exception and will be replaced back during
exception handling. After replacing instructions we have to execute
fence.i to make sure this data store is visible to the subsequent
instruction fetch.

Signed-off-by: tfx2001 <tfx2001@outlook.com>
Signed-off-by: tfx2001 <tfx2001@outlook.com>
Signed-off-by: tfx2001 <tfx2001@outlook.com>
@tfx2001 tfx2001 force-pushed the dev/atomic-emulation branch from bed01ea to d4f04d9 Compare August 14, 2024 17:34
Copy link
Collaborator

@luojia65 luojia65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tfx2001 tfx2001 merged commit 0cf5ef0 into main Aug 15, 2024
2 checks passed
@tfx2001 tfx2001 deleted the dev/atomic-emulation branch August 15, 2024 01:21
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

Successfully merging this pull request may close these issues.

2 participants